Skip to content

Commit

Permalink
Add examples using NSGA-II for solving a multi-objective TSP problem
Browse files Browse the repository at this point in the history
  • Loading branch information
ajnebro committed Nov 28, 2024
1 parent e9b7e78 commit 572b470
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 44 deletions.
26 changes: 26 additions & 0 deletions examples/NSGAIIMultiObjectiveTSPDefaultSettings.jl
Original file line number Diff line number Diff line change
@@ -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
35 changes: 35 additions & 0 deletions examples/NSGAIIMultiObjectiveTSPExplicitSettings.jl
Original file line number Diff line number Diff line change
@@ -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
44 changes: 0 additions & 44 deletions examples/NSGAIISolvingMultiObjectiveTSP.jl

This file was deleted.

0 comments on commit 572b470

Please sign in to comment.