Skip to content

Commit

Permalink
add removeBetween function to manipulate IntDomain (#430)
Browse files Browse the repository at this point in the history
  • Loading branch information
Max9294D authored Aug 7, 2023
1 parent af364fb commit 4e36204
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/CP/constraints/sumlessthan.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ struct SumLessThan <: Constraint
numberOfFreeVars ::StateObject{Int}
sumOfFixedVars ::StateObject{Int}
freeIds ::Array{Int}
function SumLessThan(x::Array{<:AbstractIntVar}, upper::Int, trailer)
function SumLessThan(x::Array{<:AbstractIntVar}, upper::Int, trailer)
@assert !isempty(x)

freeIds = zeros(length(x))
Expand Down
20 changes: 20 additions & 0 deletions src/CP/variables/IntDomain.jl
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,26 @@ function removeBelow!(dom::IntDomain, value::Int)
return pruned
end

"""
removeBetween!(dom::IntDomain, min::Int, max::Int)
Remove every integer of `dom` that is *strictly* between `min` and `max`. Return the pruned values.
"""
function removeBetween!(dom::IntDomain, min::Int, max::Int)
if dom.max.value < max && dom.min.value > min
return removeAll!(dom)
end

pruned = Int[]
for i in min+1:(max-1)
if i in dom
remove!(dom, i)
push!(pruned, i)
end
end
return pruned
end

"""
assign!(dom::IntDomain, value::Int)
Expand Down

0 comments on commit 4e36204

Please sign in to comment.