Apps

## Apps.MpecExamples History

February 14, 2019, at 03:04 PM by 10.37.111.106 -
Changed lines 201-206 from:

### Maximum Selector (MAX) Operator

to:

GEKKO MIN function (min2)

See GEKKO Documentation for additional examples.

from gekko import GEKKO m = GEKKO() x1 = m.Param(-2) x2 = m.Param(-1)

1. use min2

y = m.min2(x1,x2) m.solve() # solve print('x1: ' + str(x1.value)) print('x2: ' + str(x2.value)) print('y: ' + str(y.value)) (:sourceend:)

### Maximum Selector (MAX) Operator

(:source lang=python:)

(:sourceend:)

GEKKO MAX function (min2)

See GEKKO Documentation for additional examples.

(:source lang=python:) from gekko import GEKKO m = GEKKO() x1 = m.Param(-2) x2 = m.Param(-1)

1. use max2

y = m.max2(x1,x2) m.solve() # solve print('x1: ' + str(x1.value)) print('x2: ' + str(x2.value)) print('y: ' + str(y.value))

February 14, 2019, at 02:17 PM by 10.37.111.106 -
Changed lines 59-64 from:

### Absolute Value (ABS) Operator

to:

GEKKO SIGNUM function (sign2)

See GEKKO Documentation for additional examples.

from gekko import GEKKO m = GEKKO() x = m.Param(-2)

1. use sign2 to define a new variable

y = m.sign2(x) m.solve() # solve print('x: ' + str(x.value)) print('y: ' + str(y.value)) (:sourceend:)

### Absolute Value (ABS) Operator

(:source lang=python:)

Deleted line 130:
Changed lines 138-141 from:
1. solve

m.solve()

to:

m.solve() # solve

February 14, 2019, at 02:05 PM by 10.37.111.106 -
Changed line 144 from:

Model signum

to:

Model

Changed line 201 from:

Model signum

to:

Model

February 14, 2019, at 01:28 PM by 10.37.111.106 -
February 14, 2019, at 01:16 PM by 10.37.111.106 -
Changed line 11 from:

(:html:)<font size=2><pre>

to:

(:source lang=python:)

Changed lines 35-38 from:

</pre></font>(:htmlend:)

(:html:)<font size=2><pre>

to:

(:sourceend:)

(:source lang=python:)

Changed lines 55-56 from:

</pre></font>(:htmlend:)

to:

(:sourceend:)

Changed line 63 from:

(:html:)<font size=2><pre>

to:

(:source lang=python:)

Changed lines 86-88 from:

</pre></font>(:htmlend:)

(:html:)<font size=2><pre>

to:

(:sourceend:)

(:source lang=python:)

Changed lines 106-107 from:

</pre></font>(:htmlend:)

to:

(:sourceend:)

Changed line 137 from:

(:html:)<font size=2><pre>

to:

(:source lang=python:)

Changed lines 164-166 from:

</pre></font>(:htmlend:)

(:html:)<font size=2><pre>

to:

(:sourceend:)

(:source lang=python:)

Changed lines 186-187 from:

</pre></font>(:htmlend:)

to:

(:sourceend:)

Changed line 194 from:

(:html:)<font size=2><pre>

to:

(:source lang=python:)

Changed lines 221-223 from:

</pre></font>(:htmlend:)

(:html:)<font size=2><pre>

to:

(:sourceend:)

(:source lang=python:)

Changed line 243 from:

</pre></font>(:htmlend:)

to:

(:sourceend:)

February 12, 2019, at 03:23 PM by 10.37.233.114 -

GEKKO ABS function (abs2)

See GEKKO Documentation for additional examples.

(:source lang=python:) from gekko import GEKKO

m = GEKKO() x = m.Param(-2)

1. use abs2 to define a new variable

y = m.abs2(x)

1. use abs2 in an equation

z = m.Var() m.Equation(z==m.abs2(x)+1)

1. solve

m.solve()

print('x: ' + str(x.value)) print('y: ' + str(y.value)) print('z: ' + str(z.value)) (:sourceend:)

