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

add max_sum_path

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