use crate::types::values::{FuzzyNumber, FuzzyScalar, FuzzyShapeDto, SetValue, ValueDto};
pub struct Value;
impl Value {
pub fn string(s: impl Into<String>) -> ValueDto {
ValueDto::String(s.into())
}
pub fn integer(i: i64) -> ValueDto {
ValueDto::Integer(i)
}
pub fn real(r: f64) -> ValueDto {
ValueDto::Real(r)
}
pub fn boolean(b: bool) -> ValueDto {
ValueDto::Boolean(b)
}
pub fn uninstantiated() -> ValueDto {
ValueDto::Uninstantiated
}
pub fn list(items: Vec<ValueDto>) -> ValueDto {
ValueDto::List(items)
}
pub fn reference(id: impl Into<String>) -> ValueDto {
ValueDto::Reference(id.into())
}
pub fn fuzzy_scalar(value: f64, membership: f64) -> ValueDto {
ValueDto::FuzzyScalar(FuzzyScalar { value, membership })
}
pub fn fuzzy_number(shape: FuzzyShapeDto) -> ValueDto {
ValueDto::FuzzyNumber(FuzzyNumber { shape })
}
pub fn set(
lower: Vec<String>,
upper: Vec<String>,
sort_constraint: Option<String>,
) -> ValueDto {
ValueDto::Set(SetValue {
lower,
upper,
sort_constraint,
})
}
}
impl From<&str> for ValueDto {
fn from(s: &str) -> Self {
ValueDto::String(s.to_string())
}
}
impl From<String> for ValueDto {
fn from(s: String) -> Self {
ValueDto::String(s)
}
}
impl From<i64> for ValueDto {
fn from(i: i64) -> Self {
ValueDto::Integer(i)
}
}
impl From<i32> for ValueDto {
fn from(i: i32) -> Self {
ValueDto::Integer(i.into())
}
}
impl From<f64> for ValueDto {
fn from(f: f64) -> Self {
ValueDto::Real(f)
}
}
impl From<bool> for ValueDto {
fn from(b: bool) -> Self {
ValueDto::Boolean(b)
}
}
pub struct FuzzyShape;
impl FuzzyShape {
pub fn triangular(a: f64, b: f64, c: f64) -> FuzzyShapeDto {
FuzzyShapeDto::Triangular { a, b, c }
}
pub fn trapezoidal(a: f64, b: f64, c: f64, d: f64) -> FuzzyShapeDto {
FuzzyShapeDto::Trapezoidal { a, b, c, d }
}
pub fn gaussian(mean: f64, std_dev: f64) -> FuzzyShapeDto {
FuzzyShapeDto::Gaussian { mean, std_dev }
}
pub fn cyclic_gaussian(mean: f64, std_dev: f64, period: f64) -> FuzzyShapeDto {
FuzzyShapeDto::CyclicGaussian {
mean,
std_dev,
period,
}
}
pub fn sigmoid(midpoint: f64, steepness: f64) -> FuzzyShapeDto {
FuzzyShapeDto::Sigmoid {
midpoint,
steepness,
}
}
pub fn bell(center: f64, width: f64, slope: f64) -> FuzzyShapeDto {
FuzzyShapeDto::Bell {
center,
width,
slope,
}
}
pub fn sigmoid_difference(
midpoint1: f64,
steepness1: f64,
midpoint2: f64,
steepness2: f64,
) -> FuzzyShapeDto {
FuzzyShapeDto::SigmoidDifference {
midpoint1,
steepness1,
midpoint2,
steepness2,
}
}
pub fn gaussian_product(mean1: f64, std_dev1: f64, mean2: f64, std_dev2: f64) -> FuzzyShapeDto {
FuzzyShapeDto::GaussianProduct {
mean1,
std_dev1,
mean2,
std_dev2,
}
}
pub fn sigmoid_product(
midpoint1: f64,
steepness1: f64,
midpoint2: f64,
steepness2: f64,
) -> FuzzyShapeDto {
FuzzyShapeDto::SigmoidProduct {
midpoint1,
steepness1,
midpoint2,
steepness2,
}
}
pub fn cosine(center: f64, width: f64) -> FuzzyShapeDto {
FuzzyShapeDto::Cosine { center, width }
}
pub fn spike(center: f64, width: f64) -> FuzzyShapeDto {
FuzzyShapeDto::Spike { center, width }
}
pub fn cauchy(center: f64, gamma: f64) -> FuzzyShapeDto {
FuzzyShapeDto::Cauchy { center, gamma }
}
pub fn s_shape(a: f64, b: f64) -> FuzzyShapeDto {
FuzzyShapeDto::SShape { a, b }
}
pub fn z_shape(a: f64, b: f64) -> FuzzyShapeDto {
FuzzyShapeDto::ZShape { a, b }
}
pub fn pi_shape(a: f64, b: f64, c: f64, d: f64) -> FuzzyShapeDto {
FuzzyShapeDto::PiShape { a, b, c, d }
}
pub fn piecewise_linear(points: Vec<(f64, f64)>) -> FuzzyShapeDto {
FuzzyShapeDto::PiecewiseLinear { points }
}
}