Skip to content

Commit

Permalink
use is_solved_and_feasible
Browse files Browse the repository at this point in the history
  • Loading branch information
Fe-r-oz committed Dec 1, 2024
1 parent a43d217 commit 08448cb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ext/QuantumCliffordJuMPExt/QuantumCliffordJuMPExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ using DocStringExtensions

import JuMP
import JuMP: @variable, @objective, @constraint, optimize!, Model, set_silent,
sum, value
sum, value, optimize!, is_solved_and_feasible
import GLPK
import GLPK: Optimizer

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ function _minimum_distance(hx, lx)
num_anc_hx = ceil(Int, log2(whx))
num_anc_logical = ceil(Int, log2(wlx))
num_var = n + m * num_anc_hx + num_anc_logical
# MIP problem solver: https://jump.dev/JuMP.jl/stable/packages/GLPK/#GLPK.jl
# GLPK.jl is a wrapper for the GNU Linear Programming Kit library.
model = Model(GLPK.Optimizer; add_bridges = false) # model
set_silent(model)
@variable(model, x[1:num_var], Bin) # binary variables
Expand Down Expand Up @@ -232,7 +234,9 @@ function _minimum_distance(hx, lx)
cnt += 1
end
@constraint(model, sum(weight[i] * x[i] for i in 1:num_var) == 1)
# Ensure the model is solved and feasible
optimize!(model)
is_solved_and_feasible(model) || error("Did not solve model")
opt_val = sum(value(x[i]) for i in 1:n)
return Int(opt_val)
end

0 comments on commit 08448cb

Please sign in to comment.