$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 public int maxCompatibleVrtxPairs = 20;
431
437
443
448 public int maxAPMappingCombinations = 250;
449
454 protected boolean writePopOnDisk = false;
455
456//------------------------------------------------------------------------------
457
463 {
465 }
466
467//------------------------------------------------------------------------------
468
469 public String getUIDFileIn()
470 {
471 return uidFileIn;
472 }
473
474//------------------------------------------------------------------------------
475
476 public String getUIDFileOut()
477 {
478 return uidFileOut;
479 }
480
481//------------------------------------------------------------------------------
482
483 public String getVisitedGraphsFile()
484 {
485 return visitedGraphsFile;
486 }
487
488//------------------------------------------------------------------------------
489
490 public String getInterfaceDir()
491 {
492 return interfaceDir;
493 }
494
495//------------------------------------------------------------------------------
496
497 public String getMonitorFile()
498 {
499 return monitorFile;
500 }
501
502//------------------------------------------------------------------------------
503
505 {
506 return monitorDumpStep;
507 }
508
509//------------------------------------------------------------------------------
510
515 public boolean recordMateSelection()
516 {
517 return recordMateSelection;
518 }
519
520//------------------------------------------------------------------------------
521
522 public int getPrecisionLevel()
523 {
524 return precisionLevel;
525 }
526
527//------------------------------------------------------------------------------
528
529 public int getNumberOfCPU()
530 {
531 return numParallelTasks;
532 }
533
534//------------------------------------------------------------------------------
535
536 public boolean isSortOrderDecreasing()
537 {
538 return sortOrderDecreasing;
539 }
540
541//------------------------------------------------------------------------------
542
544 {
546 }
547
548//------------------------------------------------------------------------------
549
550 public int getMaxTriesFactor()
551 {
552 return maxTriesPerPop;
553 }
554
555//------------------------------------------------------------------------------
556
558 {
560 }
561
562//------------------------------------------------------------------------------
563
564 public String getDataDirectory()
565 {
566 return dataDir;
567 }
568
569//------------------------------------------------------------------------------
570
571 public void setWorkingDirectory(String pathName)
572 {
573 dataDir = pathName;
574 monitorFile = dataDir + ".eaMonitor";
575 interfaceDir = pathName + DENOPTIMConstants.FSEP + "interface";
576
577 logFile = dataDir + ".log";
578
579 if (uidFileOut.equals(""))
580 {
581 uidFileOut = dataDir + DENOPTIMConstants.FSEP + DEFUIDFILEOUTNAME;
582 }
583 }
584
585//------------------------------------------------------------------------------
586
588 {
589 return replacementStrategy;
590 }
591
592//------------------------------------------------------------------------------
593
598 public boolean parentsSurvive()
599 {
600 return parentsSurvive;
601 }
602
603//------------------------------------------------------------------------------
604
606 {
608 }
609
610//------------------------------------------------------------------------------
611
613 {
614 return crowdingSigmaMiddle;
615 }
616
617//------------------------------------------------------------------------------
618
619 public double getCrowdingMultiplier()
620 {
621 return crowdingMultiplier;
622 }
623
624//------------------------------------------------------------------------------
625
627 {
629 }
630
631//------------------------------------------------------------------------------
632
634 {
636 }
637
638//------------------------------------------------------------------------------
639
641 {
643 }
644
645//------------------------------------------------------------------------------
646
647 public double getGrowthMultiplier()
648 {
649 return lvlGrowthMultiplier;
650 }
651
652//------------------------------------------------------------------------------
653
655 {
657 }
658
659//------------------------------------------------------------------------------
660
662 {
664 }
665
666//------------------------------------------------------------------------------
667
669 {
671 }
672
673//------------------------------------------------------------------------------
674
676 {
677 return molGrowthMultiplier;
678 }
679
680//------------------------------------------------------------------------------
681
683 {
685 }
686
687//------------------------------------------------------------------------------
688
689 public void setPopulationSize(int size)
690 {
691 populationSize = size;
692 }
693
694//------------------------------------------------------------------------------
695
696 public int getPopulationSize()
697 {
698 return populationSize;
699 }
700
701//------------------------------------------------------------------------------
702
704 {
705 return numGenerations;
706 }
707
708//------------------------------------------------------------------------------
709
710 public String getSelectionStrategy()
711 {
713 }
714
715 //------------------------------------------------------------------------------
716
718 {
719 return selectivePressure;
720 }
721
722//------------------------------------------------------------------------------
723
724 public List<MutationType> getExcludedMutationTypes()
725 {
727 }
728
729//------------------------------------------------------------------------------
730
732 {
733 return xoverSelectionMode;
734 }
735
736//------------------------------------------------------------------------------
737
739 {
740 return numConvGen;
741 }
742
743//------------------------------------------------------------------------------
744
746 {
747 return numOfChildren;
748 }
749
750//------------------------------------------------------------------------------
751
752 public double getCrossoverWeight()
753 {
754 return crossoverWeight;
755 }
756
757//------------------------------------------------------------------------------
758
764 {
766 }
767
768//------------------------------------------------------------------------------
769
774 public boolean keepBestSibling()
775 {
776 return keepBestSibling;
777 }
778
779//------------------------------------------------------------------------------
780
781 public double getMutationWeight()
782 {
783 return mutationWeight;
784 }
785
786//------------------------------------------------------------------------------
787
788 public double getConstructionWeight()
789 {
790 return builtAnewWeight;
791 }
792
793//------------------------------------------------------------------------------
794
796 {
798 }
799
800//------------------------------------------------------------------------------
801
803 {
804 return initPoplnFile;
805 }
806
807//------------------------------------------------------------------------------
808
814 {
816 }
817
818//------------------------------------------------------------------------------
819
821 {
823 }
824
825//------------------------------------------------------------------------------
826
827 public boolean useMolSizeBasedProb()
828 {
829 return useMolSizeBasedProb;
830 }
831
832//------------------------------------------------------------------------------
833
834 public boolean useLevelBasedProb()
835 {
836 return useLevelBasedProb;
837 }
838
839//-----------------------------------------------------------------------------
840
842 {
844 }
845
846//-----------------------------------------------------------------------------
847
848 public double getMinFitnessSD()
849 {
850 return minFitnessSD;
851 }
852
853//-----------------------------------------------------------------------------
854
855 public boolean dumpMonitor()
856 {
857 return dumpMonitor;
858 }
859
860//-----------------------------------------------------------------------------
861
863 {
865 }
866
867//-----------------------------------------------------------------------------
868
870 {
872 }
873
874//-----------------------------------------------------------------------------
875
877 {
879 }
880
881//-----------------------------------------------------------------------------
882
890 {
892 }
893
894//------------------------------------------------------------------------------
895
903 public void interpretKeyword(String key, String value)
904 throws DENOPTIMException
905 {
906 String msg = "";
907 switch (key.toUpperCase())
908 {
909 case "VERBOSITY=":
910 {
911 verbosity = Integer.parseInt(value);
912 break;
913 }
914
915 case "NUMPARALLELTASKS=":
916 {
917 if (value.length() > 0)
918 {
919 numParallelTasks = Integer.parseInt(value);
920 }
921 break;
922 }
923
924 case "PARALLELIZATION=":
925 {
926 switch (value.toUpperCase())
927 {
928 case "SYNCHRONOUS":
930 break;
931 case "ASYNCHRONOUS":
933 break;
934 default:
935 throw new DENOPTIMException("Unknown parallelization scheme.");
936 }
937 break;
938 }
939
940 case "PRECISIONLEVEL=":
941 {
942 if (value.length() > 0)
943 {
944 precisionLevel = Integer.parseInt(value);
945 }
946 break;
947 }
948
949 case "UIDFILEIN=":
950 {
951 if (value.length() > 0)
952 {
953 uidFileIn = value;
954 }
955 break;
956 }
957
958 case "UIDFILEOUT=":
959 {
960 if (value.length() > 0)
961 {
962 uidFileOut = value;
963 }
964 break;
965 }
966
967 case "MONITORFILE=":
968 {
969 if (value.length() > 0)
970 {
971 monitorFile = value;
972 }
973 break;
974 }
975
976 case "RECORDMATESELECTION=":
977 {
978 if (value.length() > 0)
979 {
981 }
982 break;
983 }
984
985 case "MONITORDUMPSTEP=":
986 {
987 if (value.length() > 0)
988 {
989 monitorDumpStep = Integer.parseInt(value);
990 dumpMonitor = true;
991 }
992 break;
993 }
994
995 case "RANDOMSEED=":
996 {
997 if (value.length() > 0)
998 {
999 seed = Long.parseLong(value);
1000 }
1001 break;
1002 }
1003
1004 case "MAXTRIESPERPOPULATION=":
1005 {
1006 if (value.length() > 0)
1007 maxTriesPerPop = Integer.parseInt(value);
1008 break;
1009 }
1010
1011 case "MAXGENETICOPSATTEMPTS=":
1012 {
1013 if (value.length() > 0)
1014 maxGeneticOpAttempts = Integer.parseInt(value);
1015 break;
1016 }
1017
1018 case "INITPOPLNFILE=":
1019 {
1020 if (value.length() > 0)
1021 {
1022 initPoplnFile = value;
1023 }
1024 break;
1025 }
1026
1027 case "INITMOLSTOFRAGMENTFILE=":
1028 {
1029 if (value.length() > 0)
1030 {
1031 initMolsToFragmentFile = value;
1032 }
1033 break;
1034 }
1035
1036 case "SORTBYINCREASINGFITNESS":
1037 {
1038 sortOrderDecreasing = false;
1039 break;
1040 }
1041
1042 case "NANFITNESSKILLSEXPERIMENT":
1043 {
1045 }
1046
1047 case "LEVELGROWTHMULTIPLIER=":
1048 {
1049 if (value.length() > 0)
1050 {
1051 lvlGrowthMultiplier = Double.parseDouble(value);
1052 useLevelBasedProb = true;
1053 }
1054 break;
1055 }
1056
1057 case "LEVELGROWTHSIGMASTEEPNESS=":
1058 {
1059 if (value.length() > 0)
1060 {
1061 lvlGrowthSigmaSteepness = Double.parseDouble(value);
1062 useLevelBasedProb = true;
1063 }
1064 break;
1065 }
1066
1067 case "LEVELGROWTHSIGMAMIDDLE=":
1068 {
1069 if (value.length() > 0)
1070 {
1071 lvlGrowthSigmaMiddle = Double.parseDouble(value);
1072 useLevelBasedProb = true;
1073 }
1074 break;
1075 }
1076
1077 case "LEVELGROWTHPROBSCHEME=":
1078 {
1080 useLevelBasedProb = true;
1081 break;
1082 }
1083
1084 case "MOLGROWTHMULTIPLIER=":
1085 {
1086 if (value.length() > 0)
1087 {
1088 molGrowthMultiplier = Double.parseDouble(value);
1089 useMolSizeBasedProb = true;
1090 }
1091 break;
1092 }
1093
1094 case "MOLGROWTHSIGMASTEEPNESS=":
1095 {
1096 if (value.length() > 0)
1097 {
1098 molGrowthSigmaSteepness = Double.parseDouble(value);
1099 useMolSizeBasedProb = true;
1100 }
1101 break;
1102 }
1103
1104 case "MOLGROWTHSIGMAMIDDLE=":
1105 {
1106 if (value.length() > 0)
1107 {
1108 molGrowthSigmaMiddle = Double.parseDouble(value);
1109 useMolSizeBasedProb = true;
1110 }
1111 break;
1112 }
1113
1114 case "MOLGROWTHPROBSCHEME=":
1115 {
1117 useMolSizeBasedProb = true;
1118 break;
1119 }
1120
1121 case "CROWDMULTIPLIER=":
1122 {
1123 if (value.length() > 0)
1124 {
1125 crowdingMultiplier = Double.parseDouble(value);
1126 }
1127 break;
1128 }
1129
1130 case "CROWDSIGMASTEEPNESS=":
1131 {
1132 if (value.length() > 0)
1133 {
1134 crowdingSigmaSteepness = Double.parseDouble(value);
1135 }
1136 break;
1137 }
1138
1139 case "CROWDSIGMAMIDDLE=":
1140 {
1141 if (value.length() > 0)
1142 {
1143 crowdingSigmaMiddle = Double.parseDouble(value);
1144 }
1145 break;
1146 }
1147
1148 case "SYMMETRYPROBABILITY=":
1149 {
1150 if (value.length() > 0)
1151 {
1152 symmetricSubProbability = Double.parseDouble(value);
1153 }
1154 break;
1155 }
1156
1157 case "CROWDPROBSCHEME=":
1158 {
1160 break;
1161 }
1162
1163 case "NUMGENERATIONS=":
1164 {
1165 if (value.length() > 0)
1166 {
1167 numGenerations = Integer.parseInt(value);
1168 }
1169 break;
1170 }
1171
1172 case "NUMCHILDREN=":
1173 {
1174 if (value.length() > 0)
1175 {
1176 numOfChildren = Integer.parseInt(value);
1177 }
1178 break;
1179 }
1180
1181 case "CROSSOVERWEIGHT=":
1182 {
1183 if (value.length() > 0)
1184 {
1185 crossoverWeight = Double.parseDouble(value);
1186 }
1187 break;
1188 }
1189
1190 case "MUTATIONWEIGHT=":
1191 {
1192 if (value.length() > 0)
1193 {
1194 mutationWeight = Double.parseDouble(value);
1195 }
1196 break;
1197 }
1198
1199 case "COUPLEMUTATIONTOCROSSOVER=":
1200 {
1201 if (value.length() > 0)
1202 {
1204 }
1205 break;
1206 }
1207
1208 case "PARENTSSURVIVE=":
1209 {
1210 if (value.length() > 0)
1211 {
1213 }
1214 break;
1215 }
1216
1217 case "EXCLUDEMUTATIONTYPE=":
1218 {
1219 if (value.length() > 0)
1220 {
1221 excludedMutationTypes.add(MutationType.valueOf(value));
1222 }
1223 break;
1224 }
1225
1226 case "CONSTRUCTIONWEIGHT=":
1227 {
1228 if (value.length() > 0)
1229 {
1230 builtAnewWeight = Double.parseDouble(value);
1231 }
1232 break;
1233 }
1234
1235 case "REPLACEMENTSTRATEGY=":
1236 {
1237 switch (value.toUpperCase())
1238 {
1239 case "NONE":
1241 break;
1242 case "ELITIST":
1244 break;
1245 default:
1246 throw new DENOPTIMException("Unknown replacement strategy.");
1247 }
1248 break;
1249 }
1250
1251 case "POPULATIONSIZE=":
1252 {
1253 if (value.length() > 0)
1254 {
1255 populationSize = Integer.parseInt(value);
1256 }
1257 break;
1258 }
1259
1260 case "NUMCONVGEN=":
1261 {
1262 if (value.length() > 0)
1263 {
1264 numConvGen = Integer.parseInt(value);
1265 }
1266 break;
1267 }
1268
1269 case "MAXRINGSADDEDBYMUTATION=":
1270 {
1271 if (value.length() > 0)
1272 {
1273 maxRingsAddedByMutation = Integer.parseInt(value);
1274 }
1275 break;
1276 }
1277
1278 case "KEEPNEWRINGSYSTEMVERTEXES":
1279 {
1281 break;
1282 }
1283
1284 case "KEEPNEWRINGSYSTEMSCAFFOLDS":
1285 {
1287 break;
1288 }
1289
1290 case "KEEPNEWRINGSYSTEMFITNESSTRSH=":
1291 {
1292 if (value.length() > 0)
1293 {
1294 saveRingSystemsFitnessThreshold = Double.parseDouble(value);
1295 }
1296 break;
1297 }
1298
1299 case "MULTISITEMUTATIONWEIGHTS=":
1300 {
1301 String[] ws = value.split(",|\\s+");
1302 List<Double> lst = new ArrayList<Double>();
1303 for (String w : ws)
1304 {
1305 if (!w.trim().equals(""))
1306 lst.add(Double.parseDouble(w));
1307 }
1308 mutliSiteMutationWeights = new double[lst.size()];
1309 for (int i=0; i<lst.size(); i++)
1310 {
1311 mutliSiteMutationWeights[i] = lst.get(i);
1312 }
1313 break;
1314 }
1315
1316 case "XOVERSELECTIONMODE=":
1317 {
1318 if (value.length() > 0)
1319 {
1320 xoverSelectionMode = -1;
1321 if (value.compareToIgnoreCase("TS") == 0)
1322 {
1324 strXoverSelectionMode = "TOURNAMENT";
1325 } else if (value.compareToIgnoreCase("RW") == 0)
1326 {
1328 strXoverSelectionMode = "ROULETTE WHEEL";
1329 } else if (value.compareToIgnoreCase("SUS") == 0)
1330 {
1332 strXoverSelectionMode = "STOCHASTIC UNIVERSAL SAMPLING";
1333 } else if (value.compareToIgnoreCase("RANDOM") == 0)
1334 {
1336 strXoverSelectionMode = "RANDOM";
1337 } else {
1338 throw new DENOPTIMException("ERROR! String '"
1339 + value + "' cannot be interpreted as a "
1340 + "parent selection strategy.");
1341 }
1342 }
1343 break;
1344 }
1345
1346 case "SELECTIVEPRESSURE=":
1347 {
1348 if (value.length() > 0)
1349 {
1350 selectivePressure = Integer.parseInt(value);
1351 }
1352 break;
1353 }
1354
1355
1356 case "NUMOFFSPRINGFROMXOVER=":
1357 {
1358 if (value.length() > 0)
1359 {
1360 maxOffsprintFromXover = Integer.parseInt(value);
1362 throw new DENOPTIMException("ERROR! Can only generate "
1363 + "up to 2 offspring from crossover, but you "
1364 + "required " + maxOffsprintFromXover);
1365 }
1366 break;
1367 }
1368
1369 case "KEEPBESTSIBLING=":
1370 {
1372 break;
1373 }
1374
1375 case "MUTATEDGRAPHCHECKFAILTOLERANT=":
1376 {
1378 break;
1379 }
1380
1381 case "XOVERGRAPHCHECKFAILTOLERANT=":
1382 {
1384 break;
1385 }
1386
1387 case "MUTATIONFAILURETOLERANT=":
1388 {
1390 break;
1391 }
1392
1393 case "XOVERFAILURETOLERANT=":
1394 {
1396 break;
1397 }
1398
1399 case "BUILDFAILURETOLERANT=":
1400 {
1402 break;
1403 }
1404
1405 case "MAXXOVERSUBGRAPHSIZE=":
1406 {
1407 if (value.length() > 0)
1408 {
1409 maxXOverableSubGraphSize = Integer.parseInt(value);
1410 }
1411 break;
1412 }
1413
1414 case "MAXXOVERCOMPATVRTXPAIRS=":
1415 {
1416 if (value.length() > 0)
1417 {
1418 maxCompatibleVrtxPairs = Integer.parseInt(value);
1419 }
1420 break;
1421 }
1422
1423 case "MAXXOVERENDPOINTSCOMBINATIONS=":
1424 {
1425 if (value.length() > 0)
1426 {
1427 maxXoverEndPointsCombinations = Integer.parseInt(value);
1428 }
1429 break;
1430 }
1431
1432 case "MAXXOVERENDPOINTSPERMUTATIONS=":
1433 {
1434 if (value.length() > 0)
1435 {
1436 maxXoverEndPointsPermutations = Integer.parseInt(value);
1437 }
1438 break;
1439 }
1440
1441 case "MAXAPMAPPINGCOMBINATIONS=":
1442 {
1443 if (value.length() > 0)
1444 {
1445 maxAPMappingCombinations = Integer.parseInt(value);
1446 }
1447 break;
1448 }
1449
1450 case "WRITEPOPULATIONTOFILE":
1451 {
1452 writePopOnDisk = true;
1453 break;
1454 }
1455
1456 default:
1457 msg = "Keyword " + key + " is not a known GeneticAlgorithm-"
1458 + "related keyword. Check input files.";
1459 throw new DENOPTIMException(msg);
1460 }
1461 }
1462
1463//------------------------------------------------------------------------------
1464
1465 public static int convertProbabilityScheme(String option)
1466 throws DENOPTIMException
1467 {
1468 int res = 0;
1469 switch (option.toUpperCase())
1470 {
1471 case "EXP_DIFF":
1472 res = 0;
1473 break;
1474 case "TANH":
1475 res = 1;
1476 break;
1477 case "SIGMA":
1478 res = 2;
1479 break;
1480 case "UNRESTRICTED":
1481 res = 3;
1482 break;
1483 default:
1484 throw new DENOPTIMException(
1485 "Unknown growth probability scheme.");
1486 }
1487 return res;
1488 }
1489
1490//-----------------------------------------------------------------------------
1491
1498 {
1499 String cdataDir = dataDir;
1500 boolean success = false;
1501 while (!success)
1502 {
1503 SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddkkmmss");
1504 timeStamp = sdf.format(new Date());
1505 String str = "RUN" + timeStamp;
1506 dataDir = cdataDir + DENOPTIMConstants.FSEP + str;
1507 success = denoptim.files.FileUtils.createDirectory(dataDir);
1508 }
1510 if (!denoptim.files.FileUtils.createDirectory(interfaceDir))
1511 {
1512 throw new DENOPTIMException("ERROR! Unable to make interface "
1513 + "folder '" + interfaceDir + "'");
1514 }
1515 denoptim.files.FileUtils.addToRecentFiles(dataDir, FileFormat.GA_RUN);
1516 }
1517
1518//------------------------------------------------------------------------------
1519
1526 {
1527 if (isMaster)
1529
1530 if (seed == 0)
1531 {
1533 seed = getRandomSeed();
1534 } else {
1536 }
1537
1538 int nproc = Runtime.getRuntime().availableProcessors();
1539 if (numParallelTasks == 0)
1540 {
1541 numParallelTasks = nproc;
1542 }
1543
1544 if (selectivePressure<0)
1545 selectivePressure = (int) Math.round(populationSize * 0.2);
1546
1548
1550 {
1553 if (!rcParams.allowRingClosures())
1554 {
1557 }
1558 }
1559
1560 if (isMaster)
1561 {
1562 StaticLogger.appLogger.log(Level.INFO, "Program log file: "
1564 + "Output files associated with the current run are "
1565 + "located in " + dataDir);
1566 }
1567 }
1568
1569//------------------------------------------------------------------------------
1570
1572 {
1573 String error = "";
1574 //TODO: use something like the following for checking the parameters:
1575 //ensureIsPositive("GA-NUMOFFSPRING", numOfChildren, "blabla");
1576 if (numOfChildren <= 0)
1577 {
1578 error = "Number of children must be a positive number.";
1579 throw new DENOPTIMException(error);
1580 }
1581 if (numGenerations <= 0)
1582 {
1583 error = "Number of generations must be a positive number.";
1584 throw new DENOPTIMException(error);
1585 }
1586
1587 if (numConvGen <= 0)
1588 {
1589 error = "Number of convergence iterations must be a positive "
1590 + "number.";
1591 throw new DENOPTIMException(error);
1592 }
1593
1594 if (symmetricSubProbability < 0. ||
1596 {
1597 error = "Symmetric molecule probability must be between 0 and 1.";
1598 throw new DENOPTIMException(error);
1599 }
1600
1601 if (mutationWeight < 0.)
1602 {
1603 error = "Weight of mutation must be a positive number";
1604 throw new DENOPTIMException(error);
1605 }
1606
1607 if (crossoverWeight < 0.)
1608 {
1609 error = "Weight of crossover must be a positive number";
1610 throw new DENOPTIMException(error);
1611 }
1612
1613 if (builtAnewWeight < 0.)
1614 {
1615 error = "Weight of construction must be a positive number";
1616 throw new DENOPTIMException(error);
1617 }
1618
1619 if (initPoplnFile.length() > 0)
1620 {
1621 if (!denoptim.files.FileUtils.checkExists(initPoplnFile))
1622 {
1623 error = "Cannot find initial population data: " + initPoplnFile;
1624 throw new DENOPTIMException(error);
1625 }
1626 }
1627
1628 if (initMolsToFragmentFile!=null && initMolsToFragmentFile.length() > 0)
1629 {
1630 if (!denoptim.files.FileUtils.checkExists(initMolsToFragmentFile))
1631 {
1632 throw new DENOPTIMException("Cannot find initial molecules to "
1633 + "fragment: " + initMolsToFragmentFile);
1634 }
1635 }
1636
1637 if (replacementStrategy < 0 || replacementStrategy > 2)
1638 {
1639 error = "Allowed values for replacementStrategy (1-2)";
1640 throw new DENOPTIMException(error);
1641 }
1642
1644 {
1645 error = "Cannot use both graph level or molecular size as criterion "
1646 + "for controlling the growth of graphs. "
1647 + "Please, use either of them.";
1648 throw new DENOPTIMException(error);
1649 } else if (!useMolSizeBasedProb && !useLevelBasedProb) {
1650 useMolSizeBasedProb = true;
1651 }
1653 }
1654
1655//------------------------------------------------------------------------------
1656
1663 public String getPrintedList()
1664 {
1665 StringBuilder sb = new StringBuilder(1024);
1666 sb.append(" " + paramTypeName() + " ").append(NL);
1667 for (Field f : this.getClass().getDeclaredFields())
1668 {
1669 try
1670 {
1671 sb.append(f.getName()).append(" = ").append(
1672 f.get(this)).append(NL);
1673 }
1674 catch (Throwable t)
1675 {
1676 sb.append("ERROR! Unable to print " + paramTypeName()
1677 + " parameters. Cause: " + t);
1678 break;
1679 }
1680 }
1681 for (RunTimeParameters otherCollector : otherParameters.values())
1682 {
1683 sb.append(otherCollector.getPrintedList());
1684 }
1685 return sb.toString();
1686 }
1687
1688//------------------------------------------------------------------------------
1689
1694 public boolean savePopFile()
1695 {
1696 return writePopOnDisk;
1697 }
1698
1699//------------------------------------------------------------------------------
1700
1707 {
1709 }
1710
1711//------------------------------------------------------------------------------
1712
1713}
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.
int maxXoverEndPointsCombinations
Limit to the number of combinations of subgraph end points considered when locating crossover sites.
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 maxCompatibleVrtxPairs
Limit to the number of compatible vertex pairs to consider for crossover.
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 maxAPMappingCombinations
Limit to the number of AP-AP mapping combinations considered by denoptim.fragspace....
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 maxXoverEndPointsPermutations
Limit to the number of permutations of subgraph end points considered for each combination when locat...
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.