diff --git a/examples/NSGAIIMultiObjectiveTSPDefaultSettings.jl b/examples/NSGAIIMultiObjectiveTSPDefaultSettings.jl new file mode 100644 index 0000000..eac1819 --- /dev/null +++ b/examples/NSGAIIMultiObjectiveTSPDefaultSettings.jl @@ -0,0 +1,26 @@ +using MetaJul + +# NSGA-II algorithm example configured from the NSGA-II template +function main() + tsp_data_dir = joinpath(@__DIR__, "..", "resources/tspDataFiles") + + problem = multiObjectiveTSP("kroAB100", [joinpath(tsp_data_dir, "kroA100.tsp"), joinpath(tsp_data_dir, "kroB100.tsp")]) + + solver::NSGAII = NSGAII(problem) + + optimize!(solver) + + front = foundSolutions(solver) + + objectivesFileName = "FUN.csv" + variablesFileName = "VAR.csv" + + println("Algorithm: ", name(solver)) + + println("Objectives stored in file ", objectivesFileName) + printObjectivesToCSVFile(objectivesFileName, front) + + println("Variables stored in file ", variablesFileName) + printVariablesToCSVFile(variablesFileName, front) + println("Computing time: ", computingTime(solver)) +end \ No newline at end of file diff --git a/examples/NSGAIIMultiObjectiveTSPExplicitSettings.jl b/examples/NSGAIIMultiObjectiveTSPExplicitSettings.jl new file mode 100644 index 0000000..c02ffa2 --- /dev/null +++ b/examples/NSGAIIMultiObjectiveTSPExplicitSettings.jl @@ -0,0 +1,35 @@ +using MetaJul + +# NSGA-II algorithm example configured from the NSGA-II template +function main() + tsp_data_dir = joinpath(@__DIR__, "..", "resources/tspDataFiles") + + problem = multiObjectiveTSP("kroAB100", [joinpath(tsp_data_dir, "kroA100.tsp"), joinpath(tsp_data_dir, "kroB100.tsp")]) + + solver::NSGAII = NSGAII( + problem, + populationSize = 100, + termination = TerminationByEvaluations(125000), + crossover = PMXCrossover(probability = 0.9), + mutation = PermutationSwapMutation(probability = 0.2)) + + + observer = EvaluationObserver(10000) + register!(observable(solver), observer) + + optimize!(solver) + + front = foundSolutions(solver) + + objectivesFileName = "FUN.csv" + variablesFileName = "VAR.csv" + + println("Algorithm: ", name(solver)) + + println("Objectives stored in file ", objectivesFileName) + printObjectivesToCSVFile(objectivesFileName, front) + + println("Variables stored in file ", variablesFileName) + printVariablesToCSVFile(variablesFileName, front) + println("Computing time: ", computingTime(solver)) +end \ No newline at end of file diff --git a/examples/NSGAIISolvingMultiObjectiveTSP.jl b/examples/NSGAIISolvingMultiObjectiveTSP.jl deleted file mode 100644 index 3f379af..0000000 --- a/examples/NSGAIISolvingMultiObjectiveTSP.jl +++ /dev/null @@ -1,44 +0,0 @@ -using MetaJul - -# NSGA-II algorithm example configured from the NSGA-II template -function main() - tsp_data_dir = joinpath(@__DIR__, "..", "resources/tspDataFiles") - - problem = multiObjectiveTSP("kroAB100", [joinpath(tsp_data_dir, "kroA100.tsp"), joinpath(tsp_data_dir, "kroB100.tsp")]) - - solver::EvolutionaryAlgorithm = EvolutionaryAlgorithm() - solver.name = "NSGA-II" - - populationSize = 100 - offspringPopulationSize = 100 - - solver.solutionsCreation = DefaultSolutionsCreation(problem, populationSize) - solver.evaluation = SequentialEvaluation(problem) - solver.termination = TerminationByEvaluations(300000) - - mutation = PermutationSwapMutation(probability = 1.0 / numberOfVariables(problem)) - crossover = PMXCrossover(probability = 0.9) - - solver.variation = CrossoverAndMutationVariation(offspringPopulationSize, crossover, mutation) - - solver.selection = BinaryTournamentSelection(solver.variation.matingPoolSize, DefaultDominanceComparator()) - - solver.replacement = RankingAndDensityEstimatorReplacement(DominanceRanking(DefaultDominanceComparator()), CrowdingDistanceDensityEstimator()) - - - optimize!(solver) - - front = foundSolutions(solver) - - objectivesFileName = "FUN.csv" - variablesFileName = "VAR.csv" - - println("Algorithm: ", name(solver)) - - println("Objectives stored in file ", objectivesFileName) - printObjectivesToCSVFile(objectivesFileName, front) - - println("Variables stored in file ", variablesFileName) - printVariablesToCSVFile(variablesFileName, front) - println("Computing time: ", computingTime(solver)) -end \ No newline at end of file