Skip to content

Commit

Permalink
fix docs + small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
olegfafurin committed Nov 10, 2023
1 parent cc2a92b commit 645e3fc
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/GraphsOptim.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ include("utils.jl")
include("flow.jl")
include("assignment.jl")
include("graph_matching.jl")
include("vertex_cover.jl")
include("min_vertex_cover.jl")
include("fractional_coloring.jl")
include("shortest_path.jl")

Expand Down
17 changes: 8 additions & 9 deletions src/vertex_cover.jl → src/min_vertex_cover.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
vertex_cover!(
min_vertex_cover!(
model, g;
var_name
)
Expand All @@ -8,24 +8,23 @@ Modify a JuMP model by adding the variable, constraints and objective necessary
The vertex cover indicator variable will be named `var_name`
"""
function min_vertex_cover!(model::Model, g::AbstractGraph; var_name)
function min_vertex_cover!(model::Model, g::AbstractGraph; integer::Bool, var_name)
if is_directed(g)
throw(ArgumentError("The graph must not be directed"))

Check warning on line 13 in src/min_vertex_cover.jl

View check run for this annotation

Codecov / codecov/patch

src/min_vertex_cover.jl#L13

Added line #L13 was not covered by tests
end

ver = collect(vertices(g))
edge_tuples = [(src(ed), dst(ed)) for ed in edges(g)]

f = @variable(model, [ver]; integer=true, base_name=String(var_name))
f = @variable(model, [ver]; integer=integer, base_name=String(var_name))
model[Symbol(var_name)] = f

for v in ver
@constraint(model, f[v] >= 0)
@constraint(model, f[v] <= 1)
end

for (u, v) in edge_tuples
@constraint(model, f[u] + f[v] >= 1)
for e in edges(g)
@constraint(model, f[src(e)] + f[dst(e)] >= 1)
end

obj = objective_function(model)
Expand All @@ -38,7 +37,7 @@ function min_vertex_cover!(model::Model, g::AbstractGraph; var_name)
end

"""
vertex_cover(
min_vertex_cover(
g, optimizer
)
Expand All @@ -52,11 +51,11 @@ Compute a minimum vertex cover of an undirected graph.
- `optimizer`: JuMP-compatible solver (default is `HiGHS.Optimizer`)
"""
function min_vertex_cover(g::AbstractGraph; optimizer=HiGHS.Optimizer)
function min_vertex_cover(g::AbstractGraph; integer::Bool=true, optimizer=HiGHS.Optimizer)
model = Model(optimizer)
set_silent(model)

min_vertex_cover!(model, g; var_name=:cover)
min_vertex_cover!(model, g; integer=integer, var_name=:cover)

optimize!(model)
@assert termination_status(model) == OPTIMAL
Expand Down
2 changes: 1 addition & 1 deletion test/vertex_cover.jl → test/min_vertex_cover.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ adj_matrix = [
0 1 0 0 0 0
]

expected_ans_options = Set([Set([1, 2]), Set([2, 3])])
expected_ans_options = [Set([1, 2]), Set([2, 3])]

graph = SimpleGraph(adj_matrix)

Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ using Test
end

@testset verbose = true "Vertex cover" begin
include("vertex_cover.jl")
include("min_vertex_cover.jl")
end

@testset verbose = true "Fractional coloring" begin
Expand Down

0 comments on commit 645e3fc

Please sign in to comment.