Slack Variable Tutorial
Main.SlackVariables History
Hide minor edits - Show changes to output
Deleted lines 36-37:
Changed lines 39-47 from:
In APMonitor Modeling Language, inequality constraints are automatically translated into equality constraints with slack variables. Slack variables can also be defined by starting a variable name with ''slk''. When the model is parsed at run-time, any variable beginning with ''slk'' is automatically assigned a lower value of zero. Alternatively, inequality constraints will be automatically converted to equality constraints with a slack variable.
to:
In APMonitor Modeling Language, inequality constraints are automatically translated into equality constraints with slack variables. Slack variables can also be defined by starting a variable name with ''slk''. When the model is parsed at run-time, any variable beginning with ''slk'' is automatically assigned a lower value of zero. Alternatively, inequality constraints will be automatically converted to equality constraints with a slack variable.
!!! Logical Conditions in Optimization
Slack variables are also useful for optimization problems with non-smooth or discontinuous functions. The following tutorial demonstrates the use of slack variables in reformulating the ABS() function, IF statements, and others.
(:html:)
<iframe width="560" height="315" src="https://www.youtube.com/embed/NPUNixLGlh0" frameborder="0" allowfullscreen></iframe>
(:htmlend:)
!!! Logical Conditions in Optimization
Slack variables are also useful for optimization problems with non-smooth or discontinuous functions. The following tutorial demonstrates the use of slack variables in reformulating the ABS() function, IF statements, and others.
(:html:)
<iframe width="560" height="315" src="https://www.youtube.com/embed/NPUNixLGlh0" frameborder="0" allowfullscreen></iframe>
(:htmlend:)
Added lines 21-22:
(:html:)<br><br><br>(:htmlend:)
Deleted line 23:
Changed line 9 from:
(:table border=1 width=80% align=left bgcolor=#FFFFFF cellspacing=0:)
to:
(:table border=1 width=100% align=left bgcolor=#FFFFFF cellspacing=0:)
Deleted lines 20-21:
Changed lines 31-55 from:
(:cellnr:)
! Example model with slack variable
! Solve slack variable problem
! Minimize total_cost
! Subject to supply < b
Model
Parameters
b = 5
End Parameters
Variables
supply
total_cost
End Variables
Equations
supply < b
total_cost = (supply-2)^2
Minimize total_cost
End Equations
End Model
(:cellnr:)
to:
Attach:slack_problem.png
Deleted line 33:
Changed lines 27-28 from:
!! Example Problem
to:
----
!!! Example Problem
!!! Example Problem
Changed lines 61-63 from:
!! Inequality Constraints in APM
to:
----
!!! Inequality Constraints in APM
!!! Inequality Constraints in APM
Changed line 31 from:
(:table border=1 width=50% align=left bgcolor=#EEEEEE cellspacing=0:)
to:
(:table border=1 width=100% align=left bgcolor=#EEEEEE cellspacing=0:)
Deleted lines 57-58:
(:html:)<br>(:htmlend:)
Changed lines 27-28 from:
to:
!! Example Problem
Changed line 59 from:
to:
!! Inequality Constraints in APM
Deleted lines 22-23:
Deleted lines 26-27:
Added lines 29-30:
Attach:table50.jpg [[https://apmonitor.com/online/view_pass.php?f=slack.apm | Click to Solve a Slack Variable Optimization Problem]]
Changed lines 57-59 from:
(:tableend:)
to:
(:tableend:)
In APMonitor Modeling Language, inequality constraints are automatically translated into equality constraints with slack variables. Slack variables can also be defined by starting a variable name with ''slk''. When the model is parsed at run-time, any variable beginning with ''slk'' is automatically assigned a lower value of zero. Alternatively, inequality constraints will be automatically converted to equality constraints with a slack variable.
In APMonitor Modeling Language, inequality constraints are automatically translated into equality constraints with slack variables. Slack variables can also be defined by starting a variable name with ''slk''. When the model is parsed at run-time, any variable beginning with ''slk'' is automatically assigned a lower value of zero. Alternatively, inequality constraints will be automatically converted to equality constraints with a slack variable.
Changed lines 7-8 from:
Slack variables are defined to transform an inequality expression into an equality expression with an added slack variable. The slack variable is defined by setting a lower bound of zero (>=0).
to:
Slack variables are defined to transform an inequality expression into an equality expression with an added slack variable. The slack variable is defined by setting a lower bound of zero (>0).
Changed line 18 from:
slack >= 0
to:
slack > 0
Changed lines 25-26 from:
to:
(:html:)
<iframe width="560" height="315" src="https://www.youtube.com/embed/jh6BK0BqqIs?rel=0" frameborder="0" allowfullscreen></iframe>
(:htmlend:)
In APMonitor, inequality constraints are automatically translated into equality constraints with slack variables. Slack variables can also be defined by starting a variable name with ''slk''. When the model is parsed at run-time, any variable beginning with ''slk'' is automatically assigned a lower value of zero. Alternatively, inequality constraints will be automatically converted to equality constraints with a slack variable.
<iframe width="560" height="315" src="https://www.youtube.com/embed/jh6BK0BqqIs?rel=0" frameborder="0" allowfullscreen></iframe>
(:htmlend:)
In APMonitor, inequality constraints are automatically translated into equality constraints with slack variables. Slack variables can also be defined by starting a variable name with ''slk''. When the model is parsed at run-time, any variable beginning with ''slk'' is automatically assigned a lower value of zero. Alternatively, inequality constraints will be automatically converted to equality constraints with a slack variable.
Changed line 59 from:
(:tableend:)
to:
(:tableend:)
Changed line 23 from:
Attach:table50.jpg [[https://apmonitor.com/online/view_pass.php?f=slack.apm | Solve Slack Variable Optimization Problems]]
to:
Attach:table50.jpg [[https://apmonitor.com/online/view_pass.php?f=slack.apm | Click to Solve a Slack Variable Optimization Problem]]
Added lines 1-4:
(:title Slack Variable Tutorial:)
(:keywords slack variables, inequality, slacks, lower bound, transform:)
(:description Slack variables are used to transform an inequality expression into an equality expression:)
(:keywords slack variables, inequality, slacks, lower bound, transform:)
(:description Slack variables are used to transform an inequality expression into an equality expression:)
Deleted line 55:
Changed lines 19-20 from:
to:
Attach:table50.jpg [[https://apmonitor.com/online/view_pass.php?f=slack.apm | Solve Slack Variable Optimization Problems]]
Deleted lines 21-26:
!!! Solve Slack Variable Problems Online
%blue%A%red%P%black%Monitor has an online interface for solving optimization problems. The optimization problem shown below as '''Example Problem''' can be solved through the web-interface at the following link:
Attach:table50.jpg [[https://apmonitor.com/online/view_pass.php?f=slack.apm | Slack Variable Solution Online]]
Changed line 13 from:
x = b + slack
to:
x = b + slack (:html:)<br>(:htmlend:)
Changed line 5 from:
(:table border=2 width=50% align=left bgcolor=#FFFFFF cellspacing=0:)
to:
(:table border=1 width=80% align=left bgcolor=#FFFFFF cellspacing=0:)
Changed line 20 from:
In APMonitor, slack variables can be defined by starting a variable name with '''slk'''. When the model is parsed at run-time, any variable beginning with ''slk'' is automatically assigned a lower value of zero. Alternatively, inequality constraints will be automatically converted to equality constraints with a slack variable.
to:
In APMonitor, slack variables can be defined by starting a variable name with ''slk''. When the model is parsed at run-time, any variable beginning with ''slk'' is automatically assigned a lower value of zero. Alternatively, inequality constraints will be automatically converted to equality constraints with a slack variable.
Changed line 20 from:
In APMonitor, slack variables can be defined by starting a variable name with ''''slk''''. When the model is parsed at run-time, any variable beginning with ''slk'' is automatically assigned a lower value of zero. Alternatively, inequality constraints will be automatically converted to equality constraints with a slack variable.
to:
In APMonitor, slack variables can be defined by starting a variable name with '''slk'''. When the model is parsed at run-time, any variable beginning with ''slk'' is automatically assigned a lower value of zero. Alternatively, inequality constraints will be automatically converted to equality constraints with a slack variable.
Changed line 17 from:
(:html:)<br><br><br><br><br><br>(:htmlend:)
to:
(:html:)<br><br><br><br><br>(:htmlend:)
Changed line 17 from:
(:html:)<br><br><br><br>(:htmlend:)
to:
(:html:)<br><br><br><br><br><br>(:htmlend:)
Changed line 17 from:
(:html:)<br>(:htmlend:)
to:
(:html:)<br><br><br><br>(:htmlend:)
Changed line 5 from:
(:table border=1 width=50% align=left bgcolor=#FFFFFF cellspacing=0:)
to:
(:table border=2 width=50% align=left bgcolor=#FFFFFF cellspacing=0:)
Changed line 5 from:
(:table border=1 width=50% align=left bgcolor=#EEEEEE cellspacing=0:)
to:
(:table border=1 width=50% align=left bgcolor=#FFFFFF cellspacing=0:)
Added lines 16-18:
(:html:)<br>(:htmlend:)
Changed lines 5-7 from:
Equation inequalities are automatically tranformed to equality expressions for solvers that do not support them
to:
(:table border=1 width=50% align=left bgcolor=#EEEEEE cellspacing=0:)
(:cellnr:)
Inequality Constraint Form
(:cell:)
x > b
(:cellnr:)
Equality Constraint Form with Slack Variable
(:cell:)
x = b + slack
slack >= 0
(:tableend:)
In APMonitor, slack variables can be defined by starting a variable name with ''''slk''''. When the model is parsed at run-time, any variable beginning with ''slk'' is automatically assigned a lower value of zero. Alternatively, inequality constraints will be automatically converted to equality constraints with a slack variable.
(:cellnr:)
Inequality Constraint Form
(:cell:)
x > b
(:cellnr:)
Equality Constraint Form with Slack Variable
(:cell:)
x = b + slack
slack >= 0
(:tableend:)
In APMonitor, slack variables can be defined by starting a variable name with ''''slk''''. When the model is parsed at run-time, any variable beginning with ''slk'' is automatically assigned a lower value of zero. Alternatively, inequality constraints will be automatically converted to equality constraints with a slack variable.
Changed line 19 from:
! Example model with slack variable declaration
to:
! Example model with slack variable
Changed lines 20-32 from:
Parameters
to:
! Solve slack variable problem
! Minimize total_cost
! Subject to supply < b
Model
Parameters
b = 5
End Parameters
Variables
supply
total_cost
End Variables
Equations
supply < b
total_cost = (supply-2)^2
Minimize total_cost
End Equations
! Minimize total_cost
! Subject to supply < b
Model
Parameters
b = 5
End Parameters
Variables
supply
total_cost
End Variables
Equations
supply < b
total_cost = (supply-2)^2
Minimize total_cost
End Equations
Changed lines 42-45 from:
p1 = 5
slk
v1 = 4
to:
Attach:slack_results.png
Changed line 3 from:
Slack variables are defined to transform a inequality expression into an equality expression with an added slack variable. The slack variable is defined by setting a lower bound of zero (>=0).
to:
Slack variables are defined to transform an inequality expression into an equality expression with an added slack variable. The slack variable is defined by setting a lower bound of zero (>=0).
Changed lines 11-12 from:
%blue%A%red%P%black%Monitor has an online interface for solving optimization problems. The optimization problem shown below can be solved through the web-interface at the following link:
to:
%blue%A%red%P%black%Monitor has an online interface for solving optimization problems. The optimization problem shown below as '''Example Problem''' can be solved through the web-interface at the following link:
Changed line 15 from:
!!! Example
to:
!!! Example Problem
Changed line 13 from:
Attach: table50.jpg [[https://apmonitor.com/online/view_pass.php?f=slack.apm | Slack Variable Solution Online]]
to:
Attach:table50.jpg [[https://apmonitor.com/online/view_pass.php?f=slack.apm | Slack Variable Solution Online]]
Changed line 13 from:
[[https://apmonitor.com/online/view_pass.php?f=slack.apm | Slack Variable Solution Online]]
to:
Attach: table50.jpg [[https://apmonitor.com/online/view_pass.php?f=slack.apm | Slack Variable Solution Online]]
Changed line 11 from:
%blue%A%red%P%black%Monitor has an online interface for solving optimization problems. The optimization problem shown below can be solved the web-interface at the following link:
to:
%blue%A%red%P%black%Monitor has an online interface for solving optimization problems. The optimization problem shown below can be solved through the web-interface at the following link:
Added lines 8-13:
!!! Solve Slack Variable Problems Online
%blue%A%red%P%black%Monitor has an online interface for solving optimization problems. The optimization problem shown below can be solved the web-interface at the following link:
[[https://apmonitor.com/online/view_pass.php?f=slack.apm | Slack Variable Solution Online]]
Changed lines 3-5 from:
Slack variables are defined to give ''slack'' for infeasibilities. Generally, a slack variable is used to turn off an equation in a region where it does not apply. The slack variable is defined by setting a lower bound of zero (>=0) and including the variable in the objective function.
Slack variables are defined by starting a variable name with''''slk''''. Thus, valid slack variable names would include names such as ''slk_1'', ''slkr'', ''slkvar[1]''. When the model is parsed at run-time, any variable beginning with ''slk'' is automatically assigned a lower value of zero and included in the objective function.
Slack variables are defined by starting a variable name with
to:
Slack variables are defined to transform a inequality expression into an equality expression with an added slack variable. The slack variable is defined by setting a lower bound of zero (>=0).
Slack variables are defined by starting a variable name with ''''slk''''. Thus, valid slack variable names would include names such as ''slk_1'', ''slkr'', ''slkvar[1]''. When the model is parsed at run-time, any variable beginning with ''slk'' is automatically assigned a lower value of zero.
Equation inequalities are automatically tranformed to equality expressions for solvers that do not support them.
Slack variables are defined by starting a variable name with ''''slk''''. Thus, valid slack variable names would include names such as ''slk_1'', ''slkr'', ''slkvar[1]''. When the model is parsed at run-time, any variable beginning with ''slk'' is automatically assigned a lower value of zero.
Equation inequalities are automatically tranformed to equality expressions for solvers that do not support them.
Added lines 1-32:
!! Slack Variables
Slack variables are defined to give ''slack'' for infeasibilities. Generally, a slack variable is used to turn off an equation in a region where it does not apply. The slack variable is defined by setting a lower bound of zero (>=0) and including the variable in the objective function.
Slack variables are defined by starting a variable name with ''''slk''''. Thus, valid slack variable names would include names such as ''slk_1'', ''slkr'', ''slkvar[1]''. When the model is parsed at run-time, any variable beginning with ''slk'' is automatically assigned a lower value of zero and included in the objective function.
!!! Example
(:table border=1 width=50% align=left bgcolor=#EEEEEE cellspacing=0:)
(:cellnr:)
! Example model with slack variable declaration
Model example
Parameters
p1 = 5
End Parameters
Variables
slk_variable
v1 < 4
End Variables
Equations
v1 = p1 - slk_variable
End Equations
End Model
(:cellnr:)
Solution
p1 = 5
slk_variable = 1
v1 = 4
(:tableend:)
Slack variables are defined to give ''slack'' for infeasibilities. Generally, a slack variable is used to turn off an equation in a region where it does not apply. The slack variable is defined by setting a lower bound of zero (>=0) and including the variable in the objective function.
Slack variables are defined by starting a variable name with ''''slk''''. Thus, valid slack variable names would include names such as ''slk_1'', ''slkr'', ''slkvar[1]''. When the model is parsed at run-time, any variable beginning with ''slk'' is automatically assigned a lower value of zero and included in the objective function.
!!! Example
(:table border=1 width=50% align=left bgcolor=#EEEEEE cellspacing=0:)
(:cellnr:)
! Example model with slack variable declaration
Model example
Parameters
p1 = 5
End Parameters
Variables
slk_variable
v1 < 4
End Variables
Equations
v1 = p1 - slk_variable
End Equations
End Model
(:cellnr:)
Solution
p1 = 5
slk_variable = 1
v1 = 4
(:tableend:)