-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIMWEBsCalibrationProgram.chpl
2245 lines (2168 loc) · 159 KB
/
IMWEBsCalibrationProgram.chpl
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
/* Constants I have used
1- Parallelization Strategy --> 1- Functional 2- Dependent-Multi-Search and 3- Hybrid
2- Calibration Types --> 1- Single-Objective 2- Multi-Objective
3- Calibration Algorithms 1- DDS 2- SRCC-DDS 3-PADDS 4- SRCC-PADDS
4- MeasureScope --> 1- Speed and 2- Convergence
*/
/* Documentation -->
1- For Functional Parallelization --> I start with one Parameter set, which is Random, and then I will send this Parameter set to all the Machines.
Then, they update the parameter set and calculate the performance values for the parameter set and FBests, and they return it to the Master.
*/
/* author: Marjan Asgari
Fall 2021 */
use List;
use Random;
use IO;
use FileSystem;
use Spawn;
use runIMWEBs;
use ConfigMethods;
use ProgramDatabase;
use ParameterSet;
use Records;
use Path;
use Math;
use DateTime;
use ManualTablesFill;
class IMWEBsCalibrationProgram{
/* The following variables should be defined before running the program:
1- We should define a total simulation number that we want to run for our program
2- We need to define the number of simulations that should be allocated to each machine at each data transfer.
*/
var EntireSimulationNumbers: int = 50 ; /* The entire number of simulations that you want to run for the project */
var ProjectPath: string; /* This the EF core Project Path */
var HDF5Path: string; /* This is the path where HDF5 libs are stored on Worker Machines; Without knowing this path, IMWEBs model can't be run */
var IMWEBsbashfilePath: string; /* IMWEBs should get run in a bash file, since before it we have to set some compiler's variables. Thus, we need a bash file which opens a bash shell, sets the variables, and runs the IMWEBs */
var IMWEBsModelPath: string;
var IMWEBsProjectPath: string;
var CSVFilesPath: string;
var CurSimIDMaster: string;
var CurParSetMaster: list(shared Parameter, parSafe=true);
var ClusterArchitecture = "Multi-Computer";
var BeginPADDSVar: string = "NONE";
var BeginPADSSFBest: real = 999;
//var ProjectName = "PADDSMultiObjective"; /* The project name we want to carry out the calibration for --> This name will be on the Base_project Table */
var ProjectName = "DDSSingleObjective"; /* The project name we want to carry out the calibration for --> This name will be on the Base_project Table */
proc init(ProPath:string, HDF5:string, IMWEBsBashfile: string, Modelpath: string, ModelProjectPath: string, csv:string){
this.ProjectPath = ProPath;
this.HDF5Path = HDF5;
this.IMWEBsbashfilePath = IMWEBsBashfile;
this.IMWEBsModelPath = Modelpath;
this.IMWEBsProjectPath = ModelProjectPath;
this.CSVFilesPath = csv;
}
proc RunAutoCalibration{
writeln("----------------------------------------------------------------------------------------------------\n");
writeln("Database Update is Beginning on ALL Worker Nodes of our Computer Cluster\n");
writeln("----------------------------------------------------------------------------------------------------\n");
writef("-------------------Database Update's Start Date-Time is: %s -------------------------------------\n", datetime.today():string);
writeln("----------------------------------------------------------------------------------------------------\n");
/* Multi-objective */
//var manualclass = new ManualTablesFill("Functional", "Multi-Objective", ProjectName, "Multi-Variable", "PADDS", "Convergence", "FV-STD", EntireSimulationNumbers:string, "0", EntireSimulationNumbers, ProjectPath, IMWEBsModelPath, IMWEBsProjectPath, 2, CSVFilesPath);
//manualclass.FillTables();
/* Single-objective */
var manualclass = new ManualTablesFill("Functional", "Single-Objective", ProjectName, "NONE", "SRCC-DDS", "Convergence", "NumberofSimulations", EntireSimulationNumbers:string, "0", EntireSimulationNumbers, ProjectPath, IMWEBsModelPath, IMWEBsProjectPath, 2, CSVFilesPath);
manualclass.FillTables();
writeln("Database Update Successfully Finished on ALL Worker Nodes of our Computer Cluster\n");
writeln("----------------------------------------------------------------------------------------------------\n");
writef("Database Update's Start End Date-Time is: %s \n", datetime.today():string);
writeln("----------------------------------------------------------------------------------------------------\n");
/*----------Only Single Objective Calibration--------------*/
var SingleObjIndicatorName = "TotalF"; /* If you are working with SingleObjective calibration and you are interested in any indicator rather than TotalFvalue,
define objective's name here.
e.g., R2, RMSE ==> Otherwise, set this variable to "TotalF"
*/
/*----------Only Multi Objective Calibration--------------*/
var StoppingCriterion: string; /* With which method, the stopping criterion should be updated -->
It can be 1-MDR 2- FV-STD 3- CD-STD */
var GDThreshold: real; /* The max acceptable closeness to the Pareto Front, if we have a Pareto Front for the problem at hand */
/*----------Only Dependent Search --------------*/
var IslandInitialTotalSimulations: int; /* How many Simulations Should be allocated to each island? */
var ParetoFrontMaster: bool = false; /* Do we have a Reference Pareto Front? If yes, set it true, otherwise --> false */
var ExchageArchiveMethod: string; /* With what method, the exchanged Archive Elements should be selected -->
It can be 1- EpsilonIndicator, 2-ScottSpacing, and 3-ObjectiveWeights */
var IslandsDBCopyPath: string; /* The path on the Coordinator Machine that All Islands' DBs should get copied at the End */
/* ----------------Now we need to read the required information for the database and assign them to variables ---------------- */
var PrDB = new ProgramDatabase(ProjectPath, ProjectName);
PrDB.getOptimizationInfo();
writeln("-----------------------Parallel Calibration of IMWEBs Hydrologic Model------------------------------\n");
writeln("----------------------------------------------------------------------------------------------------\n");
writeln("-------------------Reading the General Information of the Optimization Project ---------------------\n");
var CalibrationType: string = PrDB.getCalibrationType(); /* whether it is single-objective or multi-objective */
writef("Calibration Type is %s. Running on the Master/Controller Node: %s\n",CalibrationType, here.hostname);
writeln("----------------------------------------------------------------------------------------------------\n");
var MultiobjectiveType = PrDB.getMultiObjType(); /* whether it is 1- Multi-indicator, 2- Multi-variable and 3- Multi-VarIndicator */
writef("Multiobjective Type is %s. Running on the Master/Controller Node: %s\n", MultiobjectiveType, here.hostname);
writeln("----------------------------------------------------------------------------------------------------\n");
var ParallelizationStrategy = PrDB.getParallelizationStrategy(); /* whether it is Functional, Dependent multi-search or Hybrid */
writef("Parallelization Strategy is %s. Running on the Master/Controller Node: %s\n", ParallelizationStrategy, here.hostname);
writeln("----------------------------------------------------------------------------------------------------\n");
var CalibrationAlgorithm = PrDB.getCalibrationAlgorithm(); /* whether it is DDS, SRCC-DDS, PADDS, or SRCC-PADDS */
writef("Calibration Algorithm is %s. Running on the Master/Controller Node: %s\n", CalibrationAlgorithm, here.hostname);
StoppingCriterion = PrDB.getStoppingCriteria();
writeln("----------------------------------------------------------------------------------------------------\n");
writef("Stopping Criterion is %s. Running on the Master/Controller Node: %s\n", StoppingCriterion, here.hostname);
writeln("----------------------------------------------------------------------------------------------------\n");
var DesiredObjectiveValue = PrDB.getStoppingValue():real; /* At what objective function value should we stop? */
writef("Desired Objective Value is %s. Running on the Master/Controller Node: %s\n", DesiredObjectiveValue:string, here.hostname);
writeln("----------------------------------------------------------------------------------------------------\n");
var ExchangeFrequency = PrDB.getExchangeFrequency(); /* How frequent the information should get exchanged --> In terms of number of simulations */
writef("Exchange Frequency is %s. Running on the Master/Controller Node: %s\n",ExchangeFrequency:string, here.hostname);
writeln("----------------------------------------------------------------------------------------------------\n");
var NumFArchivesExchange = PrDB.getNumFArchivesExchange(); /* How many Non dominated solutions in the "exchanged" archive should be*/
writef("Number of Archive Elements to be Exchanged is %s. Running on the Master/Controller Node: %s\n", NumFArchivesExchange:string, here.hostname);
writeln("----------------------------------------------------------------------------------------------------\n");
var NumAllowedInArchive = PrDB.getNumAllowedInArchive(); /* If we have a bounded archive, how many non-dominated solutions should it store? What is the max value? */
writef("Number of Archive Elements to be in the Archive is %s. Running on the Master/Controller Node: %s\n", NumAllowedInArchive:string, here.hostname);
writeln("----------------------------------------------------------------------------------------------------\n");
var BoundArchive = PrDB.getBoundArchive(); /* Whether we have a bounded or unbounded archive? */
writef("Bounding Archive is %s. Running on the Master/Controller Node: %s\n",BoundArchive:string, here.hostname);
writeln("----------------------------------------------------------------------------------------------------\n");
var SRCCFreq = PrDB.getSRCCFrequency(); /* After how many simulations the worker nodes should send their results to the manager node? */
writef("SRCC Results are Sent Every %s Simulations. Running on the Master/Controller Node: %s\n",SRCCFreq:string, here.hostname);
writeln("----------------------------------------------------------------------------------------------------\n");
var MeasureScope = PrDB.getMeasureScope(); /* What is the Measure Scop? Speed or Convergence? */
writef("Measure Scope is %s. Running on the Master/Controller Node: %s\n",MeasureScope, here.hostname);
writeln("----------------------------------------------------------------------------------------------------\n");
/*-------------------------------------- This variable is going to be filled at the end of the works on all machines, on the Master Node ------------------- */
var CalibrationSpeed: real;
var MasterVariablesNames: list(string); // For storing Model Variables' names which we want to calibrate
var MasterIndicatorNames: list(list(string)); // For storing a list of indicator names for each variable, if we have Multi-VArIndicator Calibration type
var MasterObjectives: list(string); // For storing "objective names" if we have Multi-variable or multi-indicator calibration Type
/* These are locks */
var MasterTablesAvailable$: sync int = 1;
var SimuID$: sync int = 1;
/* -------------------------------------Functional Strategy -------------------------------- */
if (ParallelizationStrategy == "Functional") {
/* The idea is that with using the Functional Parallelization Strategy, Workers nodes only run the IMWEBs model and return "Performance Results" to the Master Node.
Then, the master node starts updating tables on its side. Thus, the following record is for storing Performance results */
var ArchiveStatsList: list(real); // For STD Stopping criterion for Multi-objective Calibration
var ArchiveStatsListFVS: list(list(string)); // For FVS Stopping criterion for Multi-objective Calibration
var StoppingCriterionList: list(real); // For MRD Stopping criterion
/* I can detect the failure of the machine in three spots --> In two catch blocks and 2- when the IMWEBs Success is False
in those spots, I fill the following list */
var MyRemoteLocales: [0..numLocales-2] locale = for i in 1..numLocales-1 do Locales[i];
class IamFailed {
var HostID: int;
var SimID: list(string);
var ParID: list(string);
var Numfailed: int;
proc iniit(id:int, simid:string, parid:string, numfailed:int){
this.HostID = id;
this.SimID= simid;
this.ParID = parid;
this.Numfailed = numfailed;
}
}
var readFaildList$: sync bool = true;
/* The following Lists are filled as the Worker Nodes start to operate. When their size reaches the number of locales, the Update Computers and CPU function will be called to update these two tables on the
Master Node */
class ComputerCPUtablesUpdate{
var StartSimIDs: string;
var TotalSimIDs: int;
var UpdateComHostIDs: int;
var UpdateComHostNames: string;
proc init(Sim:string, Total:int, hostid:int, hostname:string){
this.StartSimIDs = Sim;
this.TotalSimIDs = Total;
this.UpdateComHostIDs = hostid;
this.UpdateComHostNames = hostname;
}
}
// Do it for multi as well
class NodeHasFinished{
var ReadytoCease$: sync bool;
var HostName: string;
proc init(host:string){
this.HostName = host;
}
proc ChangeStatus(status:bool){
this.ReadytoCease$.writeEF(status);
}
proc readCeaseVar(){
return this.ReadytoCease$.readFE();
}
}
record RowsForMasterTablesFunctionalSingle{
var SimID: string;
var ParsetId: string;
var ParmeterSet: shared ParameterSetInitialization = new ParameterSetInitialization(ProjectPath);
var PerformanceResult: list(list(string));
var IMWEBsEndTimeDate: string;
var IMWEBsStartTimeDate: string;
var IMWEBsSimulationRunTime: string;
}
record RowsForMasterTablesFunctionalMulti{
var SimID: string;
var TotalF: real;
var ParsetId: string;
var ParmeterSet: shared ParameterSetInitialization = new ParameterSetInitialization(ProjectPath);
var PerformanceResult: list(list(string));
var VariableName: string;
var IndicatorName: list(string);
var IMWEBsEndTimeDate: string;
var IMWEBsStartTimeDate: string;
var IMWEBsSimulationRunTime: string;
}
/* The following records are for tracking Worker Machines On our cluster */
class AvailableMachinesFunctionalStrSingle{
var hostID: int;
var hostName: string;
var NumCores: int;
var Fbest: real;
var BestParSet: list(shared Parameter, parSafe=true);
var FbestArchive: real;
var BestParSetArchive: list(shared Parameter, parSafe=true);
var statusFinished: bool;
var SRCCStableResults: list(shared ParametersSRCCValues);
var WriteToMasterTables$: sync bool; /* This variable is Sync Variable since it should get locked when we are reading its data and deleting the rows which has been added to the tables,
this lock lets us not delete any information that has been added to this variable after reading data from it and before emptying this variable */
var DataforMasterTables: list(RowsForMasterTablesFunctionalSingle);
proc init(id:int, name:string, cores: int){
this.hostID = id;
this.hostName = name;
this.NumCores = cores;
this.Fbest = 999;
this.BestParSet = new list(shared Parameter, parSafe=true);
this.FbestArchive = 999;
this.BestParSetArchive = new list(shared Parameter, parSafe=true);
this.statusFinished = false;
this.SRCCStableResults = new list(shared ParametersSRCCValues);
this.WriteToMasterTables$ = true;
this.DataforMasterTables = new list(RowsForMasterTablesFunctionalSingle);
}
proc SetSRCCvalues(values: list(shared ParametersSRCCValues )){
this.SRCCStableResults = values;
}
}
class AvailableMachinesFunctionalStrMulti{
var hostID: int;
var hostName: string;
var NumCores: real;
var Fbest: real;
var UpdatedStopingCriterionValue: real;
var DDSVariableName: string;
var RepeatVariable: string = "";
var RepeatIndicator: list(string);
var DDSIndicatorName: list(string);
var objectivesDone: real; //if equal to the Numobjectives --> Crowding distance
var NumberofObjectives: real;
var crowdingDistanceParSet: list(shared Parameter, parSafe=true);
var CurrentParameterSet: list(shared Parameter, parSafe=true);
var CurrentArchive: list(string);
var statusFinished: bool;
var ArchiveFBest: real;
var BestParSetArchive: list(shared Parameter, parSafe=true);
var SRCCStableResults: list(shared ParametersSRCCValues);
var MasterArchive: list(string);
var WriteToMasterTables$: sync bool; /* This variable is Sync Variable since it should get locked when we are reading its data and deleting the rows which has been added to the tables,
this lock lets us not delete any information that has been added to this variable after reading data from it and before emptying this variable */
var DataforMasterTables: list(RowsForMasterTablesFunctionalMulti);
proc init(id:int, name:string, cores: int){
this.hostID = id;
this.hostName = name;
this.NumCores = cores;
this.Fbest = 999;
this.UpdatedStopingCriterionValue = 0;
this.DDSVariableName = "NOTSET";
this.DDSIndicatorName = new list(string);
this.objectivesDone = 0;
this.NumberofObjectives = 0;
this.crowdingDistanceParSet = new list(shared Parameter, parSafe=true);
this.CurrentParameterSet = new list(shared Parameter, parSafe=true);
this.CurrentArchive = new list(string);
this.statusFinished = false;
this.BestParSetArchive = new list(shared Parameter, parSafe=true);
this.MasterArchive = new list(string);
this.WriteToMasterTables$ = true;
this.DataforMasterTables = new list(RowsForMasterTablesFunctionalMulti);
}
proc SetSRCCvalues(values: list(shared ParametersSRCCValues)){
this.SRCCStableResults = values;
}
proc setRepeatVariable(value:string){
this.RepeatVariable = value;
}
proc setArchiveFBest(valuee:real){
this.ArchiveFBest = valuee;
}
proc setRepeatVariableIndicatorandFBest(value:string, valueee:string){
this.RepeatVariable = value;
this.RepeatIndicator.append(valueee);
}
}
/* Now we are creating Lists of Machines */
var MachinesSingle: list(shared AvailableMachinesFunctionalStrSingle);
var MachinesMulti: list(shared AvailableMachinesFunctionalStrMulti);
var ComCpuInfo: list(shared ComputerCPUtablesUpdate);
var IamFailedList : list(shared IamFailed);
var FinalStatus: list(shared NodeHasFinished);
/* This Function updates both Computers Info and CPU info tables */
var UpdateComputers$: sync bool = true;
proc updateComputerInfos(){
var StartSimIDs: list(string);
var TotalSimIDs: list(int);
var UpdateComHostIDs: list(int);
var UpdateComHostNames: list(string);
for info in ComCpuInfo{
StartSimIDs.append(info.StartSimIDs);
TotalSimIDs.append(info.TotalSimIDs);
UpdateComHostIDs.append(info.UpdateComHostIDs);
UpdateComHostNames.append(info.UpdateComHostNames);
}
PrDB.ComputersInfoUpdate(StartSimIDs, TotalSimIDs, ClusterArchitecture, "Functional", UpdateComHostIDs, UpdateComHostNames);
if (MachinesMulti.size == 0){
for M in MachinesSingle{
PrDB.CPUInfoUpdate(M.hostName, M.NumCores);
}
} else if (MachinesSingle.size == 0){
for M in MachinesMulti{
PrDB.CPUInfoUpdate(M.hostName, M.NumCores);
}
}
}
if (CalibrationType == "Single-Objective"){
for loc in 0..MyRemoteLocales.size-1 do {
on MyRemoteLocales[loc] do {
var NewMachine = new shared AvailableMachinesFunctionalStrSingle(here.id, here.hostname,here.numPUs());
if (here.numPUs() != 0){
MachinesSingle.append(NewMachine);
}
var NewCominfo = new shared ComputerCPUtablesUpdate(0:string, 0, here.id, here.hostname);
var StatusInit = new shared NodeHasFinished(here.hostname);
var FaildlistforMachines = new shared IamFailed(here.id, new list(string), new list(string),0);
ComCpuInfo.append(NewCominfo);
FinalStatus.append(StatusInit);
IamFailedList.append(FaildlistforMachines);
}
}
setInitialParameterSetFunctional(); // This sets a random ParameterSet as the Initial ParameterSet to all the machines
}
if (CalibrationType == "Multi-Objective"){
var DBClass = new ProgramDatabase(ProjectPath, ProjectName);
for loc in 0..MyRemoteLocales.size-1 do{
on MyRemoteLocales[loc] do{
var NewMachine = new shared AvailableMachinesFunctionalStrMulti(here.id, here.hostname,here.numPUs());
if (here.numPUs() != 0){
MachinesMulti.append(NewMachine);
}
var NewCominfo = new shared ComputerCPUtablesUpdate(0:string, 0, here.id, here.hostname);
var StatusInit = new shared NodeHasFinished(here.hostname);
var FaildlistforMachines = new shared IamFailed(here.id, new list(string), new list(string),0);
ComCpuInfo.append(NewCominfo);
FinalStatus.append(StatusInit);
IamFailedList.append(FaildlistforMachines);
}
}
setInitialParameterSetFunctional();
/* The point of this Block of code is the fact that we need to know exactly 1- What are the model variables we have 2- what are the indicators that we have for each model variable.
This information is required for the beginning of the PADDS algorithm since it should optimize each of these objectives as its first steps.
So, we create Variables, Indications and ObjectiveNames variables and we call them on Worker Machines. */
/* Objective Names List is a list with 1- The first element is the calibration type 2- the second element is the First Variable name with the number of variables we have
3- the third one is the first indicator name with the number of indicators for the first variable and etc */
var ObjectiveNames = PrDB.getMultiObjectiveNames();
if (ObjectiveNames[0].startsWith("Multi-Variable") == true || ObjectiveNames[0].startsWith("Multi-Indicator") == true){
ObjectiveNames.pop(0);
for Machine in MachinesMulti{
Machine.NumberofObjectives = ObjectiveNames.size;
}
MasterObjectives = ObjectiveNames;
} else {
var vars: list(string);
for i in ObjectiveNames[0].split(":"){
vars.append(i);
}
var numVar = vars.getValue[1]:int;
var count: int = 0;
var Numobj: real;
for i in 1..numVar{
var indics: list(string);
var counter = i + count;
MasterVariablesNames.append(ObjectiveNames[counter]); // Filling in the Variables List
for k in ObjectiveNames[counter+1].split(":"){
indics.append(k);
}
var indicNum = indics[1]: int; // Getting the Number of objectives the current variable has
var indic: list(string);
for j in 1..indicNum{
var temp: list(string);
for h in ObjectiveNames[counter+j].split(":"){
temp.append(h);
}
indic.append(temp[0]); // Creating a list of indicators for the current variable
Numobj = Numobj + 1; // Summing the number of objectives
count = count + 1;
}
MasterIndicatorNames.append(indic); // Appending the Indicator List for the current variable to the Indicators List
}
for Machine in MachinesMulti{
Machine.NumberofObjectives = Numobj; // Adding the Number of objectives for the current Machine
}
/* Check the correctness */
var ConsoleStringvariables: string;
for Vari in MasterVariablesNames{
ConsoleStringvariables = "/".join(ConsoleStringvariables, Vari);
}
writeln(ConsoleStringvariables);
var ConsoleStringindicators: string;
for Indi in MasterIndicatorNames{
var TempString: string;
for varIndis in Indi{
TempString = ",".join(TempString, varIndis);
}
ConsoleStringindicators = "/".join(ConsoleStringindicators, TempString);
}
writeln(ConsoleStringindicators);
}
}
/* This is For Single Objective Calibration */
proc FillMasterTablesSingleObjectiveSingle(CheckSRCCValues: bool){
writeln("****************************************************************************************************\n");
writeln("------------------------------------Updating Master Tables------------------------------------------\n");
var lock = MasterTablesAvailable$.readFE(); /* We set a lock when this function starts operating, since we do not want multiple worker machines call this function and concurrency issue happens.
So, a worker machine calls this fucntion and locks it, other machiens, whe ncall it, tehy see teh lock and teh break the call. */
record InsertData{
var hostname: string;
var hostID: int;
var PureData: list(RowsForMasterTablesFunctionalSingle);
var FBest: real;
proc init(host:string, id:int, Data:list(RowsForMasterTablesFunctionalSingle), Fbest:real){
this.hostname = host;
this.hostID = id;
this.PureData = Data;
this.FBest = Fbest;
}
}
var AllInsertData: list(InsertData);
for M in MachinesSingle{
if (M.DataforMasterTables.size != 0) { // If the machine has shared its results
var readvalue = M.WriteToMasterTables$.readFE(); // Set the lock, since we do not want to lose data
var Mdata = new InsertData(M.hostName, M.hostID, M.DataforMasterTables, M.Fbest);
M.DataforMasterTables.clear();
M.WriteToMasterTables$.writeEF(true); // Unlock
AllInsertData.append(Mdata);
}
}
for InsertRow in AllInsertData{
var hostname = InsertRow.hostname;
var hostid = InsertRow.hostID;
for Indiv in InsertRow.PureData{
var varname: list(string);
var IndicName: list(string);
var Indicvalue: list(string);
var WIndicvalue: list(string);
for row in Indiv.PerformanceResult{
varname.append(row[0]);
IndicName.append(row[3]);
Indicvalue.append(row[5]);
WIndicvalue.append(row[4]);
}
var ProgramDB = new ProgramDatabase(ProjectPath, ProjectName, InsertRow.hostname, InsertRow.hostID);
ProgramDB.UpdateMasterTablesFunctional(hostname, ProjectName, Indiv.SimID, Indiv.ParsetId, Indiv.IMWEBsEndTimeDate, Indiv.IMWEBsStartTimeDate, Indiv.IMWEBsSimulationRunTime:real, Indiv.ParmeterSet.getParameterSet(), varname, IndicName, Indicvalue, WIndicvalue);
var VarNa:string;
var IndicNa:string;
ProgramDB.Archive_Update(Indiv.ParmeterSet, InsertRow.FBest, VarNa, IndicNa, false);
/* The FValue that the the Archive Fuction returns is TotalF if you want to change it, change it in c# */
writef("--------------------------------Found Archive FVlaue is %s\n", ProgramDB.getBestF());
writef("--------------------------------Update News: Global Fvalue based on the Master Archive is %s for Machine %s Info\n", (ProgramDB.getBestF()):string, hostname);
writeln("--------------------------------\n");
for MA in MachinesSingle{
MA.FbestArchive = ProgramDB.getBestF();
MA.BestParSetArchive = ProgramDB.getBestParArchive();
}
if (CheckSRCCValues == true){
var SRCCobject = new ParametersetUpdate(ProjectPath);
var SRCCValues: list(shared ParametersSRCCValues);
writeln("--------------------------------Calculating SRCC Values is taking place!\n");
writeln("--------------------------------\n");
SRCCValues = SRCCobject.SRCCStableValue(Indiv.SimID, ProjectName, SingleObjIndicatorName);
if (SRCCValues.size != 0){
writeln("--------------------------------Stable SRCC Values have been Achieved!\n");
writeln("--------------------------------\n");
var SRCCString: string;
for M in SRCCValues{
if (SRCCString.size == 0){
var LocalString = M.ParameterCalibrationID:string;
LocalString = ":".join(LocalString, M.SRCCValue:string);
SRCCString = LocalString;
} else {
var LocalString = M.ParameterCalibrationID:string;
LocalString = ":".join(LocalString, M.SRCCValue:string);
SRCCString = "--".join(SRCCString, LocalString);
}
}
writef("--------------------------------Stable SRCC Values are %s\n", SRCCString);
writeln("--------------------------------\n");
for machine in MachinesMulti{
machine.SetSRCCvalues(SRCCValues);
}
} else {
var STDVALS= SRCCobject.getSTDValues();
if (STDVALS.size == 0){
writeln("--------------------------------Calculation of SRCC Values' Standard Deviation is Not Started Yet (Not Enough Simulations have been done)\n");
writeln("--------------------------------\n");
} else {
var stdString = "STDS are";
for std in STDVALS {
stdString = ":".join(stdString, std);
}
writef("--------------------------------NOT Stable SRCC Values are: %s\n", stdString);
writeln("--------------------------------\n");
}
}
}
}
}
writeln("---------------------------------Updating Master Tables Done!---------------------------------------\n");
writeln("****************************************************************************************************\n");
MasterTablesAvailable$.writeEF(1);
}
proc getBeginPADDSVar(){
return BeginPADDSVar;
}
proc setBeginPADDSVar(value:string){
BeginPADDSVar = value;
}
proc getBeginPADSSFBest(){
return this.BeginPADSSFBest;
}
proc setBeginPADSSFBest(value:real){
this.BeginPADSSFBest = value;
}
/* This is For Multi Objective Calibration */
proc FillMasterTablesMultiObjective(CheckSRCCValues: bool, StopCriterion:string){
var lock = MasterTablesAvailable$.readFE();
writeln("*******************************************************************************************\n");
writeln("--------------------------------Updating Master Tables-------------------------------------");
record InsertData{
var hostname: string;
var hostID: int;
var PureData: list(RowsForMasterTablesFunctionalMulti);
var FBest: real;
var MashineParameterSet: list(shared Parameter, parSafe=true);
var DDSVariable: string;
var DDSIndicators: list(string);
proc init(host:string, id:int, Data: list(RowsForMasterTablesFunctionalMulti), Fbest: real, ParameterSet: list(shared Parameter, parSafe=true), Variable: string, Indicators: list(string)){
this.hostname = host;
this.hostID = id;
this.PureData = Data;
this.FBest = Fbest;
this.MashineParameterSet = ParameterSet;
this.DDSVariable = Variable;
this.DDSIndicators = Indicators;
}
}
var AllInsertData: list(InsertData);
var DoCrowdingDis: list(bool);
var HaveRepeatedItem: bool = false;
var CurrentParameterSet: list(shared Parameter, parSafe=true);
for M in MachinesMulti{
if (M.DataforMasterTables.size != 0) {
var readvalue = M.WriteToMasterTables$.readFE();
var Mdata = new InsertData(M.hostName, M.hostID, M.DataforMasterTables, M.Fbest, M.CurrentParameterSet, M.DDSVariableName, M.DDSIndicatorName);
M.DataforMasterTables.clear();
AllInsertData.append(Mdata);
CurrentParameterSet = M.CurrentParameterSet;
M.WriteToMasterTables$.writeEF(true);
}
}
for M in MachinesMulti{
if (M.NumberofObjectives <= M.objectivesDone && M.RepeatVariable == ""){
DoCrowdingDis.append(true);
}
}
if (DoCrowdingDis.size == MachinesMulti.size) {
for M in MachinesMulti{
writeln("--------------------------------The Crowding Distance Will Begin....");
writeln("--------------------------------");
writef("--------------------------------Number of Objectives on %s: %s", M.hostName, M.NumberofObjectives);
writeln("--------------------------------");
writef("--------------------------------Number of Done Objectives on %s: %s", M.hostName, M.objectivesDone);
writeln("--------------------------------");
break;
}
}
var ArchiveBestParset: list(shared Parameter, parSafe=true);
var ArchiveFBests: real;
var MasterArchiveParSet: list(shared Parameter, parSafe=true);
var CurSimID: string;
var Masterarchive: list(string);
var MRDStopCriterion: real;
var BeginPADDSLVar: string = "NOTSET";
for InsertRow in AllInsertData{
var hostname = InsertRow.hostname;
var hostid = InsertRow.hostID;
var DDSVariable = InsertRow.DDSVariable;
var DDSIndicators = InsertRow.DDSIndicators;
var MachineFBest = InsertRow.FBest;
var MachineBestParset = InsertRow.MashineParameterSet;
for Indiv in InsertRow.PureData{
var varname: list(string);
var IndicName: list(string);
var Indicvalue: list(string);
var WIndicvalue: list(string);
var ProgramDB = new ProgramDatabase(ProjectPath, ProjectName, InsertRow.hostname, InsertRow.hostID);
for row in Indiv.PerformanceResult{
varname.append(row[0]);
IndicName.append(row[3]);
Indicvalue.append(row[5]);
WIndicvalue.append(row[4]);
}
//ProgramDB.UpdateMasterTablesFunctional(hostname, ProjectName, Indiv.SimID, Indiv.ParsetId, "Start", "End", 0, Indiv.ParmeterSet.getParameterSet(), varname, IndicName, Indicvalue, WIndicvalue);
ProgramDB.UpdateMasterTablesFunctional(hostname, ProjectName, Indiv.SimID, Indiv.ParsetId, Indiv.IMWEBsEndTimeDate, Indiv.IMWEBsStartTimeDate, Indiv.IMWEBsSimulationRunTime:real, Indiv.ParmeterSet.getParameterSet(), varname, IndicName, Indicvalue, WIndicvalue);
if (DDSVariable.size != 0 && DDSIndicators.size == 0){
writeln("--------------------------------BeginPADDS Stage is Going on Currently on the Master Node!\n");
writeln("--------------------------------\n");
if (getBeginPADDSVar().startsWith("NONE") == true && BeginPADDSLVar.startsWith(DDSVariable) == false) {
setBeginPADDSVar(DDSVariable);
BeginPADDSLVar = DDSVariable;
}
if getBeginPADDSVar().startsWith(DDSVariable) == true {
if (getBeginPADSSFBest() > MachineFBest){
setBeginPADSSFBest(MachineFBest);
ArchiveFBests = MachineFBest;
ArchiveBestParset = MachineBestParset;
var IndicNm: string;
ProgramDB.getLocalFValue(false);
ProgramDB.Archive_Update(Indiv.ParmeterSet, Indiv.TotalF, Indiv.VariableName, IndicNm, true);
if (ProgramDB.getDominanceStatus() == "ADDED"){
writef("--------------------------------Master Best Archive has been Updated. Return is %s\n", ProgramDB.getDominanceStatus());
writeln("--------------------------------\n");
CurSimIDMaster = ProgramDB.getcurentSimID();
ArchiveFBests = Indiv.TotalF;
ArchiveBestParset = Indiv.ParmeterSet.getParameterSet();
CurParSetMaster = Indiv.ParmeterSet.getParameterSet();
}
}
if (getBeginPADSSFBest() < 0.4 && getBeginPADSSFBest() > -0.2){
writef("--------------------------------DDS Stage for Objective %s has been over with TotalF Equal to %s\n", Indiv.VariableName, getBeginPADSSFBest():string );
writeln("--------------------------------\n");
setBeginPADSSFBest(999);
setBeginPADDSVar("NONE");
HaveRepeatedItem = false;
} else {
HaveRepeatedItem = true;
writef("--------------------------------DDS Stage for Objective %s will be continued\n",Indiv.VariableName);
writeln("--------------------------------\n");
for M in MachinesMulti{
M.setRepeatVariable(DDSVariable);
}
}
}
} else if (Indiv.VariableName.size != 0 && Indiv.IndicatorName.size != 0) {
writeln("--------------------------------- We are Still in the BeginPADDS on the Master Node!---------------------------------\n");
for indic in Indiv.IndicatorName{
ProgramDB.getLocalFValue(false);
ProgramDB.Archive_Update(Indiv.ParmeterSet, InsertRow.FBest, Indiv.VariableName, indic, true);
if (abs(ProgramDB.getBestF()) != 99){
writef("---------------------------------Update News: GlobalF value based on the Master Archive is %s on Machine %s\n--------------------------------------", (ProgramDB.getBestF()):string, here.hostname);
ArchiveBestParset = ProgramDB.getBestParArchive();
ArchiveFBests = ProgramDB.getBestF();
var FirstString = ":".join(ArchiveBestParset.getValue(0).getParName(), ArchiveBestParset.getValue(0).getCurrentValue():string);
for i in 1..ArchiveBestParset.size-1{
var Parameter = ":".join(ArchiveBestParset.getValue(i).getParName(), ArchiveBestParset.getValue(i).getCurrentValue():string);
FirstString = "--".join(FirstString, Parameter);
}
writef("------------------------------------BeginPADDS: Master Archive's Best ParameterSet is %s------------------------------------\n", FirstString);
}
if (ProgramDB.getDominanceStatus() != "ADDED"){
writef("--------------------------------------Master Best Archive has not been Updated. Return is %s-------------------------------------\n", ProgramDB.getDominanceStatus());
writef("--------------------------------- Hence the Workers are going to Repeat the Simulations for Varibale %s---------------------------------\n", Indiv.VariableName);
HaveRepeatedItem = true;
for M in MachinesMulti{
if (M.hostName == hostname) {
M.setRepeatVariableIndicatorandFBest(Indiv.VariableName, indic);
}
}
} else {
CurSimIDMaster = Indiv.SimID;
CurParSetMaster = Indiv.ParmeterSet.getParameterSet();
writef("-------------------------------------Master Best Archive has been Updated. Return is %s------------------------------------\n", ProgramDB.getDominanceStatus());
writeln("--------------------------------- Hence the Workers are going to Work on a New Objective---------------------------------\n");
}
}
} else if (Indiv.VariableName.size == 0 && Indiv.IndicatorName.size == 0) {
var VarNm: string;
var IndicNm: string;
ProgramDB.getLocalFValue(false);
writeln("--------------------------------We are in the PADDS on the Master Node!\n");
writeln("--------------------------------\n");
ProgramDB.Archive_Update(Indiv.ParmeterSet, 99, VarNm, IndicNm, false);
if (ProgramDB.getDominanceStatus() != "ADDED"){
CurSimID = CurSimIDMaster;
CurrentParameterSet = ProgramDB.CrowdingDistance(ProgramDB.getBestParArchive(), MultiobjectiveType);
} else {
CurSimID = Indiv.SimID;
CurSimIDMaster = CurSimID;
CurrentParameterSet = Indiv.ParmeterSet.getParameterSet();
}
MasterArchiveParSet = CurrentParameterSet;
Masterarchive = ProgramDB.getanArchivebySimID(CurSimID);
var FirstString = Masterarchive[0];
for i in 1..Masterarchive.size-1{
FirstString = "--".join(FirstString, Masterarchive[i]);
}
var SecondString = ":".join(MasterArchiveParSet.getValue(0).getParName(), MasterArchiveParSet.getValue(0).getCurrentValue():string);
for i in 1..MasterArchiveParSet.size-1{
var Parameter = ":".join(MasterArchiveParSet.getValue(i).getParName(), MasterArchiveParSet.getValue(i).getCurrentValue():string);
SecondString = "--".join(SecondString, Parameter);
}
writef("--------------------------------PADDS: Master Archive's Best ParameterSet is %s\n", SecondString);
writeln("--------------------------------\n");
writef("--------------------------------PADDS: Master Archive is %s\n", FirstString);
writeln("--------------------------------\n");
MRDStopCriterion = ProgramDB.getStoppingMDR();
writef("--------------------------------PADDS: The MRD Stopping Criterion is %s\n", MRDStopCriterion:string);
writeln("--------------------------------\n");
}
if (CheckSRCCValues == true){
var SRCCobject = new ParametersetUpdate(ProjectPath);
var SRCCValues: list(shared ParametersSRCCValues);
writeln("--------------------------------Calculating SRCC Values is taking place!\n");
writeln("--------------------------------\n");
SRCCValues = SRCCobject.SRCCStableValue(Indiv.SimID, ProjectName, "ALL");
if (SRCCValues.size != 0){
writeln("--------------------------------Stable SRCC Values have been Achieved!\n");
writeln("--------------------------------\n");
var SRCCString: string;
for M in SRCCValues{
if (SRCCString.size == 0){
var LocalString = M.ParameterCalibrationID:string;
LocalString = ":".join(LocalString, M.SRCCValue:string);
SRCCString = LocalString;
} else {
var LocalString = M.ParameterCalibrationID:string;
LocalString = ":".join(LocalString, M.SRCCValue:string);
SRCCString = "--".join(SRCCString, LocalString);
}
}
writef("--------------------------------Stable SRCC Values are %s\n", SRCCString);
writeln("--------------------------------\n");
for machine in MachinesMulti{
machine.SetSRCCvalues(SRCCValues);
}
} else {
var STDVALS= SRCCobject.getSTDValues();
if (STDVALS.size == 0){
writeln("--------------------------------Calculation of SRCC Values' Standard Deviation is Not Started Yet (Not Enough Simulations have been done)\n");
writeln("--------------------------------\n");
} else {
var stdString = "STDS are:";
for std in STDVALS {
stdString = ":".join(stdString, std);
}
writef("--------------------------------NOT Stable SRCC Values! %s\n", stdString);
writeln("--------------------------------\n");
}
}
}
}
}
if (DoCrowdingDis.size == MachinesMulti.size && HaveRepeatedItem == false){
writeln("--------------------------------Crowding Distance is taking Place! The PADDS will start on Worker Nodes!\n");
writeln("--------------------------------\n");
var CrowdingDistancePar = PrDB.CrowdingDistance(ArchiveBestParset, MultiobjectiveType);
for M in MachinesMulti{
M.crowdingDistanceParSet = CrowdingDistancePar;
M.objectivesDone = 0;
}
}
if (ArchiveBestParset.size != 0){
writeln("--------------------------------PADDS First Stage: The Best Archive Parameter Set and its associated FBest for Worker Nodes got Updated!\n");
writeln("--------------------------------\n");
for MA in MachinesMulti{
MA.BestParSetArchive = ArchiveBestParset;
MA.setArchiveFBest(ArchiveFBests);
}
} else {
for MA in MachinesMulti{
if (MA.BestParSetArchive.size != 0){
MA.BestParSetArchive = new list(shared Parameter, parSafe=true);
MA.setArchiveFBest(999);
}
}
}
if (MasterArchiveParSet.size != 0){
writeln("--------------------------------PADDS Second Stage: The Best Archive Parameter Set for Worker Nodes got Updated!\n");
writeln("--------------------------------\n");
for MA in MachinesMulti{
MA.BestParSetArchive = MasterArchiveParSet;
MA.MasterArchive = Masterarchive;
}
}
var StoppingCriterionValue: real;
var ParetoFront = ParetoFrontMaster;
var ReadGDThreshold = GDThreshold;
if (StoppingCriterion == "FV-STD" || StoppingCriterion == "CD-STD" ){
StoppingCriterionValue = 0.05; // If we are working with STD, then the STD of all objectives for the last 10 simulations should be less than 0.05 to stop
} else {
StoppingCriterionValue = 0; // If we are working with MDR, then the MRD value of the last 10 runs suoud be 0 to stop
}
/* Upadte the Stopping Criterion */
if (StopCriterion == "FV-STD") {
writeln("--------------------------------Checking Stopping Criterion (FV-STD) is Taking Place\n");
writeln("--------------------------------\n");
var ArchiveStats = PrDB.getValueForStoppingCriterionSTD(MultiobjectiveType);
ArchiveStatsListFVS.append(ArchiveStats);
writef("--------------------------------The Number of FV-STD Values we have is %s\n", ArchiveStatsListFVS.size:string);
writeln("--------------------------------\n");
if (ArchiveStatsListFVS.size == 20){
writeln("--------------------------------Evaluation of whether the Calibration need to Stop or not has started\n");
writeln("--------------------------------\n");
var FirstArchive = ArchiveStatsListFVS.getValue[0];
var n = FirstArchive.size/2 - 1;
var MaxIHomogenity: list(real);
for arch in ArchiveStatsListFVS {
var TempValue:real = 0;
for i in 0..n {
if (arch[(2*i) +1].startsWith("N") == false) {
if (arch[(2*i) +1]: real > TempValue){
TempValue = arch[(2*i) +1]: real;
}
}
}
MaxIHomogenity.append(TempValue);
}
var MaxFVSTD: real = 0;
for v in MaxIHomogenity{
if (v > MaxFVSTD){
MaxFVSTD = v;
}
}
writef("--------------------------------The Max Value for FV-STD is found as %s\n", MaxFVSTD:string);
writeln("--------------------------------\n");
if (MaxFVSTD < StoppingCriterionValue){
if (ParetoFront == false ){
writeln("--------------------------------Stopping Criterion Condition is Reached! The Calibration will Stop Soon\n");
writeln("--------------------------------\n");
for M in MachinesMulti{
if (M.hostID == here.id){
M.UpdatedStopingCriterionValue = MaxFVSTD;
}
}
} else {
var GDvalue = PrDB.gettheGDValue(MultiobjectiveType);
if (GDvalue <= GDThreshold){
for M in MachinesMulti{
M.UpdatedStopingCriterionValue = MaxFVSTD;
}
} else {
setInitialParameterSetFunctional(); /* If the algorithm has got stuck in a space, which is not the true convergence,
we need to give it a random parameter set to start with and get out of the "local" optimal */
for M in MachinesMulti{
M.BestParSetArchive = new list(shared Parameter, parSafe=true);
M.UpdatedStopingCriterionValue = 0;
M.CurrentArchive.clear();
M.BestParSetArchive.clear();
M.MasterArchive.clear();
var lock = M.WriteToMasterTables$.readFE();
M.DataforMasterTables.clear();
M.WriteToMasterTables$.writeEF(lock);
}
}
}
}
else {
writeln("--------------------------------Stopping Criterion Condition is NOT Reached! The Calibration will Continue\n");
writeln("--------------------------------\n");
for M in MachinesMulti{
M.UpdatedStopingCriterionValue = MaxFVSTD;
}
}
ArchiveStatsListFVS.clear();
}
}
/* Not Checked */
if (StopCriterion == "MDR"){
if (StoppingCriterionList.size != 10){ //We check if the MDR of the last 10 simulations are all 0 --> stop the algorithm
StoppingCriterionList.append(MRDStopCriterion);
} else if (StoppingCriterionList.size == 10){
StoppingCriterionList.pop(0);
StoppingCriterionList.append(MRDStopCriterion);
}
if (StoppingCriterionList.size == 10){
var numerofzeros: list(bool);
for i in StoppingCriterionList {
if (i == 0){
numerofzeros.append(true);
} else {
numerofzeros.append(false);
}
}
if (numerofzeros.contains(false) == false){
for M in MachinesMulti{
M.UpdatedStopingCriterionValue = 0;
}
} else {
for M in MachinesMulti{
M.UpdatedStopingCriterionValue = 100;
}
}
}
}
/* Not Checked */
if (StoppingCriterion == "CD-STD"){
var ArchiveStats = PrDB.getValueForCrowdingDistanceSTD(MultiobjectiveType);
ArchiveStatsList.append(ArchiveStats);
if (ArchiveStatsList.size == 20){ //after 20 runs?
var MaxCDSTD: real = 0;
for v in ArchiveStatsList {
if (v > MaxCDSTD){
MaxCDSTD = v;
}
}
if (MaxCDSTD < StoppingCriterionValue){
if (ParetoFront == false ){
for M in MachinesMulti{
if (M.hostID == here.id){
M.UpdatedStopingCriterionValue = MaxCDSTD;
}
}
} else {
var GDvalue = PrDB.gettheGDValue(MultiobjectiveType);
if (GDvalue <= ReadGDThreshold){
for M in MachinesMulti{
if (M.hostID == here.id){
M.UpdatedStopingCriterionValue = MaxCDSTD;
}
}
} else {
setInitialParameterSetFunctional(); /* If the algorithm has got stuck in a space, which is not the true convergence,
we need to give it a random parameter set to start with and get out of the "local" optimal */
for M in MachinesMulti{
M.BestParSetArchive = new list(shared Parameter, parSafe=true);
M.UpdatedStopingCriterionValue = 0;
M.CurrentArchive.clear();
M.BestParSetArchive.clear();
M.MasterArchive.clear();
var lock = M.WriteToMasterTables$.readFE();
M.DataforMasterTables.clear();
M.WriteToMasterTables$.writeEF(lock);
}
}
}
}
else {
for M in MachinesMulti{
M.UpdatedStopingCriterionValue = MaxCDSTD;
}
}
ArchiveStatsList.clear();
}