Skip to main content

Interval

Struct Interval 

Source
pub struct Interval<'domain, T: QuantitativeLimit> { /* private fields */ }
Expand description

Interval valuation.

Implementations§

Source§

impl<'domain, T: QuantitativeLimit + Copy + Debug + Display + Into<f64> + Add<Output = T> + Sub<Output = T>> Interval<'domain, T>

Source

pub fn new( domain: &'domain Quantitative<T>, min: T, max: T, ) -> Result<Self, IntervalError<T>>

Creates a new valuation.

§Arguments
  • domain: A quantitative domain reference.
  • min: Interval min value.
  • max: Interval max value.
§Examples
let domain = Quantitative::new(1, 5).unwrap();
assert!(Interval::new(&domain, 2, 3).is_ok());
let domain = Quantitative::new(1.2, 5.7).unwrap();
assert!(Interval::new(&domain, 2.3, 2.7).is_ok());
§Errors

IntervalError::InvalidMin: If min < domain inferior limit.

let domain = Quantitative::new(1, 5).unwrap();
assert_eq!(
    Interval::new(&domain, 0, 3),
    Err(IntervalError::InvalidMin { min: 0, inf: 1 })
);

IntervalError::InvalidMax: If max > domain superior limit.

let domain = Quantitative::new(1, 5).unwrap();
assert_eq!(
    Interval::new(&domain, 2, 6),
    Err(IntervalError::InvalidMax { max: 6, sup: 5 })
);

IntervalError::InvalidRange: If min > max.

let domain = Quantitative::new(1, 5).unwrap();
assert_eq!(
    Interval::new(&domain, 3, 2),
    Err(IntervalError::InvalidRange { min: 3, max: 2 })
);
Source

pub fn value(&self) -> (T, T)

Returns valuation values.

§Examples
let domain = Quantitative::new(1, 5).unwrap();
let valuation = Interval::new(&domain, 2, 3).unwrap();
assert_eq!(valuation.value(), (2, 3));
let domain = Quantitative::new(1.0, 5.7).unwrap();
let valuation = Interval::new(&domain, 2.0, 3.0).unwrap();
assert_eq!(valuation.value(), (2.0, 3.0));
Source

pub fn domain(&self) -> &'domain Quantitative<T>

Returns valuation domain.

§Examples
let domain = Quantitative::new(1.0, 5.7).unwrap();
let valuation = Interval::new(&domain, 2.0, 3.0).unwrap();
assert_eq!(*valuation.domain(), domain);
Source

pub fn normalize(&self) -> Interval<'_, f64>

Value normalized in domain 0.0 to 1.0.

Note that the type of value is f64.

§Examples
let domain = Quantitative::new(0.0, 10.0).unwrap();
let valuation = Interval::new(&domain, 2.0, 3.5).unwrap();
let normalized = valuation.normalize();
assert_eq!(normalized.value(), (0.2, 0.35));
assert_eq!(*normalized.domain(), NORMALIZATION_DOMAIN);

let domain = Quantitative::new(-1, 5).unwrap();
let valuation = Interval::new(&domain, 2, 5).unwrap();
let normalized = valuation.normalize();
assert_eq!(normalized.value(), (0.5, 1.0));
assert_eq!(*normalized.domain(), NORMALIZATION_DOMAIN);
Source

pub fn neg(&self) -> Self

Valuation negation.

§Examples
let domain = Quantitative::new(0, 10).unwrap();
let valuation = Interval::new(&domain, 2, 4).unwrap();
let neg = valuation.neg();
assert_eq!(neg.value(), (6, 8));
Source§

impl<'domain> Interval<'domain, f64>

Source

pub fn resume(&self) -> f64

Source§

impl<'domain> Interval<'domain, f32>

Source

pub fn resume(&self) -> f32

Source§

impl<'domain> Interval<'domain, i32>

Source

pub fn resume(&self) -> i32

Source§

impl<'domain, T> Interval<'domain, T>
where T: Mul<Output = T> + Add<Output = T> + Sub<Output = T> + Div<Output = T> + QuantitativeLimit + Into<f64>,

Source

pub fn unification( &self, domain: &'domain Qualitative<Trapezoidal>, ) -> Result<Unified<'_>, UnifiedError<'_>>

Unification of a Interval valuation in a given domain.

§Arguments
  • domain: Domain in which perform the unification.
§Examples
let domain = Quantitative::new(0, 7).unwrap();
let unification_domain = qualitative_symmetric_domain!["a", "b", "c", "d", "e"].unwrap();

let valuation = Interval::new(&domain, 5, 6).unwrap();
let unified = valuation.unification(&unification_domain).unwrap();
let measures = unified.measures();
let expected_measures =  vec![0.0, 0.0, 0.14, 1.0, 0.43];
for i in 0..(expected_measures.len()) {
    assert!(
        utilities::math::approx_equal_f32(
            measures[i],
            expected_measures[i],
            2
        ),
        "({}) Value {:.2} vs. Expected {:.2}",
        i,
        measures[i],
        expected_measures[i]
    );
}
§Errors

UnifiedError::NonBLTSDomain: If domain is a Non-BLTS domain.

let domain = Quantitative::new(0, 7).unwrap();
let unification_domain = qualitative_symmetric_domain!["a", "b", "c", "d"].unwrap();

let valuation = Interval::new(&domain, 5, 6).unwrap();
assert_eq!(
    valuation.unification(&unification_domain),
    Err(UnifiedError::NonBLTSDomain { domain: &unification_domain })
);
Source

pub fn transform_in_domain( &self, domain: &'domain Quantitative<T>, ) -> Interval<'_, T>

Transform a Interval valuation using a different domain.

Note that domain type should be equal to valuation type.

§Arguments
  • domain: Domain to be used.
§Examples
let domain = Quantitative::new(0, 7).unwrap();
let transform_domain = Quantitative::new(0, 3).unwrap();

let valuation = Interval::new(&domain, 5, 6).unwrap();
let unified = valuation.transform_in_domain(&transform_domain);
assert_eq!(unified.value(), (2, 2));

Trait Implementations§

Source§

impl<'domain, T: Debug + QuantitativeLimit> Debug for Interval<'domain, T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'domain, T: PartialEq + QuantitativeLimit> PartialEq for Interval<'domain, T>

Source§

fn eq(&self, other: &Interval<'domain, T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'domain> TryFrom<&Interval<'domain, f32>> for Numeric<'domain, f32>

Generates a Numeric valuation from an &Interval valuation.

§Examples

let domain = Quantitative::new(0.5_f32, 1.0_f32).unwrap();
let interval = Interval::new(&domain, 0.6, 0.8).unwrap();
let numeric = Numeric::try_from(&interval).unwrap();
let expected = 0.7;
assert!((numeric.value() - expected).abs() < 0.01);
Source§

type Error = NumericError<f32>

The type returned in the event of a conversion error.
Source§

fn try_from(value: &Interval<'domain, f32>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<'domain> TryFrom<&Interval<'domain, f64>> for Numeric<'domain, f64>

Generates a Numeric valuation from an &Interval valuation.

§Examples

let domain = Quantitative::new(0.5_f64, 1.0_f64).unwrap();
let interval = Interval::new(&domain, 0.6, 0.8).unwrap();
let numeric = Numeric::try_from(&interval).unwrap();
let expected = 0.7;
assert!((numeric.value() - expected).abs() < 0.01);
Source§

type Error = NumericError<f64>

The type returned in the event of a conversion error.
Source§

fn try_from(value: &Interval<'domain, f64>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<'domain> TryFrom<&Interval<'domain, i32>> for Numeric<'domain, i32>

Generates a Numeric valuation from an &Interval valuation.

§Examples

let domain = Quantitative::new(5, 10).unwrap();
let interval = Interval::new(&domain, 6, 8).unwrap();
let numeric = Numeric::try_from(&interval).unwrap();
let expected = 7;
assert_eq!(numeric.value(), expected);
Source§

type Error = NumericError<i32>

The type returned in the event of a conversion error.
Source§

fn try_from(value: &Interval<'domain, i32>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<'domain, T: QuantitativeLimit + Into<f64> + Add<Output = T> + Sub<Output = T>> TryFrom<&Numeric<'domain, T>> for Interval<'domain, T>

Generates an Interval valuation from a &Numeric valuation.

§Examples

let domain = Quantitative::new(5, 10).unwrap();
let numeric = Numeric::new(&domain, 6).unwrap();
let interval = Interval::try_from(&numeric).unwrap();
let expected = (6, 6);
assert_eq!(interval.value(), expected);
Source§

type Error = IntervalError<T>

The type returned in the event of a conversion error.
Source§

fn try_from(value: &Numeric<'domain, T>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<'domain> TryFrom<Interval<'domain, f32>> for Numeric<'domain, f32>

Generates a Numeric valuation from an Interval valuation.

Wrapper of Numeric::try_from(&Interval).

Source§

type Error = NumericError<f32>

The type returned in the event of a conversion error.
Source§

fn try_from(value: Interval<'domain, f32>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<'domain> TryFrom<Interval<'domain, f64>> for Numeric<'domain, f64>

Generates a Numeric valuation from an Interval valuation.

Wrapper of Numeric::try_from(&Interval).

Source§

type Error = NumericError<f64>

The type returned in the event of a conversion error.
Source§

fn try_from(value: Interval<'domain, f64>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<'domain> TryFrom<Interval<'domain, i32>> for Numeric<'domain, i32>

Generates a Numeric valuation from an Interval valuation.

Wrapper of Numeric::try_from(&Interval).

let domain = Quantitative::new(5, 10).unwrap();
let interval = Interval::new(&domain, 6, 8).unwrap();
let numeric = Numeric::try_from(&interval).unwrap();
let expected = 7;
assert_eq!(numeric.value(), expected);
Source§

type Error = NumericError<i32>

The type returned in the event of a conversion error.
Source§

fn try_from(value: Interval<'domain, i32>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<'domain, T: QuantitativeLimit + Into<f64> + Add<Output = T> + Sub<Output = T>> TryFrom<Numeric<'domain, T>> for Interval<'domain, T>

Generates an Interval valuation from a Numeric valuation.

Wrapper of Interval::try_from(&Numeric).

Source§

type Error = IntervalError<T>

The type returned in the event of a conversion error.
Source§

fn try_from(value: Numeric<'domain, T>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<'domain, T: QuantitativeLimit> StructuralPartialEq for Interval<'domain, T>

Source§

impl<'domain, T: QuantitativeLimit> Valuation for Interval<'domain, T>

Auto Trait Implementations§

§

impl<'domain, T> Freeze for Interval<'domain, T>
where T: Freeze,

§

impl<'domain, T> RefUnwindSafe for Interval<'domain, T>
where T: RefUnwindSafe,

§

impl<'domain, T> Send for Interval<'domain, T>
where T: Send + Sync,

§

impl<'domain, T> Sync for Interval<'domain, T>
where T: Sync,

§

impl<'domain, T> Unpin for Interval<'domain, T>
where T: Unpin,

§

impl<'domain, T> UnsafeUnpin for Interval<'domain, T>
where T: UnsafeUnpin,

§

impl<'domain, T> UnwindSafe for Interval<'domain, T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.