Skip to content

Commit

Permalink
Tests reorganized, docstrings improved, all submodules removed
Browse files Browse the repository at this point in the history
  • Loading branch information
graidl committed Jan 4, 2025
1 parent 5b55b7d commit 3b61168
Show file tree
Hide file tree
Showing 40 changed files with 916 additions and 1,131 deletions.
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"lnewinc",
"MISP",
"mknapcb",
"Mulhern",
"oberweger",
"onemax",
"printf",
Expand All @@ -50,5 +51,6 @@
"trunc",
"typeof",
"uuid"
]
],
"julia.environmentPath": "/home/guenther/proj/MHLib/MHLibDemos"
}
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,17 @@

Major changes in releases:

## Version 0.1.16
- `clear!` renamed to `Base.empty!`
- Module tests use now `TestItems.jl`, which has support integrated in VSCode
- All submodules within MHLib removed
- MaxSat demo added directly in `MHLib` to be able to perform basic tests of all algorithms.
- Other tests for different problems moved to `MHLibDemos`
- Directory reorganization: Package `MHLib`has its own directory with the same name
- Docstrings improved

## Version 0.1.15
- `Tuning`renamed to `tuning`and small fixes in it, updates for Julia 1.11.
- `Tuning`renamed to `tuning`and small fixes in it, updates for Julia 1.11

## Version 0.1.14
- `Results` from `Scheduler` is extended with field `is_local_optimum` to be able to
Expand Down
123 changes: 103 additions & 20 deletions MHLibDemos/Manifest.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
# This file is machine-generated - editing it directly is not advised

julia_version = "1.11.1"
julia_version = "1.11.2"
manifest_format = "2.0"
project_hash = "4c7f4dc6592813657be89708500a83ad16e1dca0"
project_hash = "6b69c1bd75145b6c86fff7999db198a2798d1f53"

[[deps.AliasTables]]
deps = ["PtrArrays", "Random"]
git-tree-sha1 = "9876e1e164b144ca45e9e3198d0b689cadfed9ff"
uuid = "66dad0bd-aa9a-41b7-9441-69ab47430ed8"
version = "1.1.3"

[[deps.ArgParse]]
deps = ["Logging", "TextWrap"]
git-tree-sha1 = "22cf435ac22956a7b45b0168abbc871176e7eecc"
uuid = "c7e460c6-2fb9-53a9-8c5b-16f535851c63"
version = "1.2.0"

[[deps.ArgTools]]
uuid = "0dad84c5-d112-42e6-8d28-ef12dabb789f"
version = "1.1.2"

[[deps.ArnoldiMethod]]
deps = ["LinearAlgebra", "Random", "StaticArrays"]
git-tree-sha1 = "d57bd3762d308bded22c3b82d033bff85f6195c6"
Expand Down Expand Up @@ -72,6 +82,11 @@ git-tree-sha1 = "2fb1e02f2b635d0845df5d7c167fec4dd739b00d"
uuid = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
version = "0.9.3"

[[deps.Downloads]]
deps = ["ArgTools", "FileWatching", "LibCURL", "NetworkOptions"]
uuid = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
version = "1.6.0"

[[deps.FileWatching]]
uuid = "7b1f6079-737a-58dc-b8bc-7a2ca5c1b5ee"
version = "1.11.0"
Expand Down Expand Up @@ -99,9 +114,19 @@ version = "0.2.2"

[[deps.JuliaInterpreter]]
deps = ["CodeTracking", "InteractiveUtils", "Random", "UUIDs"]
git-tree-sha1 = "fc8504eca188aaae4345649ca6105806bc584b70"
git-tree-sha1 = "10da5154188682e5c0726823c2b5125957ec3778"
uuid = "aa1ae85d-cabe-5617-a682-6adf51b2e16a"
version = "0.9.37"
version = "0.9.38"

[[deps.LibCURL]]
deps = ["LibCURL_jll", "MozillaCACerts_jll"]
uuid = "b27032c2-a3e7-50c8-80cd-2d36dbcbfd21"
version = "0.6.4"

[[deps.LibCURL_jll]]
deps = ["Artifacts", "LibSSH2_jll", "Libdl", "MbedTLS_jll", "Zlib_jll", "nghttp2_jll"]
uuid = "deac9b47-8bc7-5906-a0fe-35ac56dc84c0"
version = "8.6.0+0"

