Skip to content
This repository was archived by the owner on Jun 14, 2020. It is now read-only.

Commit d724679

Browse files
committed
temp fix for variable ordering
1 parent 6f0fdd6 commit d724679

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

src/constraints/singlevariable.jl

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,25 @@ end
4242

4343
SVCI(v::SinVar, ::S) where S = SVCI{S}(v.variable.value)
4444

45+
function hasvalue(d::Dict{T,S}, val::S)
46+
for v in values(d)
47+
if v == val
48+
return true
49+
end
50+
end
51+
return false
52+
end
53+
4554
function checkexisting(m::LinQuadOptimizer, v::SinVar, set::S) where S
4655
ref = SVCI(v, set)
47-
if haskey(constrdict(m, ref), ref)
56+
if hasvalue(constrdict(m, ref), v.variable)
4857
error("Adding the same constraint type: $(S) is not allowed for SingleVariable function")
4958
end
5059
end
5160

5261
function checkconflicting(m::LinQuadOptimizer, v::SinVar, set_to_add::S0, set_to_test::S) where S where S0
5362
ref = SVCI(v, set_to_test)
54-
if haskey(constrdict(m, ref), ref)
63+
if hasvalue(constrdict(m, ref), v.variable)
5564
error("Adding the same constraint type: $(S0) is not allowed for SingleVariable function because there is constraint of type $(S) tied to the respective variable")
5665
end
5766
end
@@ -63,7 +72,9 @@ function MOI.addconstraint!(m::LinQuadOptimizer, v::SinVar, set::S) where S <: L
6372
checkconflicting(m, v, set, MOI.Semiinteger(0.0, 0.0))
6473
checkconflicting(m, v, set, MOI.ZeroOne())
6574
setvariablebound!(m, v, set)
66-
ref = SVCI(v, set)
75+
m.last_constraint_reference += 1
76+
ref = SVCI{S}(m.last_constraint_reference)
77+
# ref = SVCI(v, set)
6778
dict = constrdict(m, ref)
6879
dict[ref] = v.variable
6980
ref
@@ -128,7 +139,9 @@ function MOI.addconstraint!(m::LinQuadOptimizer, v::SinVar, set::MOI.ZeroOne)
128139
checkconflicting(m, v, set, MOI.Integer())
129140
checkconflicting(m, v, set, MOI.Semicontinuous(0.0, 0.0))
130141
checkconflicting(m, v, set, MOI.Semiinteger(0.0, 0.0))
131-
ref = SVCI(v, set)
142+
m.last_constraint_reference += 1
143+
ref = SVCI{MOI.ZeroOne}(m.last_constraint_reference)
144+
# ref = SVCI(v, set)
132145
dict = constrdict(m, ref)
133146
ub = get_variable_upperbound(m, getcol(m, v))
134147
lb = get_variable_lowerbound(m, getcol(m, v))
@@ -170,7 +183,9 @@ function MOI.addconstraint!(m::LinQuadOptimizer, v::SinVar, set::MOI.Integer)
170183
checkconflicting(m, v, set, MOI.Semicontinuous(0.0, 0.0))
171184
checkconflicting(m, v, set, MOI.Semiinteger(0.0, 0.0))
172185
change_variable_types!(m, [getcol(m, v)], [backend_type(m, set)])
173-
ref = SVCI(v, set)
186+
m.last_constraint_reference += 1
187+
ref = SVCI{MOI.Integer}(m.last_constraint_reference)
188+
# ref = SVCI(v, set)
174189
dict = constrdict(m, ref)
175190
dict[ref] = v.variable
176191
make_problem_type_integer(m)
@@ -211,7 +226,9 @@ function MOI.addconstraint!(m::LinQuadOptimizer, v::SinVar, set::S) where S <: S
211226
change_variable_types!(m, [getcol(m, v)], [backend_type(m, set)])
212227
setvariablebound!(m, getcol(m, v), set.upper, backend_type(m, Val{:Upperbound}()))
213228
setvariablebound!(m, getcol(m, v), set.lower, backend_type(m, Val{:Lowerbound}()))
214-
ref = SVCI(v, set)
229+
m.last_constraint_reference += 1
230+
ref = SVCI{S}(m.last_constraint_reference)
231+
# ref = SVCI(v, set)
215232
dict = constrdict(m, ref)
216233
dict[ref] = v.variable
217234
make_problem_type_integer(m)

0 commit comments

Comments
 (0)