pub struct Predicate { /* private fields */ }Expand description
System requirements expressed as the inequality ax≤ b.
See the predicate module for more information on the semantics of this data type.
Implementations§
Source§impl Predicate
impl Predicate
Source§impl Predicate
impl Predicate
Sourcepub fn coefficients(&self) -> Coefficients<'_> ⓘ
pub fn coefficients(&self) -> Coefficients<'_> ⓘ
Create an iterator over the coefficient terms of the Predicate.
A coefficient term is a term that has a variable. This function does not make any guarantees about the order of iteration of the terms.
§Example
let p = banquo::predicate!{ x + 2.0 * y + 3.3 * z <= 4.2 };
for (name, coefficient) in p.coefficients() {
// ...
}Source§impl Predicate
impl Predicate
Sourcepub fn evaluate_state<State>(
&self,
state: &State,
) -> Result<f64, EvaluationError>where
State: VariableSet,
pub fn evaluate_state<State>(
&self,
state: &State,
) -> Result<f64, EvaluationError>where
State: VariableSet,
Evaluate a system state into a robustness value.
The successful output of this function is a f64 value representing the distance of the
state from making the inequality represented by the Predicate false. A positive output
value indicates that the inequality was not violated, while a negative value indicates the
inequality was violated. The unsuccessful output of this function is a [PredicateError]
which indicates the nature of the evaluation error.
Any value that implements the VariableSet trait can be evaluated with this method.
§Examples
use std::collections::HashMap;
use banquo::predicate::{Predicate, Term};
let state = HashMap::from([
("x", 1.0), ("y", 3.0), ("z", f64::NAN),
]);
// BTreeMap also implements the VariableSet trait
// let state = BTreeMap::from([
// ("x", 1.0), ("y", 3.0), ("z", f64::NAN),
// ]);
let p = Predicate::from([
Term::from(("x", 1.0)), Term::from(("y", 2.0)), Term::from(10.0)
]);
p.evaluate_state(&state); // Ok -> 3.0
let p = Predicate::from([
Term::from(("x", 1.0)), Term::from(("a", 2.0)), Term::from(10.0)
]);
p.evaluate_state(&state); // Error -> Missing variable "a"
let p = Predicate::from([
Term::from(("x", 1.0)), Term::from(("z", 2.0)), Term::from(10.0)
]);
p.evaluate_state(&state); // Error -> Variable "z" has NaN value
let p = Predicate::from([
Term::from(("x", 1.0)), Term::from(("y", f64::NAN)), Term::from(10.0)
]);
p.evaluate_state(&state); // Error -> Variable "y" has NaN coefficientTrait Implementations§
Source§impl<T> AddAssign<T> for Predicate
impl<T> AddAssign<T> for Predicate
Source§fn add_assign(&mut self, rhs: T)
fn add_assign(&mut self, rhs: T)
+= operation. Read moreSource§impl<State> Formula<State> for Predicatewhere
State: VariableSet,
Evaluate a Trace of state values by evaluating each state individually.
impl<State> Formula<State> for Predicatewhere
State: VariableSet,
Evaluate a Trace of state values by evaluating each state individually.
Source§type Error = FormulaError
type Error = FormulaError
Source§impl<T> FromIterator<T> for Predicate
impl<T> FromIterator<T> for Predicate
Source§fn from_iter<I>(terms: I) -> Selfwhere
I: IntoIterator<Item = T>,
fn from_iter<I>(terms: I) -> Selfwhere
I: IntoIterator<Item = T>,
Source§impl<T> SubAssign<T> for Predicate
impl<T> SubAssign<T> for Predicate
Source§fn sub_assign(&mut self, rhs: T)
fn sub_assign(&mut self, rhs: T)
-= operation. Read more