1
use std::fmt::Display;
2

            
3
use super::categories::{Category, CategoryOf};
4
use crate::representation::Representation;
5
use conjure_cp_core::ast::DomainPtr;
6
use conjure_cp_core::ast::domains::HasDomain;
7
use derivative::Derivative;
8
use serde::{Deserialize, Serialize};
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)]
34
pub struct DecisionVariable {
35
    pub domain: DomainPtr,
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

            
44
impl DecisionVariable {
45
25358
    pub fn new(domain: DomainPtr) -> DecisionVariable {
46
25358
        DecisionVariable {
47
25358
            domain,
48
25358
            representations: vec![],
49
25358
        }
50
25358
    }
51
}
52

            
53
impl CategoryOf for DecisionVariable {
54
128080
    fn category_of(&self) -> Category {
55
128080
        Category::Decision
56
128080
    }
57
}
58

            
59
impl HasDomain for DecisionVariable {
60
290898
    fn domain_of(&self) -> DomainPtr {
61
290898
        self.domain.clone()
62
290898
    }
63
}
64

            
65
impl Display for DecisionVariable {
66
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
67
        self.domain.fmt(f)
68
    }
69
}