Skip to content

Commit

Permalink
Bug fixes in MISP/MKP.clear!, MKP polished, Pkg updated
Browse files Browse the repository at this point in the history
  • Loading branch information
graidl committed Oct 5, 2023
1 parent 042e48c commit ef6e862
Show file tree
Hide file tree
Showing 13 changed files with 76 additions and 38 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/test"
"julia.environmentPath": "/home/guenther/proj/MHLib/MHLibDemos"
}
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ Major changes in releases:

## Upcoming

## Version 0.1.9
- bug fix in `MISPSolution.clear!` and `MKPSolution.clear!`, MKP.jl polished

## 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
Expand Down
40 changes: 35 additions & 5 deletions MHLibDemos/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

julia_version = "1.9.3"
manifest_format = "2.0"
project_hash = "dac8feb5fd248fb83d64c5946419df70b28327f1"
project_hash = "310f02b02e97b016922d1f28da101bfd8b1831be"

[[deps.ArgParse]]
deps = ["Logging", "TextWrap"]
Expand All @@ -26,6 +26,12 @@ uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"
[[deps.Base64]]
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"

[[deps.CodeTracking]]
deps = ["InteractiveUtils", "UUIDs"]
git-tree-sha1 = "a1296f0fe01a4c3f9bf0dc2934efbf4416f5db31"
uuid = "da1fd8a2-8d9e-5ec2-8556-3022fb5608a2"
version = "1.3.4"

[[deps.Compat]]
deps = ["UUIDs"]
git-tree-sha1 = "8a62af3e248a8c4bad6b32cbbe663ae02275e32c"
Expand Down Expand Up @@ -76,9 +82,9 @@ uuid = "7b1f6079-737a-58dc-b8bc-7a2ca5c1b5ee"

[[deps.Graphs]]
deps = ["ArnoldiMethod", "Compat", "DataStructures", "Distributed", "Inflate", "LinearAlgebra", "Random", "SharedArrays", "SimpleTraits", "SparseArrays", "Statistics"]
git-tree-sha1 = "1cf1d7dcb4bc32d7b4a5add4232db3750c27ecb4"
git-tree-sha1 = "899050ace26649433ef1af25bc17a815b3db52b7"
uuid = "86223c79-3864-5bf0-83f7-82e725a168b6"
version = "1.8.0"
version = "1.9.0"

[[deps.Inflate]]
git-tree-sha1 = "5cd07aab533df5170988219191dfad0519391428"
Expand All @@ -94,6 +100,12 @@ git-tree-sha1 = "630b497eafcc20001bba38a4651b327dcfc491d2"
uuid = "92d709cd-6900-40b7-9082-c6be49f344b6"
version = "0.2.2"

[[deps.JuliaInterpreter]]
deps = ["CodeTracking", "InteractiveUtils", "Random", "UUIDs"]
git-tree-sha1 = "81dc6aefcbe7421bd62cb6ca0e700779330acff8"
uuid = "aa1ae85d-cabe-5617-a682-6adf51b2e16a"
version = "0.9.25"

[[deps.LibCURL]]
deps = ["LibCURL_jll", "MozillaCACerts_jll"]
uuid = "b27032c2-a3e7-50c8-80cd-2d36dbcbfd21"
Expand Down Expand Up @@ -139,6 +151,12 @@ version = "0.3.26"
[[deps.Logging]]
uuid = "56ddb016-857b-54e1-b83d-db4d58db5568"

[[deps.LoweredCodeUtils]]
deps = ["JuliaInterpreter"]
git-tree-sha1 = "60168780555f3e663c536500aa790b6368adc02a"
uuid = "6f1432cf-f94c-5a45-995e-cdbf5db27b0b"
version = "2.3.0"

[[deps.MHLib]]
deps = ["ArgParse", "DataStructures", "Logging", "Printf", "Random", "Reexport", "StatsBase"]
path = ".."
Expand Down Expand Up @@ -209,6 +227,18 @@ git-tree-sha1 = "45e428421666073eab6f2da5c9d310d99bb12f9b"
uuid = "189a3867-3050-52da-a836-e630ba90ab69"
version = "1.2.2"