[[deps.LibGit2]]
deps = ["Base64", "LibGit2_jll", "NetworkOptions", "Printf", "SHA"]
Expand Down Expand Up @@ -129,9 +154,9 @@ version = "1.11.0"

[[deps.LogExpFunctions]]
deps = ["DocStringExtensions", "IrrationalConstants", "LinearAlgebra"]
git-tree-sha1 = "a2d09619db4e765091ee5c6ffe8872849de0feea"
git-tree-sha1 = "13ca9e2586b89836fd20cccf56e57e2b9ae7f38f"
uuid = "2ab3a3ac-af41-5b50-aa03-7779005ae688"
version = "0.3.28"
version = "0.3.29"

[deps.LogExpFunctions.extensions]
LogExpFunctionsChainRulesCoreExt = "ChainRulesCore"
Expand All @@ -149,15 +174,15 @@ version = "1.11.0"

[[deps.LoweredCodeUtils]]
deps = ["JuliaInterpreter"]
git-tree-sha1 = "260dc274c1bc2cb839e758588c63d9c8b5e639d1"
git-tree-sha1 = "688d6d9e098109051ae33d126fcfc88c4ce4a021"
uuid = "6f1432cf-f94c-5a45-995e-cdbf5db27b0b"
version = "3.0.5"
version = "3.1.0"

[[deps.MHLib]]
deps = ["ArgParse", "DataStructures", "Logging", "Printf", "Random", "Reexport", "StatsBase"]
deps = ["ArgParse", "DataStructures", "Logging", "Printf", "Random", "Reexport", "StatsBase", "TestItemRunner", "TestItems"]
path = ".."
uuid = "0f3a0e6e-e0e7-4894-bd64-856f0ae3b635"
version = "0.1.15"
version = "0.1.16"

[[deps.MacroTools]]
deps = ["Markdown", "Random"]
Expand Down Expand Up @@ -185,6 +210,10 @@ version = "1.2.0"
uuid = "a63ad114-7e13-5084-954f-fe012c677804"
version = "1.11.0"

[[deps.MozillaCACerts_jll]]
uuid = "14a3606d-f60d-562e-9121-12d972cd8159"
version = "2023.12.12"

[[deps.NetworkOptions]]
uuid = "ca575930-c2e3-43a9-ace4-1e988b2c1908"
version = "1.2.0"
Expand All @@ -195,9 +224,18 @@ uuid = "4536629a-c528-5b80-bd46-f80d51c5b363"
version = "0.3.27+1"

[[deps.OrderedCollections]]
git-tree-sha1 = "dfdf5519f235516220579f949664f1bf44e741c5"
git-tree-sha1 = "12f1439c4f986bb868acda6ea33ebc78e19b95ad"
uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
version = "1.6.3"
version = "1.7.0"

[[deps.Pkg]]
deps = ["Artifacts", "Dates", "Downloads", "FileWatching", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "Random", "SHA", "TOML", "Tar", "UUIDs", "p7zip_jll"]
uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
version = "1.11.0"
weakdeps = ["REPL"]

[deps.Pkg.extensions]
REPLExt = "REPL"

[[deps.PrecompileTools]]
deps = ["Preferences"]
Expand All @@ -216,6 +254,11 @@ deps = ["Unicode"]
uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7"
version = "1.11.0"

[[deps.PtrArrays]]
git-tree-sha1 = "77a42d78b6a92df47ab37e177b2deac405e1c88f"
uuid = "43287f4e-b6f4-7ad1-bb20-aadabca52c3d"
version = "1.2.1"

[[deps.REPL]]
deps = ["InteractiveUtils", "Markdown", "Sockets", "StyledStrings", "Unicode"]
uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
Expand All @@ -238,10 +281,14 @@ uuid = "ae029012-a4dd-5104-9daa-d747884805df"
version = "1.3.0"

[[deps.Revise]]
deps = ["CodeTracking", "Distributed", "FileWatching", "JuliaInterpreter", "LibGit2", "LoweredCodeUtils", "OrderedCollections", "REPL", "Requires", "UUIDs", "Unicode"]
git-tree-sha1 = "834aedb1369919a7b2026d7e04c2d49a311d26f4"
deps = ["CodeTracking", "FileWatching", "JuliaInterpreter", "LibGit2", "LoweredCodeUtils", "OrderedCollections", "REPL", "Requires", "UUIDs", "Unicode"]
git-tree-sha1 = "b5e7c125687aa818de948ef8a0b9dc59f043342c"
uuid = "295af30f-e4ad-537b-8983-00126c2a3abe"
version = "3.6.3"
version = "3.7.1"
weakdeps = ["Distributed"]

