Skip to content

Commit

Permalink
Further restructuring of demo applications
Browse files Browse the repository at this point in the history
  • Loading branch information
graidl committed Sep 27, 2023
1 parent ac9e508 commit 95986aa
Show file tree
Hide file tree
Showing 25 changed files with 361 additions and 339 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@
"typeof",
"uuid"
],
"julia.environmentPath": "/home/guenther/proj/MHLib/MHLibDemos"
"julia.environmentPath": "/home/guenther/proj/MHLib/test"
}
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@

Major changes in releases:

## Upcoming
- all demo applications moved into the new subpackage `MHLibDemos`
## Upcoming

## Version 0.1.8
- all demo applications refined and moved into an own subpackage `MHLibDemos`
- all symbols of submodules are now also re-exported by the main `MHLib` module
- LNS/ALNS refactored, `MethodSelector` introduced to generalize LNS
- all structures adapted to use type parameters instead of abstract types for elements
Expand Down
6 changes: 2 additions & 4 deletions MHLibDemos/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,9 @@ uuid = "56ddb016-857b-54e1-b83d-db4d58db5568"

[[deps.MHLib]]
deps = ["ArgParse", "DataStructures", "Logging", "Printf", "Random", "Reexport", "StatsBase"]
git-tree-sha1 = "db91fe635ee06d3707933aca75a9ac3384a6d7f0"
repo-rev = "master"
repo-url = "https://github.com/ac-tuwien/MHLib.jl.git"
path = ".."
uuid = "0f3a0e6e-e0e7-4894-bd64-856f0ae3b635"
version = "0.1.7"
version = "0.1.8"

[[deps.MacroTools]]
deps = ["Markdown", "Random"]
Expand Down
22 changes: 1 addition & 21 deletions MHLibDemos/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ _This project is still in early development, any feedback is much appreciated!_
the effective implementation of metaheuristics and certain hybrid optimization approaches
for solving primarily combinatorial optimization problems.

The current package `MHLibDemos.jl` provides demo applications for `MHLib.jl` that can be used as templates for your own applications.
The current package `MHLibDemos.jl` provides diverse demos for `MHLib.jl` and can be used as template for your own application.

`MHLib.jl` and `MHLibDemos.jl` is developed primarily by the
[Algorithms and Complexity Group of TU Wien](https://www.ac.tuwien.ac.at),
Expand All @@ -22,26 +22,6 @@ Vienna, Austria, since 2020.
- Thomas Jatschka
- Fabio Oberweger

## Installation

Major versions of `MHLib.jl` can be installed from the Julia REPL via

] add MHLib

The associated package `MHLibDemos.jl`, which provides diverse demos for solving classical combinatorial optimization problems with `MHLib.jl`, can be installed via

] add MHLibDemos

Development versions of both packages are available at https://github.com/ac-tuwien/MHLib.jl and can be
installed via

] add https://github.com/ac-tuwien/MHLib.jl.git

and

] add https://github.com/ac-tuwien/MHLib.jl.git#master:MHLibDemos


## Further information

See the README.md file of the main package [MHLib.jl](https://github.com/ac-tuwien/MHLib.jl).
41 changes: 5 additions & 36 deletions MHLibDemos/bin/demo_graph_coloring.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,13 @@
Standalone demo program for solving the Graph Coloring Problem.
"""

# activate MHLibDemos environment
# switch to MHLibDemos directory and activate its environment
cd(@__DIR__()*"/..")
using Pkg; Pkg.activate(".")

module Demo_GC

using ArgParse
using Random
using Revise
using MHLib
using MHLibDemos

const settings_cfg = ArgParseSettings()


function solve()
inst = GraphColoringInstance("data/fpsol2.i.1.col")
sol = GraphColoringSolution(inst)
initialize!(sol)
println(sol)

alg = GVNS(sol, [MHMethod("con", construct!, 0)],
[MHMethod("li1", local_improve!, 1)],[MHMethod("sh1", shaking!, 1)],
consider_initial_sol = true)
run!(alg)
method_statistics(alg.scheduler)
main_results(alg.scheduler)
check(sol)
return sol
end


println("Graph Coloring Demo version $(git_version())\nARGS: ", ARGS)
settings_new_default_value!(MHLib.Schedulers.settings_cfg, "mh_titer", 10000)
parse_settings!([MHLib.Schedulers.settings_cfg, MHLibDemos.settings_cfg])
println(get_settings_as_string())

end # module


Demo_GC.solve()
# Command line arguments are parsed and used to set global parameters
# use `@<filename>` to read parameters from configuration file `<filename>`
# alternatively, they may also be provided here to the call as vector of strings
solve_graph_coloring()
68 changes: 5 additions & 63 deletions MHLibDemos/bin/demo_maxsat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,71 +5,13 @@
Standalone demo program for solving the MAXSAT problem.
"""

# activate MHLibDemos environment
# switch to MHLibDemos directory and activate its environment
cd(@__DIR__()*"/..")
using Pkg; Pkg.activate(".")

module Demo_maxsat

using ArgParse
using Revise
using MHLib
using MHLibDemos


const settings_cfg = ArgParseSettings()

@add_arg_table! settings_cfg begin
"--alg"
help = "Algorithm to apply (gvns, lns, weighted-lns, alns)"
arg_type = String
default = "alns"
end

println("MAXSAT Demo version $(git_version())\nARGS: ", ARGS)
settings_new_default_value!(MHLib.settings_cfg, "ifile", "data/maxsat-adv1.cnf")
settings_new_default_value!(MHLib.Schedulers.settings_cfg, "mh_titer", 1000)
parse_settings!([MHLib.Schedulers.settings_cfg, MHLib.LNSs.settings_cfg,
MHLib.ALNSs.settings_cfg, settings_cfg])
println(get_settings_as_string())

function solve_maxsat()
inst = MAXSATInstance(settings[:ifile])
sol = MAXSATSolution(inst)
println(sol)

if settings[:alg] === "lns"
alg = LNS(sol, [MHMethod("construct", construct!, 0)],
[MHMethod("de", destroy!, 1)],
[MHMethod("re", repair!, 0)];
meths_compat = [true;;])
elseif settings[:alg] === "weighted-lns"
num_de = 5
method_selector = WeightedRandomMethodSelector(num_re:-1:1, 1:1)
alg = LNS(sol, [MHMethod("construct", construct!, 0)],
[MHMethod("de$i", destroy!, i) for i in 1:num_de],
[MHMethod("re", repair!, 0)];
method_selector)
elseif settings[:alg] === "alns"
num_de = 5
alg = ALNS(sol, [MHMethod("construct", construct!, 0)],
[MHMethod("de$i", destroy!, i) for i in 1:num_de],
[MHMethod("re", repair!, 0)])
elseif settings[:alg] === "gvns"
alg = GVNS(sol, [MHMethod("con", construct!, 0)],
[MHMethod("li1", local_improve!, 1)],
[MHMethod("sh$i", shaking!, i) for i in 1:5])
else
error("Invalid parameter alg: $(settings[:alg])")
end
run!(alg)
method_statistics(alg.scheduler)
main_results(alg.scheduler)
check(sol)
return sol
end

end # module

Demo_maxsat.solve_maxsat()
# @profview Demo_maxsat.solve_maxsat()
# Command line arguments are parsed and used to set global parameters
# use `@<filename>` to read parameters from configuration file `<filename>`
# alternatively, they may also be provided here to the call as vector of strings
solve_maxsat()
43 changes: 5 additions & 38 deletions MHLibDemos/bin/demo_misp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,13 @@
Standalone demo program for solving the MISP.
"""

# activate MHLibDemos environment
# switch to MHLibDemos directory and activate its environment
cd(@__DIR__()*"/..")
using Pkg; Pkg.activate(".")

module Demo_MISP

using ArgParse
using Random
using Revise
using MHLib
using MHLibDemos

const settings_cfg = ArgParseSettings()


function solve()
inst = MISPInstance("data/frb40-19-1.mis")
sol = MISPSolution(inst)
# initialize!(sol)
# check(sol)
# println(sol)

alg = GVNS(sol, [MHMethod("con", construct!, 0)],
[MHMethod("li1", local_improve!, 1)],
[MHMethod("sh1", shaking!, 1), MHMethod("sh2", shaking!, 2),
MHMethod("sh3", shaking!, 3)],
consider_initial_sol = true)
run!(alg)
method_statistics(alg.scheduler)
main_results(alg.scheduler)
check(sol)
return sol
end


println("MISP Demo version $(git_version())\nARGS: ", ARGS)
settings_new_default_value!(MHLib.Schedulers.settings_cfg, "mh_titer", 10000)
parse_settings!([MHLib.Schedulers.settings_cfg])
println(get_settings_as_string())

end # module

Demo_MISP.solve()
# Command line arguments are parsed and used to set global parameters
# use `@<filename>` to read parameters from configuration file `<filename>`
# alternatively, they may also be provided here to the call as vector of strings
solve_misp()
44 changes: 5 additions & 39 deletions MHLibDemos/bin/demo_mkp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,47 +5,13 @@
Standalone demo program for solving the MKP.
"""

# activate MHLibDemos environment
# switch to MHLibDemos directory and activate its environment
cd(@__DIR__()*"/..")
using Pkg; Pkg.activate(".")

module Demo_MKP

using ArgParse
using Random
using Revise
using MHLib
using MHLibDemos

const settings_cfg = ArgParseSettings()


function solve()
inst = MKPInstance("data/mknapcb5-01.txt")
sol = MKPSolution(inst)
# initialize!(sol)
# check(sol)
# println(sol)

alg = GVNS(sol, [MHMethod("con", construct!, 0)],
[MHMethod("li1", local_improve!, 1)],
[MHMethod("sh1", shaking!, 1), MHMethod("sh2", shaking!, 2),
MHMethod("sh3", shaking!, 3)],
consider_initial_sol = true)
run!(alg)
method_statistics(alg.scheduler)
main_results(alg.scheduler)
check(sol)
return sol
end


println("MKP Demo version $(git_version())\nARGS: ", ARGS)
settings_new_default_value!(MHLib.Schedulers.settings_cfg, "mh_titer", 5000)
parse_settings!([MHLib.Schedulers.settings_cfg])
println(get_settings_as_string())

end # module


Demo_MKP.solve()
# Command line arguments are parsed and used to set global parameters
# use `@<filename>` to read parameters from configuration file `<filename>`
# alternatively, they may also be provided here to the call as vector of strings
solve_mkp()
40 changes: 5 additions & 35 deletions MHLibDemos/bin/demo_onemax.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,13 @@
Standalone demo program for solving the OneMax Problem.
"""

# activate MHLibDemos environment
# switch to MHLibDemos directory and activate its environment
cd(@__DIR__()*"/..")
using Pkg; Pkg.activate(".")

module Demo_OneMax

using ArgParse
using Random
using Revise
using MHLib
using MHLibDemos

const settings_cfg = ArgParseSettings()


function solve()
sol = OneMaxSolution(settings[:onemax_n])
initialize!(sol)
println(sol)

alg = GVNS(sol, [MHMethod("con", construct!, 0)],
[MHMethod("li1", local_improve!, 1)],[MHMethod("sh1", shaking!, 1)],
consider_initial_sol = true)
run!(alg)
method_statistics(alg.scheduler)
main_results(alg.scheduler)
check(sol)
return sol
end


println("OneMax Demo version $(git_version())\nARGS: ", ARGS)
settings_new_default_value!(MHLib.Schedulers.settings_cfg, "mh_titer", 10000)
parse_settings!([MHLib.Schedulers.settings_cfg, MHLibDemos.settings_cfg])
println(get_settings_as_string())

end # module


Demo_OneMax.solve()
# Command line arguments are parsed and used to set global parameters
# use `@<filename>` to read parameters from configuration file `<filename>`
# alternatively, they may also be provided here to the call as vector of strings
solve_onemax()
Loading

0 comments on commit 95986aa

Please sign in to comment.