-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDemo.java
More file actions
2112 lines (1707 loc) · 67 KB
/
Demo.java
File metadata and controls
2112 lines (1707 loc) · 67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import java.io.*;
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import java.net.*;
import javax.swing.*;
public class Demo extends Applet implements ActionListener,ItemListener,WindowListener
{
///layout of the simulator interface is:
///menuframe: the whole window;
///variablesPanel(left);
///DrawArea(right-up);
///DrawPanel(right-down),including legend, status bar and buttons.
URL url=null;
URL helpurl=null;
public String currentInputFile;
Frame menuframe;
VariablesPanel vp;
public DrawArea da;
public DrawPanel dp;
public NetworkDynamics nd;
boolean graphRead = false;
boolean evolved = false;
boolean drawSpeeds = true;//true when speed is drawn; false when volume is drawn
public String getnetwork;
public Frame f;
public TextArea stat;
MenuBar mbar,fmbar;
public void init() {
url=getCodeBase();
vp = new VariablesPanel();
dp = new DrawPanel(this);
da = new DrawArea( dp );
getnetwork="10X10 Grid Network";
WindowDestroyer windowKiller=new WindowDestroyer();
//Define the main window
menuframe = new MenuFrame("SONG: Simulator of Network Growth 1.0", this ) ;
//define the size of menuframe according to the screen size
Dimension screensize = getToolkit().getScreenSize();
menuframe.setLayout(new BorderLayout());
menuframe.add("West", vp);
menuframe.add("Center", da);
menuframe.addWindowListener(this);
menuframe.setSize ((int)(1.0*screensize.width),
(int)(0.99*screensize.height));
menuframe.setVisible(true);
//define the menu
mbar = new MenuBar();
menuframe.setMenuBar(mbar);
Menu song = new Menu("SONG1.0");
Menu help=new Menu("Help");
MenuItem evolve1,quit,about,instruction;
song.add(evolve1 = new MenuItem("Evolve "));
song.add(quit = new MenuItem("Quit"));
help.add(instruction = new MenuItem("Instructions"));
//help.add(about=new MenuItem("About Song1.0"));
mbar.add(song);
mbar.add (help);
evolve1.addActionListener(this);
quit.addActionListener(this);
//about.addActionListener(this);
instruction.addActionListener(this);
//Define the result window
f=new Frame("Statistics");
stat=new TextArea("");
///load the 10*10 network when the window is opened
vp.network.select("10X10 Grid Network" );
dp.showStatus.setText("10X10 Network Loaded...");
dp.evolve.setEnabled(true) ;
dp.statistics .setEnabled(false);
currentInputFile = "Grid10.txt";
try {
nd = new NetworkDynamics( vp.variables,url, currentInputFile);
} catch (IOException e) {
}
dp.first.setEnabled(false);
dp.previous .setEnabled(false);
dp.next .setEnabled(false) ;
dp.last.setEnabled(false) ;
dp.statistics .setEnabled( false);
dp.whichAttribute.setEnabled(false) ;
dp.scale .setEnabled( false);
da.setMapVariables();
graphRead = true;
evolved = false;
da.currentYear = 0;
da.repaint();
///////////
}
public void paint( Graphics g ) {
//da.paint( g);
}
///define the events related to window
public void windowClosing(WindowEvent e){
Object obj = e.getSource();
if(obj.equals( menuframe))menuframe.dispose() ;
else if (obj.equals( f))f.dispose() ;
}
public void windowOpened(WindowEvent e){
da.setVisible(true) ;
}
public void windowActivated(WindowEvent e){
da.repaint() ;
}
public void windowDeactivated(WindowEvent e){
da.repaint() ;
}
public void windowIconified(WindowEvent e){
da.repaint() ;
}
public void windowDeiconified(WindowEvent e){
da.repaint() ;
}
public void windowClosed(WindowEvent e){
}
//
public void actionPerformed( ActionEvent ae) {
String arg = (String) ae.getActionCommand();
Object obj = ae.getSource();
//
if(arg=="Evolve "){
da.dp.evolve .setEnabled( false);
vp.setEnabled( false);
evolved = false;
///initializing...
try {
nd = new NetworkDynamics( vp.variables, url,currentInputFile,this);
}
catch(IOException ie) {
}
//////////////////
da.currentYear = 0;
da.dp.year.setText( " Year "+ Integer.toString( da.currentYear ) + " " );
///running...
nd.NetworkDynamix(url, vp.variables);
da.repaint();
da.dp.setVisible(true);
/////////////
da.dp.evolve .setEnabled( false);
vp.setEnabled( true);
evolved = true;
da.dp.first.setEnabled(true);
da.dp.previous .setEnabled(true);
da.dp.next .setEnabled(true) ;
da.dp.last.setEnabled(true) ;
da.dp.statistics .setEnabled( true);
da.dp.whichAttribute.setEnabled(true) ;
da.dp.scale .setEnabled( true);
}
if(arg=="Quit"){
menuframe.dispose() ;
}
if(arg=="Instructions"){
try {
helpurl=new URL(url,"HelpFileSONG1.0.htm"); }
catch (MalformedURLException e) {
System.out.println("Bad URL:" + helpurl);
}
getAppletContext().showDocument(helpurl,"_blank");
}
if(arg=="About Song1.0"){
try {
helpurl=new URL(url,"HelpFileSONG1.0.htm"); }
catch (MalformedURLException e) {
System.out.println("Bad URL:" + helpurl);
}
getAppletContext().showDocument(helpurl,"_blank");
}
if(arg=="Save"){
FileDialog savefile=new FileDialog(f,"Save Statistics...",FileDialog.SAVE);
savefile.show() ;
FileOutputStream out= null;
System.out.print(savefile.getFilenameFilter()+"\n");
System.out.print(savefile.getFile()+"\n");
File s= new File(savefile.getDirectory(),savefile.getFile() );
try{
out= new FileOutputStream(s);
}catch(Exception e)
{
System.out.println("Unable to open file");
return;
}
PrintStream psOut=new PrintStream(out);
psOut.print(stat.getText());///
try{
out.close();
}catch(IOException e){
System.out.println("e");
}
}
if(arg=="Close"){
f.dispose() ;
}
// Command Evolve
if(obj.equals(dp.evolve )){
da.dp.evolve .setEnabled( false);
vp.setEnabled( false);
evolved = false;
///initializing...
try {
nd = new NetworkDynamics( vp.variables, url,currentInputFile,this);
}
catch(IOException ie) {
}
//////////////////
da.currentYear = 0;
da.dp.year.setText( " Year "+ Integer.toString( da.currentYear ) + " " );
///running...
nd.NetworkDynamix(url, vp.variables);
da.repaint();
da.dp.setVisible(true);
/////////////
da.dp.evolve .setEnabled( false);
vp.setEnabled( true);
evolved = true;
da.dp.first.setEnabled(true);
da.dp.previous .setEnabled(true);
da.dp.next .setEnabled(true) ;
da.dp.last.setEnabled(true) ;
da.dp.statistics .setEnabled( true);
da.dp.whichAttribute.setEnabled(true) ;
da.dp.scale .setEnabled( true);
}
//Command Statistics
if(obj.equals(dp.statistics)){
//JOptionPane.showMessageDialog(menuframe,"The Moe's Results: avgSpeed="+nd.avgSpeed+"; avgVolume="+nd.avgVolume+"; vkt="+nd.vkt+"; vht="+nd.vht);
f.dispose();
f=new Frame("Statistics");
f.addWindowListener(this);
stat=new TextArea("");
Dimension screensize = getToolkit().getScreenSize();
//define the size of menuframe according to the screen size
f.setSize ((int)(0.35*screensize.width),
(int)(0.80*screensize.height));
//define the menu
fmbar = new MenuBar();
f.setMenuBar(fmbar);
Menu file = new Menu("File");
MenuItem save,close;
file.add(save = new MenuItem("Save"));
file.add(close = new MenuItem("Close"));
fmbar.add(file);
save.addActionListener(this);
close.addActionListener(this);
stat.setText( "");
f.setVisible( false);
stat.setVisible(false);
String temp="";
stat.append(new String("\n\n---Network Summary---\n\n"));
stat.append(new String(" Item Description/Value\n\n"));
stat.append(new String("0. Network Type \t"+vp.network .getSelectedItem() +"\n"));
stat.append(new String("1. Speed Distribution \t"+vp.speed.getSelectedItem() +"\n"));
stat.append(new String(" Speed Multipler \t"+vp.v99.value() +"\n"));
stat.append(new String("2. Land use Distribution \t"+vp.landuse.getSelectedItem() +"\n"));
stat.append(new String(" Land use Multipler \t"+vp.v100.value() +"\n"));
stat.append(new String("3. Travel Demand Model\t"+"\n"));
stat.append(new String("3.1 Value of Time \t"+vp.v6.value() +"\n"));
stat.append(new String("3.2 Friction Factor \t"+vp.v10.value()+"\n"));
stat.append(new String("4. Revenue Model\t"+"\n"));
stat.append(new String("4.1 Toll rate \t"+vp.v13.value() +"\n"));
stat.append(new String("4.2 Coeff. of length \t"+vp.v14.value() +"\n"));
stat.append(new String("4.3 Coeff. of speed \t"+vp.v15.value() +"\n"));
stat.append(new String("5. Cost Model\t" +"\n"));
stat.append(new String("5.1 Coeff. of length \t"+vp.v17.value() +"\n"));
stat.append(new String("5.2 Coeff. of flow \t"+vp.v18.value() +"\n"));
stat.append(new String("5.3 Coeff. of speed \t"+vp.v19.value()+"\n"));
stat.append(new String("6. Investment Model\t"+"\n"));
stat.append(new String("6.1 Speed improvement coeff. \t"+vp.v20.value() +"\n"));
stat.append(new String("\nActual Number of Iterations \t"+(nd.endyear +1) +"\n"));
stat.append(new String("\n---MOEs Results---\n\n"));
stat.append(new String(" MOE Value\n\n"));
stat.setFont(new Font("Times New Roman",Font.PLAIN|Font.ROMAN_BASELINE |Font.BOLD ,12));
stat.append(new String("AvgSpeed\t"+nd.avgSpeed +"\n"));
stat.append(new String("AvgFlow\t"+nd.avgVolume +"\n"));
stat.append(new String("vkt\t"+nd.vkt +"\n"));
stat.append(new String("vht\t"+nd.vht +"\n"));
stat.append(new String("Total Cost\t"+nd.totalCost +"\n"));
stat.append(new String("Total Revenue\t"+nd.totalRevenue +"\n"));
stat.append(new String("Cumulative Cost\t"+nd.cumulativeCost +"\n"));
stat.append(new String("Cumulative Revenue\t"+nd.cumulativeRevenue +"\n"));
stat.append(new String("Improvement Term\t")+nd.ImproveTerm +"\n");
stat.setVisible( true);
f.add(stat,"Center");
f.setVisible( true);
}
//Command << < > >>
if(arg.equals("<<")) {
da.currentYear = 0;
da.repaint();
} else if( arg.equals("<") ) {
if( da.currentYear > 0 ) {
da.currentYear--;
da.repaint();
} else {
da.currentYear = nd.endyear ;
da.repaint();
}
} else if(arg.equals(">") ) {
if(da.currentYear < nd.endyear ) {
da.currentYear ++;
da.repaint();
} else if(da.currentYear == nd.endyear){
da.currentYear = 0;
da.repaint();
}
} else if(arg.equals(">>") ) {
da.currentYear = nd.endyear;
da.repaint();
}
dp.year.setText( " Year "+ Integer.toString( da.currentYear ) + " " );
}
public void itemStateChanged( ItemEvent ie) {
String arg = (String) ie.getItem();
Object obj = ie.getSource();
if (obj.equals(dp.whichAttribute)){
if(dp.scale .getSelectedItem() =="Absolute"){
if(arg.equals( "Speed")){
drawSpeeds = true;
dp.unit.setText("");
dp.bluefor.setText("0~" + Integer.toString(5));
dp.greenfor.setText(Integer.toString(5) +"~" + Integer.toString(10));
dp.yellowfor.setText(Integer.toString(10)+"~" + Integer.toString(15));
dp.orangefor.setText(Integer.toString(15) +"~"+ Integer.toString(20));
dp.redfor.setText(Integer.toString(20) +"~"+ " ");
da.repaint();
}
else{
drawSpeeds = false;
dp.unit.setText("");
dp.bluefor.setText("0~" + Integer.toString(1000));
dp.greenfor.setText(Integer.toString(1000)+"~" + Integer.toString(2000));
dp.yellowfor.setText(Integer.toString(2000)+"~" + Integer.toString(3000));
dp.orangefor.setText(Integer.toString(3000)+"~"+Integer.toString(4000));
dp.redfor.setText(Integer.toString(4000)+"~");
da.repaint();
}
}
else{
if(arg.equals( "Speed")){
drawSpeeds = true;
dp.unit.setText("");
da.repaint();
}
else{
drawSpeeds = false;
dp.unit.setText("");
da.repaint();
}
}
}
else if (obj.equals(dp.scale)){
if(arg.equals( "Relative")){
dp.unit.setText("");
dp.bluefor.setText("Lowest");
dp.greenfor.setText("Lower");
dp.yellowfor.setText("Middle");
dp.orangefor.setText("Higher");
dp.redfor.setText("Highest");
da.repaint() ;
}
else{
if(dp.whichAttribute.getSelectedItem() .equals( "Speed")){
drawSpeeds = true;
dp.unit.setText("");
dp.bluefor.setText("0~" + Integer.toString(5));
dp.greenfor.setText(Integer.toString(5) +"~" + Integer.toString(10));
dp.yellowfor.setText(Integer.toString(10)+"~" + Integer.toString(15));
dp.orangefor.setText(Integer.toString(15) +"~"+ Integer.toString(20));
dp.redfor.setText(Integer.toString(20) +"~"+ " ");
da.repaint();
}
else{
drawSpeeds = false;
dp.unit.setText("");
dp.bluefor.setText("0~" + Integer.toString(1000));
dp.greenfor.setText(Integer.toString(1000)+"~" + Integer.toString(2000));
dp.yellowfor.setText(Integer.toString(2000)+"~" + Integer.toString(3000));
dp.orangefor.setText(Integer.toString(3000)+"~"+Integer.toString(4000));
dp.redfor.setText(Integer.toString(4000)+"~");
da.repaint();
}
}
}
}
public void writeStat(URL url){
PrintWriter out=null;
try
{
out=new PrintWriter(new FileOutputStream("Stat.htm") );
}
catch(IOException e)
{
System.out.print("Error opening the files!");
System.exit(0);
}
dp.showStatus.setText("right!");
dp.repaint() ;
out.print("<html>"+
// "<head>"+
// "<meta http-equiv=\"Content-Language\" content=\"en-us\">"+
// "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=gb2312\">"+
// "<meta name=\"GENERATOR\" content=\"Microsoft FrontPage 4.0\">"+
// "<meta name=\"ProgId\" content=\"FrontPage.Editor.Document\">"+
"<title>Statistics</title>"+
// "</head>"+
"<body>"+
"<p align=\"left\"><font face=\"Times New Roman\" size=\"4\"><b>Statistics</b></font></p>"+
"<p align=\"left\"><font face=\"Times New Roman\" size=\"3\"><b><u>MOE's Results</u></b></font></p>"+
"<table border=\"1\">"+
" <tr>"+
"<td align=\"center\"><font face=\"Times New Roman\" size=\"3\">MOE</font></td>"+
"<td align=\"center\"><font face=\"Times New Roman\" size=\"3\">Value</font></td>"+
"</tr>"+
"<tr><td align=\"center\"><font face=\"Times New Roman\" size=\"3\">Average Speed</font></td><td><p align=\"center\">¡¡<font face=\"Times New Roman\" size=\"3\">"+nd.avgSpeed+"</font></p></td></tr>"+
"<tr><td align=\"center\"><font face=\"Times New Roman\" size=\"3\">Average Flow</font></td><td><p align=\"center\">¡¡<font face=\"Times New Roman\" size=\"3\">"+nd.avgVolume+"</font></p></td></tr>"+
"<tr><td align=\"center\"><font face=\"Times New Roman\" size=\"3\">vkt</font></td><td><p align=\"center\">¡¡<font face=\"Times New Roman\" size=\"3\">"+nd.vkt+"</font></p></td></tr>"+
"<tr><td align=\"center\"><font face=\"Times New Roman\" size=\"3\">vht</font></td><td><p align=\"center\">¡¡<font face=\"Times New Roman\" size=\"3\">"+nd.vht+"</font></p></td></tr>"+
"</table>"+
"<p><font face=\"Times New Roman\" size=\"3\"><b><u>Network Summary</u></b></font></p>"+
"<table border=\"1\">"+
"<tr><td></td><td><font face=\"Times New Roman\" size=\"3\">Description or Value</font></td></tr>"+
"<tr><td><font face=\"Times New Roman\" size=\"3\">0. Network Type</font></td><td><font face=\"Times New Roman\" size=\"3\">"+vp.network .getSelectedItem() +"</font></td></tr>"+
"<tr><td><font face=\"Times New Roman\" size=\"3\">1. Speed Distribution</font></td><td><font face=\"Times New Roman\" size=\"3\">"+vp.speed .getSelectedItem() +"</font></td></tr>"+
"<tr><td><font face=\"Times New Roman\" size=\"3\">2. Land use Distribution</font></td><td><font face=\"Times New Roman\" size=\"3\">"+vp.landuse.getSelectedItem() +"</font></td></tr>"+
"<tr><td><font face=\"Times New Roman\" size=\"3\">5. Travel Demand Model</font></td><td><font face=\"Times New Roman\" size=\"3\">"+"</font></td></tr>"+
"<tr><td><font face=\"Times New Roman\" size=\"3\">5.1 Value of Time</font></td><td><font face=\"Times New Roman\" size=\"3\">"+vp.v6.value() +"</font></td></tr>"+
"<tr><td><font face=\"Times New Roman\" size=\"3\">5.2 Friction Factor</font></td><td><font face=\"Times New Roman\" size=\"3\">"+vp.v10.value() +"</font></td></tr>"+
"<tr><td><font face=\"Times New Roman\" size=\"3\">6. Revenue Model</font></td><td><font face=\"Times New Roman\" size=\"3\">"+"</font></td></tr>"+
"<tr><td><font face=\"Times New Roman\" size=\"3\">6.1 Toll rate</font></td><td><font face=\"Times New Roman\" size=\"3\">"+vp.v13.value() +"</font></td></tr>"+
"<tr><td><font face=\"Times New Roman\" size=\"3\">6.2 Coeff. of length</font></td><td><font face=\"Times New Roman\" size=\"3\">"+vp.v14.value() +"</font></td></tr>"+
"<tr><td><font face=\"Times New Roman\" size=\"3\">6.3 Coeff. of speed</font></td><td><font face=\"Times New Roman\" size=\"3\">"+vp.v15.value() +"</font></td></tr>"+
"<tr><td><font face=\"Times New Roman\" size=\"3\">7. Cost Model</font></td><td><font face=\"Times New Roman\" size=\"3\">"+"</font></td></tr>"+
"<tr><td><font face=\"Times New Roman\" size=\"3\">7.1 Coeff. of length</font></td><td><font face=\"Times New Roman\" size=\"3\">"+vp.v17.value() +"</font></td></tr>"+
"<tr><td><font face=\"Times New Roman\" size=\"3\">7.2 Coeff. of flow</font></td><td><font face=\"Times New Roman\" size=\"3\">"+vp.v18.value() +"</font></td></tr>"+
"<tr><td><font face=\"Times New Roman\" size=\"3\">7.3 Coeff. of speed</font></td><td><font face=\"Times New Roman\" size=\"3\">"+vp.v19.value() +"</font></td></tr>"+
"<tr><td><font face=\"Times New Roman\" size=\"3\">8 Investment Model</font></td><td><font face=\"Times New Roman\" size=\"3\">"+"</font></td></tr>"+
"<tr><td><font face=\"Times New Roman\" size=\"3\">8.1 Speed improvement coeff.</font></td><td><font face=\"Times New Roman\" size=\"3\">"+vp.v20.value() +"</font></td></tr>"+
"</table></body></html>");
out.close();
}
/// total 23 variable are allocated to get the parameters of models
/// some of them are 'visible' in the interface
/// the others are 'invisible' and are fixed by default
/// this method is used to give the values of some 'invisible' variables
public void writeVariables(){
//total 23 variables in vp.variables[]
//0,1,3,4,5,11 can be obtained from pull-down boxes
//6-10,13-15,17-20 can be obtained from scrollbars,where 7=13,8=14,9=15
//12,16,21,22 are fixed
//2 never used
//from pull-down boxes
//0,1
if(vp.speed .getSelectedItem() .equals(vp.speed)){
if(vp.speed .getSelectedItem() .equals("Uniform")){
vp.variables[0]=5*(float)vp.v99.value();;
vp.variables[1]=5*(float)vp.v99.value();;
}
else if(vp.speed .getSelectedItem() .equals("Random")){
vp.variables[0]=1*(float)vp.v99.value();;
vp.variables[1]=10*(float)vp.v99.value();;
}
else if(vp.speed .getSelectedItem() .equals("Prespecified Random")){
if(getnetwork.equals("5X5 Grid Network")){vp.variables[0]=vp.variables[1]=-5;}
else if(getnetwork.equals("10X10 Grid Network")){vp.variables[0]=vp.variables[1]=-10;}
else if(getnetwork.equals("15X15 Grid Network")){vp.variables[0]=vp.variables[1]=-15;}
else if(getnetwork.equals("20X20 Grid Network")){vp.variables[0]=vp.variables[1]=-20;}
else if(getnetwork.equals("A Network with River")){vp.variables[0]=vp.variables[1]=-99;}
}
}
//3,4,5
if(vp.landuse.getSelectedItem() .equals(vp.landuse)){
if(vp.landuse.getSelectedItem() .equals("Uniform")){
vp.variables[3]=10*(float)vp.v100.value();
vp.variables[4]=10*(float)vp.v100.value();
vp.variables[5]=(float)0.0;
}
else if(vp.landuse.getSelectedItem() .equals("Random")){
vp.variables[3]=5*(float)vp.v100.value();
vp.variables[4]=15*(float)vp.v100.value();
vp.variables[5]=(float)0.0;
}
else if(vp.landuse.getSelectedItem() .equals("Downtown")){
vp.variables[3]=5*(float)vp.v100.value();
vp.variables[4]=15*(float)vp.v100.value();
vp.variables[5]=(float)1.0;
}
else if(vp.landuse.getSelectedItem() .equals("Prespecified Random")){
if(getnetwork.equals("5X5 Grid Network")){vp.variables[3]=vp.variables[4]=-5;}
else if(getnetwork.equals("10X10 Grid Network")){vp.variables[3]=vp.variables[4]=-10;}
else if(getnetwork.equals("15X15 Grid Network")){vp.variables[3]=vp.variables[4]=-15;}
else if(getnetwork.equals("20X20 Grid Network")){vp.variables[3]=vp.variables[4]=-20;}
else if(getnetwork.equals("A Network with River")){vp.variables[3]=vp.variables[4]=-99;}
vp.variables[5]=(float)0.0;
}
}
//11
if(vp.speed.getSelectedItem()=="Uniform" && vp.landuse.getSelectedItem()=="Uniform")
vp.variables[11]=1;
else if(vp.speed.getSelectedItem()=="Uniform" && vp.landuse.getSelectedItem()=="Downtown")
vp.variables[11]=1;
else
vp.variables[11]=0;
if(vp.network.getSelectedItem()=="A Network with River")
vp.variables[11]=0;
///from scroll bars
vp.variables[6]=(float)vp.v6.value();
vp.variables[13]=(float)vp.v13.value();
vp.variables[10]=(float)vp.v10.value();
vp.variables[14]=(float)vp.v14.value();
vp.variables[15]=(float)vp.v15.value();
vp.variables[17]=(float)vp.v17.value();
vp.variables[18]=(float)vp.v18.value();
vp.variables[19]=(float)vp.v19.value();
vp.variables[20]=(float)vp.v20.value();
vp.variables[7]=vp.variables[13];
vp.variables[8]=vp.variables[14];
vp.variables[9]=vp.variables[15];
///fixed
vp.variables [12]=1;
vp.variables [16]=365;
vp.variables [21]=0;
vp.variables [22]=20;
}
class DrawPanel extends Panel {
Demo sd;
Panel legend=new Panel();
Panel button=new Panel();;
Panel status=new Panel();;
///////////////////////////////////////////////
Choice whichAttribute = new Choice ();
Choice scale = new Choice ();
//Button help=new Button("Help");
Label blank=new Label(" ");
Button evolve = new Button("Evolve");
Button statistics=new Button("Statistics");
Button first = new Button("<<");
Button previous = new Button("<");
Label year = new Label( " Year 0 " , Label.CENTER );
Button next = new Button(">");
Button last = new Button(">>");
////////////////////////////////////////////////
Label unit=new Label("");
Label blue=new Label(" ");
Label green=new Label(" ");
Label yellow=new Label(" ");
Label orange=new Label(" ");
Label red=new Label(" ");
Label bluefor=new Label(" ");
Label greenfor=new Label(" ");
Label yellowfor=new Label(" ");
Label orangefor=new Label(" ");
Label redfor=new Label(" ");
////////////////////////////////////////////////
Label showStatus=new Label("");
public DrawPanel( Demo sd) {
showStatus.setFont(new Font("",Font.BOLD,12));
this.sd = sd;
setLayout(new BorderLayout());
// button panel
whichAttribute.addItem("Speed");
whichAttribute.addItem("Volume");
whichAttribute.select("Speed");
drawSpeeds=true;
whichAttribute.addItemListener(this.sd);
scale.addItem("Absolute");
scale.addItem("Relative");
scale.select("Absolute");
scale.addItemListener(this.sd);
evolve.addActionListener(this.sd);
first.addActionListener(this.sd);
previous.addActionListener(this.sd);
next.addActionListener(this.sd);
last.addActionListener(this.sd);
statistics.addActionListener( this.sd);
evolve.setEnabled(false);
statistics.setEnabled(false);
first.setEnabled(false);
previous .setEnabled(false);
next .setEnabled(false) ;
last.setEnabled(false) ;
scale.setEnabled( false);
whichAttribute.setEnabled(false) ;
button.add(evolve);
button.add(blank);
button.add(scale);
button.add(whichAttribute);
button.add( first);
button.add( previous );
button.add(year);
button.add( next );
button.add( last);
button.add(new Label(" "));
button.add(statistics);
add(button,"South");
// legend panel
legend.setLayout( new GridLayout(1,11));
blue.setBackground(new Color(60, 100, 250));
legend.add(blue);
legend.add(bluefor);
green.setBackground(new Color(8, 140, 14));
legend.add(green);
legend.add(greenfor);
yellow.setBackground(Color.YELLOW );
legend.add(yellow);
legend.add(yellowfor);
orange.setBackground(new Color(250, 125, 0));
legend.add(orange);
legend.add(orangefor);
red.setBackground(new Color(200, 20, 20));
legend.add(red);
legend.add(redfor);
if (scale.getSelectedItem() =="Absolute"){
if (whichAttribute.getSelectedIndex() ==0)
{
unit.setText("");
bluefor.setText("0~" + Integer.toString(5));
greenfor.setText(Integer.toString(5) +"~" + Integer.toString(10));
yellowfor.setText(Integer.toString(10)+"~" + Integer.toString(15));
orangefor.setText(Integer.toString(15) +"~"+ Integer.toString(20));
redfor.setText(Integer.toString(20) +"~"+ " ");
repaint();
}
else
{
unit.setText("");
drawSpeeds = false;
bluefor.setText("0~" + Integer.toString(1000));
greenfor.setText(Integer.toString(1000)+"~" + Integer.toString(2000));
yellowfor.setText(Integer.toString(2000)+"~" + Integer.toString(3000));
orangefor.setText(Integer.toString(3000)+"~"+Integer.toString(4000));
redfor.setText(Integer.toString(4000)+"~");
repaint();
}
}
else{
unit.setText("");
bluefor.setText("Lowest");
greenfor.setText("Lower");
yellowfor.setText("Middle");
orangefor.setText("Higher");
redfor.setText("Highest");
repaint() ;
}
add(legend,"North");
// status panel
status.setLayout( new GridLayout(1,1));
status.add(showStatus);
add(status,"Center");
}
}
class DrawArea extends Panel {
DrawPanel dp;
int Scale; // Scale of magnification or diminision; scale=dim/Max
int Trans; // translation
int dim; // size of the DrawArea,, which is equal to the number of pixes of the draw area
int radius; //Radius of circle that represents a node
Dimension d; //Current Dimension of the DrawArea (dynamic variable)
Dimension sd;
int Max; // Maximum number of cells
int n;
int currentYear = 0;
float c1,c2,c3,c4; //used to decide which color to use
public DrawArea(DrawPanel dp) {
this.dp = dp;
setLayout(new BorderLayout() );
add("South", dp );
}
void setMapVariables() {
n = (int)vp.variables[22] +1;
Max = nd.Max;
sd = getToolkit().getScreenSize();
//System.out.print(sd.width +"\t"+sd.height);
d=getSize() ;
//System.out.println(" Dimension of the DrawArea: width = "+d.width + " height = " + d.height );
dim = (int) ( (d.width<d.height) ? (0.90*d.width) : (0.90*d.height) );
//System.out.println("dim = "+ dim);
if(Max != 0){
Scale = (int)(dim/Max);
} else {
System.out.println("From DrawArea class Max variable is 0. Erorr!!!!!");
Scale = 2;
}
if(Scale == 0)
Scale = 1;
Trans = (int) (0.05*dim);
radius = (int) (Scale);
if(radius == 0)
radius = 1;
//System.out.println("Trans = "+Trans+"; radius = "+ radius);
//System.out.println("End of setScale()!!!!!");
}
//// network will be drawn for the current year
private void drawLinks_Speed(Graphics g) {
float min, max;
//read speed/volume data into the matrix f
FloatStack f[] = null;
if(evolved) {
if( drawSpeeds)
f = nd.Speed[currentYear];
else {
//if( currentYear == n-1 )
// f = nd.Volume[n-2];
//else
f = nd.Volume[currentYear];
}
} else
f = nd.dg.Speed;
float temp = 0;
min = 10;
max = 1 ;
for(int i=0; i<nd.dg.Vertices(); i++) {
for(int j=0; j<nd.dg.NoofLinks(i+1); j++) {
temp = f[i].access(j);
if( max < temp)
max = temp;
if( min > temp)
min = temp;
}
}
//System.out.println ("max="+max+"; min="+min+"\n");
int xcoord[] = new int[5];
int ycoord[] = new int[5];
float factor;
for(int i =0; i<nd.dg.Vertices(); i++) {
for(int j=0; j<nd.dg.NoofLinks(i+1); j++) {
factor = (float)(0.5*f[i].access(j) );
int startx, starty, endx, endy;
startx = Trans+(int)(Scale/2) + (int)(nd.dg.XCoordinate(i+1)*Scale);
starty = Trans- (int)(Scale/2)+ (int)(Scale*Max) - (int)(nd.dg.YCoordinate(i+1)*Scale);
int k = nd.dg.EndNodeNumbers(i+1, j+1);
endx = Trans+(int)(Scale/2) + (int)(nd.dg.XCoordinate(k)*Scale);
endy = Trans - (int)(Scale/2)+(int) (Scale* Max) - (int)(nd.dg.YCoordinate(k)*Scale);
if (dp.scale .getSelectedItem() =="Absolute"){
///absolute scale
if(drawSpeeds)
{c1=5;c2=10;c3=15;c4=20;}
else
{c1=1000;c2=2000;c3=3000;c4=4000;}
if( f[i].access( j ) <= c1 ) {
g.setColor(new Color(60, 100, 250) ); /////Blue
//g.setColor(new Color(150, 150, 150) );
factor = (float) (0.5*Scale);
//count1++;
}
else if ( f[i].access( j ) <= c2 ) {
g.setColor(new Color(8, 140, 14) ); ////Green
//g.setColor(new Color( 115, 115, 115) );
factor = (float) (0.75*Scale);
//count2++;
}
else if ( f[i].access( j ) <= c3 ) {
g.setColor(Color.yellow); ////// Yellow
//g.setColor(new Color(70, 70, 70) );
factor = (float) (Scale);
//count3++;
}
else if ( f[i].access( j ) <= c4 ) {
g.setColor(new Color(250, 125, 0)); ////// Oringe
//g.setColor(new Color(70, 70, 70) );
factor = (float) (Scale);
//count3++;
}
else {
g.setColor(new Color (200, 20, 20) ); //// Red
//g.setColor(new Color(25, 25, 25) );
factor = (float) (1.25*Scale);
//count4++;
}
}
else{
////relative scale
float step = (max-min)/5;
if( f[i].access( j ) <= min+step ) {
g.setColor(new Color(60, 100, 250) ); /////Blue
//g.setColor(new Color(150, 150, 150) );sc
factor = (float) (0.5*Scale);
//count1++;
}
else if ( f[i].access( j ) <= min+2*step ) {
g.setColor(new Color(8, 140, 14) ); ////Green
//g.setColor(new Color( 115, 115, 115) );
factor = (float) (0.75*Scale);
//count2++;
}
else if ( f[i].access( j ) <= min+3*step ) {
g.setColor(Color.yellow); ////// Yellow
//g.setColor(new Color(70, 70, 70) );
factor = (float) (Scale);
//count3++;
}
else if ( f[i].access( j ) <= min+4*step ) {
g.setColor(new Color(250, 125, 0)); ////// Oringe
//g.setColor(new Color(70, 70, 70) );
factor = (float) (Scale);
//count3++;
}
else {
g.setColor(new Color (200, 20, 20) ); //// Red
//g.setColor(new Color(25, 25, 25) );
factor = (float) (1.25*Scale);
//count4++;
}