@@ -12,7 +12,7 @@ var problemFilename = utils.getQueryParam('problem') || null;
12
12
var seed = utils . getQueryParam ( 'seed' ) || 'random!' ;
13
13
var problem = null ;
14
14
var rng = seedrandom ( seed ) ;
15
- var nodeCount = parseInt ( utils . getQueryParam ( 'nodes' ) , 10 ) || 25 ;
15
+ var nodeCount = parseInt ( utils . getQueryParam ( 'nodes' ) , 10 ) || 20 ;
16
16
var iterationLog = bows ( 'Iteration' ) ;
17
17
var bestLog = bows ( 'Optimum' ) ;
18
18
var size = 500 ;
@@ -41,6 +41,8 @@ function create(problem) {
41
41
localStorage . removeItem ( 'debug' ) ;
42
42
}
43
43
44
+ setProblemSelector ( )
45
+
44
46
tsp = problem || new RandomTSP ( nodeCount , size , size , rng ) ;
45
47
display = new Display ( size , size ) ;
46
48
display . clearBest ( ) ;
@@ -72,7 +74,7 @@ function onNewBest(i, walk, length) {
72
74
*/
73
75
function onIteration ( i , pheromones ) {
74
76
iterationLog ( i ) ;
75
- d3 . select ( '.iterationCount' ) . text ( 'Iteration: ' + i ) ;
77
+ d3 . select ( '.iterationCount' ) . text ( i ) ;
76
78
var matrix = [ ] ;
77
79
for ( let i = 0 ; i < tsp . distances . length ; i ++ ) {
78
80
matrix [ i ] = [ ] ;
@@ -91,6 +93,37 @@ function onIteration(i, pheromones) {
91
93
display . printHeatMap ( matrix , 1 , 'pheromoneMatrix' ) ;
92
94
}
93
95
96
+ function updateProblem ( ) {
97
+ let val = d3 . select ( '.js-problem' ) . property ( 'value' ) ;
98
+ if ( val . indexOf ( 'random' ) === 0 ) {
99
+ var size = val . split ( '-' ) . map ( x => x . trim ( ) ) [ 1 ] ;
100
+ window . location = `/?nodes=${ size } ` ;
101
+ } else {
102
+ window . location = `/?problem=${ val } .tsp` ;
103
+ }
104
+ }
105
+
106
+ function setProblemSelector ( ) {
107
+ let checkOption = function ( option , i ) {
108
+ if ( problemFilename ) {
109
+ if ( d3 . select ( this ) . attr ( 'value' ) === problemFilename . split ( '.' ) [ 0 ] ) {
110
+ d3 . select ( this ) . attr ( 'selected' , 'selected' ) ;
111
+ }
112
+ } else if ( nodeCount ) {
113
+ var split = d3 . select ( this ) . attr ( 'value' ) . split ( '-' ) ;
114
+ console . log ( parseInt ( split [ 1 ] ) === nodeCount , parseInt ( split [ 1 ] ) , nodeCount )
115
+ if ( parseInt ( split [ 1 ] ) === nodeCount ) {
116
+ d3 . select ( this ) . attr ( 'selected' , 'selected' ) ;
117
+ }
118
+ }
119
+ }
120
+
121
+ var x = d3
122
+ . selectAll ( '.js-problem option' )
123
+ . each ( checkOption ) ;
124
+
125
+ }
126
+
94
127
/**
95
128
* Starts the process!
96
129
*/
@@ -125,5 +158,8 @@ d3.select('#refresh')
125
158
d3 . select ( '#run' )
126
159
. on ( 'click' , ( ) => run ( ) ) ;
127
160
161
+ d3 . select ( '.js-problem' )
162
+ . on ( 'change' , ( ) => updateProblem ( ) ) ;
163
+
128
164
129
165
0 commit comments