Skip to content

Add ConflictCount and conflict_index to ConstraintConflictStatus #2775

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
77 changes: 76 additions & 1 deletion src/attributes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1844,6 +1844,16 @@ struct ConflictStatus <: AbstractModelAttribute end

attribute_value_type(::ConflictStatus) = ConflictStatusCode

"""
ConflictCount()

An [`AbstractModelAttribute`](@ref) for the number of conflicts found by the
solver in the most recent call to [`compute_conflict!`](@ref).
"""
struct ConflictCount <: AbstractModelAttribute end

attribute_value_type(::ConflictCount) = Int

"""
ListOfVariableAttributesSet()

Expand Down Expand Up @@ -2677,13 +2687,78 @@ end

A constraint attribute to query the [`ConflictParticipationStatusCode`](@ref)
indicating whether the constraint participates in the conflict.

## `conflict_index`

The optimizer may return multiple conflicts. See [`ConflictCount`](@ref)
for querying the number of conflicts found.

## Implementation

Optimizers should implement the following methods:
```julia
MOI.get(::Optimizer, ::MOI.ConstraintConflictStatus, ::MOI.ConstraintIndex)::T
```
They should not implement [`set`](@ref) or [`supports`](@ref).
"""
struct ConstraintConflictStatus <: AbstractConstraintAttribute end
struct ConstraintConflictStatus <: AbstractConstraintAttribute
conflict_index::Int
ConstraintConflictStatus(conflict_index = 1) = new(conflict_index)
end

function attribute_value_type(::ConstraintConflictStatus)
return ConflictParticipationStatusCode
end

"""
ListOfConstraintIndicesInConflict(conflict_index::Int = 1)

An [`AbstractModelAttribute`](@ref) for the `Vector{ConstraintIndex}` of all
constraints that participate in the conflict with index `conflict_index`.

The `conflict_index` is 1 by default, but it can be set to any value between
1 and the number of conflicts found by the solver, as indicated by
[`ConflictCount`](@ref).

## Implementation
Optimizers may implement the following methods:
```julia
MOI.get(
::Optimizer,
::MOI.ListOfConstraintIndicesInConflict,
)::Vector{MOI.ConstraintIndex}
```
A ineficient fallback is available for `get`.
They should not implement [`set`](@ref) or [`supports`](@ref).
"""
struct ListOfConstraintIndicesInConflict <: MOI.AbstractModelAttribute
conflict_index::Int
ListOfConstraintIndicesInConflict(conflict_index = 1) = new(conflict_index)
end

function attribute_value_type(::ListOfConstraintIndicesInConflict)
return Vector{ConstraintIndex}
end

function get(
model::ModelLike,
attr::ListOfConstraintIndicesInConflict,
)::Vector{ConstraintIndex}
result = Vector{ConstraintIndex}()
conflict_index = attr.conflict_index
constraint_types = get(model, ListOfConstraintTypesPresent())
for (F, S) in constraint_types
constraints = MOI.get(model, ListOfConstraintIndices{F,S}())
for con in constraints
status = get(model, ConstraintConflictStatus(conflict_index), con)
if status == NOT_IN_CONFLICT
push!(result, con)
end
end
end
return result
end

"""
UserDefinedFunction(name::Symbol, arity::Int) <: AbstractModelAttribute

Expand Down
Loading