[[deps.Requires]]
deps = ["UUIDs"]
git-tree-sha1 = "838a3a4188e2ded87a4f9f184b4b0d78a1e91cb7"
uuid = "ae029012-a4dd-5104-9daa-d747884805df"
version = "1.3.0"

[[deps.Revise]]
deps = ["CodeTracking", "Distributed", "FileWatching", "JuliaInterpreter", "LibGit2", "LoweredCodeUtils", "OrderedCollections", "Pkg", "REPL", "Requires", "UUIDs", "Unicode"]
git-tree-sha1 = "609c26951d80551620241c3d7090c71a73da75ab"
uuid = "295af30f-e4ad-537b-8983-00126c2a3abe"
version = "3.5.6"

[[deps.SHA]]
uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce"
version = "0.7.0"
Expand Down Expand Up @@ -241,9 +271,9 @@ uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"

[[deps.StaticArrays]]
deps = ["LinearAlgebra", "Random", "StaticArraysCore"]
git-tree-sha1 = "d5fb407ec3179063214bc6277712928ba78459e2"
git-tree-sha1 = "0adf069a2a490c47273727e029371b31d44b72b2"
uuid = "90137ffa-7385-5640-81b9-e52037218182"
version = "1.6.4"
version = "1.6.5"
weakdeps = ["Statistics"]

[deps.StaticArrays.extensions]
Expand Down
3 changes: 2 additions & 1 deletion MHLibDemos/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ ArgParse = "c7e460c6-2fb9-53a9-8c5b-16f535851c63"
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
MHLib = "0f3a0e6e-e0e7-4894-bd64-856f0ae3b635"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Revise = "295af30f-e4ad-537b-8983-00126c2a3abe"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"

[compat]
ArgParse = "1"
Graphs = "1.8"
StatsBase = "0.33, 0.34"
MHLib = "0.1"
StatsBase = "0.33, 0.34"
julia = "1.6"
5 changes: 4 additions & 1 deletion MHLibDemos/bin/demo_misp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ using MHLibDemos
# 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()
# solve_misp()

