$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.utils.MutationType;
37
38
44public class GAParameters extends RunTimeParameters
45{
49 public String timeStamp = "NOTIMESTAMP";
50
54 private String dataDir = System.getProperty("user.dir");
55
60 private String interfaceDir = dataDir
61 + System.getProperty("file.separator") + "interface";
62
67 protected String initPoplnFile = "";
68
73 protected String initMolsToFragmentFile = null;
74
79 protected String uidFileIn = "";
80
85 protected String uidFileOut = "";
86
90 private String monitorFile = "";
91
95 private boolean recordMateSelection = false;
96
100 private final String DEFUIDFILEOUTNAME = "MOLUID.txt";
101
105 protected String visitedGraphsFile = "GRAPHS.txt";
106
110 protected int populationSize = 50;
111
116 protected int numOfChildren = 5;
117
121 protected int numConvGen = 5;
122
126 protected int numGenerations = 100;
127
132 protected int maxTriesPerPop = 25;
133
138 protected int maxGeneticOpAttempts = 100;
139
145 protected int replacementStrategy = 1;
146
153 protected boolean parentsSurvive = true;
154
158 protected int lvlGrowthProbabilityScheme = 0;
159
164 protected double lvlGrowthMultiplier = 0.5;
165
170 protected double lvlGrowthSigmaSteepness = 1.0;
171
176 protected double lvlGrowthSigmaMiddle = 2.5;
177
182 protected boolean useLevelBasedProb = false;
183
188 protected boolean useMolSizeBasedProb = false;
189
193 protected int molGrowthProbabilityScheme = 2;
194
199 protected double molGrowthMultiplier = 0.5;
200
205 protected double molGrowthSigmaSteepness = 0.2;
206
211 protected double molGrowthSigmaMiddle = 25;
212
218 protected int crowdingProbabilityScheme = 3;
219
224 protected double crowdingMultiplier = 0.5;
225
230 protected double crowdingSigmaSteepness = 1.0;
231
236 protected double crowdingSigmaMiddle = 2.5;
237
241 protected double symmetricSubProbability = 0.8;
242
246 protected double mutationWeight = 1.0;
247
254 protected boolean coupleMutationAndCrossover = false;
255
259 protected double builtAnewWeight = 1.0;
260
264 protected double crossoverWeight = 1.0;
265
269 protected int xoverSelectionMode = 3;
270
275
281 protected int selectivePressure = -1;
282
286 protected int maxOffsprintFromXover = 1;
287
291 protected boolean keepBestSibling = false;
292
296 List<MutationType> excludedMutationTypes = new ArrayList<MutationType>();
297
301 protected long seed = 0L;
302
306 protected int parallelizationScheme = 1;
307
311 protected int numParallelTasks = 0;
312
316 protected boolean sortOrderDecreasing = true;
317
321 protected boolean nanFitnessKillsExperiment = false;
322
326 protected int precisionLevel = 3;
327
332 protected int monitorDumpStep = 50;
333
337 protected boolean dumpMonitor = false;
338
342 protected double minFitnessSD = 0.000001;
343
347 protected int maxRingsAddedByMutation = 1;
348
353 protected boolean saveRingSystemsAsTemplatesScaffolds = false;
354
360 protected boolean saveRingSystemsAsTemplatesNonScaff = false;
361
368 protected double saveRingSystemsFitnessThreshold = 0.10;
369
373 private double[] mutliSiteMutationWeights = new double[]{0,10,1};
374
379 public int maxUIDMemory = 1000000;
380
385 public String uidMemoryOnDisk = "memory_UIDs.txt";
386
392 public boolean mutatedGraphFailedEvalTolerant = true;
393
400 public boolean xoverGraphFailedEvalTolerant = true;
401
406 public boolean xoverFailureTolerant = true;
407
412 public boolean mutationFailureTolerant = true;
413
419 public boolean buildAnewFailureTolerant = true;
420
425
430 protected boolean writePopOnDisk = false;
431
432//------------------------------------------------------------------------------
433
439 {
441 }
442
443//------------------------------------------------------------------------------
444
445 public String getUIDFileIn()
446 {
447 return uidFileIn;
448 }
449
450//------------------------------------------------------------------------------
451
452 public String getUIDFileOut()
453 {
454 return uidFileOut;
455 }
456
457//------------------------------------------------------------------------------
458
459 public String getVisitedGraphsFile()
460 {
461 return visitedGraphsFile;
462 }
463
464//------------------------------------------------------------------------------
465
466 public String getInterfaceDir()
467 {
468 return interfaceDir;
469 }
470
471//------------------------------------------------------------------------------
472
473 public String getMonitorFile()
474 {
475 return monitorFile;
476 }
477
478//------------------------------------------------------------------------------
479
481 {
482 return monitorDumpStep;
483 }
484
485//------------------------------------------------------------------------------
486
491 public boolean recordMateSelection()
492 {
493 return recordMateSelection;
494 }
495
496//------------------------------------------------------------------------------
497
498 public int getPrecisionLevel()
499 {
500 return precisionLevel;
501 }
502
503//------------------------------------------------------------------------------
504
505 public int getNumberOfCPU()
506 {
507 return numParallelTasks;
508 }
509
510//------------------------------------------------------------------------------
511
512 public boolean isSortOrderDecreasing()
513 {
514 return sortOrderDecreasing;
515 }
516
517//------------------------------------------------------------------------------
518
520 {
522 }
523
524//------------------------------------------------------------------------------
525
526 public int getMaxTriesFactor()
527 {
528 return maxTriesPerPop;
529 }
530
531//------------------------------------------------------------------------------
532
534 {
536 }
537
538//------------------------------------------------------------------------------
539
540 public String getDataDirectory()
541 {
542 return dataDir;
543 }
544
545//------------------------------------------------------------------------------
546
547 public void setWorkingDirectory(String pathName)
548 {
549 dataDir = pathName;
550 monitorFile = dataDir + ".eaMonitor";
551 interfaceDir = pathName + DENOPTIMConstants.FSEP + "interface";
552
553 logFile = dataDir + ".log";
554
555 if (uidFileOut.equals(""))
556 {
557 uidFileOut = dataDir + DENOPTIMConstants.FSEP + DEFUIDFILEOUTNAME;
558 }
559 }
560
561//------------------------------------------------------------------------------
562
564 {
565 return replacementStrategy;
566 }
567
568//------------------------------------------------------------------------------
569
574 public boolean parentsSurvive()
575 {
576 return parentsSurvive;
577 }
578
579//------------------------------------------------------------------------------
580
582 {
584 }
585
586//------------------------------------------------------------------------------
587
589 {
590 return crowdingSigmaMiddle;
591 }
592
593//------------------------------------------------------------------------------
594
595 public double getCrowdingMultiplier()
596 {
597 return crowdingMultiplier;
598 }
599
600//------------------------------------------------------------------------------
601
603 {
605 }
606
607//------------------------------------------------------------------------------
608
610 {
612 }
613
614//------------------------------------------------------------------------------
615
617 {
619 }
620
621//------------------------------------------------------------------------------
622
623 public double getGrowthMultiplier()
624 {
625 return lvlGrowthMultiplier;
626 }
627
628//------------------------------------------------------------------------------
629
631 {
633 }
634
635//------------------------------------------------------------------------------
636
638 {
640 }
641
642//------------------------------------------------------------------------------
643
645 {
647 }
648
649//------------------------------------------------------------------------------
650
652 {
653 return molGrowthMultiplier;
654 }
655
656//------------------------------------------------------------------------------
657
659 {
661 }
662
663//------------------------------------------------------------------------------
664
665 public void setPopulationSize(int size)
666 {
667 populationSize = size;
668 }
669
670//------------------------------------------------------------------------------
671
672 public int getPopulationSize()
673 {
674 return populationSize;
675 }
676
677//------------------------------------------------------------------------------
678
680 {
681 return numGenerations;
682 }
683
684//------------------------------------------------------------------------------
685
686 public String getSelectionStrategy()
687 {
689 }
690
691 //------------------------------------------------------------------------------
692
694 {
695 return selectivePressure;
696 }
697
698//------------------------------------------------------------------------------
699
700 public List<MutationType> getExcludedMutationTypes()
701 {
703 }
704
705//------------------------------------------------------------------------------
706
708 {
709 return xoverSelectionMode;
710 }
711
712//------------------------------------------------------------------------------
713
715 {
716 return numConvGen;
717 }
718
719//------------------------------------------------------------------------------
720
722 {
723 return numOfChildren;
724 }
725
726//------------------------------------------------------------------------------
727
728 public double getCrossoverWeight()
729 {
730 return crossoverWeight;
731 }
732
733//------------------------------------------------------------------------------
734
740 {
742 }
743
744//------------------------------------------------------------------------------
745
750 public boolean keepBestSibling()
751 {
752 return keepBestSibling;
753 }
754
755//------------------------------------------------------------------------------
756
757 public double getMutationWeight()
758 {
759 return mutationWeight;
760 }
761
762//------------------------------------------------------------------------------
763
764 public double getConstructionWeight()
765 {
766 return builtAnewWeight;
767 }
768
769//------------------------------------------------------------------------------
770
772 {
774 }
775
776//------------------------------------------------------------------------------
777
779 {
780 return initPoplnFile;
781 }
782
783//------------------------------------------------------------------------------
784
790 {
792 }
793
794//------------------------------------------------------------------------------
795
797 {
799 }
800
801//------------------------------------------------------------------------------
802
803 public boolean useMolSizeBasedProb()
804 {
805 return useMolSizeBasedProb;
806 }
807
808//------------------------------------------------------------------------------
809
810 public boolean useLevelBasedProb()
811 {
812 return useLevelBasedProb;
813 }
814
815//-----------------------------------------------------------------------------
816
818 {
820 }
821
822//-----------------------------------------------------------------------------
823
824 public double getMinFitnessSD()
825 {
826 return minFitnessSD;
827 }
828
829//-----------------------------------------------------------------------------
830
831 public boolean dumpMonitor()
832 {
833 return dumpMonitor;
834 }
835
836//-----------------------------------------------------------------------------
837
839 {
841 }
842
843//-----------------------------------------------------------------------------
844
846 {
848 }
849
850//-----------------------------------------------------------------------------
851
853 {
855 }
856
857//-----------------------------------------------------------------------------
858
866 {
868 }
869
870//------------------------------------------------------------------------------
871
879 public void interpretKeyword(String key, String value)
880 throws DENOPTIMException
881 {
882 String msg = "";
883 switch (key.toUpperCase())
884 {
885 case "VERBOSITY=":
886 {
887 verbosity = Integer.parseInt(value);
888 break;
889 }
890
891 case "NUMPARALLELTASKS=":
892 {
893 if (value.length() > 0)
894 {
895 numParallelTasks = Integer.parseInt(value);
896 }
897 break;
898 }
899
900 case "PARALLELIZATION=":
901 {
902 switch (value.toUpperCase())
903 {
904 case "SYNCHRONOUS":
906 break;
907 case "ASYNCHRONOUS":
909 break;
910 default:
911 throw new DENOPTIMException("Unknown parallelization scheme.");
912 }
913 break;
914 }
915
916 case "PRECISIONLEVEL=":
917 {
918 if (value.length() > 0)
919 {
920 precisionLevel = Integer.parseInt(value);
921 }
922 break;
923 }
924
925 case "UIDFILEIN=":
926 {
927 if (value.length() > 0)
928 {
929 uidFileIn = value;
930 }
931 break;
932 }
933
934 case "UIDFILEOUT=":
935 {
936 if (value.length() > 0)
937 {
938 uidFileOut = value;
939 }
940 break;
941 }
942
943 case "MONITORFILE=":
944 {
945 if (value.length() > 0)
946 {
947 monitorFile = value;
948 }
949 break;
950 }
951
952 case "RECORDMATESELECTION=":
953 {
954 if (value.length() > 0)
955 {
957 }
958 break;
959 }
960
961 case "MONITORDUMPSTEP=":
962 {
963 if (value.length() > 0)
964 {
965 monitorDumpStep = Integer.parseInt(value);
966 dumpMonitor = true;
967 }
968 break;
969 }
970
971 case "RANDOMSEED=":
972 {
973 if (value.length() > 0)
974 {
975 seed = Long.parseLong(value);
976 }
977 break;
978 }
979
980 case "MAXTRIESPERPOPULATION=":
981 {
982 if (value.length() > 0)
983 maxTriesPerPop = Integer.parseInt(value);
984 break;
985 }
986
987 case "MAXGENETICOPSATTEMPTS=":
988 {
989 if (value.length() > 0)
990 maxGeneticOpAttempts = Integer.parseInt(value);
991 break;
992 }
993
994 case "INITPOPLNFILE=":
995 {
996 if (value.length() > 0)
997 {
998 initPoplnFile = value;
999 }
1000 break;
1001 }
1002
1003 case "INITMOLSTOFRAGMENTFILE=":
1004 {
1005 if (value.length() > 0)
1006 {
1007 initMolsToFragmentFile = value;
1008 }
1009 break;
1010 }
1011
1012 case "SORTBYINCREASINGFITNESS":
1013 {
1014 sortOrderDecreasing = false;
1015 break;
1016 }
1017
1018 case "NANFITNESSKILLSEXPERIMENT":
1019 {
1021 }
1022
1023 case "LEVELGROWTHMULTIPLIER=":
1024 {
1025 if (value.length() > 0)
1026 {
1027 lvlGrowthMultiplier = Double.parseDouble(value);
1028 useLevelBasedProb = true;
1029 }
1030 break;
1031 }
1032
1033 case "LEVELGROWTHSIGMASTEEPNESS=":
1034 {
1035 if (value.length() > 0)
1036 {
1037 lvlGrowthSigmaSteepness = Double.parseDouble(value);
1038 useLevelBasedProb = true;
1039 }
1040 break;
1041 }
1042
1043 case "LEVELGROWTHSIGMAMIDDLE=":
1044 {
1045 if (value.length() > 0)
1046 {
1047 lvlGrowthSigmaMiddle = Double.parseDouble(value);
1048 useLevelBasedProb = true;
1049 }
1050 break;
1051 }
1052
1053 case "LEVELGROWTHPROBSCHEME=":
1054 {
1056 useLevelBasedProb = true;
1057 break;
1058 }
1059
1060 case "MOLGROWTHMULTIPLIER=":
1061 {
1062 if (value.length() > 0)
1063 {
1064 molGrowthMultiplier = Double.parseDouble(value);
1065 useMolSizeBasedProb = true;
1066 }
1067 break;
1068 }
1069
1070 case "MOLGROWTHSIGMASTEEPNESS=":
1071 {
1072 if (value.length() > 0)
1073 {
1074 molGrowthSigmaSteepness = Double.parseDouble(value);
1075 useMolSizeBasedProb = true;
1076 }
1077 break;
1078 }
1079
1080 case "MOLGROWTHSIGMAMIDDLE=":
1081 {
1082 if (value.length() > 0)
1083 {
1084 molGrowthSigmaMiddle = Double.parseDouble(value);
1085 useMolSizeBasedProb = true;
1086 }
1087 break;
1088 }
1089
1090 case "MOLGROWTHPROBSCHEME=":
1091 {
1093 useMolSizeBasedProb = true;
1094 break;
1095 }
1096
1097 case "CROWDMULTIPLIER=":
1098 {
1099 if (value.length() > 0)
1100 {
1101 crowdingMultiplier = Double.parseDouble(value);
1102 }
1103 break;
1104 }
1105
1106 case "CROWDSIGMASTEEPNESS=":
1107 {
1108 if (value.length() > 0)
1109 {
1110 crowdingSigmaSteepness = Double.parseDouble(value);
1111 }
1112 break;
1113 }
1114
1115 case "CROWDSIGMAMIDDLE=":
1116 {
1117 if (value.length() > 0)
1118 {
1119 crowdingSigmaMiddle = Double.parseDouble(value);
1120 }
1121 break;
1122 }
1123
1124 case "SYMMETRYPROBABILITY=":
1125 {
1126 if (value.length() > 0)
1127 {
1128 symmetricSubProbability = Double.parseDouble(value);
1129 }
1130 break;
1131 }
1132
1133 case "CROWDPROBSCHEME=":
1134 {
1136 break;
1137 }
1138
1139 case "NUMGENERATIONS=":
1140 {
1141 if (value.length() > 0)
1142 {
1143 numGenerations = Integer.parseInt(value);
1144 }
1145 break;
1146 }
1147
1148 case "NUMCHILDREN=":
1149 {
1150 if (value.length() > 0)
1151 {
1152 numOfChildren = Integer.parseInt(value);
1153 }
1154 break;
1155 }
1156
1157 case "CROSSOVERWEIGHT=":
1158 {
1159 if (value.length() > 0)
1160 {
1161 crossoverWeight = Double.parseDouble(value);
1162 }
1163 break;
1164 }
1165
1166 case "MUTATIONWEIGHT=":
1167 {
1168 if (value.length() > 0)
1169 {
1170 mutationWeight = Double.parseDouble(value);
1171 }
1172 break;
1173 }
1174
1175 case "COUPLEMUTATIONTOCROSSOVER=":
1176 {
1177 if (value.length() > 0)
1178 {
1180 }
1181 break;
1182 }
1183
1184 case "PARENTSSURVIVE=":
1185 {
1186 if (value.length() > 0)
1187 {
1189 }
1190 break;
1191 }
1192
1193 case "EXCLUDEMUTATIONTYPE=":
1194 {
1195 if (value.length() > 0)
1196 {
1197 excludedMutationTypes.add(MutationType.valueOf(value));
1198 }
1199 break;
1200 }
1201
1202 case "CONSTRUCTIONWEIGHT=":
1203 {
1204 if (value.length() > 0)
1205 {
1206 builtAnewWeight = Double.parseDouble(value);
1207 }
1208 break;
1209 }
1210
1211 case "REPLACEMENTSTRATEGY=":
1212 {
1213 switch (value.toUpperCase())
1214 {
1215 case "NONE":
1217 break;
1218 case "ELITIST":
1220 break;
1221 default:
1222 throw new DENOPTIMException("Unknown replacement strategy.");
1223 }
1224 break;
1225 }
1226
1227 case "POPULATIONSIZE=":
1228 {
1229 if (value.length() > 0)
1230 {
1231 populationSize = Integer.parseInt(value);
1232 }
1233 break;
1234 }
1235
1236 case "NUMCONVGEN=":
1237 {
1238 if (value.length() > 0)
1239 {
1240 numConvGen = Integer.parseInt(value);
1241 }
1242 break;
1243 }
1244
1245 case "MAXRINGSADDEDBYMUTATION=":
1246 {
1247 if (value.length() > 0)
1248 {
1249 maxRingsAddedByMutation = Integer.parseInt(value);
1250 }
1251 break;
1252 }
1253
1254 case "KEEPNEWRINGSYSTEMVERTEXES":
1255 {
1257 break;
1258 }
1259
1260 case "KEEPNEWRINGSYSTEMSCAFFOLDS":
1261 {
1263 break;
1264 }
1265
1266 case "KEEPNEWRINGSYSTEMFITNESSTRSH=":
1267 {
1268 if (value.length() > 0)
1269 {
1270 saveRingSystemsFitnessThreshold = Double.parseDouble(value);
1271 }
1272 break;
1273 }
1274
1275 case "MULTISITEMUTATIONWEIGHTS=":
1276 {
1277 String[] ws = value.split(",|\\s+");
1278 List<Double> lst = new ArrayList<Double>();
1279 for (String w : ws)
1280 {
1281 if (!w.trim().equals(""))
1282 lst.add(Double.parseDouble(w));
1283 }
1284 mutliSiteMutationWeights = new double[lst.size()];
1285 for (int i=0; i<lst.size(); i++)
1286 {
1287 mutliSiteMutationWeights[i] = lst.get(i);
1288 }
1289 break;
1290 }
1291
1292 case "XOVERSELECTIONMODE=":
1293 {
1294 if (value.length() > 0)
1295 {
1296 xoverSelectionMode = -1;
1297 if (value.compareToIgnoreCase("TS") == 0)
1298 {
1300 strXoverSelectionMode = "TOURNAMENT";
1301 } else if (value.compareToIgnoreCase("RW") == 0)
1302 {
1304 strXoverSelectionMode = "ROULETTE WHEEL";
1305 } else if (value.compareToIgnoreCase("SUS") == 0)
1306 {
1308 strXoverSelectionMode = "STOCHASTIC UNIVERSAL SAMPLING";
1309 } else if (value.compareToIgnoreCase("RANDOM") == 0)
1310 {
1312 strXoverSelectionMode = "RANDOM";
1313 } else {
1314 throw new DENOPTIMException("ERROR! String '"
1315 + value + "' cannot be interpreted as a "
1316 + "parent selection strategy.");
1317 }
1318 }
1319 break;
1320 }
1321
1322 case "SELECTIVEPRESSURE=":
1323 {
1324 if (value.length() > 0)
1325 {
1326 selectivePressure = Integer.parseInt(value);
1327 }
1328 break;
1329 }
1330
1331
1332 case "NUMOFFSPRINGFROMXOVER=":
1333 {
1334 if (value.length() > 0)
1335 {
1336 maxOffsprintFromXover = Integer.parseInt(value);
1338 throw new DENOPTIMException("ERROR! Can only generate "
1339 + "up to 2 offspring from crossover, but you "
1340 + "required " + maxOffsprintFromXover);
1341 }
1342 break;
1343 }
1344
1345 case "KEEPBESTSIBLING=":
1346 {
1348 break;
1349 }
1350
1351 case "MUTATEDGRAPHCHECKFAILTOLERANT=":
1352 {
1354 break;
1355 }
1356
1357 case "XOVERGRAPHCHECKFAILTOLERANT=":
1358 {
1360 break;
1361 }
1362
1363 case "MUTATIONFAILURETOLERANT=":
1364 {
1366 break;
1367 }
1368
1369 case "XOVERFAILURETOLERANT=":
1370 {
1372 break;
1373 }
1374
1375 case "BUILDFAILURETOLERANT=":
1376 {
1378 break;
1379 }
1380
1381 case "MAXXOVERSUBGRAPHSIZE=":
1382 {
1383 if (value.length() > 0)
1384 {
1385 maxXOverableSubGraphSize = Integer.parseInt(value);
1386 }
1387 break;
1388 }
1389
1390 case "WRITEPOPULATIONTOFILE":
1391 {
1392 writePopOnDisk = true;
1393 break;
1394 }
1395
1396 default:
1397 msg = "Keyword " + key + " is not a known GeneticAlgorithm-"
1398 + "related keyword. Check input files.";
1399 throw new DENOPTIMException(msg);
1400 }
1401 }
1402
1403//------------------------------------------------------------------------------
1404
1405 public static int convertProbabilityScheme(String option)
1406 throws DENOPTIMException
1407 {
1408 int res = 0;
1409 switch (option.toUpperCase())
1410 {
1411 case "EXP_DIFF":
1412 res = 0;
1413 break;
1414 case "TANH":
1415 res = 1;
1416 break;
1417 case "SIGMA":
1418 res = 2;
1419 break;
1420 case "UNRESTRICTED":
1421 res = 3;
1422 break;
1423 default:
1424 throw new DENOPTIMException(
1425 "Unknown growth probability scheme.");
1426 }
1427 return res;
1428 }
1429
1430//-----------------------------------------------------------------------------
1431
1438 {
1439 String cdataDir = dataDir;
1440 boolean success = false;
1441 while (!success)
1442 {
1443 SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddkkmmss");
1444 timeStamp = sdf.format(new Date());
1445 String str = "RUN" + timeStamp;
1446 dataDir = cdataDir + DENOPTIMConstants.FSEP + str;
1447 success = denoptim.files.FileUtils.createDirectory(dataDir);
1448 }
1450 if (!denoptim.files.FileUtils.createDirectory(interfaceDir))
1451 {
1452 throw new DENOPTIMException("ERROR! Unable to make interface "
1453 + "folder '" + interfaceDir + "'");
1454 }
1455 denoptim.files.FileUtils.addToRecentFiles(dataDir, FileFormat.GA_RUN);
1456 }
1457
1458//------------------------------------------------------------------------------
1459
1466 {
1467 if (isMaster)
1469
1470 if (seed == 0)
1471 {
1473 seed = getRandomSeed();
1474 } else {
1476 }
1477
1478 int nproc = Runtime.getRuntime().availableProcessors();
1479 if (numParallelTasks == 0)
1480 {
1481 numParallelTasks = nproc;
1482 }
1483
1484 if (selectivePressure<0)
1485 selectivePressure = (int) Math.round(populationSize * 0.2);
1486
1488
1490 {
1493 if (!rcParams.allowRingClosures())
1494 {
1497 }
1498 }
1499
1500 if (isMaster)
1501 {
1502 StaticLogger.appLogger.log(Level.INFO, "Program log file: "
1504 + "Output files associated with the current run are "
1505 + "located in " + dataDir);
1506 }
1507 }
1508
1509//------------------------------------------------------------------------------
1510
1512 {
1513 String error = "";
1514 //TODO: use something like the following for checking the parameters:
1515 //ensureIsPositive("GA-NUMOFFSPRING", numOfChildren, "blabla");
1516 if (numOfChildren <= 0)
1517 {
1518 error = "Number of children must be a positive number.";
1519 throw new DENOPTIMException(error);
1520 }
1521 if (numGenerations <= 0)
1522 {
1523 error = "Number of generations must be a positive number.";
1524 throw new DENOPTIMException(error);
1525 }
1526
1527 if (numConvGen <= 0)
1528 {
1529 error = "Number of convergence iterations must be a positive "
1530 + "number.";
1531 throw new DENOPTIMException(error);
1532 }
1533
1534 if (symmetricSubProbability < 0. ||
1536 {
1537 error = "Symmetric molecule probability must be between 0 and 1.";
1538 throw new DENOPTIMException(error);
1539 }
1540
1541 if (mutationWeight < 0.)
1542 {
1543 error = "Weight of mutation must be a positive number";
1544 throw new DENOPTIMException(error);
1545 }
1546
1547 if (crossoverWeight < 0.)
1548 {
1549 error = "Weight of crossover must be a positive number";
1550 throw new DENOPTIMException(error);
1551 }
1552
1553 if (builtAnewWeight < 0.)
1554 {
1555 error = "Weight of construction must be a positive number";
1556 throw new DENOPTIMException(error);
1557 }
1558
1559 if (initPoplnFile.length() > 0)
1560 {
1561 if (!denoptim.files.FileUtils.checkExists(initPoplnFile))
1562 {
1563 error = "Cannot find initial population data: " + initPoplnFile;
1564 throw new DENOPTIMException(error);
1565 }
1566 }
1567
1568 if (initMolsToFragmentFile!=null && initMolsToFragmentFile.length() > 0)
1569 {
1570 if (!denoptim.files.FileUtils.checkExists(initMolsToFragmentFile))
1571 {
1572 throw new DENOPTIMException("Cannot find initial molecules to "
1573 + "fragment: " + initMolsToFragmentFile);
1574 }
1575 }
1576
1577 if (replacementStrategy < 0 || replacementStrategy > 2)
1578 {
1579 error = "Allowed values for replacementStrategy (1-2)";
1580 throw new DENOPTIMException(error);
1581 }
1582
1584 {
1585 error = "Cannot use both graph level or molecular size as criterion "
1586 + "for controlling the growth of graphs. "
1587 + "Please, use either of them.";
1588 throw new DENOPTIMException(error);
1589 } else if (!useMolSizeBasedProb && !useLevelBasedProb) {
1590 useMolSizeBasedProb = true;
1591 }
1593 }
1594
1595//------------------------------------------------------------------------------
1596
1603 public String getPrintedList()
1604 {
1605 StringBuilder sb = new StringBuilder(1024);
1606 sb.append(" " + paramTypeName() + " ").append(NL);
1607 for (Field f : this.getClass().getDeclaredFields())
1608 {
1609 try
1610 {
1611 sb.append(f.getName()).append(" = ").append(
1612 f.get(this)).append(NL);
1613 }
1614 catch (Throwable t)
1615 {
1616 sb.append("ERROR! Unable to print " + paramTypeName()
1617 + " parameters. Cause: " + t);
1618 break;
1619 }
1620 }
1621 for (RunTimeParameters otherCollector : otherParameters.values())
1622 {
1623 sb.append(otherCollector.getPrintedList());
1624 }
1625 return sb.toString();
1626 }
1627
1628//------------------------------------------------------------------------------
1629
1634 public boolean savePopFile()
1635 {
1636 return writePopOnDisk;
1637 }
1638
1639//------------------------------------------------------------------------------
1640
1647 {
1649 }
1650
1651//------------------------------------------------------------------------------
1652
1653}
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.