pub struct ParametricPolytope { /* private fields */ }Expand description
A family of polytopes {x : hₖ(j, x) ≥ 0} whose half-spaces are affine
in x with coefficients polynomial in one parameter j.
at instantiates the family exactly at a rational j;
polytope_at / vertices_at /
volume_at do the same with a per-value cache, for
tree builders that revisit the same samples.
use symplex::prelude::*;
use symplex::polytope::ParametricPolytope;
use symplex::linprog::{q, qi};
let ctx = Context::new();
let (j, r, t) = (ctx.symbol("j"), ctx.symbol("r"), ctx.symbol("t"));
// 0 ≤ r ≤ 1/2, 0 ≤ t ≤ 1, (2j + 1)·t ≥ j·r + 1
let hyps = [r.clone(), ctx.rational(1, 2) - &r, t.clone(), 1 - &t, (&j * 2 + 1) * &t - &j * &r - 1];
let mut cell = ParametricPolytope::new(&hyps, &[r, t], &j).unwrap();
assert_eq!(cell.volume_at(&qi(2)).unwrap(), q(7, 20)); // ∫₀^{1/2} (1 − (2r + 1)/5) dr
assert_eq!(cell.vertices_at(&qi(2)).unwrap().len(), 4);
assert!(cell.at(&qi(100)).unwrap().contains(&[q(1, 4), q(3, 4)]));Implementations§
Source§impl ParametricPolytope
impl ParametricPolytope
Sourcepub fn new(hyps: &[Ex], vars: &[Ex], param: &Ex) -> Result<Self, SymplexError>
pub fn new(hyps: &[Ex], vars: &[Ex], param: &Ex) -> Result<Self, SymplexError>
Build from hypotheses hₖ(j, x) ≥ 0, each affine in vars with
coefficients polynomial (rational) in param.
§Errors
SymplexError::InvalidArgument if a hypothesis is not a polynomial
in the variables and the parameter, is not affine in the variables,
or has a symbolic coefficient; or if the lists are empty.
Sourcepub fn at(&self, value: &Q) -> Result<Polytope, SymplexError>
pub fn at(&self, value: &Q) -> Result<Polytope, SymplexError>
The polytope at param = value, exactly (no cache). Pure rational
arithmetic on the stored polynomials — no expression arena is
touched, so sampling a family densely is cheap.
§Errors
Only internal failures (the substitution of a rational is always affine in the variables).
Sourcepub fn polytope_at(&mut self, value: &Q) -> Result<&Polytope, SymplexError>
pub fn polytope_at(&mut self, value: &Q) -> Result<&Polytope, SymplexError>
Sourcepub fn vertices_at(&mut self, value: &Q) -> Result<&[Vec<Q>], SymplexError>
pub fn vertices_at(&mut self, value: &Q) -> Result<&[Vec<Q>], SymplexError>
Sourcepub fn is_empty_at(&mut self, value: &Q) -> Result<bool, SymplexError>
pub fn is_empty_at(&mut self, value: &Q) -> Result<bool, SymplexError>
Sourcepub fn contains_at(&mut self, value: &Q, x: &[Q]) -> Result<bool, SymplexError>
pub fn contains_at(&mut self, value: &Q, x: &[Q]) -> Result<bool, SymplexError>
Sourcepub fn clear_cache(&mut self)
pub fn clear_cache(&mut self)
Forget every cached instantiation.
Trait Implementations§
Source§impl Clone for ParametricPolytope
impl Clone for ParametricPolytope
Auto Trait Implementations§
impl !RefUnwindSafe for ParametricPolytope
impl !UnwindSafe for ParametricPolytope
impl Freeze for ParametricPolytope
impl Send for ParametricPolytope
impl Sync for ParametricPolytope
impl Unpin for ParametricPolytope
impl UnsafeUnpin for ParametricPolytope
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
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