pub struct Variable {
pub id: VariableId,
pub name: String,
pub states: Vec<String>,
}Expand description
A discrete random variable with named states.
§Example
use cvx_bayes::Variable;
let task = Variable::new(0, "task_type", vec![
"pick_and_place".into(),
"heat_then_place".into(),
"clean_then_place".into(),
]);
assert_eq!(task.n_states(), 3);
assert_eq!(task.state_index("heat_then_place"), Some(1));Fields§
§id: VariableIdUnique ID in the network.
name: StringHuman-readable name.
states: Vec<String>Named states (e.g., [“success”, “failure”]).
Implementations§
Source§impl Variable
impl Variable
Sourcepub fn new(id: VariableId, name: impl Into<String>, states: Vec<String>) -> Self
pub fn new(id: VariableId, name: impl Into<String>, states: Vec<String>) -> Self
Create a new variable with named states.
Sourcepub fn binary(id: VariableId, name: impl Into<String>) -> Self
pub fn binary(id: VariableId, name: impl Into<String>) -> Self
Create a binary variable (two states: “true”, “false”).
Sourcepub fn state_index(&self, state_name: &str) -> Option<usize>
pub fn state_index(&self, state_name: &str) -> Option<usize>
Get state index by name.
Sourcepub fn state_name(&self, index: usize) -> Option<&str>
pub fn state_name(&self, index: usize) -> Option<&str>
Get state name by index.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Variable
impl<'de> Deserialize<'de> for Variable
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for Variable
impl RefUnwindSafe for Variable
impl Send for Variable
impl Sync for Variable
impl Unpin for Variable
impl UnsafeUnpin for Variable
impl UnwindSafe for Variable
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
Mutably borrows from an owned value. Read more