Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conflict report #276

Merged
merged 8 commits into from
Sep 9, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
import
  • Loading branch information
matbesancon committed Sep 8, 2023
commit b7f840b8a4e217ea86a60d2e531ac8ed9620530d
4 changes: 2 additions & 2 deletions src/MOI_wrapper/conflict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,94 +2,94 @@
"""
Computes a set of constraints which could not be satisfied when trying to minimize the total violations.
"""
function compute_minimum_unsatisfied_constraints!(o::Optimizer)
if o.conflict_status != MOI.COMPUTE_CONFLICT_NOT_CALLED
error("Conflict computation is destructive for the model and cannot be called twice.")

Check warning on line 7 in src/MOI_wrapper/conflict.jl

View check run for this annotation

Codecov / codecov/patch

src/MOI_wrapper/conflict.jl#L5-L7

Added lines #L5 - L7 were not covered by tests
end
# free the transformed problem first
if LibSCIP.SCIPgetStage(o) != LibSCIP.SCIP_STAGE_PROBLEM
@SCIP_CALL LibSCIP.SCIPfreeTransform(o)

Check warning on line 11 in src/MOI_wrapper/conflict.jl

View check run for this annotation

Codecov / codecov/patch

src/MOI_wrapper/conflict.jl#L10-L11

Added lines #L10 - L11 were not covered by tests
end
# first transform all variable bound constraints to constraint bounds
for (F, S) in MOI.get(o, MOI.ListOfConstraintTypesPresent())
sname = replace(string(S), "MathOptInterface." => "", "{Float64}" => "")
if Tuple{F, S} <: Tuple{VI, BOUNDS}
for (idx, c_index) in enumerate(MOI.get(o, MOI.ListOfConstraintIndices{F,S}()))
s = MOI.get(o, MOI.ConstraintSet(), c_index)
MOI.delete(o, c_index)
vi = MOI.VariableIndex(c_index.value)
ci_new = MOI.add_constraint(o, 1.0 * vi, s)
MOI.set(o, MOI.ConstraintName(), ci_new, "varcons_$(c_index.value)_$sname")
end

Check warning on line 23 in src/MOI_wrapper/conflict.jl

View check run for this annotation

Codecov / codecov/patch

src/MOI_wrapper/conflict.jl#L14-L23

Added lines #L14 - L23 were not covered by tests
end
end

Check warning on line 25 in src/MOI_wrapper/conflict.jl

View check run for this annotation

Codecov / codecov/patch

src/MOI_wrapper/conflict.jl#L25

Added line #L25 was not covered by tests
# we need names for all constraints
for (F, S) in MOI.get(o, MOI.ListOfConstraintTypesPresent())
if F === VI
continue

Check warning on line 29 in src/MOI_wrapper/conflict.jl

View check run for this annotation

Codecov / codecov/patch

src/MOI_wrapper/conflict.jl#L27-L29

Added lines #L27 - L29 were not covered by tests
end
for (idx, c_index) in enumerate(MOI.get(o, MOI.ListOfConstraintIndices{F,S}()))
if MOI.get(o, MOI.ConstraintName(), c_index) == ""
cons_ptr = cons(o, c_index)
handler_name = unsafe_string(SCIPconshdlrGetName(SCIPconsGetHdlr(cons_ptr)))
cons_name = "$(handler_name)_moi_$(idx)"
MOI.set(o, MOI.ConstraintName(), c_index, cons_name)

Check warning on line 36 in src/MOI_wrapper/conflict.jl

View check run for this annotation

Codecov / codecov/patch

src/MOI_wrapper/conflict.jl#L31-L36

Added lines #L31 - L36 were not covered by tests
end
end
end
success = Ref{LibSCIP.SCIP_Bool}(SCIP.FALSE)
@SCIP_CALL LibSCIP.SCIPtransformMinUC(o, success)
if success[] != SCIP.TRUE
error("Failed to compute the minimum unsatisfied constraints system.\nSome constraint types may not support the required transformations")

Check warning on line 43 in src/MOI_wrapper/conflict.jl

View check run for this annotation

Codecov / codecov/patch

src/MOI_wrapper/conflict.jl#L38-L43

Added lines #L38 - L43 were not covered by tests
end
MOI.optimize!(o)
st = MOI.get(o, MOI.TerminationStatus())
if st != MOI.OPTIMAL
error("Unexpected status $st when computing conflicts")

Check warning on line 48 in src/MOI_wrapper/conflict.jl

View check run for this annotation

Codecov / codecov/patch

src/MOI_wrapper/conflict.jl#L45-L48