July 20, 2017, at 01:49 AM by 144.5.226.51 -
Changed lines 225-227 from:
• Mojica, J.L., Petersen, D.J., Hansen, B., Powell, K.M., Hedengren, J.D., Optimal Combined Long-Term Facility Design and Short-Term Operational Strategy for CHP Capacity Investments, Energy, Vol 118, 1 January 2017, pp. 97–115. Article
to:

#### Reference

Mojica, J.L., Petersen, D.J., Hansen, B., Powell, K.M., Hedengren, J.D., Optimal Combined Long-Term Facility Design and Short-Term Operational Strategy for CHP Capacity Investments, Energy, Vol 118, 1 January 2017, pp. 97–115. Article

July 20, 2017, at 01:49 AM by 144.5.226.51 -
Changed lines 223-225 from:

to:

• Mojica, J.L., Petersen, D.J., Hansen, B., Powell, K.M., Hedengren, J.D., Optimal Combined Long-Term Facility Design and Short-Term Operational Strategy for CHP Capacity Investments, Energy, Vol 118, 1 January 2017, pp. 97–115. Article
July 20, 2017, at 01:47 AM by 144.5.226.51 -
Changed line 39 from:

to:

# SIGN function MPEC as an Object

Changed line 90 from:

to:

# MAX function MPEC as an Object

July 20, 2017, at 01:46 AM by 144.5.226.51 -
Changed line 39 from:

to:

# SIGN function as an Object

Changed line 90 from:

to:

# ABS function as an Object

(:html:)<font size=2><pre> Objects

  f = max


End Objects

Connections

  f.x[1] = x1
f.x[2] = x2
f.y = y


End Connections

Parameters

  x1 = -2
x2 =  4


End Parameters

Variables

  y


End Variables </pre></font>(:htmlend:)

July 20, 2017, at 01:43 AM by 144.5.226.51 -

(:html:)<font size=2><pre> Objects

  f = min


End Objects

Connections

  f.x[1] = x1
f.x[2] = x2
f.y = y


End Connections

Parameters

  x1 = -2
x2 = -1


End Parameters

Variables

  y


End Variables </pre></font>(:htmlend:)

July 20, 2017, at 01:41 AM by 144.5.226.51 -

(:html:)<font size=2><pre>

# SIGN function with Object

Objects

  f = sign


End Objects

Connections

  f.x = x
f.y = y


End Connections

Parameters

  x = -2


End Parameters

Variables

  y


End Variables </pre></font>(:htmlend:)

July 20, 2017, at 01:37 AM by 144.5.226.51 -
Changed lines 45-46 from:

to:

# y = -x if the corresponding element of X is < than zero

July 20, 2017, at 01:37 AM by 144.5.226.51 -
Changed lines 68-72 from:

to:

# MPEC formulation for ABS function using an object

Changed lines 71-72 from:
to:

End Objects

Changed lines 76-77 from:
to:

End Connections

Changed lines 80-81 from:
to:

End Parameters

End Variables

Deleted line 85:
July 20, 2017, at 01:22 AM by 144.5.226.51 -
Changed lines 47-66 from:

Model abs

  Parameters
x = -2
End Parameters

Variables
y

s_a >= 0
s_b >= 0
End Variables

Equations
! test abs operator, y = abs(x)
x = s_b - s_a
y = s_a + s_b

minimize s_a*s_b
End Equations


End Model

to:

Parameters

  x = -2


End Parameters

Variables

  y

s_a >= 0
s_b >= 0


End Variables

Equations

  ! test abs operator, y = abs(x)
x = s_b - s_a
y = s_a + s_b

minimize s_a*s_b


End Equations

(:html:)<font size=2><pre>

# this uses the APMonitor object 'abs'

Objects

  f = abs


Connections

  f.x = x
f.y = y


Parameters

  x = -2


Variables

  y


</pre></font>(:htmlend:)

March 06, 2010, at 09:44 AM by 206.180.155.75 -
Changed line 11 from:

(:html:)<font size=1><pre>

to:

(:html:)<font size=2><pre>

Changed line 42 from:

(:html:)<font size=1><pre>

to:

(:html:)<font size=2><pre>

Changed line 74 from:

(:html:)<font size=1><pre>

to:

(:html:)<font size=2><pre>

Changed line 108 from:

