Slack Range
SlackRangeFunction computes the exact distance of a linear expression from the closed interval
The constructor validates lower <= upper and accepts scalar bounds:
SlackRangeFunction(
input: LinearPolynomial<V>,
lower: V,
upper: V,
bigM: V? = null,
converter: IntoValue<V>,
name: String,
displayName: String? = null
)fromLinearIntermediateSymbol creates the adapter form when the input is a linear intermediate symbol. The result polynomial is the internal exact MaxFunction result, so it cannot be inflated by leaving it out of the objective.
Solver mathematical model
For candidates
This is the exact maximum formulation:
Rust parity
Rust exposes the same scalar-bound API:
let slack = SlackRangeFunction::new(
1, "slack_range", input, -2.0_f64, 2.0_f64,
);
assert_eq!(slack.lower_bound(), &-2.0);
assert_eq!(slack.upper_bound(), &2.0);Its MaxFunction encoding and direct evaluation implement the same formula.
Kotlin/Rust example
val slack = SlackRangeFunction(
input = input,
lower = Flt64(-2.0),
upper = Flt64(2.0),
converter = IntoValue.Identity,
name = "slack-range"
)
check(slack.evaluate(values) == Flt64(0.0))let slack = SlackRangeFunction::new(1, "slack_range", input, -2.0_f64, 2.0_f64);
assert_eq!(slack.calculate_value(&tokens, false), Some(0.0));Tests and references
- Kotlin:
SlackRangeFunctionDedicatedTest.kt - Kotlin implementation:
SlackRange.kt - Rust implementation:
slack_range.rs - Rust focused test:
function_symbol_slack_range.rs
The focused tests assert all four helpers and the seven exact-Max rows with an explicit Big-M, while also covering all three distance regions and reversed bounds.
Both implementations validate finite ordered bounds. Rust also provides SlackRangeFunction::with_big_m for an explicit positive finite Big-M; the default constructor delegates to the shared fallback or token-derived policy.