Added lines #L45 - L48 were not covered by tests
end
o.conflict_status = if MOI.get(o, MOI.ObjectiveValue()) > 0
MOI.CONFLICT_FOUND

Check warning on line 51 in src/MOI_wrapper/conflict.jl

View check run for this annotation

Codecov / codecov/patch

src/MOI_wrapper/conflict.jl#L50-L51

Added lines #L50 - L51 were not covered by tests
else
MOI.NO_CONFLICT_EXISTS

Check warning on line 53 in src/MOI_wrapper/conflict.jl

View check run for this annotation

Codecov / codecov/patch

src/MOI_wrapper/conflict.jl#L53

Added line #L53 was not covered by tests
end
return

Check warning on line 55 in src/MOI_wrapper/conflict.jl

View check run for this annotation

Codecov / codecov/patch

src/MOI_wrapper/conflict.jl#L55

Added line #L55 was not covered by tests
end

"""
Model attribute representing whether why the Minimum Unsatisfiable Constraint analysis terminated.
"""
struct UnsatisfiableSystemStatus <: AbstractModelAttribute end
struct UnsatisfiableSystemStatus <: MOI.AbstractModelAttribute end

attribute_value_type(::UnsatisfiableSystemStatus) = MOI.ConflictStatusCode

Check warning on line 63 in src/MOI_wrapper/conflict.jl

View check run for this annotation

Codecov / codecov/patch

src/MOI_wrapper/conflict.jl#L63

Added line #L63 was not covered by tests

MOI.get(o::Optimizer, ::UnsatisfiableSystemStatus) = o.conflict_status

Check warning on line 65 in src/MOI_wrapper/conflict.jl

View check run for this annotation

Codecov / codecov/patch

src/MOI_wrapper/conflict.jl#L65

Added line #L65 was not covered by tests

"""
Attribute representing whether the constraint could be satisfied in the Minimum Unsatisfiable Constraint analysis.

Note that this is different from a constraint belonging to an Irreducible Infeasible Subsystem.
"""
struct ConstraintSatisfiabilityStatus <: AbstractConstraintAttribute end
struct ConstraintSatisfiabilityStatus <: MOI.AbstractConstraintAttribute end

function attribute_value_type(::ConstraintSatisfiabilityStatus)
return MOI.ConflictParticipationStatusCode

Check warning on line 75 in src/MOI_wrapper/conflict.jl

View check run for this annotation

Codecov / codecov/patch

src/MOI_wrapper/conflict.jl#L74-L75

Added lines #L74 - L75 were not covered by tests
end

function MOI.get(o::Optimizer, ::ConstraintSatisfiabilityStatus, index::MOI.ConstraintIndex{MOI.VariableIndex})
o.conflict_status == MOI.CONFLICT_FOUND || error("no conflict")

Check warning on line 79 in src/MOI_wrapper/conflict.jl

View check run for this annotation

Codecov / codecov/patch

src/MOI_wrapper/conflict.jl#L78-L79

Added lines #L78 - L79 were not covered by tests
# we cannot determine whether variable constraint (integer, binary, variable bounds) participate
return MOI.MAYBE_IN_CONFLICT

Check warning on line 81 in src/MOI_wrapper/conflict.jl

View check run for this annotation

Codecov / codecov/patch

src/MOI_wrapper/conflict.jl#L81

Added line #L81 was not covered by tests
end

function MOI.get(o::Optimizer, ::ConstraintSatisfiabilityStatus, index::MOI.ConstraintIndex)
o.conflict_status == MOI.CONFLICT_FOUND || error("no conflict")
c_name = MOI.get(o, MOI.ConstraintName(), index)
slack_name = "$(c_name)_master"
ptr = SCIPfindVar(o, slack_name)
if ptr == C_NULL
error("No constraint name corresponds to the index $index - name $c_name")

Check warning on line 90 in src/MOI_wrapper/conflict.jl

View check run for this annotation

Codecov / codecov/patch

src/MOI_wrapper/conflict.jl#L84-L90

Added lines #L84 - L90 were not covered by tests
end
sol = SCIPgetBestSol(o)
slack_value = SCIPgetSolVal(o, sol, ptr)
return slack_value > 0.5 ? MOI.IN_CONFLICT : MOI.NOT_IN_CONFLICT

Check warning on line 94 in src/MOI_wrapper/conflict.jl

View check run for this annotation

Codecov / codecov/patch

src/MOI_wrapper/conflict.jl#L92-L94

Added lines #L92 - L94 were not covered by tests
end
Loading