(:html:)<font size=1><pre>

to:

(:html:)<font size=2><pre>

Changed line 136 from:

to:

October 09, 2009, at 06:13 PM by 158.35.225.227 -
Changed line 3 from:

Mathematical Programs with Equilibrium Constraints (MPECs) are formulations that can be used to model certain classes of discrete events. MPECs can be more efficient than solving mixed integer formulations of the optimization problems.

to:

Mathematical Programs with Equilibrium Constraints (MPECs) are formulations that can be used to model certain classes of discrete events. MPECs can be more efficient than solving mixed integer formulations of the optimization problems because it avoids the combinatorial difficulties of searching for optimal discrete variables.

October 09, 2009, at 06:12 PM by 158.35.225.227 -
Changed line 3 from:

Mathematical Programs with Equilibrium Constraints (MPECs) are formulations that can be used to model certain classes of discrete events. MPECs can be more efficient than solving mixed integer problems.

to:

Mathematical Programs with Equilibrium Constraints (MPECs) are formulations that can be used to model certain classes of discrete events. MPECs can be more efficient than solving mixed integer formulations of the optimization problems.

October 09, 2009, at 06:10 PM by 158.35.225.227 -
Changed line 16 from:

Model signum

to:

Model sign

Changed line 47 from:

Model signum

to:

Model abs

Changed line 96 from:
    y = x1 + s_a

to:
    y = x1 - s_a

September 25, 2009, at 03:01 AM by 206.180.155.75 -

# y = x2 if x2 < x1

Model signum

  Parameters
x1 = -2
x2 = -1
End Parameters

Variables
y

! slack variables
s_a >= 0
s_b >= 0
End Variables

Equations
! test min operator, y = min(x1,x2)
x2 - x1 = s_b - s_a
y = x1 + s_a

minimize s_a*s_b
End Equations


End Model </pre></font>(:htmlend:)

### Maximum Selector (MAX) Operator

(:html:)<font size=1><pre>

# y = x2 if x2 > x1

Model signum

  Parameters
x1 = -2
x2 = 4
End Parameters

Variables
y

! slack variables
s_a >= 0
s_b >= 0
End Variables

Equations
! test max operator, y = max(x1,x2)
x2 - x1 = s_a - s_b
y = x1 + s_a

minimize s_a*s_b
End Equations


End Model

September 25, 2009, at 02:51 AM by 206.180.155.75 -

(:html:)<font size=1><pre>

# y = -x if the corresponding element of X is less than zero

Model signum

  Parameters
x = -2
End Parameters

Variables
y

s_a >= 0
s_b >= 0
End Variables

Equations
! test abs operator, y = abs(x)
x = s_b - s_a
y = s_a + s_b

minimize s_a*s_b
End Equations


End Model </pre></font>(:htmlend:)

### Minimum Selector (MIN) Operator

September 25, 2009, at 02:45 AM by 206.180.155.75 -
Changed lines 7-14 from:

to:

Deleted line 35:

### Absolute Value (ABS) Operator

(:html:)<font size=1><pre> </pre></font>(:htmlend:)

September 25, 2009, at 02:41 AM by 206.180.155.75 -
Changed lines 9-13 from:
to:

#### SIGN Operator

September 25, 2009, at 02:39 AM by 206.180.155.75 -
Deleted lines 10-11:

Changed lines 12-13 from:

</pre></font>(:htmlend:)

to:

# -1 if the corresponding element of X is less than zero

Model signum

  Parameters
x = -2
End Parameters

Variables
y >= -1, <= 1

s_a >= 0
s_b >= 0
End Variables

Equations
! test sign operator, y = sign(x)
x = s_b - s_a

minimize s_a*(1+y) + s_b*(1-y)
End Equations


End Model </pre></font>(:htmlend:)

September 24, 2009, at 04:15 AM by 206.180.155.75 -

## MPEC: Mathematical Programs with Equilibrium Constraints

Mathematical Programs with Equilibrium Constraints (MPECs) are formulations that can be used to model certain classes of discrete events. MPECs can be more efficient than solving mixed integer problems.

### MPEC examples

(:html:)<font size=1><pre>

</pre></font>(:htmlend:)