[deps.Revise.extensions]
DistributedExt = "Distributed"

[[deps.SHA]]
uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce"
Expand Down Expand Up @@ -279,9 +326,9 @@ version = "1.11.0"

[[deps.StaticArrays]]
deps = ["LinearAlgebra", "PrecompileTools", "Random", "StaticArraysCore"]
git-tree-sha1 = "777657803913ffc7e8cc20f0fd04b634f871af8f"
git-tree-sha1 = "47091a0340a675c738b1304b58161f3b0839d454"
uuid = "90137ffa-7385-5640-81b9-e52037218182"
version = "1.9.8"
version = "1.9.10"

[deps.StaticArrays.extensions]
StaticArraysChainRulesCoreExt = "ChainRulesCore"
Expand Down Expand Up @@ -313,10 +360,10 @@ uuid = "82ae8749-77ed-4fe6-ae5f-f523153014b0"
version = "1.7.0"

[[deps.StatsBase]]
deps = ["DataAPI", "DataStructures", "LinearAlgebra", "LogExpFunctions", "Missings", "Printf", "Random", "SortingAlgorithms", "SparseArrays", "Statistics", "StatsAPI"]
git-tree-sha1 = "5cf7606d6cef84b543b483848d4ae08ad9832b21"
deps = ["AliasTables", "DataAPI", "DataStructures", "LinearAlgebra", "LogExpFunctions", "Missings", "Printf", "Random", "SortingAlgorithms", "SparseArrays", "Statistics", "StatsAPI"]
git-tree-sha1 = "29321314c920c26684834965ec2ce0dacc9cf8e5"
uuid = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
version = "0.34.3"
version = "0.34.4"

[[deps.StyledStrings]]
uuid = "f489334b-da3d-4c2e-b8f0-e476e12c162b"
Expand All @@ -332,6 +379,27 @@ deps = ["Dates"]
uuid = "fa267f1f-6049-4f14-aa54-33bafae1ed76"
version = "1.0.3"

[[deps.Tar]]
deps = ["ArgTools", "SHA"]
uuid = "a4e569a6-e804-4fa4-b0f3-eef7a1d5b13e"
version = "1.10.0"

[[deps.Test]]
deps = ["InteractiveUtils", "Logging", "Random", "Serialization"]
uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
version = "1.11.0"

[[deps.TestItemRunner]]
deps = ["Pkg", "TOML", "Test", "TestItems", "UUIDs"]
git-tree-sha1 = "29647c5398be04a1d697265ba385bdf3f623c993"
uuid = "f8b46487-2199-4994-9208-9a1283c18c0a"
version = "1.0.5"

[[deps.TestItems]]
git-tree-sha1 = "42fd9023fef18b9b78c8343a4e2f3813ffbcefcb"
uuid = "1c621080-faea-4a02-84b6-bbd5e436b8fe"
version = "1.0.0"

[[deps.TextWrap]]
git-tree-sha1 = "43044b737fa70bc12f6105061d3da38f881a3e3c"
uuid = "b718987f-49a8-5099-9789-dcd902bef87d"
Expand All @@ -346,7 +414,22 @@ version = "1.11.0"
uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"
version = "1.11.0"

[[deps.Zlib_jll]]
deps = ["Libdl"]
uuid = "83775a58-1f1d-513f-b197-d71354ab007a"
version = "1.2.13+1"

[[deps.libblastrampoline_jll]]
deps = ["Artifacts", "Libdl"]
uuid = "8e850b90-86db-534c-a0d3-1478176c7d93"
version = "5.11.0+0"

[[deps.nghttp2_jll]]
deps = ["Artifacts", "Libdl"]
uuid = "8e850ede-7688-5339-a07c-302acd2aaf8d"
version = "1.59.0+0"

[[deps.p7zip_jll]]
deps = ["Artifacts", "Libdl"]
uuid = "3f19e933-33d8-53b3-aaab-bd5110c3b7a0"
version = "17.4.0+2"
4 changes: 3 additions & 1 deletion MHLibDemos/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ MHLib = "0f3a0e6e-e0e7-4894-bd64-856f0ae3b635"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Revise = "295af30f-e4ad-537b-8983-00126c2a3abe"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
TestItemRunner = "f8b46487-2199-4994-9208-9a1283c18c0a"
TestItems = "1c621080-faea-4a02-84b6-bbd5e436b8fe"

