Skip to content

Slack

Function Form

z=slack(x,y)={max(0,xy),compute positive slackmax(0,yx),compute negative slack|xy|,compute both positive and negative slack

Additional Variables

negRR: Negative slack.

posRR: Positive slack.

Derived Symbol

z=neg+pos

Mathematical Model

Compute Both Positive and Negative Slack

s.t.x+negpos=y

Compute Positive Slack

s.t.xposy

Compute Negative Slack

s.t.x+negy

Code Example

kotlin
import kotlinx.coroutines.*
import fuookami.ospf.kotlin.utils.math.*
import fuookami.ospf.kotlin.core.frontend.variable.*
import fuookami.ospf.kotlin.core.frontend.expression.polynomial.*
import fuookami.ospf.kotlin.core.frontend.expression.symbol.linear_function.*
import fuookami.ospf.kotlin.core.frontend.inequality.*
import fuookami.ospf.kotlin.core.frontend.model.mechanism.*
import fuookami.ospf.kotlin.core.backend.plugins.scip.*

val x = RealVar("x")
x.range.leq(Flt64.two)
x.range.geq(-Flt64.three)
val slack = SlackFunction(
    x = x,
    y = Flt64.five,
    name = "slack"
)

val model = LinearMetaModel()
model.add(x)
model.add(slack)
model.minimize(slack)

val solver = ScipLinearSolver()
val result = runBlocking { solver(model) }
assert(result.value!!.obj eq Flt64.three)
assert(result.value!!.solution[0] eq Flt64.two)

Complete Implementation Reference:

Complete Example Reference: