Skip to content

Commit

Permalink
Merge pull request #57 from SECQUOIA/Improve_Linan
Browse files Browse the repository at this point in the history
Remove associate and unused variables
  • Loading branch information
bernalde authored Aug 27, 2024
2 parents 46bc880 + 6349c63 commit 774ede2
Showing 1 changed file with 3 additions and 14 deletions.
17 changes: 3 additions & 14 deletions gdplib/ex1_linan_2023/ex1_linan_2023.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ def build_model():
m.sub1 = pyo.Set(initialize=[3], within=m.set1)

# Variables
m.Y1 = pyo.BooleanVar(m.set1, doc="Boolean variable associated to set 1")
m.Y2 = pyo.BooleanVar(m.set2, doc="Boolean variable associated to set 2")

m.alpha = pyo.Var(
within=pyo.Reals, bounds=(-0.1, 0.4), doc="continuous variable alpha"
)
Expand Down Expand Up @@ -130,10 +127,6 @@ def Disjunction1(m): # Disjunction for first Boolean variable

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

# Associate boolean variables to disjuncts
for n1 in m.set1:
m.Y1[n1].associate_binary_var(m.Y1_disjunct[n1].indicator_var)

# Second disjunction
def build_disjuncts2(m, set2): # Disjuncts for second Boolean variable
"""
Expand Down Expand Up @@ -188,10 +181,6 @@ def Disjunction2(m): # Disjunction for first Boolean variable

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

# Associate boolean variables to disjuncts
for n2 in m.set2:
m.Y2[n2].associate_binary_var(m.Y2_disjunct[n2].indicator_var)

# Logical constraints

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

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

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

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

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

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

Expand Down

0 comments on commit 774ede2

Please sign in to comment.