From c9fcfc295c1aebaf4cbbc09ca3e8545d6716baf3 Mon Sep 17 00:00:00 2001 From: Jason Park Date: Fri, 20 May 2016 11:44:49 -0500 Subject: [PATCH] add max_sum_path --- js/module/array1d.js | 7 ++++--- js/module/array2d.js | 24 +++++++++++++----------- js/module/graph.js | 25 +++++++++++++------------ js/module/weighted_graph.js | 33 +++++++++++++++++---------------- 4 files changed, 47 insertions(+), 42 deletions(-) diff --git a/js/module/array1d.js b/js/module/array1d.js index 069334b..f204bcd 100644 --- a/js/module/array1d.js +++ b/js/module/array1d.js @@ -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 diff --git a/js/module/array2d.js b/js/module/array2d.js index 80c6b92..cf4f261 100644 --- a/js/module/array2d.js +++ b/js/module/array2d.js @@ -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 diff --git a/js/module/graph.js b/js/module/graph.js index d006776..e6cf2cc 100644 --- a/js/module/graph.js +++ b/js/module/graph.js @@ -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 = []; diff --git a/js/module/weighted_graph.js b/js/module/weighted_graph.js index a57d760..6b6f2cb 100644 --- a/js/module/weighted_graph.js +++ b/js/module/weighted_graph.js @@ -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 -- GitLab