$darkmode
DENOPTIM
GAParameters.java
Go to the documentation of this file.
1/*
2 * DENOPTIM
3 * Copyright (C) 2019 Vishwesh Venkatraman <vishwesh.venkatraman@ntnu.no> and
4 * Marco Foscato <marco.foscato@uib.no>
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published
8 * by the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
15 *
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20package denoptim.programs.denovo;
21
22import java.lang.reflect.Field;
23import java.text.SimpleDateFormat;
24import java.util.ArrayList;
25import java.util.Date;
26import java.util.List;
27import java.util.logging.Level;
28
29import denoptim.constants.DENOPTIMConstants;
30import denoptim.exception.DENOPTIMException;
31import denoptim.files.FileFormat;
32import denoptim.graph.rings.RingClosureParameters;
33import denoptim.logging.Monitor;
34import denoptim.logging.StaticLogger;
35import denoptim.programs.RunTimeParameters;
36import denoptim.programs.RunTimeParameters.ParametersType;
37import denoptim.utils.MutationType;
38
39
45public class GAParameters extends RunTimeParameters
46{
50 public String timeStamp = "NOTIMESTAMP";
51
55 private String dataDir = System.getProperty("user.dir");
56
61 private String interfaceDir = dataDir
62 + System.getProperty("file.separator") + "interface";
63
68 protected String initPoplnFile = "";
69
74 protected String initMolsToFragmentFile = null;
75
80 protected String uidFileIn = "";
81
86 protected String uidFileOut = "";
87
91 private String monitorFile = "";
92
96 private boolean recordMateSelection = false;
97
101 private final String DEFUIDFILEOUTNAME = "MOLUID.txt";
102
106 protected String visitedGraphsFile = "GRAPHS.txt";
107
111 protected int populationSize = 50;
112
117 protected int numOfChildren = 5;
118
122 protected int numConvGen = 5;
123
127 protected int numGenerations = 100;
128
133 protected int maxTriesPerPop = 25;
134
139 protected int maxGeneticOpAttempts = 100;
140
146 protected int replacementStrategy = 1;
147
154 protected boolean parentsSurvive = true;
155
159 protected int lvlGrowthProbabilityScheme = 0;
160
165 protected double lvlGrowthMultiplier = 0.5;
166
171 protected double lvlGrowthSigmaSteepness = 1.0;
172
177 protected double lvlGrowthSigmaMiddle = 2.5;
178
183 protected boolean useLevelBasedProb = false;
184
189 protected boolean useMolSizeBasedProb = false;
190
194 protected int molGrowthProbabilityScheme = 2;
195
200 protected double molGrowthMultiplier = 0.5;
201
206 protected double molGrowthSigmaSteepness = 0.2;
207
212 protected double molGrowthSigmaMiddle = 25;
213
219 protected int crowdingProbabilityScheme = 3;
220
225 protected double crowdingMultiplier = 0.5;
226
231 protected double crowdingSigmaSteepness = 1.0;
232
237 protected double crowdingSigmaMiddle = 2.5;
238
242 protected double symmetricSubProbability = 0.8;
243
247 protected double mutationWeight = 1.0;
248
255 protected boolean coupleMutationAndCrossover = false;
256
260 protected double builtAnewWeight = 1.0;
261
265 protected double crossoverWeight = 1.0;
266
270 protected int xoverSelectionMode = 3;
271
276
282 protected int selectivePressure = -1;
283
287 protected int maxOffsprintFromXover = 1;
288
292 protected boolean keepBestSibling = false;
293
297 List<MutationType> excludedMutationTypes = new ArrayList<MutationType>();
298
302 protected long seed = 0L;
303
307 protected int parallelizationScheme = 1;
308
312 protected int numParallelTasks = 0;
313
317 protected boolean sortOrderDecreasing = true;
318
322 protected boolean nanFitnessKillsExperiment = false;
323
327 protected int precisionLevel = 3;
328
333 protected int monitorDumpStep = 50;
334
338 protected boolean dumpMonitor = false;
339
343 protected double minFitnessSD = 0.000001;
344
348 protected int maxRingsAddedByMutation = 1;
349
354 protected boolean saveRingSystemsAsTemplatesScaffolds = false;
355
361 protected boolean saveRingSystemsAsTemplatesNonScaff = false;
362
369 protected double saveRingSystemsFitnessThreshold = 0.10;
370
374 private double[] mutliSiteMutationWeights = new double[]{0,10,1};
375
380 public int maxUIDMemory = 1000000;
381
386 public String uidMemoryOnDisk = "memory_UIDs.txt";
387
393 public boolean mutatedGraphFailedEvalTolerant = true;
394
401 public boolean xoverGraphFailedEvalTolerant = true;
402
407 public boolean xoverFailureTolerant = true;
408
413 public boolean mutationFailureTolerant = true;
414
420 public boolean buildAnewFailureTolerant = true;
421
426
431 protected boolean writePopOnDisk = false;
432
433//------------------------------------------------------------------------------
434
440 {
442 }
443
444//------------------------------------------------------------------------------
445
446 public String getUIDFileIn()
447 {
448 return uidFileIn;
449 }
450
451//------------------------------------------------------------------------------
452
453 public String getUIDFileOut()
454 {
455 return uidFileOut;
456 }
457
458//------------------------------------------------------------------------------
459
460 public String getVisitedGraphsFile()
461 {
462 return visitedGraphsFile;
463 }
464
465//------------------------------------------------------------------------------
466
467 public String getInterfaceDir()
468 {
469 return interfaceDir;
470 }
471
472//------------------------------------------------------------------------------
473
474 public String getMonitorFile()
475 {
476 return monitorFile;
477 }
478
479//------------------------------------------------------------------------------
480
482 {
483 return monitorDumpStep;
484 }
485
486//------------------------------------------------------------------------------
487
492 public boolean recordMateSelection()
493 {
494 return recordMateSelection;
495 }
496
497//------------------------------------------------------------------------------
498
499 public int getPrecisionLevel()
500 {
501 return precisionLevel;
502 }
503
504//------------------------------------------------------------------------------
505
506 public int getNumberOfCPU()
507 {
508 return numParallelTasks;
509 }
510
511//------------------------------------------------------------------------------
512
513 public boolean isSortOrderDecreasing()
514 {
515 return sortOrderDecreasing;
516 }
517
518//------------------------------------------------------------------------------
519
521 {
523 }
524
525//------------------------------------------------------------------------------
526
527 public int getMaxTriesFactor()
528 {
529 return maxTriesPerPop;
530 }
531
532//------------------------------------------------------------------------------
533
535 {
537 }
538
539//------------------------------------------------------------------------------
540
541 public String getDataDirectory()
542 {
543 return dataDir;
544 }
545
546//------------------------------------------------------------------------------
547
548 public void setWorkingDirectory(String pathName)
549 {
550 dataDir = pathName;
551 monitorFile = dataDir + ".eaMonitor";
552 interfaceDir = pathName + DENOPTIMConstants.FSEP + "interface";
553
554 logFile = dataDir + ".log";
555
556 if (uidFileOut.equals(""))
557 {
558 uidFileOut = dataDir + DENOPTIMConstants.FSEP + DEFUIDFILEOUTNAME;
559 }
560 }
561
562//------------------------------------------------------------------------------
563
565 {
566 return replacementStrategy;
567 }
568
569//------------------------------------------------------------------------------
570
575 public boolean parentsSurvive()
576 {
577 return parentsSurvive;
578 }
579
580//------------------------------------------------------------------------------
581
583 {
585 }
586
587//------------------------------------------------------------------------------
588
590 {
591 return crowdingSigmaMiddle;
592 }
593
594//------------------------------------------------------------------------------
595
596 public double getCrowdingMultiplier()
597 {
598 return crowdingMultiplier;
599 }
600
601//------------------------------------------------------------------------------
602
604 {
606 }
607
608//------------------------------------------------------------------------------
609
611 {
613 }
614
615//------------------------------------------------------------------------------
616
618 {
620 }
621
622//------------------------------------------------------------------------------
623
624 public double getGrowthMultiplier()
625 {
626 return lvlGrowthMultiplier;
627 }
628
629//------------------------------------------------------------------------------
630
632 {
634 }
635
636//------------------------------------------------------------------------------
637
639 {
641 }
642
643//------------------------------------------------------------------------------
644
646 {
648 }
649
650//------------------------------------------------------------------------------
651
653 {
654 return molGrowthMultiplier;
655 }
656
657//------------------------------------------------------------------------------
658
660 {
662 }
663
664//------------------------------------------------------------------------------
665
666 public void setPopulationSize(int size)
667 {
668 populationSize = size;
669 }
670
671//------------------------------------------------------------------------------
672
673 public int getPopulationSize()
674 {
675 return populationSize;
676 }
677
678//------------------------------------------------------------------------------
679
681 {
682 return numGenerations;
683 }
684
685//------------------------------------------------------------------------------
686
687 public String getSelectionStrategy()
688 {
690 }
691
692 //------------------------------------------------------------------------------
693
695 {
696 return selectivePressure;
697 }
698
699//------------------------------------------------------------------------------
700
701 public List<MutationType> getExcludedMutationTypes()
702 {
704 }
705
706//------------------------------------------------------------------------------
707
709 {
710 return xoverSelectionMode;
711 }
712
713//------------------------------------------------------------------------------
714
716 {
717 return numConvGen;
718 }
719
720//------------------------------------------------------------------------------
721
723 {
724 return numOfChildren;
725 }
726
727//------------------------------------------------------------------------------
728
729 public double getCrossoverWeight()
730 {
731 return crossoverWeight;
732 }
733
734//------------------------------------------------------------------------------
735
741 {
743 }
744
745//------------------------------------------------------------------------------
746
751 public boolean keepBestSibling()
752 {
753 return keepBestSibling;
754 }
755
756//------------------------------------------------------------------------------
757
758 public double getMutationWeight()
759 {
760 return mutationWeight;
761 }
762
763//------------------------------------------------------------------------------
764
765 public double getConstructionWeight()
766 {
767 return builtAnewWeight;
768 }
769
770//------------------------------------------------------------------------------
771
773 {
775 }
776
777//------------------------------------------------------------------------------
778
780 {
781 return initPoplnFile;
782 }
783
784//------------------------------------------------------------------------------
785
791 {
793 }
794
795//------------------------------------------------------------------------------
796
798 {
800 }
801
802//------------------------------------------------------------------------------
803
804 public boolean useMolSizeBasedProb()
805 {
806 return useMolSizeBasedProb;
807 }
808
809//------------------------------------------------------------------------------
810
811 public boolean useLevelBasedProb()
812 {
813 return useLevelBasedProb;
814 }
815
816//-----------------------------------------------------------------------------
817
819 {
821 }
822
823//-----------------------------------------------------------------------------
824
825 public double getMinFitnessSD()
826 {
827 return minFitnessSD;
828 }
829
830//-----------------------------------------------------------------------------
831
832 public boolean dumpMonitor()
833 {
834 return dumpMonitor;
835 }
836
837//-----------------------------------------------------------------------------
838
840 {
842 }
843
844//-----------------------------------------------------------------------------
845
847 {
849 }
850
851//-----------------------------------------------------------------------------
852
854 {
856 }
857
858//-----------------------------------------------------------------------------
859
867 {
869 }
870
871//------------------------------------------------------------------------------
872
880 public void interpretKeyword(String key, String value)
881 throws DENOPTIMException
882 {
883 String msg = "";
884 switch (key.toUpperCase())
885 {
886 case "VERBOSITY=":
887 {
888 verbosity = Integer.parseInt(value);
889 break;
890 }
891
892 case "NUMPARALLELTASKS=":
893 {
894 if (value.length() > 0)
895 {
896 numParallelTasks = Integer.parseInt(value);
897 }
898 break;
899 }
900
901 case "PARALLELIZATION=":
902 {
903 switch (value.toUpperCase())
904 {
905 case "SYNCHRONOUS":
907 break;
908 case "ASYNCHRONOUS":
910 break;
911 default:
912 throw new DENOPTIMException("Unknown parallelization scheme.");
913 }
914 break;
915 }
916
917 case "PRECISIONLEVEL=":
918 {
919 if (value.length() > 0)
920 {
921 precisionLevel = Integer.parseInt(value);
922 }
923 break;
924 }
925
926 case "UIDFILEIN=":
927 {
928 if (value.length() > 0)
929 {
930 uidFileIn = value;
931 }
932 break;
933 }
934
935 case "UIDFILEOUT=":
936 {
937 if (value.length() > 0)
938 {
939 uidFileOut = value;
940 }
941 break;
942 }
943
944 case "MONITORFILE=":
945 {
946 if (value.length() > 0)
947 {
948 monitorFile = value;
949 }
950 break;
951 }
952
953 case "RECORDMATESELECTION=":
954 {
955 if (value.length() > 0)
956 {
958 }
959 break;
960 }
961
962 case "MONITORDUMPSTEP=":
963 {
964 if (value.length() > 0)
965 {
966 monitorDumpStep = Integer.parseInt(value);
967 dumpMonitor = true;
968 }
969 break;
970 }
971
972 case "RANDOMSEED=":
973 {
974 if (value.length() > 0)
975 {
976 seed = Long.parseLong(value);
977 }
978 break;
979 }
980
981 case "MAXTRIESPERPOPULATION=":
982 {
983 if (value.length() > 0)
984 maxTriesPerPop = Integer.parseInt(value);
985 break;
986 }
987
988 case "MAXGENETICOPSATTEMPTS=":
989 {
990 if (value.length() > 0)
991 maxGeneticOpAttempts = Integer.parseInt(value);
992 break;
993 }
994
995 case "INITPOPLNFILE=":
996 {
997 if (value.length() > 0)
998 {
999 initPoplnFile = value;
1000 }
1001 break;
1002 }
1003
1004 case "INITMOLSTOFRAGMENTFILE=":
1005 {
1006 if (value.length() > 0)
1007 {
1008 initMolsToFragmentFile = value;
1009 }
1010 break;
1011 }
1012
1013 case "SORTBYINCREASINGFITNESS":
1014 {
1015 sortOrderDecreasing = false;
1016 break;
1017 }
1018
1019 case "NANFITNESSKILLSEXPERIMENT":
1020 {
1022 }
1023
1024 case "LEVELGROWTHMULTIPLIER=":
1025 {
1026 if (value.length() > 0)
1027 {
1028 lvlGrowthMultiplier = Double.parseDouble(value);
1029 useLevelBasedProb = true;
1030 }
1031 break;
1032 }
1033
1034 case "LEVELGROWTHSIGMASTEEPNESS=":
1035 {
1036 if (value.length() > 0)
1037 {
1038 lvlGrowthSigmaSteepness = Double.parseDouble(value);
1039 useLevelBasedProb = true;
1040 }
1041 break;
1042 }
1043
1044 case "LEVELGROWTHSIGMAMIDDLE=":
1045 {
1046 if (value.length() > 0)
1047 {
1048 lvlGrowthSigmaMiddle = Double.parseDouble(value);
1049 useLevelBasedProb = true;
1050 }
1051 break;
1052 }
1053
1054 case "LEVELGROWTHPROBSCHEME=":
1055 {
1057 useLevelBasedProb = true;
1058 break;
1059 }
1060
1061 case "MOLGROWTHMULTIPLIER=":
1062 {
1063 if (value.length() > 0)
1064 {
1065 molGrowthMultiplier = Double.parseDouble(value);
1066 useMolSizeBasedProb = true;
1067 }
1068 break;
1069 }
1070
1071 case "MOLGROWTHSIGMASTEEPNESS=":
1072 {
1073 if (value.length() > 0)
1074 {
1075 molGrowthSigmaSteepness = Double.parseDouble(value);
1076 useMolSizeBasedProb = true;
1077 }
1078 break;
1079 }
1080
1081 case "MOLGROWTHSIGMAMIDDLE=":
1082 {
1083 if (value.length() > 0)
1084 {
1085 molGrowthSigmaMiddle = Double.parseDouble(value);
1086 useMolSizeBasedProb = true;
1087 }
1088 break;
1089 }
1090
1091 case "MOLGROWTHPROBSCHEME=":
1092 {
1094 useMolSizeBasedProb = true;
1095 break;
1096 }
1097
1098 case "CROWDMULTIPLIER=":
1099 {
1100 if (value.length() > 0)
1101 {
1102 crowdingMultiplier = Double.parseDouble(value);
1103 }
1104 break;
1105 }
1106
1107 case "CROWDSIGMASTEEPNESS=":
1108 {
1109 if (value.length() > 0)
1110 {
1111 crowdingSigmaSteepness = Double.parseDouble(value);
1112 }
1113 break;
1114 }
1115
1116 case "CROWDSIGMAMIDDLE=":
1117 {
1118 if (value.length() > 0)
1119 {
1120 crowdingSigmaMiddle = Double.parseDouble(value);
1121 }
1122 break;
1123 }
1124
1125 case "SYMMETRYPROBABILITY=":
1126 {
1127 if (value.length() > 0)
1128 {
1129 symmetricSubProbability = Double.parseDouble(value);
1130 }
1131 break;
1132 }
1133
1134 case "CROWDPROBSCHEME=":
1135 {
1137 break;
1138 }
1139
1140 case "NUMGENERATIONS=":
1141 {
1142 if (value.length() > 0)
1143 {
1144 numGenerations = Integer.parseInt(value);
1145 }
1146 break;
1147 }
1148
1149 case "NUMCHILDREN=":
1150 {
1151 if (value.length() > 0)
1152 {
1153 numOfChildren = Integer.parseInt(value);
1154 }
1155 break;
1156 }
1157
1158 case "CROSSOVERWEIGHT=":
1159 {
1160 if (value.length() > 0)
1161 {
1162 crossoverWeight = Double.parseDouble(value);
1163 }
1164 break;
1165 }
1166
1167 case "MUTATIONWEIGHT=":
1168 {
1169 if (value.length() > 0)
1170 {
1171 mutationWeight = Double.parseDouble(value);
1172 }
1173 break;
1174 }
1175
1176 case "COUPLEMUTATIONTOCROSSOVER=":
1177 {
1178 if (value.length() > 0)
1179 {
1181 }
1182 break;
1183 }
1184
1185 case "PARENTSSURVIVE=":
1186 {
1187 if (value.length() > 0)
1188 {
1190 }
1191 break;
1192 }
1193
1194 case "EXCLUDEMUTATIONTYPE=":
1195 {
1196 if (value.length() > 0)
1197 {
1198 excludedMutationTypes.add(MutationType.valueOf(value));
1199 }
1200 break;
1201 }
1202
1203 case "CONSTRUCTIONWEIGHT=":
1204 {
1205 if (value.length() > 0)
1206 {
1207 builtAnewWeight = Double.parseDouble(value);
1208 }
1209 break;
1210 }
1211
1212 case "REPLACEMENTSTRATEGY=":
1213 {
1214 switch (value.toUpperCase())
1215 {
1216 case "NONE":
1218 break;
1219 case "ELITIST":
1221 break;
1222 default:
1223 throw new DENOPTIMException("Unknown replacement strategy.");
1224 }
1225 break;
1226 }
1227
1228 case "POPULATIONSIZE=":
1229 {
1230 if (value.length() > 0)
1231 {
1232 populationSize = Integer.parseInt(value);
1233 }
1234 break;
1235 }
1236
1237 case "NUMCONVGEN=":
1238 {
1239 if (value.length() > 0)
1240 {
1241 numConvGen = Integer.parseInt(value);
1242 }
1243 break;
1244 }
1245
1246 case "MAXRINGSADDEDBYMUTATION=":
1247 {
1248 if (value.length() > 0)
1249 {
1250 maxRingsAddedByMutation = Integer.parseInt(value);
1251 }
1252 break;
1253 }
1254
1255 case "KEEPNEWRINGSYSTEMVERTEXES":
1256 {
1258 break;
1259 }
1260
1261 case "KEEPNEWRINGSYSTEMSCAFFOLDS":
1262 {
1264 break;
1265 }
1266
1267 case "KEEPNEWRINGSYSTEMFITNESSTRSH=":
1268 {
1269 if (value.length() > 0)
1270 {
1271 saveRingSystemsFitnessThreshold = Double.parseDouble(value);
1272 }
1273 break;
1274 }
1275
1276 case "MULTISITEMUTATIONWEIGHTS=":
1277 {
1278 String[] ws = value.split(",|\\s+");
1279 List<Double> lst = new ArrayList<Double>();
1280 for (String w : ws)
1281 {
1282 if (!w.trim().equals(""))
1283 lst.add(Double.parseDouble(w));
1284 }
1285 mutliSiteMutationWeights = new double[lst.size()];
1286 for (int i=0; i<lst.size(); i++)
1287 {
1288 mutliSiteMutationWeights[i] = lst.get(i);
1289 }
1290 break;
1291 }
1292
1293 case "XOVERSELECTIONMODE=":
1294 {
1295 if (value.length() > 0)
1296 {
1297 xoverSelectionMode = -1;
1298 if (value.compareToIgnoreCase("TS") == 0)
1299 {
1301 strXoverSelectionMode = "TOURNAMENT";
1302 } else if (value.compareToIgnoreCase("RW") == 0)
1303 {
1305 strXoverSelectionMode = "ROULETTE WHEEL";
1306 } else if (value.compareToIgnoreCase("SUS") == 0)
1307 {
1309 strXoverSelectionMode = "STOCHASTIC UNIVERSAL SAMPLING";
1310 } else if (value.compareToIgnoreCase("RANDOM") == 0)
1311 {
1313 strXoverSelectionMode = "RANDOM";
1314 } else {
1315 throw new DENOPTIMException("ERROR! String '"
1316 + value + "' cannot be interpreted as a "
1317 + "parent selection strategy.");
1318 }
1319 }
1320 break;
1321 }
1322
1323 case "SELECTIVEPRESSURE=":
1324 {
1325 if (value.length() > 0)
1326 {
1327 selectivePressure = Integer.parseInt(value);
1328 }
1329 break;
1330 }
1331
1332
1333 case "NUMOFFSPRINGFROMXOVER=":
1334 {
1335 if (value.length() > 0)
1336 {
1337 maxOffsprintFromXover = Integer.parseInt(value);
1339 throw new DENOPTIMException("ERROR! Can only generate "
1340 + "up to 2 offspring from crossover, but you "
1341 + "required " + maxOffsprintFromXover);
1342 }
1343 break;
1344 }
1345
1346 case "KEEPBESTSIBLING=":
1347 {
1349 break;
1350 }
1351
1352 case "MUTATEDGRAPHCHECKFAILTOLERANT=":
1353 {
1355 break;
1356 }
1357
1358 case "XOVERGRAPHCHECKFAILTOLERANT=":
1359 {
1361 break;
1362 }
1363
1364 case "MUTATIONFAILURETOLERANT=":
1365 {
1367 break;
1368 }
1369
1370 case "XOVERFAILURETOLERANT=":
1371 {
1373 break;
1374 }
1375
1376 case "BUILDFAILURETOLERANT=":
1377 {
1379 break;
1380 }
1381
1382 case "MAXXOVERSUBGRAPHSIZE=":
1383 {
1384 if (value.length() > 0)
1385 {
1386 maxXOverableSubGraphSize = Integer.parseInt(value);
1387 }
1388 break;
1389 }
1390
1391 case "WRITEPOPULATIONTOFILE":
1392 {
1393 writePopOnDisk = true;
1394 break;
1395 }
1396
1397 default:
1398 msg = "Keyword " + key + " is not a known GeneticAlgorithm-"
1399 + "related keyword. Check input files.";
1400 throw new DENOPTIMException(msg);
1401 }
1402 }
1403
1404//------------------------------------------------------------------------------
1405
1406 public static int convertProbabilityScheme(String option)
1407 throws DENOPTIMException
1408 {
1409 int res = 0;
1410 switch (option.toUpperCase())
1411 {
1412 case "EXP_DIFF":
1413 res = 0;
1414 break;
1415 case "TANH":
1416 res = 1;
1417 break;
1418 case "SIGMA":
1419 res = 2;
1420 break;
1421 case "UNRESTRICTED":
1422 res = 3;
1423 break;
1424 default:
1425 throw new DENOPTIMException(
1426 "Unknown growth probability scheme.");
1427 }
1428 return res;
1429 }
1430
1431//-----------------------------------------------------------------------------
1432
1439 {
1440 String cdataDir = dataDir;
1441 boolean success = false;
1442 while (!success)
1443 {
1444 SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddkkmmss");
1445 timeStamp = sdf.format(new Date());
1446 String str = "RUN" + timeStamp;
1447 dataDir = cdataDir + DENOPTIMConstants.FSEP + str;
1448 success = denoptim.files.FileUtils.createDirectory(dataDir);
1449 }
1451 if (!denoptim.files.FileUtils.createDirectory(interfaceDir))
1452 {
1453 throw new DENOPTIMException("ERROR! Unable to make interface "
1454 + "folder '" + interfaceDir + "'");
1455 }
1456 denoptim.files.FileUtils.addToRecentFiles(dataDir, FileFormat.GA_RUN);
1457 }
1458
1459//------------------------------------------------------------------------------
1460
1467 {
1468 if (isMaster)
1470
1471 if (seed == 0)
1472 {
1474 seed = getRandomSeed();
1475 } else {
1477 }
1478
1479 int nproc = Runtime.getRuntime().availableProcessors();
1480 if (numParallelTasks == 0)
1481 {
1482 numParallelTasks = nproc;
1483 }
1484
1485 if (selectivePressure<0)
1486 selectivePressure = (int) Math.round(populationSize * 0.2);
1487
1489
1491 {
1494 if (!rcParams.allowRingClosures())
1495 {
1498 }
1499 }
1500
1501 if (isMaster)
1502 {
1503 StaticLogger.appLogger.log(Level.INFO, "Program log file: "
1505 + "Output files associated with the current run are "
1506 + "located in " + dataDir);
1507 }
1508 }
1509
1510//------------------------------------------------------------------------------
1511
1513 {
1514 String error = "";
1515 //TODO: use something like the following for checking the parameters:
1516 //ensureIsPositive("GA-NUMOFFSPRING", numOfChildren, "blabla");
1517 if (numOfChildren <= 0)
1518 {
1519 error = "Number of children must be a positive number.";
1520 throw new DENOPTIMException(error);
1521 }
1522 if (numGenerations <= 0)
1523 {
1524 error = "Number of generations must be a positive number.";
1525 throw new DENOPTIMException(error);
1526 }
1527
1528 if (numConvGen <= 0)
1529 {
1530 error = "Number of convergence iterations must be a positive "
1531 + "number.";
1532 throw new DENOPTIMException(error);
1533 }
1534
1535 if (symmetricSubProbability < 0. ||
1537 {
1538 error = "Symmetric molecule probability must be between 0 and 1.";
1539 throw new DENOPTIMException(error);
1540 }
1541
1542 if (mutationWeight < 0.)
1543 {
1544 error = "Weight of mutation must be a positive number";
1545 throw new DENOPTIMException(error);
1546 }
1547
1548 if (crossoverWeight < 0.)
1549 {
1550 error = "Weight of crossover must be a positive number";
1551 throw new DENOPTIMException(error);
1552 }
1553
1554 if (builtAnewWeight < 0.)
1555 {
1556 error = "Weight of construction must be a positive number";
1557 throw new DENOPTIMException(error);
1558 }
1559
1560 if (initPoplnFile.length() > 0)
1561 {
1562 if (!denoptim.files.FileUtils.checkExists(initPoplnFile))
1563 {
1564 error = "Cannot find initial population data: " + initPoplnFile;
1565 throw new DENOPTIMException(error);
1566 }
1567 }
1568
1569 if (initMolsToFragmentFile!=null && initMolsToFragmentFile.length() > 0)
1570 {
1571 if (!denoptim.files.FileUtils.checkExists(initMolsToFragmentFile))
1572 {
1573 throw new DENOPTIMException("Cannot find initial molecules to "
1574 + "fragment: " + initMolsToFragmentFile);
1575 }
1576 }
1577
1578 if (replacementStrategy < 0 || replacementStrategy > 2)
1579 {
1580 error = "Allowed values for replacementStrategy (1-2)";
1581 throw new DENOPTIMException(error);
1582 }
1583
1585 {
1586 error = "Cannot use both graph level or molecular size as criterion "
1587 + "for controlling the growth of graphs. "
1588 + "Please, use either of them.";
1589 throw new DENOPTIMException(error);
1590 } else if (!useMolSizeBasedProb && !useLevelBasedProb) {
1591 useMolSizeBasedProb = true;
1592 }
1594 }
1595
1596//------------------------------------------------------------------------------
1597
1604 public String getPrintedList()
1605 {
1606 StringBuilder sb = new StringBuilder(1024);
1607 sb.append(" " + paramTypeName() + " ").append(NL);
1608 for (Field f : this.getClass().getDeclaredFields())
1609 {
1610 try
1611 {
1612 sb.append(f.getName()).append(" = ").append(
1613 f.get(this)).append(NL);
1614 }
1615 catch (Throwable t)
1616 {
1617 sb.append("ERROR! Unable to print " + paramTypeName()
1618 + " parameters. Cause: " + t);
1619 break;
1620 }
1621 }
1622 for (RunTimeParameters otherCollector : otherParameters.values())
1623 {
1624 sb.append(otherCollector.getPrintedList());
1625 }
1626 return sb.toString();
1627 }
1628
1629//------------------------------------------------------------------------------
1630
1635 public boolean savePopFile()
1636 {
1637 return writePopOnDisk;
1638 }
1639
1640//------------------------------------------------------------------------------
1641
1648 {
1650 }
1651
1652//------------------------------------------------------------------------------
1653
1654}
General set of constants used in DENOPTIM.
static final String EOL
new line character
Parameters and setting related to handling ring closures.
Logger class for DENOPTIM.
static final Logger appLogger
Collection of parameters controlling the behavior of the software.
Map< ParametersType, RunTimeParameters > otherParameters
Collection of other parameters by type.
boolean isMaster
Flag signaling this is the master collection of parameters.
boolean containsParameters(ParametersType type)
static boolean readYesNoTrueFalse(String s)
Reads a string searching for any common way to say either yes/true (including shorthand t/y) or no/fa...
RunTimeParameters getParameters(ParametersType type)
String paramTypeName()
Returns a string defining the type the parameters collected here.
void checkOtherParameters()
Checks any of the parameter collections contained in this instance.
final String NL
New line character.
Randomizer startRandomizer()
Starts a program specific randomizer, i.e., a tool for generating random numbers and taking random de...
void processOtherParameters()
Processes any of the parameter collections contained in this instance.
int verbosity
Verbosity level for logger.
Parameters for genetic algorithm.
boolean buildAnewFailureTolerant
Flag that enables the ignoring of construction from scratch events triggering exceptions.
int maxRingsAddedByMutation
Maximum number of rings added by a single mutation operation.
int monitorDumpStep
Monitor dumps step.
boolean saveRingSystemsAsTemplatesScaffolds
Flag controlling the possibility of collecting cyclic graph systems that include a scaffold and save ...
int maxXOverableSubGraphSize
Limit to the size of subgraphs that are exchanged during crossover.
int xoverSelectionMode
Crossover parents selection strategy: integer code.
void interpretKeyword(String key, String value)
Processes a keyword/value pair and assign the related parameters.
boolean useMolSizeBasedProb
Flag recording the intention to use molecular size-controlled graph extension probability.
double symmetricSubProbability
The probability at which symmetric substitution occurs.
boolean mutationFailureTolerant
Flag that enables the ignoring of mutation events triggering exceptions.
boolean recordMateSelection
Flag defining whether we record which mates are selected or not.
double lvlGrowthSigmaMiddle
Parameters controlling the growth probability function of type 'SIGMA': level at which p=50% (can be ...
int parallelizationScheme
Parallelization scheme: synchronous or asynchronous.
int maxOffsprintFromXover
Number of offspring that a single crossover operation can produce.
int lvlGrowthProbabilityScheme
Definition of the growth probability function:
boolean saveRingSystemsAsTemplatesNonScaff
Flag controlling the possibility of collecting cyclic graph systems that do NOT include a scaffold an...
boolean dumpMonitor
Flag controlling if we dump monitored data or not.
boolean sortOrderDecreasing
Flag controlling how to sort the population based on the fitness.
String timeStamp
Time stamp identifying this run.
long seed
The seed value for random number generation.
String visitedGraphsFile
Pathname to the file containing the list of previously visited graph.
int maxUIDMemory
Maximum number of unique identifiers kept in memory.
static int convertProbabilityScheme(String option)
int numConvGen
Number of identical generations before convergence is reached.
String monitorFile
Pathname of file where EA monitors dumps are printed.
final String DEFUIDFILEOUTNAME
Default name of the UIDFileOut.
boolean nanFitnessKillsExperiment
Flag controlling whether we allow NaN fitness to kill design experiments.
boolean mutatedGraphFailedEvalTolerant
Flag that enables the ignoring of mutated graphs that lead to a failure in the evaluation of graphs t...
boolean useLevelBasedProb
Flag recording the intention to use level-controlled graph extension probability.
boolean parentsSurvive
Flag defining if population members can survive multiple generations (when this variable is true) or ...
int getMaxRingsAddedByMutation()
Return the value of the number of rings that we are allowed to add in a single MutationType#ADDRING m...
boolean keepBestSibling
Flag controlling if we choose the best sibling out of crossover.
double lvlGrowthSigmaSteepness
Parameters controlling the growth probability function of type 'SIGMA': steepness of the function whe...
String getPrintedList()
Returns the list of parameters in a string with newline characters as delimiters.
double crowdingSigmaMiddle
Parameters controlling the crowding probability function of type 'SIGMA': level at which p=50% (can b...
String uidMemoryOnDisk
Text file used to store unique identifiers beyond the limits of the memory (see GAParameters#maxUIDMe...
int numOfChildren
Number of children (i.e., new offspring) to be produced in each generation.
void checkParameters()
Evaluate consistency of input parameters.
int selectivePressure
Intensity for selecting high fitness parents.
double[] mutliSiteMutationWeights
The weights of multi-site mutations.
double crowdingMultiplier
Parameter controlling the crowding probability function of types 'EXP_DIFF' and 'TANH'.
boolean writePopOnDisk
Flag requesting to write a SDF file that collects all the population members each time we report the ...
double saveRingSystemsFitnessThreshold
Fitness threshold for adding template to building block libraries.
String dataDir
Pathname to the working directory for the current run.
double mutationWeight
The relative weight at which mutation is performed.
int numParallelTasks
Maximum number of parallel tasks.
int maxTriesPerPop
Factor controlling the maximum number of attempts to build a graph so that the maximum number of atte...
double molGrowthSigmaMiddle
Parameters controlling the molGrowth probability function of type 'SIGMA': level at which p=50% (can ...
int populationSize
Size of the population.
boolean coupleMutationAndCrossover
Flag defining if we want mutation to occur on offspring that result from crossover (i....
double builtAnewWeight
The relative weight at which construction from scratch is performed.
double molGrowthMultiplier
Parameter controlling the molGrowth probability function of types 'EXP_DIFF' and 'TANH'.
List< MutationType > getExcludedMutationTypes()
double minFitnessSD
Minimal standard deviation accepted in the fitness values of the initial population.
double crowdingSigmaSteepness
Parameters controlling the crowding probability function of type 'SIGMA': steepness of the function w...
int numGenerations
Maximum number of generations to run for.
double molGrowthSigmaSteepness
Parameters controlling the molGrowth probability function of type 'SIGMA': steepness of the function ...
String uidFileOut
Pathname of the file where the individuals unique identifiers will be recorded.
int crowdingProbabilityScheme
Definition of the crowding probability function.
String initPoplnFile
Pathname of the initial population file.
void createWorkingDirectory()
Create the directory that will store the output of the GA run.
String strXoverSelectionMode
Crossover parents selection strategy: string.
String interfaceDir
Pathname to the interface directory for the current run.
boolean xoverGraphFailedEvalTolerant
Flag that enables the ignoring of crossover-ed graphs that lead to a f ailure in the evaluation of gr...
boolean xoverFailureTolerant
Flag that enables the ignoring of crossover events triggering exceptions.
void processParameters()
Processes currently loaded fields.
double crossoverWeight
The relative weight at which crossover is performed.
String initMolsToFragmentFile
Pathname to the file collecting molecules to fragment to generate initial population.
double lvlGrowthMultiplier
Parameter controlling the growth probability function of types 'EXP_DIFF' and 'TANH'.
List< MutationType > excludedMutationTypes
Mutation types that are excluded everywhere.
void setWorkingDirectory(String pathName)
int replacementStrategy
Replacement strategy: 1) replace worst individuals with new ones that are better than the worst,...
int precisionLevel
Precision for reporting the value of the fitness.
int molGrowthProbabilityScheme
Definition of the molGrowth probability function:
String uidFileIn
Pathname of the file with the list of individuals unique identifiers that are initially known.
int maxGeneticOpAttempts
Maximum number of attempts to perform any genetic operation (i.e., either crossover or mutation) on a...
File formats identified by DENOPTIM.
Definition: FileFormat.java:32
GA_PARAMS
Parameters pertaining the genetic algorithm.
RC_PARAMS
Parameters pertaining to ring closures in graphs.
Types of mutation defined in relation to what happens to the target vertex (i.e., the actual mutation...
ADDFUSEDRING
Adds a subgraph that introduced a fused ring.
ADDRING
Creates a ring-closure to add a ring.