# for testing on a small random graph
solve_misp(["--seed", "3", "--ifile", "gnm-10-13"])
4 changes: 2 additions & 2 deletions MHLibDemos/src/GraphColoring.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Solution to a Graph Coloring instance.
It is a `VectorSolution{Int}`.
Attributes
- `x`: array with the assigned colors
- `x`: vector with the assigned colors
"""
mutable struct GraphColoringSolution <: VectorSolution{Int}
inst::GraphColoringInstance
Expand Down Expand Up @@ -123,7 +123,7 @@ function MHLib.check(s::GraphColoringSolution; kwargs...)
if sum(s.x .> s.inst.colors) >= 1
error("Too many colors used")
end
invoke(check, Tuple{supertype(typeof(s))}, s; kwargs...)
invoke(MHLib.check, Tuple{supertype(typeof(s))}, s; kwargs...)
end


Expand Down
1 change: 1 addition & 0 deletions MHLibDemos/src/MHLibDemos.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module MHLibDemos

using Revise
using ArgParse
using Graphs

Expand Down
6 changes: 3 additions & 3 deletions MHLibDemos/src/MISP.jl
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ Base.copy(s::MISPSolution) =
MISPSolution(s.inst, s.obj_val, s.obj_val_valid, copy(s.x), s.sel, copy(s.covered))

Base.show(io::IO, s::MISPSolution) =
println(io, s.x)
println(io, s.x[1:s.sel])

MHLib.calc_objective(s::MISPSolution) =
s.sel > 0 ? sum(s.inst.p[s.x[1:s.sel]]) : 0
Expand All @@ -125,9 +125,9 @@ function MHLib.check(s::MISPSolution; kwargs...)
end
end

function clear!(s::MISPSolution)
function MHLib.clear!(s::MISPSolution)
fill!(s.covered, 0)
invoke(clear!, Tuple{SubsetVectorSolution}, s)
invoke(MHLib.clear!, Tuple{SubsetVectorSolution}, s)
end

"""
Expand Down
38 changes: 15 additions & 23 deletions MHLibDemos/src/MKP.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct MKPInstance
n::Int
m::Int
p::Vector{Int}
r::Array{Int, 2}
r::Matrix{Int}
b::Vector{Int}
r_min::Int
obj_opt::Float64
Expand All @@ -43,32 +43,24 @@ end
Read MKP instance from file.
"""
function MKPInstance(file_name::String)
local n::Int
local m::Int
local p::Vector{Int}
local r::Array{Int,2}
local b::Vector{Int}
local r_min::Int
local obj_opt::Float64
all_values = Vector{Int}()

all_values = Int[]
open(file_name) do f
for line in eachline(f)
for word in split(line)
push!(all_values, parse(Int,word))
end
end
n = all_values[1]
m = all_values[2]
if length(all_values) != 3+n+m*n+m
error("Invalid number of values in MKP instance file $(file_name)")
end
obj_opt = all_values[3]
p = Vector{Int}(all_values[4:4+n-1])
r = reshape(Vector{Int}(all_values[4+n:4+n+m*n-1]),(m,n))
b = Vector{Int}(all_values[4+n+m*n:4+n+m*n+m-1])
r_min = min(minimum(r),1)
end
n = all_values[1]
m = all_values[2]
if length(all_values) != 3+n+m*n+m
error("Invalid number of values in MKP instance file $(file_name)")
end
obj_opt = all_values[3]
p = all_values[4:4+n-1]
r = reshape(all_values[4+n:4+n+m*n-1], (m,n))
b = all_values[4+n+m*n:4+n+m*n+m-1]
r_min = min(minimum(r),1)
MKPInstance(n, m, p, r, b, r_min, obj_opt)
end

Expand Down Expand Up @@ -108,7 +100,7 @@ Base.copy(s::MKPSolution) =
copy(s.all_elements), s.sel)

Base.show(io::IO, s::MKPSolution) =
println(io, s.x)
println(io, s.x[1:s.sel])

MHLib.calc_objective(s::MKPSolution) =
s.sel > 0 ? sum(s.inst.p[s.x[1:s.sel]]) : 0
Expand Down Expand Up @@ -138,9 +130,9 @@ function MHLib.check(s::MKPSolution; kwargs...)
end
end

function clear!(s::MKPSolution)
function MHLib.clear!(s::MKPSolution)
fill!(s.y, 0)
invoke(clear, Tuple{SubsetVectorSolution}, s)
invoke(MHLib.clear!, Tuple{SubsetVectorSolution}, s)
end

"""
Expand Down
7 changes: 7 additions & 0 deletions MHLibDemos/test/Manifest.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This file is machine-generated - editing it directly is not advised

julia_version = "1.9.3"
manifest_format = "2.0"
project_hash = "da39a3ee5e6b4b0d3255bfef95601890afd80709"

[deps]
1 change: 1 addition & 0 deletions MHLibDemos/test/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[deps]
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "MHLib"
uuid = "0f3a0e6e-e0e7-4894-bd64-856f0ae3b635"
authors = ["Guenther Raidl <[email protected]> and others"]
version = "0.1.8"
version = "0.1.9"

[deps]
ArgParse = "c7e460c6-2fb9-53a9-8c5b-16f535851c63"
Expand Down
2 changes: 1 addition & 1 deletion src/SubsetVectorSolutions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ Check correctness of solution; throw an exception if error detected.
- `unsorted`: if set, it is not checked if the solution is sorted
"""
function MHLib.check(s::SubsetVectorSolution; unsorted::Bool=true, kwargs...)
if !(1 <= s.sel <= length(s.x))
if !(0 <= s.sel <= length(s.x))
error("Invalid attribute sel in solution: $(s.sel)")
end
if unselected_elems_in_x(s)
Expand Down

2 comments on commit ef6e862

@graidl
Copy link
Collaborator Author

@graidl graidl commented on ef6e862 Oct 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/92805

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.9 -m "<description of version>" ef6e862a0f42e79fb805d096afb2f9f23b72e6f5
git push origin v0.1.9

Please sign in to comment.