[compat]
ArgParse = "1"
Graphs = "1.8"
MHLib = "0.1"
StatsBase = "0.33, 0.34"
TestItemRunner = "1.0.5"
julia = "1.10"
37 changes: 17 additions & 20 deletions MHLibDemos/src/GraphColoring.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ using StatsBase
using Graphs
using MHLib

export GraphColoringInstance, GraphColoringSolution, solve_graph_coloring
export GraphColoringInstance, GraphColoringSolution, solve_graph_coloring,
graph_coloring_settings_cfg

# We define a problem-specific parameter:
const graph_coloring_settings_cfg = ArgParseSettings()
Expand Down Expand Up @@ -58,7 +59,7 @@ function GraphColoringInstance(name::AbstractString)
GraphColoringInstance(graph, n, m, colors)
end

function show(io::IO, inst::GraphColoringInstance)
function Base.show(io::IO, inst::GraphColoringInstance)
println(io, "n=$(inst.n), m=$(inst.m)")
end

Expand Down Expand Up @@ -128,24 +129,23 @@ end


"""
construct!(s::GraphColoringSolution, par, result)
construct!(s::GraphColoringSolution, ::Nothing, result)
Constructs a new solution. Here we just call initialize!.
`MHMethod` that constructs a new solution. Here we just call initialize!.
"""
function MHLib.Schedulers.construct!(s::GraphColoringSolution, par::Int, result::Result)
initialize!(s)
end

MHLib.construct!(s::GraphColoringSolution, ::Nothing, ::Result) = initialize!(s)


"""
local_improve!(s::GraphColoringSolution, par, result)
Performs one iteration of a local search following a first improvement strategy.
`MHMethod` that performs one iteration of a local search.
Following a first improvement strategy.
The neighborhood used is defined by all solutions that can be created by changing the color
of a vertex involved in a conflict.
"""
function MHLib.Schedulers.local_improve!(s::GraphColoringSolution, par::Int, result::Result)
function MHLib.local_improve!(s::GraphColoringSolution, ::Nothing, result::Result)
n = length(s.x)
order = sample(1:n, n, replace = false)
for p in order
Expand Down Expand Up @@ -177,10 +177,9 @@ end
"""
shaking!(s::GraphColoringSolution, par, result)
Perform shaking by randomly assigning a different color
to 'par' many random vertices that are involved in conflicts.
`MHMethod` that randomly assigns different colors to 'par' vertices involved in conflicts.
"""
function MHLib.Schedulers.shaking!(s::GraphColoringSolution, par::Int, result::Result)
function MHLib.shaking!(s::GraphColoringSolution, par::Int, result::Result)
under_conflict = Vector{Int}()
result.changed = false

Expand All @@ -194,10 +193,8 @@ function MHLib.Schedulers.shaking!(s::GraphColoringSolution, par::Int, result::R
end
end

for i in 1:par
if length(under_conflict) == 0
return
end
for _ in 1:par
iszero(under_conflict) && return

index = sample(1:length(under_conflict))[1]
u = under_conflict[index]
Expand Down Expand Up @@ -229,17 +226,17 @@ function solve_graph_coloring(args=ARGS)
args isa AbstractString && (args = split(args))

# We set some new default values for parameters and parse all relevant arguments
settings_new_default_value!(MHLib.Schedulers.settings_cfg, "mh_titer", 1000)
settings_new_default_value!(MHLib.scheduler_settings_cfg, "mh_titer", 1000)
settings_new_default_value!(MHLib.settings_cfg, "ifile", "data/fpsol2.i.1.col")
parse_settings!([MHLib.Schedulers.settings_cfg, graph_coloring_settings_cfg], args)
parse_settings!([MHLib.schedulers_settings_cfg, graph_coloring_settings_cfg], args)
println(get_settings_as_string())

inst = GraphColoringInstance(settings[:ifile])
sol = GraphColoringSolution(inst)
initialize!(sol)
println(sol)

alg = GVNS(sol, [MHMethod("con", construct!, 0)],
alg = GVNS(sol, [MHMethod("con", construct!)],
[MHMethod("li1", local_improve!, 1)],[MHMethod("sh1", shaking!, 1)],
consider_initial_sol = true)
run!(alg)
Expand Down
Loading

0 comments on commit 3b61168

Please sign in to comment.