Skip to content

Commit 774ede2

Browse files
authored
Merge pull request #57 from SECQUOIA/Improve_Linan
Remove associate and unused variables
2 parents 46bc880 + 6349c63 commit 774ede2

File tree

1 file changed

+3
-14
lines changed

1 file changed

+3
-14
lines changed

gdplib/ex1_linan_2023/ex1_linan_2023.py

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@ def build_model():
4040
m.sub1 = pyo.Set(initialize=[3], within=m.set1)
4141

4242
# Variables
43-
m.Y1 = pyo.BooleanVar(m.set1, doc="Boolean variable associated to set 1")
44-
m.Y2 = pyo.BooleanVar(m.set2, doc="Boolean variable associated to set 2")
45-
4643
m.alpha = pyo.Var(
4744
within=pyo.Reals, bounds=(-0.1, 0.4), doc="continuous variable alpha"
4845
)
@@ -130,10 +127,6 @@ def Disjunction1(m): # Disjunction for first Boolean variable
130127

131128
m.Disjunction1 = Disjunction(rule=Disjunction1, xor=False)
132129

133-
# Associate boolean variables to disjuncts
134-
for n1 in m.set1:
135-
m.Y1[n1].associate_binary_var(m.Y1_disjunct[n1].indicator_var)
136-
137130
# Second disjunction
138131
def build_disjuncts2(m, set2): # Disjuncts for second Boolean variable
139132
"""
@@ -188,10 +181,6 @@ def Disjunction2(m): # Disjunction for first Boolean variable
188181

189182
m.Disjunction2 = Disjunction(rule=Disjunction2, xor=False)
190183

191-
# Associate boolean variables to disjuncts
192-
for n2 in m.set2:
193-
m.Y2[n2].associate_binary_var(m.Y2_disjunct[n2].indicator_var)
194-
195184
# Logical constraints
196185

197186
# Constraint that allow to apply the reformulation over Y1
@@ -209,7 +198,7 @@ def select_one_Y1(m):
209198
Pyomo.LogicalConstraint
210199
Logical constraint that make Y1 to be true for only one element
211200
"""
212-
return pyo.exactly(1, m.Y1)
201+
return pyo.exactly(1, [m.Y1_disjunct[n].indicator_var for n in m.set1])
213202

214203
m.oneY1 = pyo.LogicalConstraint(rule=select_one_Y1)
215204

@@ -228,7 +217,7 @@ def select_one_Y2(m):
228217
Pyomo.LogicalConstraint
229218
Logical constraint that make Y2 to be true for only one element
230219
"""
231-
return pyo.exactly(1, m.Y2)
220+
return pyo.exactly(1, [m.Y2_disjunct[n].indicator_var for n in m.set2])
232221

233222
m.oneY2 = pyo.LogicalConstraint(rule=select_one_Y2)
234223

@@ -248,7 +237,7 @@ def infeasR_rule(m):
248237
Pyomo.LogicalConstraint
249238
Logical constraint that defines an infeasible region on Y1[3]
250239
"""
251-
return pyo.land([pyo.lnot(m.Y1[j]) for j in m.sub1])
240+
return pyo.land([pyo.lnot(m.Y1_disjunct[j].indicator_var) for j in m.sub1])
252241

253242
m.infeasR = pyo.LogicalConstraint(rule=infeasR_rule)
254243

0 commit comments

Comments
 (0)