pub struct StochasticProblem<S: Scalar> { /* private fields */ }Expand description
Declarative builder for stochastic optimization problems.
Build a problem with the fluent API, then call .solve() to perform
Sample-Average Approximation (SAA) optimization.
Implementations§
Source§impl<S: Scalar> StochasticProblem<S>
impl<S: Scalar> StochasticProblem<S>
Sourcepub fn new(n: usize) -> Self
pub fn new(n: usize) -> Self
Create a new stochastic optimization problem with n decision variables.
Sourcepub fn all_bounds(self, bounds: &[(S, S)]) -> Self
pub fn all_bounds(self, bounds: &[(S, S)]) -> Self
Set bounds for all variables at once.
Sourcepub fn objective<F>(self, f: F) -> Self
pub fn objective<F>(self, f: F) -> Self
Set the parameterized objective function f(x, params).
The solver minimizes the expected value E[f(x, xi)] over the
stochastic parameters.
Sourcepub fn constraint_det_ineq<F>(self, f: F) -> Self
pub fn constraint_det_ineq<F>(self, f: F) -> Self
Add a deterministic inequality constraint g(x) <= 0.
Sourcepub fn constraint_det_eq<F>(self, f: F) -> Self
pub fn constraint_det_eq<F>(self, f: F) -> Self
Add a deterministic equality constraint h(x) = 0.
Sourcepub fn chance_constraint<F>(self, f: F, probability: S) -> Self
pub fn chance_constraint<F>(self, f: F, probability: S) -> Self
Add a chance constraint: P{g(x, xi) <= 0} >= probability.
The constraint function g(x, params) should return a value where
g <= 0 means the constraint is satisfied.
Sourcepub fn param(self, p: StochasticParam<S>) -> Self
pub fn param(self, p: StochasticParam<S>) -> Self
Add a stochastic parameter directly.
Sourcepub fn param_normal(self, name: &str, mean: S, std: S) -> Self
pub fn param_normal(self, name: &str, mean: S, std: S) -> Self
Add a normally distributed stochastic parameter.
Sourcepub fn param_uniform(self, name: &str, lo: S, hi: S) -> Self
pub fn param_uniform(self, name: &str, lo: S, hi: S) -> Self
Add a uniformly distributed stochastic parameter.
Sourcepub fn minimize_cvar(self, alpha: S) -> Self
pub fn minimize_cvar(self, alpha: S) -> Self
Minimize CVaR (Conditional Value at Risk) at confidence level alpha
instead of the expected value.
Uses the Rockafellar-Uryasev reformulation:
CVaR_alpha(X) = min_t { t + 1/(1-alpha) * E[max(0, X - t)] }
An auxiliary variable t (VaR estimate) is appended to the decision vector.
Requires alpha in (0, 1), typically 0.9 or 0.95.
Source§impl<S: Scalar + SimpleEntity + Conjugate<Canonical = S> + ComplexField> StochasticProblem<S>
impl<S: Scalar + SimpleEntity + Conjugate<Canonical = S> + ComplexField> StochasticProblem<S>
Sourcepub fn solve(self) -> Result<StochasticResult<S>, OptimError>
pub fn solve(self) -> Result<StochasticResult<S>, OptimError>
Solve the stochastic optimization problem using SAA.
- Generates
n_samplesscenarios by sampling all stochastic parameters. - Builds a deterministic SAA problem:
min (1/N) sum f(x, xi_s). - Chance constraints are enforced via smooth quadratic penalty.
- Solves and evaluates constraint satisfaction at the optimal point.
Auto Trait Implementations§
impl<S> Freeze for StochasticProblem<S>where
S: Freeze,
impl<S> !RefUnwindSafe for StochasticProblem<S>
impl<S> !Send for StochasticProblem<S>
impl<S> !Sync for StochasticProblem<S>
impl<S> Unpin for StochasticProblem<S>where
S: Unpin,
impl<S> UnsafeUnpin for StochasticProblem<S>where
S: UnsafeUnpin,
impl<S> !UnwindSafe for StochasticProblem<S>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more