Skip to content

Commit

Permalink
Fix error in computation of domain cardinality (#297)
Browse files Browse the repository at this point in the history
  • Loading branch information
jardinetsouffleton authored Dec 8, 2022
1 parent afc6130 commit 79e60f5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
44 changes: 30 additions & 14 deletions src/CP/core/model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,34 @@ mutable struct CPModel
adhocInfo ::Any


CPModel(trailer) = new(Dict{String, AbstractVar}(), Dict{String, Bool}(), Dict{String, AbstractVar}(), Constraint[], trailer, nothing, nothing, Statistics(Dict{String, Int}(), 0, 0, 0, 0, 0, 0, 0, 0, Solution[],Int[], nothing, nothing, nothing, nothing, nothing, Dict{Constraint, Int}()), Limit(nothing, nothing, nothing), nothing)
CPModel(trailer) = new(
Dict{String, AbstractVar}(),
Dict{String, Bool}(),
Dict{String, AbstractVar}(),
Constraint[],
trailer,
nothing,
nothing,
Statistics(Dict{String, Int}(),
0,
0,
0,
0,
0,
0,
0,
0,
Solution[],
Int[],
nothing,
nothing,
nothing,
nothing,
nothing,
Dict{Constraint, Int}()),
Limit(nothing, nothing, nothing),
nothing
)
end

CPModel() = CPModel(Trailer())
Expand Down Expand Up @@ -371,17 +398,8 @@ Returns the sum of the cardinalities of the variable domains.
function global_domain_cardinality(model::CPModel)
cardinality = 0
for (id, x) in model.variables
if isa(x.domain,BoolDomain)
cardinality += length(x.domain.inner.values)
if !isempty(x.children)
for child in x.children
cardinality += length(child.domain.inner.values)
end
end
elseif isa(x.domain,IntSetDomain)
cardinality += length(x.domain)
else
cardinality += length(x.domain)
cardinality += length(x.domain)
if !(isa(x.domain, IntSetDomain) || isa(x, IntVarViewMul))
if !isempty(x.children)
for child in x.children
cardinality += length(child.domain)
Expand All @@ -392,8 +410,6 @@ function global_domain_cardinality(model::CPModel)
return cardinality
end



"""
updateStatistics!(model::CPModel, pruned)
Expand Down
2 changes: 1 addition & 1 deletion src/CP/variables/BoolVarView.jl
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,4 @@ end

parentValue(::BoolVarViewNot, v::Bool) = ! v
childrenValue(::BoolVar, v::Bool) = v
childrenValue(y::BoolVarViewNot, v::Bool) = ! childrenValue(y.x, v)
childrenValue(y::BoolVarViewNot, v::Bool) = ! childrenValue(y.x, v)

0 comments on commit 79e60f5

Please sign in to comment.