$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 final String DEFUIDFILEOUTNAME = "MOLUID.txt";
97
101 protected String visitedGraphsFile = "GRAPHS.txt";
102
106 protected int populationSize = 50;
107
112 protected int numOfChildren = 5;
113
117 protected int numConvGen = 5;
118
122 protected int numGenerations = 100;
123
128 protected int maxTriesPerPop = 25;
129
134 protected int maxGeneticOpAttempts = 100;
135
141 protected int replacementStrategy = 1;
142
149 protected boolean parentsSurvive = true;
150
154 protected int lvlGrowthProbabilityScheme = 0;
155
160 protected double lvlGrowthMultiplier = 0.5;
161
166 protected double lvlGrowthSigmaSteepness = 1.0;
167
172 protected double lvlGrowthSigmaMiddle = 2.5;
173
178 protected boolean useLevelBasedProb = false;
179
184 protected boolean useMolSizeBasedProb = false;
185
189 protected int molGrowthProbabilityScheme = 2;
190
195 protected double molGrowthMultiplier = 0.5;
196
201 protected double molGrowthSigmaSteepness = 0.2;
202
207 protected double molGrowthSigmaMiddle = 25;
208
214 protected int crowdingProbabilityScheme = 3;
215
220 protected double crowdingMultiplier = 0.5;
221
226 protected double crowdingSigmaSteepness = 1.0;
227
232 protected double crowdingSigmaMiddle = 2.5;
233
237 protected double symmetricSubProbability = 0.8;
238
242 protected double mutationWeight = 1.0;
243
250 protected boolean coupleMutationAndCrossover = false;
251
255 protected double builtAnewWeight = 1.0;
256
260 protected double crossoverWeight = 1.0;
261
265 protected int xoverSelectionMode = 3;
266
271
275 protected int maxOffsprintFromXover = 1;
276
280 protected boolean keepBestSibling = false;
281
285 List<MutationType> excludedMutationTypes = new ArrayList<MutationType>();
286
290 protected long seed = 0L;
291
295 protected int parallelizationScheme = 1;
296
300 protected int numParallelTasks = 0;
301
305 protected boolean sortOrderDecreasing = true;
306
310 protected int precisionLevel = 3;
311
316 protected int monitorDumpStep = 50;
317
321 protected boolean dumpMonitor = false;
322
326 protected double minFitnessSD = 0.000001;
327
331 protected int maxRingsAddedByMutation = 1;
332
337 protected boolean saveRingSystemsAsTemplatesScaffolds = false;
338
344 protected boolean saveRingSystemsAsTemplatesNonScaff = false;
345
352 protected double saveRingSystemsFitnessThreshold = 0.10;
353
357 private double[] mutliSiteMutationWeights = new double[]{0,10,1};
358
363 public int maxUIDMemory = 1000000;
364
369 public String uidMemoryOnDisk = "memory_UIDs.txt";
370
376 public boolean mutatedGraphFailedEvalTolerant = true;
377
384 public boolean xoverGraphFailedEvalTolerant = true;
385
390 public boolean xoverFailureTolerant = true;
391
396 public boolean mutationFailureTolerant = true;
397
403 public boolean buildAnewFailureTolerant = true;
404
409
414 protected boolean writePopOnDisk = false;
415
416//------------------------------------------------------------------------------
417
423 {
425 }
426
427//------------------------------------------------------------------------------
428
429 public String getUIDFileIn()
430 {
431 return uidFileIn;
432 }
433
434//------------------------------------------------------------------------------
435
436 public String getUIDFileOut()
437 {
438 return uidFileOut;
439 }
440
441//------------------------------------------------------------------------------
442
443 public String getVisitedGraphsFile()
444 {
445 return visitedGraphsFile;
446 }
447
448//------------------------------------------------------------------------------
449
450 public String getInterfaceDir()
451 {
452 return interfaceDir;
453 }
454
455//------------------------------------------------------------------------------
456
457 public String getMonitorFile()
458 {
459 return monitorFile;
460 }
461
462//------------------------------------------------------------------------------
463
465 {
466 return monitorDumpStep;
467 }
468
469//------------------------------------------------------------------------------
470
471 public int getPrecisionLevel()
472 {
473 return precisionLevel;
474 }
475
476//------------------------------------------------------------------------------
477
478 public int getNumberOfCPU()
479 {
480 return numParallelTasks;
481 }
482
483//------------------------------------------------------------------------------
484
485 public boolean isSortOrderDecreasing()
486 {
487 return sortOrderDecreasing;
488 }
489
490//------------------------------------------------------------------------------
491
492 public int getMaxTriesFactor()
493 {
494 return maxTriesPerPop;
495 }
496
497//------------------------------------------------------------------------------
498
500 {
502 }
503
504//------------------------------------------------------------------------------
505
506 public String getDataDirectory()
507 {
508 return dataDir;
509 }
510
511//------------------------------------------------------------------------------
512
513 public void setWorkingDirectory(String pathName)
514 {
515 dataDir = pathName;
516 monitorFile = dataDir + ".eaMonitor";
517 interfaceDir = pathName + DENOPTIMConstants.FSEP + "interface";
518
519 logFile = dataDir + ".log";
520
521 if (uidFileOut.equals(""))
522 {
523 uidFileOut = dataDir + DENOPTIMConstants.FSEP + DEFUIDFILEOUTNAME;
524 }
525 }
526
527//------------------------------------------------------------------------------
528
530 {
531 return replacementStrategy;
532 }
533
534//------------------------------------------------------------------------------
535
540 public boolean parentsSurvive()
541 {
542 return parentsSurvive;
543 }
544
545//------------------------------------------------------------------------------
546
548 {
550 }
551
552//------------------------------------------------------------------------------
553
555 {
556 return crowdingSigmaMiddle;
557 }
558
559//------------------------------------------------------------------------------
560
561 public double getCrowdingMultiplier()
562 {
563 return crowdingMultiplier;
564 }
565
566//------------------------------------------------------------------------------
567
569 {
571 }
572
573//------------------------------------------------------------------------------
574
576 {
578 }
579
580//------------------------------------------------------------------------------
581
583 {
585 }
586
587//------------------------------------------------------------------------------
588
589 public double getGrowthMultiplier()
590 {
591 return lvlGrowthMultiplier;
592 }
593
594//------------------------------------------------------------------------------
595
597 {
599 }
600
601//------------------------------------------------------------------------------
602
604 {
606 }
607
608//------------------------------------------------------------------------------
609
611 {
613 }
614
615//------------------------------------------------------------------------------
616
618 {
619 return molGrowthMultiplier;
620 }
621
622//------------------------------------------------------------------------------
623
625 {
627 }
628
629//------------------------------------------------------------------------------
630
631 public void setPopulationSize(int size)
632 {
633 populationSize = size;
634 }
635
636//------------------------------------------------------------------------------
637
638 public int getPopulationSize()
639 {
640 return populationSize;
641 }
642
643//------------------------------------------------------------------------------
644
646 {
647 return numGenerations;
648 }
649
650//------------------------------------------------------------------------------
651
652 public String getSelectionStrategy()
653 {
655 }
656
657//------------------------------------------------------------------------------
658
659 public List<MutationType> getExcludedMutationTypes()
660 {
662 }
663
664//------------------------------------------------------------------------------
665
667 {
668 return xoverSelectionMode;
669 }
670
671//------------------------------------------------------------------------------
672
674 {
675 return numConvGen;
676 }
677
678//------------------------------------------------------------------------------
679
681 {
682 return numOfChildren;
683 }
684
685//------------------------------------------------------------------------------
686
687 public double getCrossoverWeight()
688 {
689 return crossoverWeight;
690 }
691
692//------------------------------------------------------------------------------
693
699 {
701 }
702
703//------------------------------------------------------------------------------
704
709 public boolean keepBestSibling()
710 {
711 return keepBestSibling;
712 }
713
714//------------------------------------------------------------------------------
715
716 public double getMutationWeight()
717 {
718 return mutationWeight;
719 }
720
721//------------------------------------------------------------------------------
722
723 public double getConstructionWeight()
724 {
725 return builtAnewWeight;
726 }
727
728//------------------------------------------------------------------------------
729
731 {
733 }
734
735//------------------------------------------------------------------------------
736
738 {
739 return initPoplnFile;
740 }
741
742//------------------------------------------------------------------------------
743
749 {
751 }
752
753//------------------------------------------------------------------------------
754
756 {
758 }
759
760//------------------------------------------------------------------------------
761
762 public boolean useMolSizeBasedProb()
763 {
764 return useMolSizeBasedProb;
765 }
766
767//------------------------------------------------------------------------------
768
769 public boolean useLevelBasedProb()
770 {
771 return useLevelBasedProb;
772 }
773
774//-----------------------------------------------------------------------------
775
777 {
779 }
780
781//-----------------------------------------------------------------------------
782
783 public double getMinFitnessSD()
784 {
785 return minFitnessSD;
786 }
787
788//-----------------------------------------------------------------------------
789
790 public boolean dumpMonitor()
791 {
792 return dumpMonitor;
793 }
794
795//-----------------------------------------------------------------------------
796
798 {
800 }
801
802//-----------------------------------------------------------------------------
803
805 {
807 }
808
809//-----------------------------------------------------------------------------
810
812 {
814 }
815
816//-----------------------------------------------------------------------------
817
825 {
827 }
828
829//------------------------------------------------------------------------------
830
838 public void interpretKeyword(String key, String value)
839 throws DENOPTIMException
840 {
841 String msg = "";
842 switch (key.toUpperCase())
843 {
844 case "VERBOSITY=":
845 {
846 verbosity = Integer.parseInt(value);
847 break;
848 }
849
850 case "NUMPARALLELTASKS=":
851 {
852 if (value.length() > 0)
853 {
854 numParallelTasks = Integer.parseInt(value);
855 }
856 break;
857 }
858
859 case "PARALLELIZATION=":
860 {
861 switch (value.toUpperCase())
862 {
863 case "SYNCHRONOUS":
865 break;
866 case "ASYNCHRONOUS":
868 break;
869 default:
870 throw new DENOPTIMException("Unknown parallelization scheme.");
871 }
872 break;
873 }
874
875 case "PRECISIONLEVEL=":
876 {
877 if (value.length() > 0)
878 {
879 precisionLevel = Integer.parseInt(value);
880 }
881 break;
882 }
883
884 case "UIDFILEIN=":
885 {
886 if (value.length() > 0)
887 {
888 uidFileIn = value;
889 }
890 break;
891 }
892
893 case "UIDFILEOUT=":
894 {
895 if (value.length() > 0)
896 {
897 uidFileOut = value;
898 }
899 break;
900 }
901
902 case "MONITORFILE=":
903 {
904 if (value.length() > 0)
905 {
906 monitorFile = value;
907 }
908 break;
909 }
910
911 case "MONITORDUMPSTEP=":
912 {
913 if (value.length() > 0)
914 {
915 monitorDumpStep = Integer.parseInt(value);
916 dumpMonitor = true;
917 }
918 break;
919 }
920
921 case "RANDOMSEED=":
922 {
923 if (value.length() > 0)
924 {
925 seed = Long.parseLong(value);
926 }
927 break;
928 }
929
930 case "MAXTRIESPERPOPULATION=":
931 {
932 if (value.length() > 0)
933 maxTriesPerPop = Integer.parseInt(value);
934 break;
935 }
936
937 case "MAXGENETICOPSATTEMPTS=":
938 {
939 if (value.length() > 0)
940 maxGeneticOpAttempts = Integer.parseInt(value);
941 break;
942 }
943
944 case "INITPOPLNFILE=":
945 {
946 if (value.length() > 0)
947 {
948 initPoplnFile = value;
949 }
950 break;
951 }
952
953 case "INITMOLSTOFRAGMENTFILE=":
954 {
955 if (value.length() > 0)
956 {
958 }
959 break;
960 }
961
962 case "SORTBYINCREASINGFITNESS":
963 {
964 if (value.length() > 0)
965 {
966 sortOrderDecreasing = false;
967 }
968 break;
969 }
970
971 case "LEVELGROWTHMULTIPLIER=":
972 {
973 if (value.length() > 0)
974 {
975 lvlGrowthMultiplier = Double.parseDouble(value);
976 useLevelBasedProb = true;
977 }
978 break;
979 }
980
981 case "LEVELGROWTHSIGMASTEEPNESS=":
982 {
983 if (value.length() > 0)
984 {
985 lvlGrowthSigmaSteepness = Double.parseDouble(value);
986 useLevelBasedProb = true;
987 }
988 break;
989 }
990
991 case "LEVELGROWTHSIGMAMIDDLE=":
992 {
993 if (value.length() > 0)
994 {
995 lvlGrowthSigmaMiddle = Double.parseDouble(value);
996 useLevelBasedProb = true;
997 }
998 break;
999 }
1000
1001 case "LEVELGROWTHPROBSCHEME=":
1002 {
1004 useLevelBasedProb = true;
1005 break;
1006 }
1007
1008 case "MOLGROWTHMULTIPLIER=":
1009 {
1010 if (value.length() > 0)
1011 {
1012 molGrowthMultiplier = Double.parseDouble(value);
1013 useMolSizeBasedProb = true;
1014 }
1015 break;
1016 }
1017
1018 case "MOLGROWTHSIGMASTEEPNESS=":
1019 {
1020 if (value.length() > 0)
1021 {
1022 molGrowthSigmaSteepness = Double.parseDouble(value);
1023 useMolSizeBasedProb = true;
1024 }
1025 break;
1026 }
1027
1028 case "MOLGROWTHSIGMAMIDDLE=":
1029 {
1030 if (value.length() > 0)
1031 {
1032 molGrowthSigmaMiddle = Double.parseDouble(value);
1033 useMolSizeBasedProb = true;
1034 }
1035 break;
1036 }
1037
1038 case "MOLGROWTHPROBSCHEME=":
1039 {
1041 useMolSizeBasedProb = true;
1042 break;
1043 }
1044
1045 case "CROWDMULTIPLIER=":
1046 {
1047 if (value.length() > 0)
1048 {
1049 crowdingMultiplier = Double.parseDouble(value);
1050 }
1051 break;
1052 }
1053
1054 case "CROWDSIGMASTEEPNESS=":
1055 {
1056 if (value.length() > 0)
1057 {
1058 crowdingSigmaSteepness = Double.parseDouble(value);
1059 }
1060 break;
1061 }
1062
1063 case "CROWDSIGMAMIDDLE=":
1064 {
1065 if (value.length() > 0)
1066 {
1067 crowdingSigmaMiddle = Double.parseDouble(value);
1068 }
1069 break;
1070 }
1071
1072 case "SYMMETRYPROBABILITY=":
1073 {
1074 if (value.length() > 0)
1075 {
1076 symmetricSubProbability = Double.parseDouble(value);
1077 }
1078 break;
1079 }
1080
1081 case "CROWDPROBSCHEME=":
1082 {
1084 break;
1085 }
1086
1087 case "NUMGENERATIONS=":
1088 {
1089 if (value.length() > 0)
1090 {
1091 numGenerations = Integer.parseInt(value);
1092 }
1093 break;
1094 }
1095
1096 case "NUMCHILDREN=":
1097 {
1098 if (value.length() > 0)
1099 {
1100 numOfChildren = Integer.parseInt(value);
1101 }
1102 break;
1103 }
1104
1105 case "CROSSOVERWEIGHT=":
1106 {
1107 if (value.length() > 0)
1108 {
1109 crossoverWeight = Double.parseDouble(value);
1110 }
1111 break;
1112 }
1113
1114 case "MUTATIONWEIGHT=":
1115 {
1116 if (value.length() > 0)
1117 {
1118 mutationWeight = Double.parseDouble(value);
1119 }
1120 break;
1121 }
1122
1123 case "COUPLEMUTATIONTOCROSSOVER=":
1124 {
1125 if (value.length() > 0)
1126 {
1128 }
1129 break;
1130 }
1131
1132 case "PARENTSSURVIVE=":
1133 {
1134 if (value.length() > 0)
1135 {
1137 }
1138 break;
1139 }
1140
1141 case "EXCLUDEMUTATIONTYPE=":
1142 {
1143 if (value.length() > 0)
1144 {
1145 excludedMutationTypes.add(MutationType.valueOf(value));
1146 }
1147 break;
1148 }
1149
1150 case "CONSTRUCTIONWEIGHT=":
1151 {
1152 if (value.length() > 0)
1153 {
1154 builtAnewWeight = Double.parseDouble(value);
1155 }
1156 break;
1157 }
1158
1159 case "REPLACEMENTSTRATEGY=":
1160 {
1161 switch (value.toUpperCase())
1162 {
1163 case "NONE":
1165 break;
1166 case "ELITIST":
1168 break;
1169 default:
1170 throw new DENOPTIMException("Unknown replacement strategy.");
1171 }
1172 break;
1173 }
1174
1175 case "POPULATIONSIZE=":
1176 {
1177 if (value.length() > 0)
1178 {
1179 populationSize = Integer.parseInt(value);
1180 }
1181 break;
1182 }
1183
1184 case "NUMCONVGEN=":
1185 {
1186 if (value.length() > 0)
1187 {
1188 numConvGen = Integer.parseInt(value);
1189 }
1190 break;
1191 }
1192
1193 case "MAXRINGSADDEDBYMUTATION=":
1194 {
1195 if (value.length() > 0)
1196 {
1197 maxRingsAddedByMutation = Integer.parseInt(value);
1198 }
1199 break;
1200 }
1201
1202 case "KEEPNEWRINGSYSTEMVERTEXES":
1203 {
1205 break;
1206 }
1207
1208 case "KEEPNEWRINGSYSTEMSCAFFOLDS":
1209 {
1211 break;
1212 }
1213
1214 case "KEEPNEWRINGSYSTEMFITNESSTRSH=":
1215 {
1216 if (value.length() > 0)
1217 {
1218 saveRingSystemsFitnessThreshold = Double.parseDouble(value);
1219 }
1220 break;
1221 }
1222
1223 case "MULTISITEMUTATIONWEIGHTS=":
1224 {
1225 String[] ws = value.split(",|\\s+");
1226 List<Double> lst = new ArrayList<Double>();
1227 for (String w : ws)
1228 {
1229 if (!w.trim().equals(""))
1230 lst.add(Double.parseDouble(w));
1231 }
1232 mutliSiteMutationWeights = new double[lst.size()];
1233 for (int i=0; i<lst.size(); i++)
1234 {
1235 mutliSiteMutationWeights[i] = lst.get(i);
1236 }
1237 break;
1238 }
1239
1240 case "XOVERSELECTIONMODE=":
1241 {
1242 if (value.length() > 0)
1243 {
1244 xoverSelectionMode = -1;
1245 if (value.compareToIgnoreCase("TS") == 0)
1246 {
1248 strXoverSelectionMode = "TOURNAMENT";
1249 } else if (value.compareToIgnoreCase("RW") == 0)
1250 {
1252 strXoverSelectionMode = "ROULETTE WHEEL";
1253 } else if (value.compareToIgnoreCase("SUS") == 0)
1254 {
1256 strXoverSelectionMode = "STOCHASTIC UNIVERSAL SAMPLING";
1257 } else if (value.compareToIgnoreCase("RANDOM") == 0)
1258 {
1260 strXoverSelectionMode = "RANDOM";
1261 } else {
1262 throw new DENOPTIMException("ERROR! String '"
1263 + value + "' cannot be interpreted as a "
1264 + "parent selection strategy.");
1265 }
1266 }
1267 break;
1268 }
1269
1270 case "NUMOFFSPRINGFROMXOVER=":
1271 {
1272 if (value.length() > 0)
1273 {
1274 maxOffsprintFromXover = Integer.parseInt(value);
1276 throw new DENOPTIMException("ERROR! Can only generate "
1277 + "up to 2 offspring from crossover, but you "
1278 + "required " + maxOffsprintFromXover);
1279 }
1280 break;
1281 }
1282
1283 case "KEEPBESTSIBLING=":
1284 {
1286 break;
1287 }
1288
1289 case "MUTATEDGRAPHCHECKFAILTOLERANT=":
1290 {
1292 break;
1293 }
1294
1295 case "XOVERGRAPHCHECKFAILTOLERANT=":
1296 {
1298 break;
1299 }
1300
1301 case "MUTATIONFAILURETOLERANT=":
1302 {
1304 break;
1305 }
1306
1307 case "XOVERFAILURETOLERANT=":
1308 {
1310 break;
1311 }
1312
1313 case "BUILDFAILURETOLERANT=":
1314 {
1316 break;
1317 }
1318
1319 case "MAXXOVERSUBGRAPHSIZE=":
1320 {
1321 if (value.length() > 0)
1322 {
1323 maxXOverableSubGraphSize = Integer.parseInt(value);
1324 }
1325 break;
1326 }
1327
1328 case "WRITEPOPULATIONTOFILE":
1329 {
1330 writePopOnDisk = true;
1331 break;
1332 }
1333
1334 default:
1335 msg = "Keyword " + key + " is not a known GeneticAlgorithm-"
1336 + "related keyword. Check input files.";
1337 throw new DENOPTIMException(msg);
1338 }
1339 }
1340
1341//------------------------------------------------------------------------------
1342
1343 public static int convertProbabilityScheme(String option)
1344 throws DENOPTIMException
1345 {
1346 int res = 0;
1347 switch (option.toUpperCase())
1348 {
1349 case "EXP_DIFF":
1350 res = 0;
1351 break;
1352 case "TANH":
1353 res = 1;
1354 break;
1355 case "SIGMA":
1356 res = 2;
1357 break;
1358 case "UNRESTRICTED":
1359 res = 3;
1360 break;
1361 default:
1362 throw new DENOPTIMException(
1363 "Unknown growth probability scheme.");
1364 }
1365 return res;
1366 }
1367
1368//-----------------------------------------------------------------------------
1369
1376 {
1377 String cdataDir = dataDir;
1378 boolean success = false;
1379 while (!success)
1380 {
1381 SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddkkmmss");
1382 timeStamp = sdf.format(new Date());
1383 String str = "RUN" + timeStamp;
1384 dataDir = cdataDir + DENOPTIMConstants.FSEP + str;
1385 success = denoptim.files.FileUtils.createDirectory(dataDir);
1386 }
1388 if (!denoptim.files.FileUtils.createDirectory(interfaceDir))
1389 {
1390 throw new DENOPTIMException("ERROR! Unable to make interface "
1391 + "folder '" + interfaceDir + "'");
1392 }
1393 denoptim.files.FileUtils.addToRecentFiles(dataDir, FileFormat.GA_RUN);
1394 }
1395
1396//------------------------------------------------------------------------------
1397
1404 {
1405 if (isMaster)
1407
1408 if (seed == 0)
1409 {
1411 seed = getRandomSeed();
1412 } else {
1414 }
1415
1416 int nproc = Runtime.getRuntime().availableProcessors();
1417 if (numParallelTasks == 0)
1418 {
1419 numParallelTasks = nproc;
1420 }
1421
1423
1425 {
1428 if (!rcParams.allowRingClosures())
1429 {
1431 }
1432 }
1433
1434 if (isMaster)
1435 {
1436 StaticLogger.appLogger.log(Level.INFO, "Program log file: "
1438 + "Output files associated with the current run are "
1439 + "located in " + dataDir);
1440 }
1441 }
1442
1443//------------------------------------------------------------------------------
1444
1446 {
1447 String error = "";
1448 //TODO: use something like the following for checking the parameters:
1449 //ensureIsPositive("GA-NUMOFFSPRING", numOfChildren, "blabla");
1450 if (numOfChildren <= 0)
1451 {
1452 error = "Number of children must be a positive number.";
1453 throw new DENOPTIMException(error);
1454 }
1455 if (numGenerations <= 0)
1456 {
1457 error = "Number of generations must be a positive number.";
1458 throw new DENOPTIMException(error);
1459 }
1460
1461 if (numConvGen <= 0)
1462 {
1463 error = "Number of convergence iterations must be a positive "
1464 + "number.";
1465 throw new DENOPTIMException(error);
1466 }
1467
1468 if (symmetricSubProbability < 0. ||
1470 {
1471 error = "Symmetric molecule probability must be between 0 and 1.";
1472 throw new DENOPTIMException(error);
1473 }
1474
1475 if (mutationWeight < 0.)
1476 {
1477 error = "Weight of mutation must be a positive number";
1478 throw new DENOPTIMException(error);
1479 }
1480
1481 if (crossoverWeight < 0.)
1482 {
1483 error = "Weight of crossover must be a positive number";
1484 throw new DENOPTIMException(error);
1485 }
1486
1487 if (builtAnewWeight < 0.)
1488 {
1489 error = "Weight of construction must be a positive number";
1490 throw new DENOPTIMException(error);
1491 }
1492
1493 if (initPoplnFile.length() > 0)
1494 {
1495 if (!denoptim.files.FileUtils.checkExists(initPoplnFile))
1496 {
1497 error = "Cannot find initial population data: " + initPoplnFile;
1498 throw new DENOPTIMException(error);
1499 }
1500 }
1501
1502 if (initMolsToFragmentFile!=null && initMolsToFragmentFile.length() > 0)
1503 {
1504 if (!denoptim.files.FileUtils.checkExists(initMolsToFragmentFile))
1505 {
1506 throw new DENOPTIMException("Cannot find initial molecules to "
1507 + "fragment: " + initMolsToFragmentFile);
1508 }
1509 }
1510
1511 if (replacementStrategy < 0 || replacementStrategy > 2)
1512 {
1513 error = "Allowed values for replacementStrategy (1-2)";
1514 throw new DENOPTIMException(error);
1515 }
1516
1518 {
1519 error = "Cannot use both graph level or molecular size as criterion "
1520 + "for controlling the growth of graphs. "
1521 + "Please, use either of them.";
1522 throw new DENOPTIMException(error);
1523 } else if (!useMolSizeBasedProb && !useLevelBasedProb) {
1524 useMolSizeBasedProb = true;
1525 }
1527 }
1528
1529//------------------------------------------------------------------------------
1530
1537 public String getPrintedList()
1538 {
1539 StringBuilder sb = new StringBuilder(1024);
1540 sb.append(" " + paramTypeName() + " ").append(NL);
1541 for (Field f : this.getClass().getDeclaredFields())
1542 {
1543 try
1544 {
1545 sb.append(f.getName()).append(" = ").append(
1546 f.get(this)).append(NL);
1547 }
1548 catch (Throwable t)
1549 {
1550 sb.append("ERROR! Unable to print " + paramTypeName()
1551 + " parameters. Cause: " + t);
1552 break;
1553 }
1554 }
1555 for (RunTimeParameters otherCollector : otherParameters.values())
1556 {
1557 sb.append(otherCollector.getPrintedList());
1558 }
1559 return sb.toString();
1560 }
1561
1562//------------------------------------------------------------------------------
1563
1568 public boolean savePopFile()
1569 {
1570 return writePopOnDisk;
1571 }
1572
1573//------------------------------------------------------------------------------
1574
1581 {
1583 }
1584
1585//------------------------------------------------------------------------------
1586
1587}
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.
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 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.
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...
ADDRING
Creates a ring-closure to add a ring.