diff --git a/bin/com/a_SGA/Crossover.class b/bin/com/a_SGA/Crossover.class
deleted file mode 100644
index cd16dab..0000000
Binary files a/bin/com/a_SGA/Crossover.class and /dev/null differ
diff --git a/bin/com/a_SGA/FullReplacement.class b/bin/com/a_SGA/FullReplacement.class
deleted file mode 100644
index 5aff011..0000000
Binary files a/bin/com/a_SGA/FullReplacement.class and /dev/null differ
diff --git a/bin/com/a_SGA/IReplacement.class b/bin/com/a_SGA/IReplacement.class
deleted file mode 100644
index fd82d27..0000000
Binary files a/bin/com/a_SGA/IReplacement.class and /dev/null differ
diff --git a/bin/com/a_SGA/Mutation.class b/bin/com/a_SGA/Mutation.class
deleted file mode 100644
index a4112e0..0000000
Binary files a/bin/com/a_SGA/Mutation.class and /dev/null differ
diff --git a/bin/com/a_SGA/NPointCrossover.class b/bin/com/a_SGA/NPointCrossover.class
deleted file mode 100644
index b33b911..0000000
Binary files a/bin/com/a_SGA/NPointCrossover.class and /dev/null differ
diff --git a/bin/com/a_SGA/Parameter.class b/bin/com/a_SGA/Parameter.class
deleted file mode 100644
index cfdb43d..0000000
Binary files a/bin/com/a_SGA/Parameter.class and /dev/null differ
diff --git a/bin/com/a_SGA/RestrictedReplacement.class b/bin/com/a_SGA/RestrictedReplacement.class
deleted file mode 100644
index 5fe7aef..0000000
Binary files a/bin/com/a_SGA/RestrictedReplacement.class and /dev/null differ
diff --git a/bin/com/a_SGA/SGASolver.class b/bin/com/a_SGA/SGASolver.class
deleted file mode 100644
index f807ca1..0000000
Binary files a/bin/com/a_SGA/SGASolver.class and /dev/null differ
diff --git a/bin/com/a_SGA/Selection.class b/bin/com/a_SGA/Selection.class
deleted file mode 100644
index a5801a3..0000000
Binary files a/bin/com/a_SGA/Selection.class and /dev/null differ
diff --git a/bin/com/a_SGA/TourWithReplacement.class b/bin/com/a_SGA/TourWithReplacement.class
deleted file mode 100644
index a757f52..0000000
Binary files a/bin/com/a_SGA/TourWithReplacement.class and /dev/null differ
diff --git a/bin/com/a_SGA/TourWithoutReplacement.class b/bin/com/a_SGA/TourWithoutReplacement.class
deleted file mode 100644
index 0649ca7..0000000
Binary files a/bin/com/a_SGA/TourWithoutReplacement.class and /dev/null differ
diff --git a/bin/com/a_SGA/Truncation$PosFit.class b/bin/com/a_SGA/Truncation$PosFit.class
deleted file mode 100644
index c769519..0000000
Binary files a/bin/com/a_SGA/Truncation$PosFit.class and /dev/null differ
diff --git a/bin/com/a_SGA/Truncation.class b/bin/com/a_SGA/Truncation.class
deleted file mode 100644
index f5e8468..0000000
Binary files a/bin/com/a_SGA/Truncation.class and /dev/null differ
diff --git a/bin/com/a_SGA/UniformCrossover.class b/bin/com/a_SGA/UniformCrossover.class
deleted file mode 100644
index fb82d8d..0000000
Binary files a/bin/com/a_SGA/UniformCrossover.class and /dev/null differ
diff --git a/bin/com/a_SGA/WorstReplacement$PosFit.class b/bin/com/a_SGA/WorstReplacement$PosFit.class
deleted file mode 100644
index 1bd3ed0..0000000
Binary files a/bin/com/a_SGA/WorstReplacement$PosFit.class and /dev/null differ
diff --git a/bin/com/a_SGA/WorstReplacement.class b/bin/com/a_SGA/WorstReplacement.class
deleted file mode 100644
index 3a33727..0000000
Binary files a/bin/com/a_SGA/WorstReplacement.class and /dev/null differ
diff --git a/bin/com/b_UMDA/FullReplacement.class b/bin/com/b_UMDA/FullReplacement.class
deleted file mode 100644
index 4fb1f57..0000000
Binary files a/bin/com/b_UMDA/FullReplacement.class and /dev/null differ
diff --git a/bin/com/b_UMDA/IReplacement.class b/bin/com/b_UMDA/IReplacement.class
deleted file mode 100644
index 73f2fb4..0000000
Binary files a/bin/com/b_UMDA/IReplacement.class and /dev/null differ
diff --git a/bin/com/b_UMDA/Parameter.class b/bin/com/b_UMDA/Parameter.class
deleted file mode 100644
index 6400486..0000000
Binary files a/bin/com/b_UMDA/Parameter.class and /dev/null differ
diff --git a/bin/com/b_UMDA/RestrictedReplacement.class b/bin/com/b_UMDA/RestrictedReplacement.class
deleted file mode 100644
index 5ace2d8..0000000
Binary files a/bin/com/b_UMDA/RestrictedReplacement.class and /dev/null differ
diff --git a/bin/com/b_UMDA/Selection.class b/bin/com/b_UMDA/Selection.class
deleted file mode 100644
index 67a4cd3..0000000
Binary files a/bin/com/b_UMDA/Selection.class and /dev/null differ
diff --git a/bin/com/b_UMDA/TourWithReplacement.class b/bin/com/b_UMDA/TourWithReplacement.class
deleted file mode 100644
index 66cdddb..0000000
Binary files a/bin/com/b_UMDA/TourWithReplacement.class and /dev/null differ
diff --git a/bin/com/b_UMDA/TourWithoutReplacement.class b/bin/com/b_UMDA/TourWithoutReplacement.class
deleted file mode 100644
index 3158361..0000000
Binary files a/bin/com/b_UMDA/TourWithoutReplacement.class and /dev/null differ
diff --git a/bin/com/b_UMDA/Truncation$PosFit.class b/bin/com/b_UMDA/Truncation$PosFit.class
deleted file mode 100644
index 2790fc3..0000000
Binary files a/bin/com/b_UMDA/Truncation$PosFit.class and /dev/null differ
diff --git a/bin/com/b_UMDA/Truncation.class b/bin/com/b_UMDA/Truncation.class
deleted file mode 100644
index defd054..0000000
Binary files a/bin/com/b_UMDA/Truncation.class and /dev/null differ
diff --git a/bin/com/b_UMDA/UMDASolver.class b/bin/com/b_UMDA/UMDASolver.class
deleted file mode 100644
index f080625..0000000
Binary files a/bin/com/b_UMDA/UMDASolver.class and /dev/null differ
diff --git a/bin/com/b_UMDA/UniModel.class b/bin/com/b_UMDA/UniModel.class
deleted file mode 100644
index 116d2e2..0000000
Binary files a/bin/com/b_UMDA/UniModel.class and /dev/null differ
diff --git a/bin/com/b_UMDA/WorstReplacement$PosFit.class b/bin/com/b_UMDA/WorstReplacement$PosFit.class
deleted file mode 100644
index ba9ed83..0000000
Binary files a/bin/com/b_UMDA/WorstReplacement$PosFit.class and /dev/null differ
diff --git a/bin/com/b_UMDA/WorstReplacement.class b/bin/com/b_UMDA/WorstReplacement.class
deleted file mode 100644
index 9e2d8c5..0000000
Binary files a/bin/com/b_UMDA/WorstReplacement.class and /dev/null differ
diff --git a/bin/com/c_ECGA/Cache.class b/bin/com/c_ECGA/Cache.class
deleted file mode 100644
index 78a0cac..0000000
Binary files a/bin/com/c_ECGA/Cache.class and /dev/null differ
diff --git a/bin/com/c_ECGA/ECGASolver.class b/bin/com/c_ECGA/ECGASolver.class
deleted file mode 100644
index a5f907b..0000000
Binary files a/bin/com/c_ECGA/ECGASolver.class and /dev/null differ
diff --git a/bin/com/c_ECGA/FullReplacement.class b/bin/com/c_ECGA/FullReplacement.class
deleted file mode 100644
index 00f452e..0000000
Binary files a/bin/com/c_ECGA/FullReplacement.class and /dev/null differ
diff --git a/bin/com/c_ECGA/IReplacement.class b/bin/com/c_ECGA/IReplacement.class
deleted file mode 100644
index fc7edf0..0000000
Binary files a/bin/com/c_ECGA/IReplacement.class and /dev/null differ
diff --git a/bin/com/c_ECGA/MPModel.class b/bin/com/c_ECGA/MPModel.class
deleted file mode 100644
index 9ac810f..0000000
Binary files a/bin/com/c_ECGA/MPModel.class and /dev/null differ
diff --git a/bin/com/c_ECGA/Parameter.class b/bin/com/c_ECGA/Parameter.class
deleted file mode 100644
index e6b11d0..0000000
Binary files a/bin/com/c_ECGA/Parameter.class and /dev/null differ
diff --git a/bin/com/c_ECGA/RestrictedReplacement.class b/bin/com/c_ECGA/RestrictedReplacement.class
deleted file mode 100644
index 62835f5..0000000
Binary files a/bin/com/c_ECGA/RestrictedReplacement.class and /dev/null differ
diff --git a/bin/com/c_ECGA/Selection.class b/bin/com/c_ECGA/Selection.class
deleted file mode 100644
index b53f358..0000000
Binary files a/bin/com/c_ECGA/Selection.class and /dev/null differ
diff --git a/bin/com/c_ECGA/Subset.class b/bin/com/c_ECGA/Subset.class
deleted file mode 100644
index 66db632..0000000
Binary files a/bin/com/c_ECGA/Subset.class and /dev/null differ
diff --git a/bin/com/c_ECGA/TourWithReplacement.class b/bin/com/c_ECGA/TourWithReplacement.class
deleted file mode 100644
index 3822198..0000000
Binary files a/bin/com/c_ECGA/TourWithReplacement.class and /dev/null differ
diff --git a/bin/com/c_ECGA/TourWithoutReplacement.class b/bin/com/c_ECGA/TourWithoutReplacement.class
deleted file mode 100644
index aa63e64..0000000
Binary files a/bin/com/c_ECGA/TourWithoutReplacement.class and /dev/null differ
diff --git a/bin/com/c_ECGA/Truncation$PosFit.class b/bin/com/c_ECGA/Truncation$PosFit.class
deleted file mode 100644
index 2c74da4..0000000
Binary files a/bin/com/c_ECGA/Truncation$PosFit.class and /dev/null differ
diff --git a/bin/com/c_ECGA/Truncation.class b/bin/com/c_ECGA/Truncation.class
deleted file mode 100644
index fd1e337..0000000
Binary files a/bin/com/c_ECGA/Truncation.class and /dev/null differ
diff --git a/bin/com/c_ECGA/WorstReplacement$PosFit.class b/bin/com/c_ECGA/WorstReplacement$PosFit.class
deleted file mode 100644
index c78470f..0000000
Binary files a/bin/com/c_ECGA/WorstReplacement$PosFit.class and /dev/null differ
diff --git a/bin/com/c_ECGA/WorstReplacement.class b/bin/com/c_ECGA/WorstReplacement.class
deleted file mode 100644
index e2a52fd..0000000
Binary files a/bin/com/c_ECGA/WorstReplacement.class and /dev/null differ
diff --git a/bin/com/d_HBOA/BDMetric.class b/bin/com/d_HBOA/BDMetric.class
deleted file mode 100644
index 0b4d61c..0000000
Binary files a/bin/com/d_HBOA/BDMetric.class and /dev/null differ
diff --git a/bin/com/d_HBOA/BICMetric.class b/bin/com/d_HBOA/BICMetric.class
deleted file mode 100644
index 020bcaa..0000000
Binary files a/bin/com/d_HBOA/BICMetric.class and /dev/null differ
diff --git a/bin/com/d_HBOA/BayesianNetwork.class b/bin/com/d_HBOA/BayesianNetwork.class
deleted file mode 100644
index ce0b18b..0000000
Binary files a/bin/com/d_HBOA/BayesianNetwork.class and /dev/null differ
diff --git a/bin/com/d_HBOA/DecisionGraph.class b/bin/com/d_HBOA/DecisionGraph.class
deleted file mode 100644
index d611ece..0000000
Binary files a/bin/com/d_HBOA/DecisionGraph.class and /dev/null differ
diff --git a/bin/com/d_HBOA/FullReplacement.class b/bin/com/d_HBOA/FullReplacement.class
deleted file mode 100644
index 7f10a21..0000000
Binary files a/bin/com/d_HBOA/FullReplacement.class and /dev/null differ
diff --git a/bin/com/d_HBOA/HBOASolver.class b/bin/com/d_HBOA/HBOASolver.class
deleted file mode 100644
index d1912f9..0000000
Binary files a/bin/com/d_HBOA/HBOASolver.class and /dev/null differ
diff --git a/bin/com/d_HBOA/IBayesianMetric.class b/bin/com/d_HBOA/IBayesianMetric.class
deleted file mode 100644
index b81b8a7..0000000
Binary files a/bin/com/d_HBOA/IBayesianMetric.class and /dev/null differ
diff --git a/bin/com/d_HBOA/IGraph.class b/bin/com/d_HBOA/IGraph.class
deleted file mode 100644
index f059428..0000000
Binary files a/bin/com/d_HBOA/IGraph.class and /dev/null differ
diff --git a/bin/com/d_HBOA/IReplacement.class b/bin/com/d_HBOA/IReplacement.class
deleted file mode 100644
index 7668ab5..0000000
Binary files a/bin/com/d_HBOA/IReplacement.class and /dev/null differ
diff --git a/bin/com/d_HBOA/Leaf.class b/bin/com/d_HBOA/Leaf.class
deleted file mode 100644
index 6d0644b..0000000
Binary files a/bin/com/d_HBOA/Leaf.class and /dev/null differ
diff --git a/bin/com/d_HBOA/Parameter.class b/bin/com/d_HBOA/Parameter.class
deleted file mode 100644
index 3343ed1..0000000
Binary files a/bin/com/d_HBOA/Parameter.class and /dev/null differ
diff --git a/bin/com/d_HBOA/RestrictedReplacement.class b/bin/com/d_HBOA/RestrictedReplacement.class
deleted file mode 100644
index 8bc75a7..0000000
Binary files a/bin/com/d_HBOA/RestrictedReplacement.class and /dev/null differ
diff --git a/bin/com/d_HBOA/Selection.class b/bin/com/d_HBOA/Selection.class
deleted file mode 100644
index b56ef8b..0000000
Binary files a/bin/com/d_HBOA/Selection.class and /dev/null differ
diff --git a/bin/com/d_HBOA/TourWithReplacement.class b/bin/com/d_HBOA/TourWithReplacement.class
deleted file mode 100644
index 88ddbe9..0000000
Binary files a/bin/com/d_HBOA/TourWithReplacement.class and /dev/null differ
diff --git a/bin/com/d_HBOA/TourWithoutReplacement.class b/bin/com/d_HBOA/TourWithoutReplacement.class
deleted file mode 100644
index 465b843..0000000
Binary files a/bin/com/d_HBOA/TourWithoutReplacement.class and /dev/null differ
diff --git a/bin/com/d_HBOA/Truncation$PosFit.class b/bin/com/d_HBOA/Truncation$PosFit.class
deleted file mode 100644
index b607568..0000000
Binary files a/bin/com/d_HBOA/Truncation$PosFit.class and /dev/null differ
diff --git a/bin/com/d_HBOA/Truncation.class b/bin/com/d_HBOA/Truncation.class
deleted file mode 100644
index 99ac876..0000000
Binary files a/bin/com/d_HBOA/Truncation.class and /dev/null differ
diff --git a/bin/com/d_HBOA/Variable.class b/bin/com/d_HBOA/Variable.class
deleted file mode 100644
index 9631a36..0000000
Binary files a/bin/com/d_HBOA/Variable.class and /dev/null differ
diff --git a/bin/com/d_HBOA/WorstReplacement$PosFit.class b/bin/com/d_HBOA/WorstReplacement$PosFit.class
deleted file mode 100644
index 3170f94..0000000
Binary files a/bin/com/d_HBOA/WorstReplacement$PosFit.class and /dev/null differ
diff --git a/bin/com/d_HBOA/WorstReplacement.class b/bin/com/d_HBOA/WorstReplacement.class
deleted file mode 100644
index c079856..0000000
Binary files a/bin/com/d_HBOA/WorstReplacement.class and /dev/null differ
diff --git a/bin/com/z_PORTFOLIO/ECGA.class b/bin/com/z_PORTFOLIO/ECGA.class
deleted file mode 100644
index 9955d88..0000000
Binary files a/bin/com/z_PORTFOLIO/ECGA.class and /dev/null differ
diff --git a/bin/com/z_PORTFOLIO/HBOA.class b/bin/com/z_PORTFOLIO/HBOA.class
deleted file mode 100644
index f713b46..0000000
Binary files a/bin/com/z_PORTFOLIO/HBOA.class and /dev/null differ
diff --git a/bin/com/z_PORTFOLIO/HierarchicalTrapOne.class b/bin/com/z_PORTFOLIO/HierarchicalTrapOne.class
deleted file mode 100644
index 508a6df..0000000
Binary files a/bin/com/z_PORTFOLIO/HierarchicalTrapOne.class and /dev/null differ
diff --git a/bin/com/z_PORTFOLIO/HierarchicalTrapTwo.class b/bin/com/z_PORTFOLIO/HierarchicalTrapTwo.class
deleted file mode 100644
index ee14bd2..0000000
Binary files a/bin/com/z_PORTFOLIO/HierarchicalTrapTwo.class and /dev/null differ
diff --git a/bin/com/z_PORTFOLIO/IEASolver.class b/bin/com/z_PORTFOLIO/IEASolver.class
deleted file mode 100644
index 7b7361e..0000000
Binary files a/bin/com/z_PORTFOLIO/IEASolver.class and /dev/null differ
diff --git a/bin/com/z_PORTFOLIO/IEAlgorithm.class b/bin/com/z_PORTFOLIO/IEAlgorithm.class
deleted file mode 100644
index 42bc488..0000000
Binary files a/bin/com/z_PORTFOLIO/IEAlgorithm.class and /dev/null differ
diff --git a/bin/com/z_PORTFOLIO/IProblem.class b/bin/com/z_PORTFOLIO/IProblem.class
deleted file mode 100644
index 2626e77..0000000
Binary files a/bin/com/z_PORTFOLIO/IProblem.class and /dev/null differ
diff --git a/bin/com/z_PORTFOLIO/Individual.class b/bin/com/z_PORTFOLIO/Individual.class
deleted file mode 100644
index 891fcb1..0000000
Binary files a/bin/com/z_PORTFOLIO/Individual.class and /dev/null differ
diff --git a/bin/com/z_PORTFOLIO/IsingSpin.class b/bin/com/z_PORTFOLIO/IsingSpin.class
deleted file mode 100644
index ab5760c..0000000
Binary files a/bin/com/z_PORTFOLIO/IsingSpin.class and /dev/null differ
diff --git a/bin/com/z_PORTFOLIO/OneMax.class b/bin/com/z_PORTFOLIO/OneMax.class
deleted file mode 100644
index 4d7a37f..0000000
Binary files a/bin/com/z_PORTFOLIO/OneMax.class and /dev/null differ
diff --git a/bin/com/z_PORTFOLIO/PORTFOLIO.class b/bin/com/z_PORTFOLIO/PORTFOLIO.class
deleted file mode 100644
index 1e3b68d..0000000
Binary files a/bin/com/z_PORTFOLIO/PORTFOLIO.class and /dev/null differ
diff --git a/bin/com/z_PORTFOLIO/ParBestSoFar.class b/bin/com/z_PORTFOLIO/ParBestSoFar.class
deleted file mode 100644
index a632209..0000000
Binary files a/bin/com/z_PORTFOLIO/ParBestSoFar.class and /dev/null differ
diff --git a/bin/com/z_PORTFOLIO/ParEngine.class b/bin/com/z_PORTFOLIO/ParEngine.class
deleted file mode 100644
index 2ebbea4..0000000
Binary files a/bin/com/z_PORTFOLIO/ParEngine.class and /dev/null differ
diff --git a/bin/com/z_PORTFOLIO/ParParameter.class b/bin/com/z_PORTFOLIO/ParParameter.class
deleted file mode 100644
index 478cd6d..0000000
Binary files a/bin/com/z_PORTFOLIO/ParParameter.class and /dev/null differ
diff --git a/bin/com/z_PORTFOLIO/ParRegister.class b/bin/com/z_PORTFOLIO/ParRegister.class
deleted file mode 100644
index 2fb5e49..0000000
Binary files a/bin/com/z_PORTFOLIO/ParRegister.class and /dev/null differ
diff --git a/bin/com/z_PORTFOLIO/ParStopper.class b/bin/com/z_PORTFOLIO/ParStopper.class
deleted file mode 100644
index 0de43a4..0000000
Binary files a/bin/com/z_PORTFOLIO/ParStopper.class and /dev/null differ
diff --git a/bin/com/z_PORTFOLIO/Population.class b/bin/com/z_PORTFOLIO/Population.class
deleted file mode 100644
index 0d90e1d..0000000
Binary files a/bin/com/z_PORTFOLIO/Population.class and /dev/null differ
diff --git a/bin/com/z_PORTFOLIO/PortEngine.class b/bin/com/z_PORTFOLIO/PortEngine.class
deleted file mode 100644
index 680cf05..0000000
Binary files a/bin/com/z_PORTFOLIO/PortEngine.class and /dev/null differ
diff --git a/bin/com/z_PORTFOLIO/PortParameter.class b/bin/com/z_PORTFOLIO/PortParameter.class
deleted file mode 100644
index 4f72925..0000000
Binary files a/bin/com/z_PORTFOLIO/PortParameter.class and /dev/null differ
diff --git a/bin/com/z_PORTFOLIO/PortPress.class b/bin/com/z_PORTFOLIO/PortPress.class
deleted file mode 100644
index dc2cf50..0000000
Binary files a/bin/com/z_PORTFOLIO/PortPress.class and /dev/null differ
diff --git a/bin/com/z_PORTFOLIO/PortRegister.class b/bin/com/z_PORTFOLIO/PortRegister.class
deleted file mode 100644
index 8f17703..0000000
Binary files a/bin/com/z_PORTFOLIO/PortRegister.class and /dev/null differ
diff --git a/bin/com/z_PORTFOLIO/PortStopper.class b/bin/com/z_PORTFOLIO/PortStopper.class
deleted file mode 100644
index 2a3012a..0000000
Binary files a/bin/com/z_PORTFOLIO/PortStopper.class and /dev/null differ
diff --git a/bin/com/z_PORTFOLIO/PortTime.class b/bin/com/z_PORTFOLIO/PortTime.class
deleted file mode 100644
index 7939275..0000000
Binary files a/bin/com/z_PORTFOLIO/PortTime.class and /dev/null differ
diff --git a/bin/com/z_PORTFOLIO/Problem.class b/bin/com/z_PORTFOLIO/Problem.class
deleted file mode 100644
index 43d54a2..0000000
Binary files a/bin/com/z_PORTFOLIO/Problem.class and /dev/null differ
diff --git a/bin/com/z_PORTFOLIO/Quadratic.class b/bin/com/z_PORTFOLIO/Quadratic.class
deleted file mode 100644
index 25ed9a2..0000000
Binary files a/bin/com/z_PORTFOLIO/Quadratic.class and /dev/null differ
diff --git a/bin/com/z_PORTFOLIO/RandomPopulation.class b/bin/com/z_PORTFOLIO/RandomPopulation.class
deleted file mode 100644
index 05f0eb1..0000000
Binary files a/bin/com/z_PORTFOLIO/RandomPopulation.class and /dev/null differ
diff --git a/bin/com/z_PORTFOLIO/SGA.class b/bin/com/z_PORTFOLIO/SGA.class
deleted file mode 100644
index f2c3e15..0000000
Binary files a/bin/com/z_PORTFOLIO/SGA.class and /dev/null differ
diff --git a/bin/com/z_PORTFOLIO/SelectedSet.class b/bin/com/z_PORTFOLIO/SelectedSet.class
deleted file mode 100644
index 3be7262..0000000
Binary files a/bin/com/z_PORTFOLIO/SelectedSet.class and /dev/null differ
diff --git a/bin/com/z_PORTFOLIO/ThreeDeceptive.class b/bin/com/z_PORTFOLIO/ThreeDeceptive.class
deleted file mode 100644
index 30004b4..0000000
Binary files a/bin/com/z_PORTFOLIO/ThreeDeceptive.class and /dev/null differ
diff --git a/bin/com/z_PORTFOLIO/ThreeDeceptiveBiPolar.class b/bin/com/z_PORTFOLIO/ThreeDeceptiveBiPolar.class
deleted file mode 100644
index 73ea8bc..0000000
Binary files a/bin/com/z_PORTFOLIO/ThreeDeceptiveBiPolar.class and /dev/null differ
diff --git a/bin/com/z_PORTFOLIO/ThreeDeceptiveOverlapping.class b/bin/com/z_PORTFOLIO/ThreeDeceptiveOverlapping.class
deleted file mode 100644
index aa625bd..0000000
Binary files a/bin/com/z_PORTFOLIO/ThreeDeceptiveOverlapping.class and /dev/null differ
diff --git a/bin/com/z_PORTFOLIO/TrapK.class b/bin/com/z_PORTFOLIO/TrapK.class
deleted file mode 100644
index afb0e9a..0000000
Binary files a/bin/com/z_PORTFOLIO/TrapK.class and /dev/null differ
diff --git a/bin/com/z_PORTFOLIO/UMDA.class b/bin/com/z_PORTFOLIO/UMDA.class
deleted file mode 100644
index dfdb731..0000000
Binary files a/bin/com/z_PORTFOLIO/UMDA.class and /dev/null differ
diff --git a/bin/com/z_PORTFOLIO/UniformSixBlocks.class b/bin/com/z_PORTFOLIO/UniformSixBlocks.class
deleted file mode 100644
index 50c792d..0000000
Binary files a/bin/com/z_PORTFOLIO/UniformSixBlocks.class and /dev/null differ
diff --git a/bin/com/z_PORTFOLIO/ZeroMax.class b/bin/com/z_PORTFOLIO/ZeroMax.class
deleted file mode 100644
index 39ddd70..0000000
Binary files a/bin/com/z_PORTFOLIO/ZeroMax.class and /dev/null differ
diff --git a/bin/com/z_PORTFOLIO/ZeroQuadratic.class b/bin/com/z_PORTFOLIO/ZeroQuadratic.class
deleted file mode 100644
index 0b95a17..0000000
Binary files a/bin/com/z_PORTFOLIO/ZeroQuadratic.class and /dev/null differ
diff --git a/bin/com/z_PORTFOLIO/ZeroThreeDeceptive.class b/bin/com/z_PORTFOLIO/ZeroThreeDeceptive.class
deleted file mode 100644
index b526cea..0000000
Binary files a/bin/com/z_PORTFOLIO/ZeroThreeDeceptive.class and /dev/null differ
diff --git a/bin/com/z_PORTFOLIO/ZeroThreeDeceptiveBiPolar.class b/bin/com/z_PORTFOLIO/ZeroThreeDeceptiveBiPolar.class
deleted file mode 100644
index 154410a..0000000
Binary files a/bin/com/z_PORTFOLIO/ZeroThreeDeceptiveBiPolar.class and /dev/null differ
diff --git a/bin/com/z_PORTFOLIO/ZeroThreeDeceptiveOverlapping.class b/bin/com/z_PORTFOLIO/ZeroThreeDeceptiveOverlapping.class
deleted file mode 100644
index a6e57a7..0000000
Binary files a/bin/com/z_PORTFOLIO/ZeroThreeDeceptiveOverlapping.class and /dev/null differ
diff --git a/bin/com/z_PORTFOLIO/ZeroTrapK.class b/bin/com/z_PORTFOLIO/ZeroTrapK.class
deleted file mode 100644
index 602ed5f..0000000
Binary files a/bin/com/z_PORTFOLIO/ZeroTrapK.class and /dev/null differ
diff --git a/bin/com/z_PORTFOLIO/ZeroUniformSixBlocks.class b/bin/com/z_PORTFOLIO/ZeroUniformSixBlocks.class
deleted file mode 100644
index b395b06..0000000
Binary files a/bin/com/z_PORTFOLIO/ZeroUniformSixBlocks.class and /dev/null differ
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..d9c3c61
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,53 @@
+
+
+ 4.0.0
+
+ g
+ g
+ 1.0-SNAPSHOT
+
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ 2.18.1
+
+
+
+ **/*.java
+
+ true
+ false
+ true
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.3
+
+ 1.8
+ 1.8
+
+
+
+
+
+
+
+
+ com.goldmansachs
+ gs-collections
+ 6.2.0
+
+
+
+
\ No newline at end of file
diff --git a/src/com/a_SGA/Mutation.java b/src/com/a_SGA/Mutation.java
deleted file mode 100644
index 1eedd97..0000000
--- a/src/com/a_SGA/Mutation.java
+++ /dev/null
@@ -1,26 +0,0 @@
-package com.a_SGA;
-
-import com.z_PORTFOLIO.Individual;
-import com.z_PORTFOLIO.PORTFOLIO;
-import com.z_PORTFOLIO.Problem;
-
-class Mutation{
- private double pMutation; // Probability of mutation;
-
- public Mutation(double pMutation){this.pMutation = pMutation;}
-
- public double getPMutation(){return pMutation;}
-
- public void mutate(Individual[] newIndividuals){
- if(pMutation > 0) // Perform mutation only if pMutation > 0.
- for(int i = 0; i < newIndividuals.length; i++)
- for(int j = 0; j < Problem.n; j++)
- if(PORTFOLIO.random.nextDouble() < pMutation){ // Perform mutation in every position with probability pMutation.
- char allele = newIndividuals[i].getAllele(j);
- if(allele == '0')
- newIndividuals[i].setAllele(j, '1');
- else
- newIndividuals[i].setAllele(j, '0');
- }
- }
-}
\ No newline at end of file
diff --git a/src/com/a_SGA/Crossover.java b/src/main/java/com/a_SGA/Crossover.java
similarity index 93%
rename from src/com/a_SGA/Crossover.java
rename to src/main/java/com/a_SGA/Crossover.java
index de69fb1..972e6fd 100644
--- a/src/com/a_SGA/Crossover.java
+++ b/src/main/java/com/a_SGA/Crossover.java
@@ -13,7 +13,7 @@ abstract class Crossover{
}
class NPointCrossover extends Crossover{
- private int nCrossover; // Number of cross points. NOTE: nCrossover = 1, 2, ..., n-1
+ private final int nCrossover; // Number of cross points. NOTE: nCrossover = 1, 2, ..., n-1
public NPointCrossover(double pCrossover, int nCrossover){
this.pCrossover = pCrossover;
@@ -27,7 +27,7 @@ public Individual[] cross(Population selectedSet){
Individual indiv1 = selectedSet.getIndividualCopy(i);
Individual indiv2 = selectedSet.getIndividualCopy(i+1);
if(PORTFOLIO.random.nextDouble() < pCrossover){ // Perform NPointCrossover with probability pCrossover.
- TreeSet crossPoints = new TreeSet();
+ TreeSet crossPoints = new TreeSet<>();
do crossPoints.add(PORTFOLIO.random.nextInt(Problem.n)); // Choose exactly nCrossover cross points.
while(crossPoints.size() < nCrossover);
@@ -52,7 +52,7 @@ public Individual[] cross(Population selectedSet){
}
class UniformCrossover extends Crossover{
- private double pSwap;
+ private final double pSwap;
public UniformCrossover(double pCrossover, double pSwap){
this.pCrossover = pCrossover;
diff --git a/src/main/java/com/a_SGA/Mutation.java b/src/main/java/com/a_SGA/Mutation.java
new file mode 100644
index 0000000..6e2106c
--- /dev/null
+++ b/src/main/java/com/a_SGA/Mutation.java
@@ -0,0 +1,26 @@
+package com.a_SGA;
+
+import com.z_PORTFOLIO.Individual;
+import com.z_PORTFOLIO.PORTFOLIO;
+import com.z_PORTFOLIO.Problem;
+
+class Mutation{
+ private final double pMutation; // Probability of mutation;
+
+ public Mutation(double pMutation){this.pMutation = pMutation;}
+
+ public double getPMutation(){return pMutation;}
+
+ public void mutate(Individual[] newIndividuals){
+ if(pMutation > 0) // Perform mutation only if pMutation > 0.
+ for (Individual newIndividual : newIndividuals)
+ for (int j = 0; j < Problem.n; j++)
+ if (PORTFOLIO.random.nextDouble() < pMutation) { // Perform mutation in every position with probability pMutation.
+ char allele = newIndividual.getAllele(j);
+ if (allele == '0')
+ newIndividual.setAllele(j, '1');
+ else
+ newIndividual.setAllele(j, '0');
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/com/a_SGA/Parameter.java b/src/main/java/com/a_SGA/Parameter.java
similarity index 90%
rename from src/com/a_SGA/Parameter.java
rename to src/main/java/com/a_SGA/Parameter.java
index 012a243..dc55a12 100644
--- a/src/com/a_SGA/Parameter.java
+++ b/src/main/java/com/a_SGA/Parameter.java
@@ -1,13 +1,13 @@
package com.a_SGA;
+import com.z_PORTFOLIO.Problem;
+
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.Scanner;
-import com.z_PORTFOLIO.Problem;
-
public class Parameter{
@@ -81,12 +81,12 @@ private static void validateOptionName(String line, String option, int nLine){
if(option.length() >= line.length())
exitError("Line " + nLine + " --> Missing equal sign '='");
if(!validateName(option))
- exitError("Line " + nLine + " --> INVALID OPTION NAME '" + option + "'");
+ exitError("Line " + nLine + " --> INVALID OPTION NAME '" + option + '\'');
}
private static boolean validateName(String name){
- for(int i = 0; i < optionNames.length; i++)
- if(name.equals((String)optionNames[i]))
+ for (String optionName : optionNames)
+ if (name.equals((String) optionName))
return true;
return false;
}
@@ -200,25 +200,25 @@ public static IReplacement initializeReplacement(int currentN){
public static String writeParameters(String indent){
String str = " Selection Method:";
if(selectionMethod == 1)
- str += "\n" + indent + " Selection = Tournament Selection with replacement" +
- "\n" + indent + " tourSize = " + tourSize +
- "\n" + indent + " offspringSize = " + pOffspringSize;
+ str += '\n' + indent + " Selection = Tournament Selection with replacement" +
+ '\n' + indent + " tourSize = " + tourSize +
+ '\n' + indent + " offspringSize = " + pOffspringSize;
if(selectionMethod == 2)
- str += "\n" + indent + " Selection = Tournament Selection without replacement" +
- "\n" + indent + " tourSize = " + tourSize +
- "\n" + indent + " offspringSize = " + pOffspringSize;
+ str += '\n' + indent + " Selection = Tournament Selection without replacement" +
+ '\n' + indent + " tourSize = " + tourSize +
+ '\n' + indent + " offspringSize = " + pOffspringSize;
if(selectionMethod == 3)
- str += "\n" + indent + " Selection = Truncation" +
- "\n" + indent + " offspringSize = " + pOffspringSize;
+ str += '\n' + indent + " Selection = Truncation" +
+ '\n' + indent + " offspringSize = " + pOffspringSize;
str += "\n\n Operators:" +
- "\n" + indent + "pCrossover = " + pCrossover +
- "\n" + indent + "nCrossover = " + nCrossover +
- "\n" + indent + "pMutation = " + pMutation +
+ '\n' + indent + "pCrossover = " + pCrossover +
+ '\n' + indent + "nCrossover = " + nCrossover +
+ '\n' + indent + "pMutation = " + pMutation +
"\n\n Replacement Method:" +
- "\n" + indent + "Replacement Type = " + replacementType ;
+ '\n' + indent + "Replacement Type = " + replacementType ;
if(replacementType == 1)
- str += "\n" + indent + " windowSize = " + windowSize;
+ str += '\n' + indent + " windowSize = " + windowSize;
return str;
}
diff --git a/src/com/a_SGA/Replacement.java b/src/main/java/com/a_SGA/Replacement.java
similarity index 82%
rename from src/com/a_SGA/Replacement.java
rename to src/main/java/com/a_SGA/Replacement.java
index ff3ec2c..6128a67 100644
--- a/src/com/a_SGA/Replacement.java
+++ b/src/main/java/com/a_SGA/Replacement.java
@@ -12,7 +12,7 @@ abstract class IReplacement{
}
class RestrictedReplacement extends IReplacement{
- private int windowSize;
+ private final int windowSize;
public RestrictedReplacement(int wSize, int currentN){
int wS = currentN/20;
@@ -24,25 +24,24 @@ public RestrictedReplacement(int wSize, int currentN){
public void replace(Population population, Individual[] newIndividuals){
int N = population.getN();
- for(int i = 0; i < newIndividuals.length; i++){
- Individual candidate = newIndividuals[i];
+ for (Individual candidate : newIndividuals) {
int bestPosition = -1;
int bestDistance = Integer.MAX_VALUE;
- for(int j = 1; j < windowSize; j++){ // Find within the window, the individual CLOSEST to the candidate.
+ for (int j = 1; j < windowSize; j++) { // Find within the window, the individual CLOSEST to the candidate.
int picked = PORTFOLIO.random.nextInt(N);
- Individual individual = population.getIndividual(picked);
+ Individual individual = population.getIndividual(picked);
int distance = individual.distance(candidate);
- if(distance < bestDistance){
+ if (distance < bestDistance) {
bestPosition = picked;
bestDistance = distance;
}
}
float candidateFit = candidate.computeFitness();
- if(candidateFit > population.getFitness(bestPosition)){
+ if (candidateFit > population.getFitness(bestPosition)) {
population.setIndividual(bestPosition, candidate, candidateFit);
double bestFit = population.getBestFit();
- if(candidateFit > bestFit){ // The new individual is also the best.
- population.setBestPos(bestPosition); // Update information about the best individual.
+ if (candidateFit > bestFit) { // The new individual is also the best.
+ population.setBestPos(bestPosition); // Update information about the best individual.
population.setBestFit(candidateFit);
}
}
@@ -56,7 +55,7 @@ class WorstReplacement extends IReplacement{
// Use this inner class to sort the current population, in ascending order of fitness.
// BEGIN: Inner class 'PosFit'
- class PosFit implements Comparable{
+ static class PosFit implements Comparable{
int position;
double fitness;
@@ -79,17 +78,15 @@ public int compareTo(PosFit posFit){
}
public String toString(){
- return "(" + position + ";" + fitness + ")";
+ return "(" + position + ';' + fitness + ')';
}
} // END: Inner class 'PosFit'
-
- private PosFit[] sortedPopulation;
-
+
public WorstReplacement(){} // Default constructor
public void replace(Population population, Individual[] newIndividuals){
int sortN = population.getN();
- sortedPopulation = new PosFit[sortN];
+ PosFit[] sortedPopulation = new PosFit[sortN];
for(int i = 0; i < sortN; i++)
sortedPopulation[i] = new PosFit(i, population.getFitness(i));
Arrays.sort(sortedPopulation); // Sort population in ascending order of fitness.
diff --git a/src/com/a_SGA/SGASolver.java b/src/main/java/com/a_SGA/SGASolver.java
similarity index 82%
rename from src/com/a_SGA/SGASolver.java
rename to src/main/java/com/a_SGA/SGASolver.java
index d3e1563..7e100ba 100644
--- a/src/com/a_SGA/SGASolver.java
+++ b/src/main/java/com/a_SGA/SGASolver.java
@@ -17,10 +17,10 @@
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public class SGASolver extends IEASolver{
- private Selection selection; // NOTE: Use Parameter.initializeSelector() to generate the chosen selector type.
- private Crossover crossover; // NOTE: Use Parameter.initializeCrossover() to generate the chosen crossover type.
- private Mutation mutation; // NOTE: Use Parameter.initializeMutation() to generate the chosen mutation type.
- private IReplacement replacement; // NOTE: Use Parameter.initializeReplacement() to generate the chosen replacement type.
+ private final Selection selection; // NOTE: Use Parameter.initializeSelector() to generate the chosen selector type.
+ private final Crossover crossover; // NOTE: Use Parameter.initializeCrossover() to generate the chosen crossover type.
+ private final Mutation mutation; // NOTE: Use Parameter.initializeMutation() to generate the chosen mutation type.
+ private final IReplacement replacement; // NOTE: Use Parameter.initializeReplacement() to generate the chosen replacement type.
public SGASolver(String paramFile, int currentN){
diff --git a/src/com/a_SGA/Selection.java b/src/main/java/com/a_SGA/Selection.java
similarity index 95%
rename from src/com/a_SGA/Selection.java
rename to src/main/java/com/a_SGA/Selection.java
index c830f73..9353509 100644
--- a/src/com/a_SGA/Selection.java
+++ b/src/main/java/com/a_SGA/Selection.java
@@ -1,11 +1,11 @@
package com.a_SGA;
-import java.util.Arrays;
-
import com.z_PORTFOLIO.PORTFOLIO;
import com.z_PORTFOLIO.Population;
import com.z_PORTFOLIO.SelectedSet;
+import java.util.Arrays;
+
abstract class Selection{
public int NS; // Selection Set size. NOTE: This is initialized and refreshed by Parameter.
@@ -16,7 +16,7 @@ public Selection(){} // Default empty constructor.
}
class TourWithReplacement extends Selection{
- int tourSize; // Default: 2 (binary tournament).
+ final int tourSize; // Default: 2 (binary tournament).
public TourWithReplacement(int NS, int tourSize){
this.NS = NS;
@@ -52,7 +52,7 @@ public SelectedSet select(Population population){
class TourWithoutReplacement extends Selection{
- int tourSize; // Default binary tournament
+ final int tourSize; // Default binary tournament
public TourWithoutReplacement(int NS, int tourSize){
this.NS = NS;
@@ -99,7 +99,7 @@ private int tourSelect(Population population, SelectedSet selectedSet, int[] num
return maxPos;
}
- private int[] shuffle(int n){
+ private static int[] shuffle(int n){
int[] numbers = new int[n];
for(int i = 0; i < n; i++)
numbers[i] = i;
@@ -120,7 +120,7 @@ class Truncation extends Selection{
PosFit[] sortedPopulation;
// Use this inner class to sort the current population, in ascending order of fitness.
- class PosFit implements Comparable{
+ static class PosFit implements Comparable{
int position;
double fitness;
@@ -143,7 +143,7 @@ public int compareTo(PosFit posFit){
}
public String toString(){
- return "(" + position + ";" + fitness + ")";
+ return "(" + position + ';' + fitness + ')';
}
}// END: inner class PosFit.
diff --git a/src/com/b_UMDA/Parameter.java b/src/main/java/com/b_UMDA/Parameter.java
similarity index 88%
rename from src/com/b_UMDA/Parameter.java
rename to src/main/java/com/b_UMDA/Parameter.java
index 8eb9922..15c25b6 100644
--- a/src/com/b_UMDA/Parameter.java
+++ b/src/main/java/com/b_UMDA/Parameter.java
@@ -1,13 +1,14 @@
package com.b_UMDA;
+import com.z_PORTFOLIO.PortParameter;
+import com.z_PORTFOLIO.Problem;
+
import java.io.BufferedReader;
import java.io.DataInputStream;
-import java.io.FileInputStream;
+import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Scanner;
-import com.z_PORTFOLIO.Problem;
-
public class Parameter{
@@ -17,7 +18,6 @@ public class Parameter{
// Selector parameters
private static float pNS; // Size of selection set as a proportion of N. Default = 1 (The same value as N)
- private static int NS; // Size of the selection set. Depends on the chosen selection method.
private static int selectionMethod; // Selection method. Default = 1 (Tournament selection)
private static int tourSize; // Size of tournament. Use only with Tournament Selection (selection = 1 or 2)
private static float tau; // Proportion of truncated population. Use only with Truncation (selectionMethod = 3)
@@ -43,7 +43,7 @@ public class Parameter{
public static void initializeParameters(String parameterFile){
try{
// Open the file to be read
- FileInputStream fstream = new FileInputStream(parameterFile);
+ InputStream fstream = PortParameter.stream(parameterFile);
// Create an object of DataInputStream
DataInputStream in = new DataInputStream(fstream);
BufferedReader buff = new BufferedReader(new InputStreamReader(in));
@@ -74,12 +74,12 @@ private static void validateOptionName(String line, String option, int nLine){
if(option.length() >= line.length())
exitError("Line " + nLine + " --> Missing equal sign '='");
if(!validateName(option))
- exitError("Line " + nLine + " --> INVALID OPTION NAME '" + option + "'");
+ exitError("Line " + nLine + " --> INVALID OPTION NAME '" + option + '\'');
}
private static boolean validateName(String name){
- for(int i = 0; i < optionNames.length; i++)
- if(name.equals((String)optionNames[i]))
+ for (String optionName : optionNames)
+ if (name.equals((String) optionName))
return true;
return false;
}
@@ -142,7 +142,8 @@ private static void validateOptionValue(String optionName,String optionValue, in
public static Selection initializeSelection(int N){
switch(selectionMethod){
- case 1: NS = (int)(pNS*N);
+ case 1:
+ int NS = (int) (pNS * N);
return new TourWithReplacement(NS, tourSize);
case 2: NS = (int)(pNS*N);
return new TourWithoutReplacement(NS, tourSize);
@@ -175,21 +176,21 @@ public static IReplacement initializeReplacement(int currentN){
public static String writeParameters(String indent){
String str = " Selection Method:";
if(selectionMethod == 1)
- str += "\n" + indent + " Selection = Tournament Selection with replacement" +
- "\n" + indent + " pNS = " + pNS +
- "\n" + indent + " tourSize = " + tourSize;
+ str += '\n' + indent + " Selection = Tournament Selection with replacement" +
+ '\n' + indent + " pNS = " + pNS +
+ '\n' + indent + " tourSize = " + tourSize;
if(selectionMethod == 2)
- str += "\n" + indent + " Selection = Tournament Selection without replacement" +
- "\n" + indent + " pNS = " + pNS +
- "\n" + indent + " tourSize = " + tourSize;
+ str += '\n' + indent + " Selection = Tournament Selection without replacement" +
+ '\n' + indent + " pNS = " + pNS +
+ '\n' + indent + " tourSize = " + tourSize;
if(selectionMethod == 3)
- str += "\n" + indent + " Selection = Truncation" +
- "\n" + indent + " tau = " + tau;
+ str += '\n' + indent + " Selection = Truncation" +
+ '\n' + indent + " tau = " + tau;
str += "\n\n" + " Replacement Method:" +
- "\n" + indent + "Replacement Type = " + replacementType +
- "\n" + indent + " pOffspringSize = " + pOffspringSize;
+ '\n' + indent + "Replacement Type = " + replacementType +
+ '\n' + indent + " pOffspringSize = " + pOffspringSize;
if(replacementType == 1)
- str += "\n" + indent + " windowSize = " + windowSize;
+ str += '\n' + indent + " windowSize = " + windowSize;
return str;
}
diff --git a/src/com/b_UMDA/Replacement.java b/src/main/java/com/b_UMDA/Replacement.java
similarity index 63%
rename from src/com/b_UMDA/Replacement.java
rename to src/main/java/com/b_UMDA/Replacement.java
index b69a8f5..ec9e26a 100644
--- a/src/com/b_UMDA/Replacement.java
+++ b/src/main/java/com/b_UMDA/Replacement.java
@@ -1,18 +1,19 @@
package com.b_UMDA;
-import java.util.Arrays;
-
-import com.z_PORTFOLIO.PORTFOLIO;
import com.z_PORTFOLIO.Individual;
+import com.z_PORTFOLIO.PORTFOLIO;
import com.z_PORTFOLIO.Population;
+import java.util.Arrays;
+import java.util.List;
+
abstract class IReplacement{
- abstract void replace(Population population, Individual[] newIndividuals);
+ abstract void replace(Population population, List newIndividuals);
}
class RestrictedReplacement extends IReplacement{
- private int windowSize;
+ private final int windowSize;
public RestrictedReplacement(int wSize, int currentN){
int wS = currentN/20;
@@ -22,27 +23,26 @@ public RestrictedReplacement(int wSize, int currentN){
this.windowSize = wSize;
}
- public void replace(Population population, Individual[] newIndividuals){
+ public void replace(Population population, List newIndividuals){
int N = population.getN();
- for(int i = 0; i < newIndividuals.length; i++){
- Individual candidate = newIndividuals[i];
+ for (Individual candidate : newIndividuals) {
int bestPosition = -1;
int bestDistance = Integer.MAX_VALUE;
- for(int j = 1; j < windowSize; j++){ // Find within the window, the individual CLOSEST to the candidate.
+ for (int j = 1; j < windowSize; j++) { // Find within the window, the individual CLOSEST to the candidate.
int picked = PORTFOLIO.random.nextInt(N);
- Individual individual = population.getIndividual(picked);
+ Individual individual = population.getIndividual(picked);
int distance = individual.distance(candidate);
- if(distance < bestDistance){
+ if (distance < bestDistance) {
bestPosition = picked;
bestDistance = distance;
}
}
float candidateFit = candidate.computeFitness();
- if(candidateFit > population.getFitness(bestPosition)){
+ if (candidateFit > population.getFitness(bestPosition)) {
population.setIndividual(bestPosition, candidate, candidateFit);
double bestFit = population.getBestFit();
- if(candidateFit > bestFit){ // The new individual is also the best.
- population.setBestPos(bestPosition); // Update information about the best individual.
+ if (candidateFit > bestFit) { // The new individual is also the best.
+ population.setBestPos(bestPosition); // Update information about the best individual.
population.setBestFit(candidateFit);
}
}
@@ -56,7 +56,7 @@ class WorstReplacement extends IReplacement{
// Use this inner class to sort the current population, in ascending order of fitness.
// BEGIN: Inner class 'PosFit'
- class PosFit implements Comparable{
+ static class PosFit implements Comparable{
int position;
double fitness;
@@ -71,32 +71,33 @@ class PosFit implements Comparable{
public double getFitness(){return this.fitness;}
public int compareTo(PosFit posFit){
- if (this.fitness < posFit.fitness)
+ final double pf = posFit.fitness;
+ final double f = this.fitness;
+ if (f < pf)
return -1;
- if (this.fitness > posFit.fitness)
+ if (f > pf)
return 1;
return 0;
}
public String toString(){
- return "(" + position + ";" + fitness + ")";
+ return "(" + position + ';' + fitness + ')';
}
} // END: Inner class 'PosFit'
-
- private PosFit[] sortedPopulation;
-
+
public WorstReplacement(){} // Default constructor
- public void replace(Population population, Individual[] newIndividuals){
+ public void replace(Population population, List newIndividuals){
int sortN = population.getN();
- sortedPopulation = new PosFit[sortN];
+ PosFit[] sortedPopulation = new PosFit[sortN];
for(int i = 0; i < sortN; i++)
sortedPopulation[i] = new PosFit(i, population.getFitness(i));
Arrays.sort(sortedPopulation); // Sort population in ascending order of fitness.
- for(int i = 0; i < newIndividuals.length; i++){
+ for(int i = 0; i < newIndividuals.size(); i++){
int newPos = sortedPopulation[i].getPosition();
- double newFit = newIndividuals[i].computeFitness();
- population.setIndividual(newPos, newIndividuals[i], newFit);
+ final Individual nii = newIndividuals.get(i);
+ double newFit = nii.computeFitness();
+ population.setIndividual(newPos, nii, newFit);
double bestFit = population.getBestFit();
if(newFit > bestFit){ // The new individual is also the best.
population.setBestPos(newPos); // Update information about the best individual.
@@ -109,10 +110,11 @@ public void replace(Population population, Individual[] newIndividuals){
class FullReplacement extends IReplacement{
- public void replace(Population population, Individual[] newIndividuals){
- for(int i = 0; i < newIndividuals.length; i++){
- double newFit = newIndividuals[i].computeFitness();
- population.setIndividual(i, newIndividuals[i], newFit);
+ public void replace(Population population, List newIndividuals){
+ for(int i = 0; i < newIndividuals.size(); i++){
+ final Individual nii = newIndividuals.get(i);
+ double newFit = nii.computeFitness();
+ population.setIndividual(i, nii, newFit);
double bestFit = population.getBestFit();
if(newFit > bestFit){ // The new individual is also the best.
population.setBestPos(i); // Update information about the best individual.
diff --git a/src/com/b_UMDA/Selection.java b/src/main/java/com/b_UMDA/Selection.java
similarity index 90%
rename from src/com/b_UMDA/Selection.java
rename to src/main/java/com/b_UMDA/Selection.java
index 7f2b987..e3b8d60 100644
--- a/src/com/b_UMDA/Selection.java
+++ b/src/main/java/com/b_UMDA/Selection.java
@@ -1,11 +1,11 @@
package com.b_UMDA;
-import java.util.Arrays;
-
import com.z_PORTFOLIO.PORTFOLIO;
import com.z_PORTFOLIO.Population;
import com.z_PORTFOLIO.SelectedSet;
+import java.util.Arrays;
+
abstract class Selection{
public int NS; // Selection Set size. NOTE: This is initialized and refreshed by Parameter.
@@ -16,7 +16,7 @@ public Selection(){} // Default empty constructor.
}
class TourWithReplacement extends Selection{
- int tourSize; // Default: 2 (binary tournament).
+ final int tourSize; // Default: 2 (binary tournament).
public TourWithReplacement(int NS, int tourSize){
this.NS = NS;
@@ -52,7 +52,7 @@ public SelectedSet select(Population population){
class TourWithoutReplacement extends Selection{
- int tourSize; // Default binary tournament
+ final int tourSize; // Default binary tournament
public TourWithoutReplacement(int NS, int tourSize){
this.NS = NS;
@@ -99,7 +99,7 @@ private int tourSelect(Population population, SelectedSet selectedSet, int[] num
return maxPos;
}
- private int[] shuffle(int n){
+ private static int[] shuffle(int n){
int[] numbers = new int[n];
for(int i = 0; i < n; i++)
numbers[i] = i;
@@ -120,8 +120,8 @@ class Truncation extends Selection{
PosFit[] sortedPopulation;
// Use this inner class to sort the current population, in ascending order of fitness.
- class PosFit implements Comparable{
- int position;
+ static class PosFit implements Comparable{
+ final int position;
double fitness;
PosFit(int position, double fitness){
@@ -131,19 +131,21 @@ class PosFit implements Comparable{
public int getPosition(){return this.position;}
public double getFitness(){return this.fitness;}
- public void setPosition(int position){this.position = position;}
+ //public void setPosition(int position){this.position = position;}
public void setFitness(double fitness){this.fitness = fitness;}
- public int compareTo(PosFit posFit){
- if (this.fitness < posFit.fitness)
+ public int compareTo(final PosFit posFit){
+ final double f = this.fitness;
+ final double pf = posFit.fitness;
+ if (f < pf)
return -1;
- if (this.fitness > posFit.fitness)
+ if (f > pf)
return 1;
return 0;
}
public String toString(){
- return "(" + position + ";" + fitness + ")";
+ return "(" + position + ';' + fitness + ')';
}
}// END: inner class PosFit.
diff --git a/src/com/b_UMDA/UMDASolver.java b/src/main/java/com/b_UMDA/UMDASolver.java
similarity index 74%
rename from src/com/b_UMDA/UMDASolver.java
rename to src/main/java/com/b_UMDA/UMDASolver.java
index 507c0da..54cf0e2 100644
--- a/src/com/b_UMDA/UMDASolver.java
+++ b/src/main/java/com/b_UMDA/UMDASolver.java
@@ -1,9 +1,12 @@
package com.b_UMDA;
-import com.z_PORTFOLIO.Individual;
import com.z_PORTFOLIO.IEASolver;
+import com.z_PORTFOLIO.Individual;
import com.z_PORTFOLIO.SelectedSet;
+import java.util.ArrayList;
+import java.util.List;
+
/////////////////////////////////////////////////////////////////////////////////////////////////
// Each concrete Solver inherits the following fields from the abstract class IEASolver:
//
@@ -17,9 +20,9 @@
///////////////////////////////////////////////////////////////////////////////////////////////
public class UMDASolver extends IEASolver{
- private Selection selection; // NOTE: Use Parameter.initializeSelector() to generate the chosen selector type.
- private UniModel uniModel; // NOTE: Use initializeMPModel() to initialize the chosen bayesian network generator.
- private IReplacement replacement; // NOTE: Use Parameter.initializeReplacement() to generate the chosen replacement type.
+ private final Selection selection; // NOTE: Use Parameter.initializeSelector() to generate the chosen selector type.
+ private final UniModel uniModel; // NOTE: Use initializeMPModel() to initialize the chosen bayesian network generator.
+ private final IReplacement replacement; // NOTE: Use Parameter.initializeReplacement() to generate the chosen replacement type.
public UMDASolver(String paramFile, int currentN){
@@ -29,14 +32,15 @@ public UMDASolver(String paramFile, int currentN){
uniModel = Parameter.initializeUniModel(N);
replacement = Parameter.initializeReplacement(currentN);
}
-
+
+ final List ind = new ArrayList();
public void nextGeneration(){
currentGeneration++;
SelectedSet selectedSet = selection.select(currentPopulation); // 1. SELECTION. NOTE: selectedSet computes its own unifrequencies.
- Individual[] newIndividuals = uniModel.sampleNewIndividuals(selectedSet); // 2. SAMPLING with UniFrequencies.
+ List newIndividuals = uniModel.sampleNewIndividuals(selectedSet, ind); // 2. SAMPLING with UniFrequencies.
replacement.replace(currentPopulation, newIndividuals); // 3. REPLACEMENT. NOTE: This function is responsible for updating the information about the best individual.
- updateFitnessCalls(newIndividuals.length); // NOTE: replace() computes the fitness only of the newIndividuals.
+ updateFitnessCalls(newIndividuals.size()); // NOTE: replace() computes the fitness only of the newIndividuals.
currentPopulation.computeUnivariateFrequencies();
avgFitness = currentPopulation.computeAvgFitness(); // NOTE: Every nextGeneration() must compute the average fitness of its current Population!
// No need to update information about the best individual. Replacement is responsible for that.
diff --git a/src/com/b_UMDA/UniModel.java b/src/main/java/com/b_UMDA/UniModel.java
similarity index 57%
rename from src/com/b_UMDA/UniModel.java
rename to src/main/java/com/b_UMDA/UniModel.java
index 819d5f8..a5d1423 100644
--- a/src/com/b_UMDA/UniModel.java
+++ b/src/main/java/com/b_UMDA/UniModel.java
@@ -5,23 +5,24 @@
import com.z_PORTFOLIO.Problem;
import com.z_PORTFOLIO.SelectedSet;
+import java.util.List;
+
class UniModel{
- public int offspringSize;
+ public final int offspringSize;
public UniModel(int offSize){offspringSize = offSize;}
- public Individual[] sampleNewIndividuals(SelectedSet selectedSet){
- Individual[] newIndividuals = new Individual[offspringSize];
+ public List sampleNewIndividuals(SelectedSet selectedSet, List newIndividuals){
+ newIndividuals.clear();
int[] frequencies = selectedSet.getUniFrequencies();
int NS = selectedSet.getN();
for(int i = 0; i < offspringSize; i++){
- newIndividuals[i] = new Individual();
+ Individual x = new Individual();
+ newIndividuals.add( x );
+ final char[] data = x.getIndividual();
for(int j = 0; j < Problem.n; j++){
double probJ = ((double)(frequencies[j]))/NS;
- if (PORTFOLIO.random.nextDouble() < probJ)
- newIndividuals[i].setAllele(j, '1');
- else
- newIndividuals[i].setAllele(j, '0');
+ data[j] = (PORTFOLIO.random.nextDouble() < probJ) ? '1' : '0';;
}
}
return newIndividuals;
diff --git a/src/com/c_ECGA/Cache.java b/src/main/java/com/c_ECGA/Cache.java
similarity index 87%
rename from src/com/c_ECGA/Cache.java
rename to src/main/java/com/c_ECGA/Cache.java
index b1eae48..1a01665 100644
--- a/src/com/c_ECGA/Cache.java
+++ b/src/main/java/com/c_ECGA/Cache.java
@@ -2,15 +2,18 @@
import com.z_PORTFOLIO.Problem;
+import java.util.Arrays;
+
class Cache{
public int maxSize;
public int nMergedSets;
- public Subset[] mergedSets; // NOTE: Try implementing subclass 'MergedSet' instead.
- public int[] idA, idB;
- public double[] compressions;
+ public final Subset[] mergedSets; // NOTE: Try implementing subclass 'MergedSet' instead.
+ public final int[] idA;
+ public final int[] idB;
+ public final double[] compressions;
- private int[] emptyPositions;
+ private final int[] emptyPositions;
private int nEmptyPositions;
public Cache(){
@@ -90,7 +93,7 @@ public void compact(){
maxSize = newMaxSize;
}
- public String toString(){return "Sets: " + mergedSets + "\nidA: " + idA + "\nidB: " + idB;}
+ public String toString(){return "Sets: " + Arrays.toString(mergedSets) + "\nidA: " + Arrays.toString(idA) + "\nidB: " + Arrays.toString(idB);}
}
diff --git a/src/com/c_ECGA/ECGASolver.java b/src/main/java/com/c_ECGA/ECGASolver.java
similarity index 86%
rename from src/com/c_ECGA/ECGASolver.java
rename to src/main/java/com/c_ECGA/ECGASolver.java
index 8551747..8050325 100644
--- a/src/com/c_ECGA/ECGASolver.java
+++ b/src/main/java/com/c_ECGA/ECGASolver.java
@@ -18,9 +18,9 @@
public class ECGASolver extends IEASolver{
- private Selection selection; // NOTE: Use Parameter.initializeSelector() to generate the chosen selector type.
- private MPModel mPModel; // NOTE: Use initializeMPModel() to initialize the chosen bayesian network generator.
- private IReplacement replacement; // NOTE: Use Parameter.initializeReplacement() to generate the chosen replacement type.
+ private final Selection selection; // NOTE: Use Parameter.initializeSelector() to generate the chosen selector type.
+ private final MPModel mPModel; // NOTE: Use initializeMPModel() to initialize the chosen bayesian network generator.
+ private final IReplacement replacement; // NOTE: Use Parameter.initializeReplacement() to generate the chosen replacement type.
public ECGASolver(String paramFile, int currentN){
diff --git a/src/com/c_ECGA/MPModel.java b/src/main/java/com/c_ECGA/MPModel.java
similarity index 95%
rename from src/com/c_ECGA/MPModel.java
rename to src/main/java/com/c_ECGA/MPModel.java
index 7f70163..f151a3a 100644
--- a/src/com/c_ECGA/MPModel.java
+++ b/src/main/java/com/c_ECGA/MPModel.java
@@ -5,12 +5,14 @@
import com.z_PORTFOLIO.Problem;
import com.z_PORTFOLIO.SelectedSet;
+import java.util.Arrays;
+
class MPModel{
- public int offspringSize; // NOTE: The MPM is responsible for sampling new individuals.
+ public final int offspringSize; // NOTE: The MPM is responsible for sampling new individuals.
private Subset[] subsets;
- private int maxSubsets;
+ private final int maxSubsets;
private int nSubsets;
private Cache cache;
@@ -106,8 +108,7 @@ public Individual[] sampleNewIndividuals(SelectedSet selectedSet){
for(int j = 0; j < offspringSize; j++){
int pick = PORTFOLIO.random.nextInt(offspringSize); // NOTE: Implement makeShuffle(offspringSize) to ensure non-replacement
Individual pickIndiv = selectedSet.getIndividual(pick);
- for(int l = 0; l < xList.length; l++){
- int locus = xList[l];
+ for (int locus : xList) {
char allele = pickIndiv.getAllele(locus);
newIndividuals[j].setAllele(locus, allele);
}
@@ -117,7 +118,7 @@ public Individual[] sampleNewIndividuals(SelectedSet selectedSet){
}
public String toString(){
- return "Subsets: " + subsets + "\nCache: " + cache;
+ return "Subsets: " + Arrays.toString(subsets) + "\nCache: " + cache;
}
}
diff --git a/src/com/c_ECGA/Parameter.java b/src/main/java/com/c_ECGA/Parameter.java
similarity index 89%
rename from src/com/c_ECGA/Parameter.java
rename to src/main/java/com/c_ECGA/Parameter.java
index 70609fa..892d2c5 100644
--- a/src/com/c_ECGA/Parameter.java
+++ b/src/main/java/com/c_ECGA/Parameter.java
@@ -1,12 +1,14 @@
package com.c_ECGA;
+import com.z_PORTFOLIO.Problem;
+
import java.io.BufferedReader;
import java.io.DataInputStream;
-import java.io.FileInputStream;
+import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Scanner;
-import com.z_PORTFOLIO.Problem;
+import static com.z_PORTFOLIO.PortParameter.stream;
public class Parameter{
@@ -19,7 +21,6 @@ public class Parameter{
// Selector parameters
private static float pNS; // Size of selection set as a proportion of N. Default = 1 (The same value as N)
- private static int NS; // Size of the selection set. Depends on the chosen selection method.
private static int selectionMethod; // Selection method. Default = 1 (Tournament selection)
private static int tourSize; // Size of tournament. Use only with Tournament Selection (selection = 1 or 2)
private static float tau; // Proportion of truncated population. Use only with Truncation (selectionMethod = 3)
@@ -49,7 +50,7 @@ public class Parameter{
public static void initializeParameters(String parameterFile){
try{
// Open the file to be read
- FileInputStream fstream = new FileInputStream(parameterFile);
+ InputStream fstream = stream(parameterFile);
// Create an object of DataInputStream
DataInputStream in = new DataInputStream(fstream);
BufferedReader buff = new BufferedReader(new InputStreamReader(in));
@@ -80,12 +81,12 @@ private static void validateOptionName(String line, String option, int nLine){
if(option.length() >= line.length())
exitError("Line " + nLine + " --> Missing equal sign '='");
if(!validateName(option))
- exitError("Line " + nLine + " --> INVALID OPTION NAME '" + option + "'");
+ exitError("Line " + nLine + " --> INVALID OPTION NAME '" + option + '\'');
}
private static boolean validateName(String name){
- for(int i = 0; i < optionNames.length; i++)
- if(name.equals((String)optionNames[i]))
+ for (String optionName : optionNames)
+ if (name.equals((String) optionName))
return true;
return false;
}
@@ -155,7 +156,8 @@ private static void validateOptionValue(String optionName,String optionValue, in
public static Selection initializeSelection(int N){
switch(selectionMethod){
- case 1: NS = (int)(pNS*N);
+ case 1:
+ int NS = (int) (pNS * N);
return new TourWithReplacement(NS, tourSize);
case 2: NS = (int)(pNS*N);
return new TourWithoutReplacement(NS, tourSize);
@@ -195,21 +197,21 @@ public static IReplacement initializeReplacement(int currentN){
public static String writeParameters(String indent){
String str = " Selection Method:";
if(selectionMethod == 1)
- str += "\n" + indent + " Selection = Tournament Selection with replacement" +
- "\n" + indent + " pNS = " + pNS +
- "\n" + indent + " tourSize = " + tourSize;
+ str += '\n' + indent + " Selection = Tournament Selection with replacement" +
+ '\n' + indent + " pNS = " + pNS +
+ '\n' + indent + " tourSize = " + tourSize;
if(selectionMethod == 2)
- str += "\n" + indent + " Selection = Tournament Selection without replacement" +
- "\n" + indent + " pNS = " + pNS +
- "\n" + indent + " tourSize = " + tourSize;
+ str += '\n' + indent + " Selection = Tournament Selection without replacement" +
+ '\n' + indent + " pNS = " + pNS +
+ '\n' + indent + " tourSize = " + tourSize;
if(selectionMethod == 3)
- str += "\n" + indent + " Selection = Truncation" +
- "\n" + indent + " tau = " + tau;
+ str += '\n' + indent + " Selection = Truncation" +
+ '\n' + indent + " tau = " + tau;
str += "\n\n" + " Replacement Method:" +
- "\n" + indent + "Replacement Type = " + replacementType +
- "\n" + indent + " pOffspringSize = " + pOffspringSize;
+ '\n' + indent + "Replacement Type = " + replacementType +
+ '\n' + indent + " pOffspringSize = " + pOffspringSize;
if(replacementType == 1)
- str += "\n" + indent + " windowSize = " + windowSize;
+ str += '\n' + indent + " windowSize = " + windowSize;
return str;
}
diff --git a/src/com/c_ECGA/Replacement.java b/src/main/java/com/c_ECGA/Replacement.java
similarity index 72%
rename from src/com/c_ECGA/Replacement.java
rename to src/main/java/com/c_ECGA/Replacement.java
index ab81dbd..e517505 100644
--- a/src/com/c_ECGA/Replacement.java
+++ b/src/main/java/com/c_ECGA/Replacement.java
@@ -1,18 +1,18 @@
package com.c_ECGA;
-import java.util.Arrays;
-
-import com.z_PORTFOLIO.PORTFOLIO;
import com.z_PORTFOLIO.Individual;
+import com.z_PORTFOLIO.PORTFOLIO;
import com.z_PORTFOLIO.Population;
+import java.util.Arrays;
+
-abstract class IReplacement{
- abstract void replace(Population population, Individual[] newIndividuals);
+interface IReplacement{
+ void replace(Population population, Individual[] newIndividuals);
}
-class RestrictedReplacement extends IReplacement{
- private int windowSize;
+class RestrictedReplacement implements IReplacement{
+ private final int windowSize;
public RestrictedReplacement(int wSize, int currentN){
int wS = currentN/20;
@@ -24,25 +24,24 @@ public RestrictedReplacement(int wSize, int currentN){
public void replace(Population population, Individual[] newIndividuals){
int N = population.getN();
- for(int i = 0; i < newIndividuals.length; i++){
- Individual candidate = newIndividuals[i];
+ for (Individual candidate : newIndividuals) {
int bestPosition = -1;
int bestDistance = Integer.MAX_VALUE;
- for(int j = 1; j < windowSize; j++){ // Find within the window, the individual CLOSEST to the candidate.
+ for (int j = 1; j < windowSize; j++) { // Find within the window, the individual CLOSEST to the candidate.
int picked = PORTFOLIO.random.nextInt(N);
- Individual individual = population.getIndividual(picked);
+ Individual individual = population.getIndividual(picked);
int distance = individual.distance(candidate);
- if(distance < bestDistance){
+ if (distance < bestDistance) {
bestPosition = picked;
bestDistance = distance;
}
}
float candidateFit = candidate.computeFitness();
- if(candidateFit > population.getFitness(bestPosition)){
+ if (candidateFit > population.getFitness(bestPosition)) {
population.setIndividual(bestPosition, candidate, candidateFit);
double bestFit = population.getBestFit();
- if(candidateFit > bestFit){ // The new individual is also the best.
- population.setBestPos(bestPosition); // Update information about the best individual.
+ if (candidateFit > bestFit) { // The new individual is also the best.
+ population.setBestPos(bestPosition); // Update information about the best individual.
population.setBestFit(candidateFit);
}
}
@@ -52,21 +51,19 @@ public void replace(Population population, Individual[] newIndividuals){
-class WorstReplacement extends IReplacement{
+class WorstReplacement implements IReplacement{
// Use this inner class to sort the current population, in ascending order of fitness.
// BEGIN: Inner class 'PosFit'
- class PosFit implements Comparable{
- int position;
- double fitness;
+ static class PosFit implements Comparable{
+ public final int position;
+ public final double fitness;
PosFit(int position, double fitness){
this.position = position;
this.fitness = fitness;
}
- public void setPosition(int position){this.position = position;}
- public void setFitness(double fitness){this.fitness = fitness;}
public int getPosition(){return this.position;}
public double getFitness(){return this.fitness;}
@@ -79,17 +76,15 @@ public int compareTo(PosFit posFit){
}
public String toString(){
- return "(" + position + ";" + fitness + ")";
+ return "(" + position + ';' + fitness + ')';
}
} // END: Inner class 'PosFit'
-
- private PosFit[] sortedPopulation;
-
+
public WorstReplacement(){} // Default constructor
public void replace(Population population, Individual[] newIndividuals){
int sortN = population.getN();
- sortedPopulation = new PosFit[sortN];
+ PosFit[] sortedPopulation = new PosFit[sortN];
for(int i = 0; i < sortN; i++)
sortedPopulation[i] = new PosFit(i, population.getFitness(i));
Arrays.sort(sortedPopulation); // Sort population in ascending order of fitness.
@@ -107,7 +102,7 @@ public void replace(Population population, Individual[] newIndividuals){
}// END: Class WorstReplacement
-class FullReplacement extends IReplacement{
+class FullReplacement implements IReplacement{
public void replace(Population population, Individual[] newIndividuals){
for(int i = 0; i < newIndividuals.length; i++){
diff --git a/src/com/c_ECGA/Selection.java b/src/main/java/com/c_ECGA/Selection.java
similarity index 95%
rename from src/com/c_ECGA/Selection.java
rename to src/main/java/com/c_ECGA/Selection.java
index 3c4be00..6fe4f6b 100644
--- a/src/com/c_ECGA/Selection.java
+++ b/src/main/java/com/c_ECGA/Selection.java
@@ -16,7 +16,7 @@ public Selection(){} // Default empty constructor.
}
class TourWithReplacement extends Selection{
- int tourSize; // Default: 2 (binary tournament).
+ final int tourSize; // Default: 2 (binary tournament).
public TourWithReplacement(int NS, int tourSize){
this.NS = NS;
@@ -52,7 +52,7 @@ public SelectedSet select(Population population){
class TourWithoutReplacement extends Selection{
- int tourSize; // Default binary tournament
+ final int tourSize; // Default binary tournament
public TourWithoutReplacement(int NS, int tourSize){
this.NS = NS;
@@ -99,7 +99,7 @@ private int tourSelect(Population population, SelectedSet selectedSet, int[] num
return maxPos;
}
- private int[] shuffle(int n){
+ private static int[] shuffle(int n){
int[] numbers = new int[n];
for(int i = 0; i < n; i++)
numbers[i] = i;
@@ -120,7 +120,7 @@ class Truncation extends Selection{
PosFit[] sortedPopulation;
// Use this inner class to sort the current population, in ascending order of fitness.
- class PosFit implements Comparable{
+ static class PosFit implements Comparable{
int position;
double fitness;
@@ -143,7 +143,7 @@ public int compareTo(PosFit posFit){
}
public String toString(){
- return "(" + position + ";" + fitness + ")";
+ return "(" + position + ';' + fitness + ')';
}
}// END: inner class PosFit.
diff --git a/src/com/c_ECGA/Subset.java b/src/main/java/com/c_ECGA/Subset.java
similarity index 85%
rename from src/com/c_ECGA/Subset.java
rename to src/main/java/com/c_ECGA/Subset.java
index e9834ee..6311841 100644
--- a/src/com/c_ECGA/Subset.java
+++ b/src/main/java/com/c_ECGA/Subset.java
@@ -5,10 +5,10 @@
class Subset{
- private int[] xList; // List of variables in this Subset.
- private int nFrequencies; // Number of possible frequencies for this Subset. nFrequencies = 2^xList.size().
- private double mComplexity, // Model Complexity
- cpComplexity; // Compressed Population Complexity
+ private final int[] xList; // List of variables in this Subset.
+ private final int nFrequencies; // Number of possible frequencies for this Subset. nFrequencies = 2^xList.size().
+ private final double mComplexity; // Model Complexity
+ private final double cpComplexity; // Compressed Population Complexity
public Subset(SelectedSet selectedSet, int Xi){
int NS = selectedSet.getN();
@@ -47,7 +47,7 @@ public Subset merge(Subset setB, SelectedSet selectedSet){ // NOTE: setC <-
return new Subset(selectedSet, xListC);
}
- public int[] mergeXList(int[] xListA, int[] xListB){
+ public static int[] mergeXList(int[] xListA, int[] xListB){
int sizeA = xListA.length,
sizeB = xListB.length,
sizeC = sizeA + sizeB;
@@ -98,7 +98,7 @@ private int[] computeFrequencies(SelectedSet selectedSet){
return frequencies;
}
- private int encode(char[] schema, int xSize){
+ private static int encode(char[] schema, int xSize){
int result = 0;
int powerof2 = 1;
for(int j = xSize-1; j >= 0; j--){
@@ -130,11 +130,10 @@ private int[] decode(int code){
public String toString(){
String str = "xList: [";
- for(int i = 0; i < xList.length; i++)
- str += xList[i] + ","; // Print the xList array.
+ for (int aXList : xList) str += aXList + ","; // Print the xList array.
str = str.substring(0, str.length()-1); // Remove the last comma.
str += "] ; MC = " + mComplexity + " ; CPC = " + cpComplexity;
- return str + "\n";
+ return str + '\n';
}
}
diff --git a/src/com/d_HBOA/BayesianMetric.java b/src/main/java/com/d_HBOA/BayesianMetric.java
similarity index 88%
rename from src/com/d_HBOA/BayesianMetric.java
rename to src/main/java/com/d_HBOA/BayesianMetric.java
index b6e3ff7..1c59870 100644
--- a/src/com/d_HBOA/BayesianMetric.java
+++ b/src/main/java/com/d_HBOA/BayesianMetric.java
@@ -6,7 +6,7 @@
abstract class IBayesianMetric {
protected int NS;
- private static double logBase2 = ((double)1)/Math.log(2);
+ private static final double logBase2 = ((double)1)/Math.log(2);
public double computeScoreGain(int mZero, int mOne, int m00, int m01, int m10, int m11){
double l0 = computeLeafGain(m00, m10);
@@ -21,7 +21,7 @@ public double computeScoreGain(int mZero, int mOne, int m00, int m01, int m10, i
class BDMetric extends IBayesianMetric{
// Precomputed logarithm list -> 0, ln(1), ln(2),..., ln(NS+1).
// Use this list to compute the score gain for each leaf.
- private static ArrayList preSumLogs = new ArrayList();
+ private static final ArrayList preSumLogs = new ArrayList<>();
BDMetric(int NS){
this.NS = NS;
@@ -51,7 +51,7 @@ class BICMetric extends IBayesianMetric{
// DEPRECATED: public BICMetric(int NS){this.NS = NS;}
protected double computeLeafGain(int m, int mX){
- if(m == mX || mX == 0) return 0; // NOTE: The case m = 0 is always included because 0 ² mX ² m, and so m = 0 => mX = 0. The reverse is not necessarily true.
+ if(m == mX || mX == 0) return 0; // NOTE: The case m = 0 is always included because 0 � mX � m, and so m = 0 => mX = 0. The reverse is not necessarily true.
double freq = ((double)mX)/((double)m); // NOTE: The return value 0 is limit-based! Is this correct, even for m = mX = 0 ?
return (double)((m-mX)*Math.log(1-freq) + mX*Math.log(freq));
}
diff --git a/src/com/d_HBOA/BayesianNetwork.java b/src/main/java/com/d_HBOA/BayesianNetwork.java
similarity index 72%
rename from src/com/d_HBOA/BayesianNetwork.java
rename to src/main/java/com/d_HBOA/BayesianNetwork.java
index 2cb79d9..b84547e 100644
--- a/src/com/d_HBOA/BayesianNetwork.java
+++ b/src/main/java/com/d_HBOA/BayesianNetwork.java
@@ -1,27 +1,27 @@
package com.d_HBOA;
-import java.util.ArrayList;
-import java.util.HashSet;
-
+import com.gs.collections.impl.set.mutable.primitive.IntHashSet;
import com.z_PORTFOLIO.Individual;
import com.z_PORTFOLIO.Problem;
import com.z_PORTFOLIO.SelectedSet;
+import java.util.ArrayList;
+
@SuppressWarnings("unchecked") // Supress warnings for creating an Array of ArrayList.
class BayesianNetwork{ // Check: B. Eckel, "Thinking in Java", 4th ed., MindView Inc., 2006, [pp. 759-761]
- public int offspringSize; // NOTE: The BN is responsible for sampling new individuals.
- private IBayesianMetric bayesianMetric;
- private int maxVertexDegree; // Maximum number of parents per vertex.
+ public final int offspringSize; // NOTE: The BN is responsible for sampling new individuals.
+ private final IBayesianMetric bayesianMetric;
+ private final int maxVertexDegree; // Maximum number of parents per vertex.
private int bestDecisionGraphPos; // Position of the decision graph (DG) that contains the best score gain.
private double bestScoreGain; // Best global score.
- private DecisionGraph[] decisionGraphs = new DecisionGraph[Problem.n];
- private HashSet[] parentList = (HashSet[])new HashSet[Problem.n]; // Use this to generate the topological ordering and the CP Tables.
- private HashSet[] adjacencyList = (HashSet[])new HashSet[Problem.n]; // Use this to insure an acyclic BN.
- private HashSet[] splitList = (HashSet[])new HashSet[Problem.n]; // Use this to choose only the correct splits.
+ private final DecisionGraph[] decisionGraphs = new DecisionGraph[Problem.n];
+ private final IntHashSet[] parentList = new IntHashSet[Problem.n]; // Use this to generate the topological ordering and the CP Tables.
+ private final IntHashSet[] adjacencyList = new IntHashSet[Problem.n]; // Use this to insure an acyclic BN.
+ private final IntHashSet[] splitList = new IntHashSet[Problem.n]; // Use this to choose only the correct splits.
@@ -57,7 +57,13 @@ public void generateModel(SelectedSet selectedSet){
}
private void generateDecisionGraphs(SelectedSet selectedSet){
- this.initializeBN(selectedSet); // Refresh the BN. Compute and store in decreasing order the first score gains, corresponding to adding a first edge to the empty BN.
+ this.initializeBN(selectedSet);
+
+
+ IntHashSet descendants = new IntHashSet(Problem.n); // Initial Capacity = stringSize; Default Load Factor = 0.75
+ IntHashSet ascendants = new IntHashSet(Problem.n); // Initial Capacity = stringSize; De
+
+ // Refresh the BN. Compute and store in decreasing order the first score gains, corresponding to adding a first edge to the empty BN.
while(bestScoreGain > 0){ // Search for the best split and store all the necessary information to effectively perform it.
DecisionGraph bestDecisionGraph = decisionGraphs[bestDecisionGraphPos];
int bestLeafPos = bestDecisionGraph.getBestLeafPos();
@@ -71,7 +77,7 @@ private void generateDecisionGraphs(SelectedSet selectedSet){
bestLeaf.resetBestSplit(splitList[bestDecisionGraphPos]);
}
else{ // Perform the best split.
- performBestSplit(bestDecisionGraphPos, bestLeafPos, bestSplitPos); // Update the BN and remove non-valid splits.
+ performBestSplit(bestDecisionGraphPos, bestLeafPos, bestSplitPos, ascendants, descendants); // Update the BN and remove non-valid splits.
computeNewLeafScores(selectedSet, bestDecisionGraphPos, bestLeafPos);
}
decisionGraphs[bestDecisionGraphPos].updateBestLeaf();
@@ -86,9 +92,9 @@ private void initializeBN(SelectedSet selectedSet){
this.bestScoreGain = Double.NEGATIVE_INFINITY;
Individual[] individuals = selectedSet.getIndividuals();
for(int i = 0; i < Problem.n; i++){ // Refresh the Bayesian Network structure.
- parentList[i] = new HashSet(Problem.n); // Initial Capacity = stringSize; Default Load Factor = 0.75
- adjacencyList[i] = new HashSet(Problem.n); // Initial Capacity = stringSize; Default Load Factor = 0.75
- splitList[i] = new HashSet(2*Problem.n); // Initial Capacity = 2*stringSize; Default Load Factor = 0.75
+ parentList[i] = new IntHashSet(Problem.n); // Initial Capacity = stringSize; Default Load Factor = 0.75
+ adjacencyList[i] = new IntHashSet(Problem.n); // Initial Capacity = stringSize; Default Load Factor = 0.75
+ splitList[i] = new IntHashSet(2 * Problem.n); // Initial Capacity = 2*stringSize; Default Load Factor = 0.75
for(int n = 0; n < Problem.n; n++)
if(n != i)
splitList[i].add(n);
@@ -99,8 +105,10 @@ private void initializeBN(SelectedSet selectedSet){
if(mZero > 0 && mOne > 0){ // If mZero = 0 or mOne = 0 there is no need to try any split with this leaf.
for(int j = 0; j < NS; j++){
char alleleJI = individuals[j].getAllele(i); // Value of Xi in individual j.
- for(int s: splitList[i]){
- char alleleS = individuals[j].getAllele(s); // Value of Xs in individual j.
+
+ final int finalJ = j;
+ splitList[i].forEach( s -> {
+ char alleleS = individuals[finalJ].getAllele(s); // Value of Xs in individual j.
if(alleleJI == '0'){
if(alleleS == '0')
newLeaf.addPossibleSplitFrequency(0, s); // m00[s]++;
@@ -113,9 +121,9 @@ private void initializeBN(SelectedSet selectedSet){
else
newLeaf.addPossibleSplitFrequency(3, s); // m11[s]++;
}
- }
+ });
}
- for(int s: splitList[i]){
+ splitList[i].forEach( s -> {
int m00 = newLeaf.getPossibleSplitFrequency(0,s);
int m01 = newLeaf.getPossibleSplitFrequency(1,s);
int m10 = newLeaf.getPossibleSplitFrequency(2,s);
@@ -123,7 +131,7 @@ private void initializeBN(SelectedSet selectedSet){
double scoreGain = bayesianMetric.computeScoreGain(mZero, mOne, m00, m01, m10, m11);
newLeaf.setScoreGain(s, scoreGain);
newLeaf.updateBestSplit(s, scoreGain); // Responsible for updating the value of the best split score gain in this leaf.
- }
+ });
} // END: if(mZero > 0 ...)
decisionGraphs[i] = new DecisionGraph(newLeaf); // Initially each graph as a single leaf and there are n-1 possible splits.
decisionGraphs[i].updateBestLeaf();
@@ -137,17 +145,22 @@ private void initializeBN(SelectedSet selectedSet){
- private void performBestSplit(int i, int j, int k){
- parentList[i].add(k); // Xk is a parent of Xi.
- adjacencyList[k].add(i); // Xi is a child of Xk.
- HashSet descendants = new HashSet(Problem.n); // Initial Capacity = stringSize; Default Load Factor = 0.75
- HashSet ascendants = new HashSet(Problem.n); // Initial Capacity = stringSize; Default Load Factor = 0.75
+ private void performBestSplit(int i, int j, int k, IntHashSet ascendants, IntHashSet descendants ){
+ ascendants.clear();
+ descendants.clear();
+
+ parentList[i].add(k); // Xk is a parent of Xi.
+ adjacencyList[k].add(i); // Xi is a child of Xk. fault Load Factor = 0.75
getDescendants(descendants, i); // NOTE: The list of descendants includes variable Xi itself.
getAscendants(ascendants, k); // NOTE: The list of ascendants includes variable Xk itself.
- for(int asc: ascendants) // No child of the child of the child of ... of Xi can be a parent of Xk.
- for(int desc: descendants) // No child of the child of the child of ... of Xi can be a parent of the parent of the parent of ... of Xk.
- splitList[asc].remove(desc); // Xdesc can no longer be a parent of Xasc. Remove splits to avoid cycles.
- decisionGraphs[i].splitBestLeaf(j, k); // Effectively perform the best split.
+ ascendants.forEach( asc -> {
+ // No child of the child of the child of ... of Xi can be a parent of Xk.
+ splitList[asc].removeAll(descendants);
+ /*for (int desc : descendants) // No child of the child of the child of ... of Xi can be a parent of the parent of the parent of ... of Xk.
+ splitList[asc].remove(desc);*/ // Xdesc can no longer be a parent of Xasc. Remove splits to avoid cycles.
+ });
+
+ decisionGraphs[i].splitBestLeaf(j, k); // Effectively perform the best split.
} // END: performBestSplit(...)
@@ -166,36 +179,38 @@ private void computeNewLeafScores(SelectedSet selectedSet, int i, int j){
else
iterator = ((Variable)iterator).getOne();
}
- int itrPosition = decisionGraphs[i].getLeafs().indexOf((Leaf)iterator);
+ int itrPosition = decisionGraphs[i].getLeafs().indexOf(iterator);
if(itrPosition == j || itrPosition == j+1){ // We've reached one of the new leafs.
int mZero = ((Leaf)iterator).getMZero();
int mOne = ((Leaf)iterator).getMOne();
if(mZero > 0 && mOne > 0){ // It's still "interesting" to split.
char alleleI = individual.getAllele(i); // Value of Xi in individual a.
- for(int split: splitList[i]){
+
+ final IGraph finalIterator = iterator;
+ splitList[i].forEach( split -> {
char alleleS = individual.getAllele(split); // Value of Xsplit in individual a.
if(alleleI == '0'){
if(alleleS == '0')
- ((Leaf)iterator).addPossibleSplitFrequency(0,split); // m00[split]++;
+ ((Leaf) finalIterator).addPossibleSplitFrequency(0,split); // m00[split]++;
else
- ((Leaf)iterator).addPossibleSplitFrequency(1,split); // m01[split]++;
+ ((Leaf) finalIterator).addPossibleSplitFrequency(1,split); // m01[split]++;
}
else{
if(alleleS == '0')
- ((Leaf)iterator).addPossibleSplitFrequency(2,split); // m10[split]++;
+ ((Leaf) finalIterator).addPossibleSplitFrequency(2,split); // m10[split]++;
else
- ((Leaf)iterator).addPossibleSplitFrequency(3,split); // m11[split]++;
+ ((Leaf) finalIterator).addPossibleSplitFrequency(3,split); // m11[split]++;
}
- }
+ });
}
}
}
for(int a = 0; a <= 1; a++){
- Leaf newLeaf = decisionGraphs[i].getLeaf(j+a); // The two new leafs are at positions 'j' and 'j+1'.
+ Leaf newLeaf = decisionGraphs[i].getLeaf(j + a); // The two new leafs are at positions 'j' and 'j+1'.
int mZero = newLeaf.getMZero();
int mOne = newLeaf.getMOne();
- if(mZero > 0 && mOne > 0)
- for(int s: splitList[i]){
+ if(mZero > 0 && mOne > 0)
+ splitList[i].forEach( s -> {
int m00 = newLeaf.getPossibleSplitFrequency(0,s);
int m01 = newLeaf.getPossibleSplitFrequency(1,s);
int m10 = newLeaf.getPossibleSplitFrequency(2,s);
@@ -203,7 +218,7 @@ private void computeNewLeafScores(SelectedSet selectedSet, int i, int j){
double scoreGain = bayesianMetric.computeScoreGain(mZero, mOne, m00, m01, m10, m11);
newLeaf.setScoreGain(s, scoreGain);
newLeaf.updateBestSplit(s, scoreGain); // Responsible for updating the value of the best split score gain in this leaf.
- }
+ });
} // END: for(int a = 0 ...)
} // END: computeNewLeafScores(...)
@@ -218,19 +233,17 @@ private void updateScoreGain(){
}
}
}
-
- private void getDescendants(HashSet descendants, int i){
- boolean notVisited = descendants.add(i);
- if(notVisited)
- for(int desc: adjacencyList[i])
- getDescendants(descendants, desc);
+
+ final private void getDescendants(final IntHashSet descendants, final int i){
+ if(descendants.add(i))
+ adjacencyList[i].forEach( desc ->
+ getDescendants(descendants, desc) );
}
-
- private void getAscendants(HashSet ascendants, int k){
- boolean notVisited = ascendants.add(k);
- if(notVisited)
- for(int asc: parentList[k])
- getAscendants(ascendants, asc);
+
+ final private void getAscendants(final IntHashSet ascendants, final int k){
+ if(ascendants.add(k))
+ parentList[k].forEach(asc ->
+ getAscendants(ascendants, asc));
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -243,7 +256,7 @@ private void getAscendants(HashSet ascendants, int k){
private void topologicalSort(){
color = new int[Problem.n]; // NOTE: color[] is initialized with all zeros, by default.
- topSort = new ArrayList();
+ topSort = new ArrayList<>();
for(int Xi = 0; Xi < Problem.n; Xi++)
if(color[Xi] == 0)
DFSVisit(Xi);
@@ -251,9 +264,10 @@ private void topologicalSort(){
private void DFSVisit(int Xi){
color[Xi] = 1; // Xi is now GRAY.
- for(int child: adjacencyList[Xi])
- if(color[child] == 0)
+ adjacencyList[Xi].forEach(child -> {
+ if(color[child] == 0)
DFSVisit(child);
+ });
topSort.add(Xi); // NOTE: Topological sort is in ASCENDENT order of finishing time.
}
@@ -277,13 +291,18 @@ public String toString(){
String aList = "";
String sList = "";
for(int i = 0; i < Problem.n; i++){
- for(int p: parentList[i])
+ /*for(int p: parentList[i])
pList += p + "|";
for(int a: adjacencyList[i])
aList += a + "|";
for(int s: splitList[i])
- sList += s + "|";
- str += i + " " + pList + " " + aList + " " + sList + "\n";
+ sList += s + "|";*/
+ pList += parentList[i];
+ aList += adjacencyList[i];
+ sList += splitList[i];
+
+
+ str += i + " " + pList + " " + aList + " " + sList + '\n';
pList = "";
aList = "";
sList = "";
diff --git a/src/com/d_HBOA/DecisionGraph.java b/src/main/java/com/d_HBOA/DecisionGraph.java
similarity index 92%
rename from src/com/d_HBOA/DecisionGraph.java
rename to src/main/java/com/d_HBOA/DecisionGraph.java
index d0da346..3606aa3 100644
--- a/src/com/d_HBOA/DecisionGraph.java
+++ b/src/main/java/com/d_HBOA/DecisionGraph.java
@@ -1,18 +1,18 @@
package com.d_HBOA;
-import java.util.ArrayList;
-import java.util.HashSet;
-
+import com.gs.collections.impl.set.mutable.primitive.IntHashSet;
import com.z_PORTFOLIO.PORTFOLIO;
import com.z_PORTFOLIO.Problem;
+import java.util.ArrayList;
+
interface IGraph{
- public void setParent(Variable parent, int side);
+ void setParent(Variable parent, int side);
}
class Variable implements IGraph{
- private int variable;
+ private final int variable;
private IGraph zero, one;
@@ -34,7 +34,7 @@ public Variable(int x, IGraph zero, IGraph one){
public void setOne(IGraph one){this.one = one;}
public void setParent(Variable parent, int side){} // No need to store a variable's parent.
- public String toString(){return "(X" + variable + " ("+ zero + ")" + " (" + one +"))";}
+ public String toString(){return "(X" + variable + " ("+ zero + ')' + " (" + one +"))";}
}
class Leaf implements IGraph{
@@ -42,8 +42,8 @@ class Leaf implements IGraph{
side,
mZero, mOne;
private Variable parent;
- private int[][] possibleSplitFrequencies = new int[4][Problem.n]; // NOTE: 0 -> m00; 1 -> m01; 2 -> m10; 3 -> m11
- private double[] scoreGains = new double[Problem.n];
+ private final int[][] possibleSplitFrequencies = new int[4][Problem.n]; // NOTE: 0 -> m00; 1 -> m01; 2 -> m10; 3 -> m11
+ private final double[] scoreGains = new double[Problem.n];
private int bestSplit;
private double bestSplitScoreGain;
@@ -86,15 +86,15 @@ public void updateBestSplit(int k, double scoreGain){ // Responsible for upd
}
}
- public void resetBestSplit(HashSet splitList){
+ public void resetBestSplit(IntHashSet splitList){
this.bestSplitScoreGain = Double.NEGATIVE_INFINITY;
- for(int s: splitList){
+ splitList.forEach( s-> {
double scoreGain = scoreGains[s];
if(scoreGain > bestSplitScoreGain){
this.bestSplit = s;
this.bestSplitScoreGain = scoreGain;
}
- }
+ });
}
public String toString(){
@@ -103,14 +103,14 @@ public String toString(){
str += scoreGains[i] + ","; // Print the scoreOrders array.
str = str.substring(0, str.length()-1); // Remove the last comma.
return "[d = " + depth + "; s = " + side + "; m0 = " + mZero +
- "; m1= " + mOne + "]" + "; scoreGains=[" + str + "]";
+ "; m1= " + mOne + ']' + "; scoreGains=[" + str + ']';
}
}
class DecisionGraph{
private IGraph graph;
- private ArrayList leafs = new ArrayList();
+ private final ArrayList leafs = new ArrayList<>();
private int bestLeafPos; // Position of the leaf that contains the best score gain for this decision graph.
private double bestLeafScoreGain; // Best score gain among all possible splits for this decision graph.
diff --git a/src/com/d_HBOA/HBOASolver.java b/src/main/java/com/d_HBOA/HBOASolver.java
similarity index 85%
rename from src/com/d_HBOA/HBOASolver.java
rename to src/main/java/com/d_HBOA/HBOASolver.java
index 7bd972e..d8131ea 100644
--- a/src/com/d_HBOA/HBOASolver.java
+++ b/src/main/java/com/d_HBOA/HBOASolver.java
@@ -19,9 +19,9 @@
public class HBOASolver extends IEASolver{
- private Selection selection; // NOTE: Use Parameter.initializeSelector() to generate the chosen selector type.
- private BayesianNetwork bayesianNetwork; // NOTE: Use initializeBayesianNetwork() to initialize the chosen bayesian network generator.
- private IReplacement replacement; // NOTE: Use Parameter.initializeReplacement() to generate the chosen replacement type.
+ private final Selection selection; // NOTE: Use Parameter.initializeSelector() to generate the chosen selector type.
+ private final BayesianNetwork bayesianNetwork; // NOTE: Use initializeBayesianNetwork() to initialize the chosen bayesian network generator.
+ private final IReplacement replacement; // NOTE: Use Parameter.initializeReplacement() to generate the chosen replacement type.
public HBOASolver(String paramFile, int currentN){
diff --git a/src/com/d_HBOA/Parameter.java b/src/main/java/com/d_HBOA/Parameter.java
similarity index 91%
rename from src/com/d_HBOA/Parameter.java
rename to src/main/java/com/d_HBOA/Parameter.java
index 4374c75..7824996 100644
--- a/src/com/d_HBOA/Parameter.java
+++ b/src/main/java/com/d_HBOA/Parameter.java
@@ -1,13 +1,14 @@
package com.d_HBOA;
+import com.z_PORTFOLIO.Problem;
+
import java.io.BufferedReader;
import java.io.DataInputStream;
-import java.io.FileInputStream;
+import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Scanner;
-import com.z_PORTFOLIO.Problem;
-
+import static com.z_PORTFOLIO.PortParameter.stream;
public class Parameter{
@@ -52,7 +53,7 @@ public class Parameter{
public static void initializeParameters(String parameterFile){
try{
// Open the file to be read
- FileInputStream fstream = new FileInputStream(parameterFile);
+ InputStream fstream = stream(parameterFile);
// Create an object of DataInputStream
DataInputStream in = new DataInputStream(fstream);
BufferedReader buff = new BufferedReader(new InputStreamReader(in));
@@ -83,12 +84,12 @@ private static void validateOptionName(String line, String option, int nLine){
if(option.length() >= line.length())
exitError("Line " + nLine + " --> Missing equal sign '='");
if(!validateName(option))
- exitError("Line " + nLine + " --> INVALID OPTION NAME '" + option + "'");
+ exitError("Line " + nLine + " --> INVALID OPTION NAME '" + option + '\'');
}
private static boolean validateName(String name){
- for(int i = 0; i < optionNames.length; i++)
- if(name.equals((String)optionNames[i]))
+ for (String optionName : optionNames)
+ if (name.equals((String) optionName))
return true;
return false;
}
@@ -203,21 +204,21 @@ public static IReplacement initializeReplacement(int currentN){
public static String writeParameters(String indent){
String str = " Selection Method:";
if(selectionMethod == 1)
- str += "\n" + indent + " Selection = Tournament Selection with replacement" +
- "\n" + indent + " pNS = " + pNS +
- "\n" + indent + " tourSize = " + tourSize;
+ str += '\n' + indent + " Selection = Tournament Selection with replacement" +
+ '\n' + indent + " pNS = " + pNS +
+ '\n' + indent + " tourSize = " + tourSize;
if(selectionMethod == 2)
- str += "\n" + indent + " Selection = Tournament Selection without replacement" +
- "\n" + indent + " pNS = " + pNS +
- "\n" + indent + " tourSize = " + tourSize;
+ str += '\n' + indent + " Selection = Tournament Selection without replacement" +
+ '\n' + indent + " pNS = " + pNS +
+ '\n' + indent + " tourSize = " + tourSize;
if(selectionMethod == 3)
- str += "\n" + indent + " Selection = Truncation" +
- "\n" + indent + " tau = " + tau;
+ str += '\n' + indent + " Selection = Truncation" +
+ '\n' + indent + " tau = " + tau;
str += "\n\n" + " Replacement Method:" +
- "\n" + indent + "Replacement Type = " + replacementType +
- "\n" + indent + " pOffspringSize = " + pOffspringSize;
+ '\n' + indent + "Replacement Type = " + replacementType +
+ '\n' + indent + " pOffspringSize = " + pOffspringSize;
if(replacementType == 1)
- str += "\n" + indent + " windowSize = " + windowSize;
+ str += '\n' + indent + " windowSize = " + windowSize;
return str;
}
diff --git a/src/com/d_HBOA/Replacement.java b/src/main/java/com/d_HBOA/Replacement.java
similarity index 80%
rename from src/com/d_HBOA/Replacement.java
rename to src/main/java/com/d_HBOA/Replacement.java
index b2994c6..a99f45c 100644
--- a/src/com/d_HBOA/Replacement.java
+++ b/src/main/java/com/d_HBOA/Replacement.java
@@ -12,7 +12,7 @@ abstract class IReplacement{
}
class RestrictedReplacement extends IReplacement{
- private int windowSize;
+ private final int windowSize;
public RestrictedReplacement(int wSize, int currentN){
int wS = currentN/20;
@@ -24,25 +24,24 @@ public RestrictedReplacement(int wSize, int currentN){
public void replace(Population population, Individual[] newIndividuals){
int N = population.getN();
- for(int i = 0; i < newIndividuals.length; i++){
- Individual candidate = newIndividuals[i];
+ for (Individual candidate : newIndividuals) {
int bestPosition = -1;
int bestDistance = Integer.MAX_VALUE;
- for(int j = 1; j < windowSize; j++){ // Find within the window, the individual CLOSEST to the candidate.
+ for (int j = 1; j < windowSize; j++) { // Find within the window, the individual CLOSEST to the candidate.
int picked = PORTFOLIO.random.nextInt(N);
- Individual individual = population.getIndividual(picked);
+ Individual individual = population.getIndividual(picked);
int distance = individual.distance(candidate);
- if(distance < bestDistance){
+ if (distance < bestDistance) {
bestPosition = picked;
bestDistance = distance;
}
}
float candidateFit = candidate.computeFitness();
- if(candidateFit > population.getFitness(bestPosition)){
+ if (candidateFit > population.getFitness(bestPosition)) {
population.setIndividual(bestPosition, candidate, candidateFit);
double bestFit = population.getBestFit();
- if(candidateFit > bestFit){ // The new individual is also the best.
- population.setBestPos(bestPosition); // Update information about the best individual.
+ if (candidateFit > bestFit) { // The new individual is also the best.
+ population.setBestPos(bestPosition); // Update information about the best individual.
population.setBestFit(candidateFit);
}
}
@@ -56,7 +55,7 @@ class WorstReplacement extends IReplacement{
// Use this inner class to sort the current population, in ascending order of fitness.
// BEGIN: Inner class 'PosFit'
- class PosFit implements Comparable{
+ static class PosFit implements Comparable{
int position;
double fitness;
@@ -79,17 +78,15 @@ public int compareTo(PosFit posFit){
}
public String toString(){
- return "(" + position + ";" + fitness + ")";
+ return "(" + position + ';' + fitness + ')';
}
} // END: Inner class 'PosFit'
-
- private PosFit[] sortedPopulation;
-
+
public WorstReplacement(){} // Default constructor
public void replace(Population population, Individual[] newIndividuals){
int sortN = population.getN();
- sortedPopulation = new PosFit[sortN];
+ PosFit[] sortedPopulation = new PosFit[sortN];
for(int i = 0; i < sortN; i++)
sortedPopulation[i] = new PosFit(i, population.getFitness(i));
Arrays.sort(sortedPopulation); // Sort population in ascending order of fitness.
diff --git a/src/com/d_HBOA/Selection.java b/src/main/java/com/d_HBOA/Selection.java
similarity index 95%
rename from src/com/d_HBOA/Selection.java
rename to src/main/java/com/d_HBOA/Selection.java
index 2c2f095..1138676 100644
--- a/src/com/d_HBOA/Selection.java
+++ b/src/main/java/com/d_HBOA/Selection.java
@@ -16,7 +16,7 @@ public Selection(){} // Default empty constructor.
}
class TourWithReplacement extends Selection{
- int tourSize; // Default: 2 (binary tournament).
+ final int tourSize; // Default: 2 (binary tournament).
public TourWithReplacement(int NS, int tourSize){
this.NS = NS;
@@ -52,7 +52,7 @@ public SelectedSet select(Population population){
class TourWithoutReplacement extends Selection{
- int tourSize; // Default binary tournament
+ final int tourSize; // Default binary tournament
public TourWithoutReplacement(int NS, int tourSize){
this.NS = NS;
@@ -99,7 +99,7 @@ private int tourSelect(Population population, SelectedSet selectedSet, int[] num
return maxPos;
}
- private int[] shuffle(int n){
+ private static int[] shuffle(int n){
int[] numbers = new int[n];
for(int i = 0; i < n; i++)
numbers[i] = i;
@@ -120,7 +120,7 @@ class Truncation extends Selection{
PosFit[] sortedPopulation;
// Use this inner class to sort the current population, in ascending order of fitness.
- class PosFit implements Comparable{
+ static class PosFit implements Comparable{
int position;
double fitness;
@@ -143,7 +143,7 @@ public int compareTo(PosFit posFit){
}
public String toString(){
- return "(" + position + ";" + fitness + ")";
+ return "(" + position + ';' + fitness + ')';
}
}// END: inner class PosFit.
diff --git a/src/com/z_PORTFOLIO/ECGA.java b/src/main/java/com/z_PORTFOLIO/ECGA.java
similarity index 100%
rename from src/com/z_PORTFOLIO/ECGA.java
rename to src/main/java/com/z_PORTFOLIO/ECGA.java
diff --git a/src/com/z_PORTFOLIO/HBOA.java b/src/main/java/com/z_PORTFOLIO/HBOA.java
similarity index 100%
rename from src/com/z_PORTFOLIO/HBOA.java
rename to src/main/java/com/z_PORTFOLIO/HBOA.java
diff --git a/src/com/z_PORTFOLIO/IEASolver.java b/src/main/java/com/z_PORTFOLIO/IEASolver.java
similarity index 96%
rename from src/com/z_PORTFOLIO/IEASolver.java
rename to src/main/java/com/z_PORTFOLIO/IEASolver.java
index 56ef923..cb74856 100644
--- a/src/com/z_PORTFOLIO/IEASolver.java
+++ b/src/main/java/com/z_PORTFOLIO/IEASolver.java
@@ -3,8 +3,8 @@
//DESIGN PATTERN STRATEGY
public abstract class IEASolver{
- protected int N;
- protected Population currentPopulation;
+ protected final int N;
+ protected final Population currentPopulation;
protected int currentGeneration; // Current generation for this solver. This is updated by each nextGeneration() call.
protected int currentFitnessCalls; // Number of fitness calls for this solver. This must be updated for all RandomPopulation() and replace() calls.
protected long totalFitnessCalls; // Total number of fitness calls for this solver. NOTE: This is not necessary. It's just extra information.
diff --git a/src/com/z_PORTFOLIO/IEAlgorithm.java b/src/main/java/com/z_PORTFOLIO/IEAlgorithm.java
similarity index 100%
rename from src/com/z_PORTFOLIO/IEAlgorithm.java
rename to src/main/java/com/z_PORTFOLIO/IEAlgorithm.java
diff --git a/src/com/z_PORTFOLIO/Individual.java b/src/main/java/com/z_PORTFOLIO/Individual.java
similarity index 86%
rename from src/com/z_PORTFOLIO/Individual.java
rename to src/main/java/com/z_PORTFOLIO/Individual.java
index 6ccb423..d9d0817 100644
--- a/src/com/z_PORTFOLIO/Individual.java
+++ b/src/main/java/com/z_PORTFOLIO/Individual.java
@@ -1,9 +1,9 @@
package com.z_PORTFOLIO;
public class Individual {
- private char[] individual = new char[Problem.n];
+ private final char[] individual;
- public Individual(){} // Default constructor
+ public Individual(){ individual = new char[Problem.n]; } // Default constructor
public Individual(Individual johnDoe){individual = johnDoe.getIndividual();} // Non shallow copy of an Individual
public Individual(char[] individual){this.individual = individual;} // Shallow copy of an Individual
@@ -16,10 +16,7 @@ public Individual(){} // Default constructor
public char[] copyIndividual(){
char[] copy = new char[Problem.n];
- for(int i = 0; i < Problem.n; i++){
- char c = individual[i];
- copy[i] = c;
- }
+ System.arraycopy(individual, 0, copy, 0, Problem.n);
return copy;
}
diff --git a/src/com/z_PORTFOLIO/PORTFOLIO.java b/src/main/java/com/z_PORTFOLIO/PORTFOLIO.java
similarity index 78%
rename from src/com/z_PORTFOLIO/PORTFOLIO.java
rename to src/main/java/com/z_PORTFOLIO/PORTFOLIO.java
index 1ac1aa3..c0fb04e 100644
--- a/src/com/z_PORTFOLIO/PORTFOLIO.java
+++ b/src/main/java/com/z_PORTFOLIO/PORTFOLIO.java
@@ -4,16 +4,18 @@
public class PORTFOLIO{
- private static String portParamFile; // Name of the main parameters file.
public static int portRuns; // Number of runs to perform with the same problem.
- public static Random random = new Random(); // Responsible for all random number operations.
+ public static final Random random = new Random(); // Responsible for all random number operations.
public static int nSuccess; // Number of successful runs;
public static PortEngine portEngine;
public static void main(String[] args){
//random.setSeed(654324); // This will fix the sequence of seeds that will be used on each run of the Portfolio.
-
- portParamFile = args[0];
+
+
+ //portParamFile = args[0];
+ String portParamFile = "PortParameters.txt";
+
nSuccess = 0;
portEngine = new PortEngine(portParamFile); // Initialize the Portfolio Engine.
diff --git a/src/com/z_PORTFOLIO/ParBestSoFar.java b/src/main/java/com/z_PORTFOLIO/ParBestSoFar.java
similarity index 96%
rename from src/com/z_PORTFOLIO/ParBestSoFar.java
rename to src/main/java/com/z_PORTFOLIO/ParBestSoFar.java
index 05ac5d7..19b793e 100644
--- a/src/com/z_PORTFOLIO/ParBestSoFar.java
+++ b/src/main/java/com/z_PORTFOLIO/ParBestSoFar.java
@@ -75,14 +75,14 @@ public void reset(){
this.bestIndividualGeneration = 0;
this.bestIndividualPopulation = null;
this.bestIndividualPosition = 0;
- this.bestIndividualFitness = Double.NEGATIVE_INFINITY;;
-
+ this.bestIndividualFitness = Double.NEGATIVE_INFINITY;
+
this.bestAverageTime = 0;
this.bestAverageIteration = 0;
this.bestAverageSolverPosition = 0;
this.bestAverageGeneration = 0;
this.bestAveragePopulation = null;
- this.bestAverageFitness = Double.NEGATIVE_INFINITY;;
+ this.bestAverageFitness = Double.NEGATIVE_INFINITY;
}
}
diff --git a/src/com/z_PORTFOLIO/ParEngine.java b/src/main/java/com/z_PORTFOLIO/ParEngine.java
similarity index 94%
rename from src/com/z_PORTFOLIO/ParEngine.java
rename to src/main/java/com/z_PORTFOLIO/ParEngine.java
index 0a191f0..8c72695 100644
--- a/src/com/z_PORTFOLIO/ParEngine.java
+++ b/src/main/java/com/z_PORTFOLIO/ParEngine.java
@@ -8,9 +8,9 @@ public class ParEngine{
private boolean inactive; // This EA can be active or already inactive.
private double multiplier; // Each EA uses this constant to compute its own maximum execution time allowed in each iteration. NOTE: All multipliers are initialized by portRegister.
private long overTime; // Each EA uses this constant to compute its own maximum execution time allowed in each iteration.
- private IEAlgorithm parAlgorithm; // Chosen EA to perform the parameterless strategy. Design Pattern Strategy.
- private ParRegister parRegister; // Responsible for storing and processing all information related with this Parameterless Engine.
- private ArrayList parSolvers; // The array of solvers on which to perform PEBS.
+ private final IEAlgorithm parAlgorithm; // Chosen EA to perform the parameterless strategy. Design Pattern Strategy.
+ private final ParRegister parRegister; // Responsible for storing and processing all information related with this Parameterless Engine.
+ private final ArrayList parSolvers; // The array of solvers on which to perform PEBS.
private int solverPosition; // Current Solver position.
private int highestN; // Highest current population size.
private int lastSolver; // Position of the last active Solver;
@@ -22,7 +22,7 @@ public ParEngine(int initPopSize, IEAlgorithm parAlgorithm, ParRegister parRegis
this.inactive = false;
this.parAlgorithm = parAlgorithm;
this.parRegister = parRegister;
- this.parSolvers = new ArrayList(); // Initialize the list of active Solvers;
+ this.parSolvers = new ArrayList<>(); // Initialize the list of active Solvers;
this.parSolvers.add(this.parAlgorithm.newIEASolver(initPopSize)); // Initialize the first Solver.
this.solverPosition = 0; // Initialize the current Solver position.
this.highestN = initPopSize; // Highest current population size.
diff --git a/src/com/z_PORTFOLIO/ParParameter.java b/src/main/java/com/z_PORTFOLIO/ParParameter.java
similarity index 95%
rename from src/com/z_PORTFOLIO/ParParameter.java
rename to src/main/java/com/z_PORTFOLIO/ParParameter.java
index 44f7ed2..1107492 100644
--- a/src/com/z_PORTFOLIO/ParParameter.java
+++ b/src/main/java/com/z_PORTFOLIO/ParParameter.java
@@ -2,10 +2,12 @@
import java.io.BufferedReader;
import java.io.DataInputStream;
-import java.io.FileInputStream;
+import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Scanner;
+import static com.z_PORTFOLIO.PortParameter.stream;
+
class ParParameter{
@@ -18,7 +20,7 @@ class ParParameter{
public static void initializeParameters(String parParameterFile){
try{
// Open the file to be read
- FileInputStream fstream = new FileInputStream(parParameterFile);
+ InputStream fstream = stream(parParameterFile);
// Create an object of DataInputStream
DataInputStream in = new DataInputStream(fstream);
BufferedReader buff = new BufferedReader(new InputStreamReader(in));
@@ -49,12 +51,12 @@ private static void validateOptionName(String line, String option, int nLine){
if(option.length() >= line.length())
exitError("Line " + nLine + " --> Missing equal sign '='");
if(!validateName(option))
- exitError("Line " + nLine + " --> INVALID OPTION NAME '" + option + "'");
+ exitError("Line " + nLine + " --> INVALID OPTION NAME '" + option + '\'');
}
private static boolean validateName(String name){
- for(int i = 0; i < optionNames.length; i++)
- if(name.equals((String)optionNames[i]))
+ for (String optionName : optionNames)
+ if (name.equals((String) optionName))
return true;
return false;
}
diff --git a/src/com/z_PORTFOLIO/ParRegister.java b/src/main/java/com/z_PORTFOLIO/ParRegister.java
similarity index 93%
rename from src/com/z_PORTFOLIO/ParRegister.java
rename to src/main/java/com/z_PORTFOLIO/ParRegister.java
index 27357b1..05ed9c3 100644
--- a/src/com/z_PORTFOLIO/ParRegister.java
+++ b/src/main/java/com/z_PORTFOLIO/ParRegister.java
@@ -3,16 +3,16 @@
public class ParRegister{
- private int index; // Each ParEngine knows its own index. This index does not depend on whether the ParEngine
+ private final int index; // Each ParEngine knows its own index. This index does not depend on whether the ParEngine
// is active or inactive and it remains constant throughout the entirety of the portfolio run.
- private String EAName; // Each ParEngine knows the name of its own EAlgorithm.
+ private final String EAName; // Each ParEngine knows the name of its own EAlgorithm.
private long maxGenerationTime; // Use this to compute next Ti.
private long totalParTime;
private long eliminationTime;
private int totalIterations;
private long currentFitnessCalls;
private long totalFitnessCalls;
- private ParBestSoFar parBestSoFar;
+ private final ParBestSoFar parBestSoFar;
public ParRegister(int index, String EAName){ // NOTE: All other fields are automatically initialized to 0, has intended.
diff --git a/src/com/z_PORTFOLIO/ParStopper.java b/src/main/java/com/z_PORTFOLIO/ParStopper.java
similarity index 97%
rename from src/com/z_PORTFOLIO/ParStopper.java
rename to src/main/java/com/z_PORTFOLIO/ParStopper.java
index ab4dec9..b9732e7 100644
--- a/src/com/z_PORTFOLIO/ParStopper.java
+++ b/src/main/java/com/z_PORTFOLIO/ParStopper.java
@@ -34,7 +34,7 @@ public static boolean criteria(ParRegister parRegister, IEASolver currentSolver)
private static boolean allFitnessEqual(Population population){
- return allFitnessEqual == -1 ? false : population.getBestFit() == population.getAvgFit();
+ return allFitnessEqual != -1 && population.getBestFit() == population.getAvgFit();
}
private static boolean uniFreqConvergence(Population population){
diff --git a/src/com/z_PORTFOLIO/Population.java b/src/main/java/com/z_PORTFOLIO/Population.java
similarity index 88%
rename from src/com/z_PORTFOLIO/Population.java
rename to src/main/java/com/z_PORTFOLIO/Population.java
index c6c8920..ea3eb00 100644
--- a/src/com/z_PORTFOLIO/Population.java
+++ b/src/main/java/com/z_PORTFOLIO/Population.java
@@ -6,11 +6,11 @@
// NOTE: Use constructor Population() to generate empty populations.
public class Population{
- protected int N; // Size for each population, in particular for SelectedSet (NS).
- public Individual[] individuals; // Population of N char[] of size xSize.
+ protected final int N; // Size for each population, in particular for SelectedSet (NS).
+ public final Individual[] individuals; // Population of N char[] of size xSize.
protected int worstPos, bestPos; // Position of Worst and Best individuals. computeFitnessValues() is responsible for computing these positions.
protected double avgFit, worstFit, bestFit; // Worst and Best fitnesses. computeFitnessValues() is responsible for computing these fitnesses.
- protected double[] fitness; // Array of N fitness values.
+ protected final double[] fitness; // Array of N fitness values.
protected int[] uniFrequencies; // Array of xSize univariate frequencies.
public Population(int otherN){
@@ -87,8 +87,11 @@ public double computeAvgFitness(){
////////////////////////////////////////////////////////////
public void computeUnivariateFrequencies(){
- uniFrequencies = new int[Problem.n]; // NOTE: uniFrequencies is initialized all zeros by default.
+ if (uniFrequencies == null || uniFrequencies.length!=Problem.n)
+ uniFrequencies = new int[Problem.n]; // NOTE: uniFrequencies is initialized all zeros by default.
+
for(int j = 0; j < Problem.n; j++){
+ uniFrequencies[j] = 0;
for(int i = 0; i < this.N; i++)
if(individuals[i].getAllele(j) == '1')
uniFrequencies[j]++;
diff --git a/src/com/z_PORTFOLIO/PortEngine.java b/src/main/java/com/z_PORTFOLIO/PortEngine.java
similarity index 99%
rename from src/com/z_PORTFOLIO/PortEngine.java
rename to src/main/java/com/z_PORTFOLIO/PortEngine.java
index 95e8a41..0ef03d8 100644
--- a/src/com/z_PORTFOLIO/PortEngine.java
+++ b/src/main/java/com/z_PORTFOLIO/PortEngine.java
@@ -24,7 +24,7 @@ public PortEngine(String portParamFile){
}
private void initializePortfolio(){
- portfolio = new ArrayList();
+ portfolio = new ArrayList<>();
//portfolio.add(new ParEngine(N0, new SGA("SGAParameters.txt"), new ParRegister(0))); // Each EA "knows" its own index in the portfolio.
portfolio.add(new ParEngine(N0, new UMDA("UMDAParameters.txt"), new ParRegister(0, "P-UMDA"))); // NOTE: When integrating a new EA to the portfolio, it is only necessary to add a new line to this block,
portfolio.add(new ParEngine(N1, new ECGA("ECGAParameters.txt"), new ParRegister(1, "P-ECGA"))); // choose the correct initial population size (N0 or N1),
diff --git a/src/com/z_PORTFOLIO/PortParameter.java b/src/main/java/com/z_PORTFOLIO/PortParameter.java
similarity index 95%
rename from src/com/z_PORTFOLIO/PortParameter.java
rename to src/main/java/com/z_PORTFOLIO/PortParameter.java
index 6b14b09..80fbbf7 100644
--- a/src/com/z_PORTFOLIO/PortParameter.java
+++ b/src/main/java/com/z_PORTFOLIO/PortParameter.java
@@ -2,12 +2,12 @@
import java.io.BufferedReader;
import java.io.DataInputStream;
-import java.io.FileInputStream;
+import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Scanner;
-class PortParameter{
+public class PortParameter{
// NOTE!! optionNames must coincide exactly with the option names in the 'Parameters.txt' file.
private static final String optionNames[] =
@@ -30,7 +30,8 @@ class PortParameter{
public static void initializeParameters(String parameterFile){ // NOTE: Execute this initialization PRIOR to any other.
try{
- FileInputStream fstream = new FileInputStream(parameterFile); // Open the file to be read
+ InputStream fstream = stream(parameterFile);
+ //new FileInputStream(parameterFile); // Open the file to be read
DataInputStream in = new DataInputStream(fstream); // Create an object of DataInputStream
BufferedReader buff = new BufferedReader(new InputStreamReader(in));
int nLine = 0; // Line number
@@ -55,18 +56,22 @@ public static void initializeParameters(String parameterFile){ // NOTE: Execu
catch(Exception e){ // Catch open file error.
System.err.println("Error: " + e.getMessage());
}
- }
-
+ }
+
+ public static InputStream stream(String parameterFile) {
+ return PortParameter.class.getClassLoader().getResourceAsStream(parameterFile);
+ }
+
private static void validateOptionName(String line, String option, int nLine){
if(option.length() >= line.length())
exitError("Line " + nLine + " --> Missing equal sign '='");
if(!validateName(option))
- exitError("Line " + nLine + " --> INVALID OPTION NAME '" + option + "'");
+ exitError("Line " + nLine + " --> INVALID OPTION NAME '" + option + '\'');
}
private static boolean validateName(String name){
- for(int i = 0; i < optionNames.length; i++)
- if(name.equals((String)optionNames[i]))
+ for (String optionName : optionNames)
+ if (name.equals((String) optionName))
return true;
return false;
}
@@ -157,7 +162,7 @@ private static void validateOptionValue(String optionName,String optionValue, in
}
if(optionName.equals("verbose")){
PortPress.verbose = Boolean.parseBoolean(optionValue);
- if(PortPress.verbose != false && PortPress.verbose != true)
+ if(PortPress.verbose && !PortPress.verbose)
exitError("Line " + nLine + " --> Verbose option must be either 'false' or 'true'.");
return; // Option validated!!
}
diff --git a/src/com/z_PORTFOLIO/PortPress.java b/src/main/java/com/z_PORTFOLIO/PortPress.java
similarity index 89%
rename from src/com/z_PORTFOLIO/PortPress.java
rename to src/main/java/com/z_PORTFOLIO/PortPress.java
index 776fb2c..bf5f5db 100644
--- a/src/com/z_PORTFOLIO/PortPress.java
+++ b/src/main/java/com/z_PORTFOLIO/PortPress.java
@@ -7,36 +7,35 @@ public class PortPress{
public static boolean verbose; // Verbose mode prints all currentSolver info in each generation. Default = false.
// NOTE: 'verbose' is initialized by PortParameter.validateOptionValue().
-
- private static String testFileName; // This file stores all the information that is also printed in the console during an entire run.
- private static FileWriter fstreamTest;
+
private static BufferedWriter testFileOut;
// TODO: Write STATS file!!
// private static String testFileNameStats; // This file stores only the statistics necessary to generate graphics.
// private static FileWriter fstreamTestStats;
// private static BufferedWriter testFileOutStats;
-
-
- private static int indentSize = 7;
+
+
private static String indent;
public static void initializePress(){
indent = "";
+ int indentSize = 7;
for(int i = 0; i < indentSize; i++)
indent += " ";
- String str = "Runs" + PORTFOLIO.portRuns + "_T0" + PortEngine.T0 + "_alpha" + PortEngine.alpha +
- "_" + Problem.problemName + "_n" + Problem.n + ".txt";
+ String str = "Runs" + PORTFOLIO.portRuns + "_T0" + PortEngine.T0 + "_alpha" + PortEngine.alpha +
+ '_' + Problem.problemName + "_n" + Problem.n + ".txt";
+ String testFileName;
if(PortEngine.nextSolver > 99){
- testFileName = "PORT-STANDALONE_" + str;
+ testFileName = "PORT-STANDALONE_" + str;
//testFileNameStats = "STATS_PORT-STANDALONE_" + str;
}
else{
- testFileName = "PORTFOLIO_" + str;
+ testFileName = "PORTFOLIO_" + str;
//testFileNameStats = "STATS_PORTFOLIO_" + str;
}
try{
- fstreamTest = new FileWriter(testFileName); // 'true' => Append to file.
+ FileWriter fstreamTest = new FileWriter(testFileName);
testFileOut = new BufferedWriter(fstreamTest);
// fstreamTestStats = new FileWriter(testFileNameStats, true); // 'true' => Append to file.
// testFileOutStats = new BufferedWriter(fstreamTest);
@@ -46,7 +45,7 @@ public static void initializePress(){
public static void printString(String str){ // NOTE: Use this method to print simultaneous in
System.out.println(str); // the console and in the testFileOut.
try{
- testFileOut.write("\n" + str);
+ testFileOut.write('\n' + str);
}catch(Exception e){System.err.println("ERROR: " + e.getMessage());}
}
@@ -86,24 +85,24 @@ public static void printInitialInfo(){
}
public static void printRunInitialInfo(int r){
- printString("\n##### RUN " + (r+1) + "/" + PORTFOLIO.portRuns + " #####" +
- "##### RUN " + (r+1) + "/" + PORTFOLIO.portRuns + " #####" +
- "##### RUN " + (r+1) + "/" + PORTFOLIO.portRuns + " #####");
+ printString("\n##### RUN " + (r+1) + '/' + PORTFOLIO.portRuns + " #####" +
+ "##### RUN " + (r+1) + '/' + PORTFOLIO.portRuns + " #####" +
+ "##### RUN " + (r+1) + '/' + PORTFOLIO.portRuns + " #####");
}
public static void printRunFinalInfo(int r){
- printString("\n##### RUN " + (r+1) + "/" + PORTFOLIO.portRuns + " #####" +
- "##### RUN " + (r+1) + "/" + PORTFOLIO.portRuns + " #####" +
- "##### RUN " + (r+1) + "/" + PORTFOLIO.portRuns + " #####");
+ printString("\n##### RUN " + (r+1) + '/' + PORTFOLIO.portRuns + " #####" +
+ "##### RUN " + (r+1) + '/' + PORTFOLIO.portRuns + " #####" +
+ "##### RUN " + (r+1) + '/' + PORTFOLIO.portRuns + " #####");
String str = "\n# " + " Success: " + PortStopper.foundOptimum() +
- "\n# " + " Current Success Rate: " + PORTFOLIO.nSuccess + "/" + (r+1) +
+ "\n# " + " Current Success Rate: " + PORTFOLIO.nSuccess + '/' + (r+1) +
"\n# " + " Final Active EAlgorithms: [ ";
for(int i = 0; i < PortEngine.portRegister.getNEA(); i++){
ParEngine parEngine = PortEngine.portfolio.get(i);
if(!parEngine.inactive())
- str += parEngine.getParRegister().getEAName() + " ";
+ str += parEngine.getParRegister().getEAName() + ' ';
}
- str += "]" +
+ str += ']' +
"\n# " + "-------------------------------";
for(int i = 0; i < PortEngine.portRegister.getNEA(); i++){
ParRegister parRegister = PortEngine.portfolio.get(i).getParRegister();
@@ -156,9 +155,9 @@ public static void printTimeSlotFinalInfo(int timeSlot){
for(int i = 0; i < PortEngine.portRegister.getNEA(); i++){
ParEngine parEngine = PortEngine.portfolio.get(i);
if(!parEngine.inactive())
- str += parEngine.getParRegister().getEAName() + " ";
+ str += parEngine.getParRegister().getEAName() + ' ';
}
- str += "]" +
+ str += ']' +
"\n=> " + " Total Fitness Calls: " + PortEngine.portRegister.getTotalFitnessCalls() +
"\n=> " + " Total Running Time: " + PortEngine.portRegister.getTotalRunTime() +
"\n=> " + " Max Generation Time: " + PORTFOLIO.portEngine.getMaxTime() +
@@ -180,14 +179,14 @@ public static void printParEngineInitialInfo(ParEngine currentParEngine, long ma
ParRegister currentParRegister = currentParEngine.getParRegister();
String str;
if(currentParEngine.inactive())
- str = "=>" +
- "\n" + "==>> INACTIVE: " + currentParRegister.getEAName() + "(" + currentParRegister.getIndex() + ")";
+ str = "=>" +
+ '\n' + "==>> INACTIVE: " + currentParRegister.getEAName() + '(' + currentParRegister.getIndex() + ')';
else{
- str = "=>" +
- "\n" + "==>> RUNNING: " + currentParRegister.getEAName() + "(" + currentParRegister.getIndex() + ")" +
+ str = "=>" +
+ '\n' + "==>> RUNNING: " + currentParRegister.getEAName() + '(' + currentParRegister.getIndex() + ')' +
" for a maximum allowed time of << " + maxTimeAllowed + " >> milliseconds."+
- "\n" +
- "\n" + indent + "Iteration GenerationTime Pop. Size Generation Avg. Fitness BestCurrentFitness BestFitnessSoFar";
+ '\n' +
+ '\n' + indent + "Iteration GenerationTime Pop. Size Generation Avg. Fitness BestCurrentFitness BestFitnessSoFar";
}
printString(str);
}
@@ -198,7 +197,7 @@ public static void printParEngineCurrentInfo(ParEngine currentParEngine, long ma
"\n====>> STOPPING: " + currentParRegister.getEAName() +
"\n=> " +
"\n=> " + " Currently Active: " + !currentParEngine.inactive() +
- "\n=> " + " CurrentTime/AllowedTime: " + currentTime + "/" + maxTimeAllowed + " milliseconds" +
+ "\n=> " + " CurrentTime/AllowedTime: " + currentTime + '/' + maxTimeAllowed + " milliseconds" +
"\n=> " + " TotalTime: " + currentParRegister.getTotalParTime() + " milliseconds" +
"\n=> " + " Max Generation Time: " + currentParRegister.getMaxGenerationTime();
if(currentParEngine.inactive())
@@ -277,7 +276,7 @@ public static void printSolverCurrentInfo(ParRegister currentParRegister, IEASol
}
public static void printFinalInfo(){
- printString("\nSUCCESS RATE = " + PORTFOLIO.nSuccess + "/" + PORTFOLIO.portRuns + "\n");
+ printString("\nSUCCESS RATE = " + PORTFOLIO.nSuccess + '/' + PORTFOLIO.portRuns + '\n');
}
public static void closeTestFileOut(){
diff --git a/src/com/z_PORTFOLIO/PortRegister.java b/src/main/java/com/z_PORTFOLIO/PortRegister.java
similarity index 99%
rename from src/com/z_PORTFOLIO/PortRegister.java
rename to src/main/java/com/z_PORTFOLIO/PortRegister.java
index 1097856..14701b6 100644
--- a/src/com/z_PORTFOLIO/PortRegister.java
+++ b/src/main/java/com/z_PORTFOLIO/PortRegister.java
@@ -1,7 +1,7 @@
package com.z_PORTFOLIO;
public class PortRegister{
- private int nEA;
+ private final int nEA;
private int nActiveParEngines;
private int firstActiveParEngine;
private int totalIterations;
diff --git a/src/com/z_PORTFOLIO/PortStopper.java b/src/main/java/com/z_PORTFOLIO/PortStopper.java
similarity index 73%
rename from src/com/z_PORTFOLIO/PortStopper.java
rename to src/main/java/com/z_PORTFOLIO/PortStopper.java
index 71ba2b3..3cc4a8c 100644
--- a/src/com/z_PORTFOLIO/PortStopper.java
+++ b/src/main/java/com/z_PORTFOLIO/PortStopper.java
@@ -12,9 +12,9 @@ public class PortStopper{
public static boolean criteria(PortRegister portRegister){
return (portRegister.getNActiveParEngines() == 0) ||
- ((maxIterations == -1)? false : portRegister.getTotalIterations() > maxIterations) ||
- ((maxFitnessCalls == -1)? false : portRegister.getTotalFitnessCalls() > maxFitnessCalls) ||
- ((maxTimeAllowed == -1)? false : portRegister.getTotalRunTime() > maxTimeAllowed);
+ ((maxIterations != -1) && portRegister.getTotalIterations() > maxIterations) ||
+ ((maxFitnessCalls != -1) && portRegister.getTotalFitnessCalls() > maxFitnessCalls) ||
+ ((maxTimeAllowed != -1) && portRegister.getTotalRunTime() > maxTimeAllowed);
}
public static int getMaxIterations(){return maxIterations;}
diff --git a/src/com/z_PORTFOLIO/PortTime.java b/src/main/java/com/z_PORTFOLIO/PortTime.java
similarity index 100%
rename from src/com/z_PORTFOLIO/PortTime.java
rename to src/main/java/com/z_PORTFOLIO/PortTime.java
diff --git a/src/com/z_PORTFOLIO/Problem.java b/src/main/java/com/z_PORTFOLIO/Problem.java
similarity index 97%
rename from src/com/z_PORTFOLIO/Problem.java
rename to src/main/java/com/z_PORTFOLIO/Problem.java
index a617bfe..7ad5863 100644
--- a/src/com/z_PORTFOLIO/Problem.java
+++ b/src/main/java/com/z_PORTFOLIO/Problem.java
@@ -14,12 +14,12 @@
///////////////////////////////////////////////////////////////////
interface IProblem{
- public float computeFitness(Individual individual);
- public String toString();
+ float computeFitness(Individual individual);
+ String toString();
}
public class Problem{
- private IProblem problem;
+ private final IProblem problem;
public static int n; // Allele size. No default, it's problem dependent.
public static float optimumValue; // Best fitness. No default, it's problem dependent.
public static String problemName;
@@ -30,7 +30,7 @@ public Problem(IProblem problem, int stringSize, float optValue, double sigmaK){
this.problem = problem;
Problem.n = stringSize;
Problem.optimumValue = optValue;
- Problem.sigma = Math.sqrt((double)(sigmaK*stringSize));
+ Problem.sigma = Math.sqrt(sigmaK*stringSize);
Problem.problemName = (sigma == 0)? problem.toString() : "NOISY-" + problem.toString();
}
@@ -40,7 +40,7 @@ public float computeFitness(Individual individual){
}
public static boolean validateXSize(Individual individual){
- return (individual.getIndividual().length == n) ? true : false;
+ return (individual.getIndividual().length == n);
}
public String toString(){
@@ -165,7 +165,7 @@ public String toString(){
//###### 5 --> ZERO TRAP-K PROBLEM ######
class ZeroTrapK implements IProblem{
- private int kay;
+ private final int kay;
public ZeroTrapK(int kay){this.kay = kay;}
public float computeFitness(Individual individual){
@@ -321,7 +321,7 @@ public String toString(){
//###### 15 --> TRAP-K PROBLEM ######
class TrapK implements IProblem{
- private int kay;
+ private final int kay;
public TrapK(int kay){this.kay = kay;}
public float computeFitness(Individual individual){
@@ -386,7 +386,7 @@ public float computeFitness(Individual individual){
float flow = 1,
fhigh = 1;
// Parameters for topTrap
- float topFlow = (float)0.9,
+ float topFlow = 0.9f,
topFhigh = 1;
// All levels except the top one.
@@ -458,9 +458,9 @@ public float computeFitness(Individual individual){
int nLevels = (int)(Math.log(levelSize)/Math.log(3));
float levelFit;
- float flow = (float)1 + (float)0.1/(float)nLevels, // Parameters for trap at all levels except the top one.
+ float flow = (float)1 + 0.1f /(float)nLevels, // Parameters for trap at all levels except the top one.
fhigh = 1;
- float topFlow = (float)0.9, // Parameters for topTrap
+ float topFlow = 0.9f, // Parameters for topTrap
topFhigh = 1;
while(levelSize > 3){ // All levels except the top one.
diff --git a/src/com/z_PORTFOLIO/RandomPopulation.java b/src/main/java/com/z_PORTFOLIO/RandomPopulation.java
similarity index 100%
rename from src/com/z_PORTFOLIO/RandomPopulation.java
rename to src/main/java/com/z_PORTFOLIO/RandomPopulation.java
diff --git a/src/com/z_PORTFOLIO/SGA.java b/src/main/java/com/z_PORTFOLIO/SGA.java
similarity index 100%
rename from src/com/z_PORTFOLIO/SGA.java
rename to src/main/java/com/z_PORTFOLIO/SGA.java
diff --git a/src/com/z_PORTFOLIO/SelectedSet.java b/src/main/java/com/z_PORTFOLIO/SelectedSet.java
similarity index 100%
rename from src/com/z_PORTFOLIO/SelectedSet.java
rename to src/main/java/com/z_PORTFOLIO/SelectedSet.java
diff --git a/src/com/z_PORTFOLIO/UMDA.java b/src/main/java/com/z_PORTFOLIO/UMDA.java
similarity index 100%
rename from src/com/z_PORTFOLIO/UMDA.java
rename to src/main/java/com/z_PORTFOLIO/UMDA.java
diff --git a/bin/ECGAParameters.txt b/src/main/resources/ECGAParameters.txt
similarity index 100%
rename from bin/ECGAParameters.txt
rename to src/main/resources/ECGAParameters.txt
diff --git a/bin/HBOAParameters.txt b/src/main/resources/HBOAParameters.txt
similarity index 100%
rename from bin/HBOAParameters.txt
rename to src/main/resources/HBOAParameters.txt
diff --git a/bin/ParParameters.txt b/src/main/resources/ParParameters.txt
similarity index 100%
rename from bin/ParParameters.txt
rename to src/main/resources/ParParameters.txt
diff --git a/bin/PortParameters.txt b/src/main/resources/PortParameters.txt
similarity index 99%
rename from bin/PortParameters.txt
rename to src/main/resources/PortParameters.txt
index 795d05a..0479799 100644
--- a/bin/PortParameters.txt
+++ b/src/main/resources/PortParameters.txt
@@ -64,11 +64,11 @@ parParamFile = ParParameters.txt
#
# Problem type.
# Default = 10 (OneMax)
-problemType = 10
+problemType = 11
# Set the 'stringSize' in accordance with the chosen problem
# Default = 100 (OneMax size)
-stringSize = 100
+stringSize = 200
# NOTE: Both stop criteria 4 and 5 on 'ParParameters.txt' depend on the optimum value.
# The user is responsible for setting the optimum value
diff --git a/bin/SGAParameters.txt b/src/main/resources/SGAParameters.txt
similarity index 100%
rename from bin/SGAParameters.txt
rename to src/main/resources/SGAParameters.txt
diff --git a/bin/UMDAParameters.txt b/src/main/resources/UMDAParameters.txt
similarity index 100%
rename from bin/UMDAParameters.txt
rename to src/main/resources/UMDAParameters.txt