forked from Pyomo/pyomo
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbard1.py
29 lines (19 loc) · 971 Bytes
/
bard1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# bard1.py QQR2-MN-8-5
# Original Pyomo coding by William Hart
# Adapted from AMPL coding by Sven Leyffer
# An MPEC from J.F. Bard, Convex two-level optimization,
# Mathematical Programming 40(1), 15-27, 1988.
# Number of variables: 2 + 3 slack + 3 multipliers
# Number of constraints: 4
from pyomo.environ import *
from pyomo.mpec import *
model = ConcreteModel()
model.x = Var(within=NonNegativeReals)
model.y = Var(within=NonNegativeReals)
# ... multipliers
model.l = Var([1,2,3])
model.f = Objective(expr=(model.x - 5)**2 + (2*model.y + 1)**2)
model.KKT = Constraint(expr=2*(model.y-1) - 1.5*model.x + model.l[1] - model.l[2]*0.5 + model.l[3] == 0)
model.lin_1 = Complementarity(expr=complements(0 <= 3*model.x - model.y - 3, model.l[1] >= 0))
model.lin_2 = Complementarity(expr=complements(0 <= - model.x + 0.5*model.y + 4, model.l[2] >= 0))
model.lin_3 = Complementarity(expr=complements(0 <= - model.x - model.y + 7, model.l[3] >= 0))