-
Notifications
You must be signed in to change notification settings - Fork 10
/
interval.jl
44 lines (38 loc) · 1.58 KB
/
interval.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
"""
IntervalConstant(x::SeaPearl.IntVar, lower::Int, upper::Int, trailer::SeaPearl.Trailer)
Inequality constraint, `lower <= x <= upper`
"""
struct IntervalConstant <: OnePropagationConstraint
x::AbstractIntVar
lower::Int
upper::Int
active::StateObject{Bool}
function IntervalConstant(x, lower, upper, trailer)
constraint = new(x, lower, upper, StateObject(true, trailer))
addOnDomainChange!(x, constraint)
return constraint
end
end
"""
propagate!(constraint::IntervalConstant, toPropagate::Set{Constraint}, prunedDomains::CPModification)
`IntervalConstant` propagation function. Basically remove the values above `upper` and below `lower`.
"""
function propagate!(constraint::IntervalConstant, toPropagate::Set{Constraint}, prunedDomains::CPModification)
if !constraint.active.value
return true
end
setValue!(constraint.active, false)
addToPrunedDomains!(prunedDomains, constraint.x, vcat(removeBelow!(constraint.x.domain, constraint.lower), removeAbove!(constraint.x.domain, constraint.upper)))
triggerDomainChange!(toPropagate, constraint.x)
if constraint in toPropagate
pop!(toPropagate, constraint)
end
return !isempty(constraint.x.domain)
end
function Base.show(io::IO, ::MIME"text/plain", con::IntervalConstant)
println(io, typeof(con), ": ", con.x.id, " ∈ ⟦", con.lower, " ", con.upper, "⟧, active = ", con.active)
print(io, " ", con.x)
end
function Base.show(io::IO, con::IntervalConstant)
print(io, typeof(con), ": ", con.x.id, " ∈ ⟦", con.lower, " ", con.upper, "⟧")
end