conjure_core/ast/variables.rs
1use std::fmt::Display;
2
3use derivative::Derivative;
4use serde::{Deserialize, Serialize};
5
6use crate::{ast::domains::Domain, representation::Representation};
7
8use super::{types::Typeable, ReturnType};
9
10/// Represents a decision variable within a computational model.
11///
12/// A `DecisionVariable` has a domain that defines the set of values it can take. The domain could be:
13/// - A boolean domain, meaning the variable can only be `true` or `false`.
14/// - An integer domain, meaning the variable can only take specific integer values or a range of integers.
15///
16/// # Fields
17/// - `domain`:
18/// - Type: `Domain`
19/// - Represents the set of possible values that this decision variable can assume. The domain can be a range of integers
20/// (IntDomain) or a boolean domain (BoolDomain).
21///
22/// # Example
23///
24/// use crate::ast::domains::{DecisionVariable, Domain, Range};
25///
26/// let bool_var = DecisionVariable::new(Domain::BoolDomain);
27/// let int_var = DecisionVariable::new(Domain::IntDomain(vec![Range::Bounded(1, 10)]));
28///
29/// println!("Boolean Variable: {}", bool_var);
30/// println!("Integer Variable: {}", int_var);
31
32#[derive(Clone, Debug, Serialize, Deserialize, Derivative)]
33#[derivative(Hash, PartialEq, Eq)]
34pub struct DecisionVariable {
35 pub domain: Domain,
36
37 // use this through [`Declaration`] - in the future, this probably will be stored in
38 // declaration / domain, not here.
39 #[serde(skip)]
40 #[derivative(Hash = "ignore", PartialEq = "ignore")]
41 pub(super) representations: Vec<Vec<Box<dyn Representation>>>,
42}
43
44impl DecisionVariable {
45 pub fn new(domain: Domain) -> DecisionVariable {
46 DecisionVariable {
47 domain,
48 representations: vec![],
49 }
50 }
51}
52
53impl Typeable for DecisionVariable {
54 fn return_type(&self) -> Option<ReturnType> {
55 todo!()
56 }
57}
58
59impl Display for DecisionVariable {
60 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
61 self.domain.fmt(f)
62 }
63}