Skip to content

Commit 8435f57

Browse files
committed
output of reformulation is the new constraints that were created
1 parent 78c6a48 commit 8435f57

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

src/gdp.jl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
abstract type :ModelVariables end
1+
mutable struct GDPdata
2+
gdp_variable_refs::Vector
3+
gdp_variable_names::Vector
4+
disjunctions::Dict
5+
end
26

37
function GDPModel()
48
model = Model()
5-
model.ext[:gdp_variable_refs] = []
6-
model.ext[:gdp_variable_names] = []
9+
model.ext[:GDPdata] = GDPdata()
10+
# model.optimize_hook =
711

812
return model
913
end

src/reformulate.jl

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,22 @@ function reformulate_disjunction(m::Model, disj...; bin_var, reformulation, para
1717
end
1818
reformulate(disj, bin_var, reformulation, param)
1919

20+
#show new constraints as a Dict
21+
new_constraints = Dict{Symbol,Any}(
22+
Symbol(bin_var,"[$i]") => disj[i] for i in eachindex(disj)
23+
)
24+
new_constraints[Symbol(bin_var,"_XOR")] = constraint_by_name(m, "XOR(disj_$bin_var)")
25+
for var in vars
26+
agg_con_name = "$(var)_$(bin_var)_aggregation"
27+
agg_con = constraint_by_name(m, agg_con_name)
28+
if !isnothing(agg_con)
29+
new_constraints[Symbol(agg_con_name)] = agg_con
30+
end
31+
end
32+
return new_constraints
33+
34+
#remove model.optimize_hook ?
35+
2036
# return m[bin_var]
2137
end
2238

@@ -26,7 +42,13 @@ function check_disjunction!(m, disj)
2642
if constr isa Tuple #NOTE: Make it so that it must be bundled in a Tuple (not Array), to avoid confusing it with a Variable Array
2743
constr_list = []
2844
for constr_j in constr
29-
push!(constr_list, check_constraint!(m, constr_j))
45+
if constr_j isa Tuple #if using a begin..end block, a tuple of constraints is created (loop through these)
46+
for constr_jk in constr_j
47+
push!(constr_list, check_constraint!(m, constr_jk))
48+
end
49+
else
50+
push!(constr_list, check_constraint!(m, constr_j))
51+
end
3052
end
3153
push!(disj_new, Tuple(constr_list))
3254
elseif constr isa Union{ConstraintRef, Array, Containers.DenseAxisArray, Containers.SparseAxisArray}

0 commit comments

Comments
 (0)