Skip to content

Commit

Permalink
Update notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
ajnebro committed Nov 28, 2024
1 parent 572b470 commit b503ed6
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 1 deletion.
2 changes: 1 addition & 1 deletion examples/SMPSOWithObserver.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function main()
#solver.velocityUpdate = DefaultVelocityUpdate(c1Min, c1Max, c2Min, c2Max)

observer = FrontPlotObserver(5000, name(problem), readFrontFromCSVFile("data/referenceFronts/ZDT6.csv"))
register!(getObservable(solver), observer)
register!(observable(solver), observer)

optimize!(solver)

Expand Down
119 changes: 119 additions & 0 deletions notebooks/NSGA-II solving multiobjective TSP.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "94d16fd5",
"metadata": {},
"source": [
"# NSGA-II solving multi-objective TSP\n",
"\n",
"This notebook shows how to use NSGA-II to solve a bi-objective TSP problem."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ebc4e903",
"metadata": {},
"outputs": [],
"source": [
"using MetaJul\n",
"\n",
"tsp_data_dir = joinpath(@__DIR__, \"..\", \"resources/tspDataFiles\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f45c2dcd",
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"problem100Cities = multiObjectiveTSP(\"kroAB100\", [joinpath(tsp_data_dir, \"kroA100.tsp\"), joinpath(tsp_data_dir, \"kroB100.tsp\")])"
]
},
{
"cell_type": "markdown",
"id": "615b7de1",
"metadata": {},
"source": [
"## Standard NSGA-II configured with default settings"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "bef9eff3",
"metadata": {},
"outputs": [],
"source": [
"solver::NSGAII = NSGAII(problem)"
]
},
{
"cell_type": "markdown",
"id": "479b963e",
"metadata": {},
"source": [
"### Run the algorithm"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d5445a96",
"metadata": {},
"outputs": [],
"source": [
"optimize!(solver) ;\n",
"\n",
"println(\"Computing time: \", computingTime(solver))"
]
},
{
"cell_type": "markdown",
"id": "545b54c9",
"metadata": {},
"source": [
"### Print the results"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "83b0fd8f",
"metadata": {},
"outputs": [],
"source": [
"using Plots\n",
" \n",
"#data to plot\n",
"x = [solution.objectives[1] for solution in foundSolutions(solver)];\n",
"y = [solution.objectives[2] for solution in foundSolutions(solver)];\n",
" \n",
"gr();\n",
" \n",
"scatter(x, y, title = \"Pareto front approximation\", label = \"Solutions\")\n",
"xlabel!(\"First objective\")\n",
"ylabel!(\"Second objective\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Julia 1.11.0",
"language": "julia",
"name": "julia-1.11"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.11.0"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

0 comments on commit b503ed6

Please sign in to comment.