提交 c9fcfc29 编写于 作者: J Jason Park

add max_sum_path

上级 004d3e58
...@@ -5,9 +5,10 @@ function Array1DTracer(module) { ...@@ -5,9 +5,10 @@ function Array1DTracer(module) {
Array1DTracer.prototype = Object.create(Array2DTracer.prototype); Array1DTracer.prototype = Object.create(Array2DTracer.prototype);
Array1DTracer.prototype.constructor = Array1DTracer; Array1DTracer.prototype.constructor = Array1DTracer;
// Override var Array1D = {
Array1DTracer.prototype.createRandomData = function (N, min, max) { createRandomData: function (N, min, max) {
return Array2DTracer.prototype.createRandomData.call(this, 1, N, min, max)[0]; return Array2D.createRandomData(1, N, min, max)[0];
}
}; };
// Override // Override
......
...@@ -25,19 +25,21 @@ Array2DTracer.prototype.clear = function () { ...@@ -25,19 +25,21 @@ Array2DTracer.prototype.clear = function () {
clearTableColor(); clearTableColor();
}; };
Array2DTracer.prototype.createRandomData = function (N, M, min, max) { var Array2D = {
if (!N) N = 10; createRandomData: function (N, M, min, max) {
if (!M) M = 10; if (!N) N = 10;
if (min === undefined) min = 1; if (!M) M = 10;
if (max === undefined) max = 9; if (min === undefined) min = 1;
var D = []; if (max === undefined) max = 9;
for (var i = 0; i < N; i++) { var D = [];
D.push([]); for (var i = 0; i < N; i++) {
for (var j = 0; j < M; j++) { D.push([]);
D[i].push((Math.random() * (max - min + 1) | 0) + min); for (var j = 0; j < M; j++) {
D[i].push((Math.random() * (max - min + 1) | 0) + min);
}
} }
return D;
} }
return D;
}; };
// Override // Override
......
...@@ -25,19 +25,20 @@ GraphTracer.prototype.clear = function () { ...@@ -25,19 +25,20 @@ GraphTracer.prototype.clear = function () {
clearGraphColor(); clearGraphColor();
}; };
// Override var Graph = {
GraphTracer.prototype.createRandomData = function (N, ratio) { createRandomData: function (N, ratio) {
if (!N) N = 5; if (!N) N = 5;
if (!ratio) ratio = .3; if (!ratio) ratio = .3;
var G = []; var G = [];
for (var i = 0; i < N; i++) { for (var i = 0; i < N; i++) {
G.push([]); G.push([]);
for (var j = 0; j < N; j++) { for (var j = 0; j < N; j++) {
if (i == j) G[i].push(0); if (i == j) G[i].push(0);
else G[i].push((Math.random() * (1 / ratio) | 0) == 0 ? 1 : 0); else G[i].push((Math.random() * (1 / ratio) | 0) == 0 ? 1 : 0);
}
} }
return G;
} }
return G;
}; };
GraphTracer.prototype.setTreeData = function (G, root) { GraphTracer.prototype.setTreeData = function (G, root) {
...@@ -85,7 +86,7 @@ GraphTracer.prototype.setTreeData = function (G, root) { ...@@ -85,7 +86,7 @@ GraphTracer.prototype.setTreeData = function (G, root) {
// Override // Override
GraphTracer.prototype.setData = function (G) { GraphTracer.prototype.setData = function (G) {
if (Tracer.prototype.setData.call(this, arguments)) return true; if (Tracer.prototype.setData.call(this, arguments)) return true;
graph.clear(); graph.clear();
var nodes = []; var nodes = [];
var edges = []; var edges = [];
......
...@@ -16,25 +16,26 @@ WeightedGraphTracer.prototype.clear = function () { ...@@ -16,25 +16,26 @@ WeightedGraphTracer.prototype.clear = function () {
clearWeights(); clearWeights();
}; };
// Override var WeightedGraph = {
WeightedGraphTracer.prototype.createRandomData = function (N, ratio, min, max) { createRandomData: function (N, ratio, min, max) {
if (!N) N = 5; if (!N) N = 5;
if (!ratio) ratio = .3; if (!ratio) ratio = .3;
if (!min) min = 1; if (!min) min = 1;
if (!max) max = 5; if (!max) max = 5;
var G = []; var G = [];
for (var i = 0; i < N; i++) { for (var i = 0; i < N; i++) {
G.push([]); G.push([]);
for (var j = 0; j < N; j++) { for (var j = 0; j < N; j++) {
if (i == j) G[i].push(0); if (i == j) G[i].push(0);
else if ((Math.random() * (1 / ratio) | 0) == 0) { else if ((Math.random() * (1 / ratio) | 0) == 0) {
G[i].push((Math.random() * (max - min + 1) | 0) + min); G[i].push((Math.random() * (max - min + 1) | 0) + min);
} else { } else {
G[i].push(0); G[i].push(0);
}
} }
} }
return G;
} }
return G;
}; };
// Override // Override
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册