Skip to main content

solverforge_core/domain/
variable.rs

1// Variable type definitions
2
3// The type of a planning variable.
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5pub enum VariableType {
6    // A genuine planning variable that the solver optimizes.
7    Genuine,
8    // A list variable containing multiple values.
9    List,
10    // A shadow variable computed from other variables.
11    Shadow(ShadowVariableKind),
12}
13
14// The kind of shadow variable.
15#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
16pub enum ShadowVariableKind {
17    // Custom shadow variable with user-defined listener.
18    Custom,
19    // Inverse of another variable (bidirectional relationship).
20    InverseRelation,
21    // Index within a list variable.
22    Index,
23    // Next element in a list variable.
24    NextElement,
25    // Previous element in a list variable.
26    PreviousElement,
27    // Cascading update from other shadow variables.
28    Cascading,
29    // Piggyback on another shadow variable's listener.
30    Piggyback,
31}
32
33// The type of value range for a planning variable.
34#[derive(Debug, Clone, PartialEq, Eq)]
35pub enum ValueRangeType {
36    // A collection of discrete values.
37    Collection,
38    // A countable range (e.g., integers from 1 to 100).
39    CountableRange {
40        // Inclusive start of the range.
41        from: i64,
42        // Exclusive end of the range.
43        to: i64,
44    },
45    // An entity-dependent value range.
46    EntityDependent,
47}
48
49impl VariableType {
50    /// Returns true if this is a genuine (non-shadow) variable.
51    ///
52    /// Genuine variables include scalar and list variables.
53    pub fn is_genuine(&self) -> bool {
54        matches!(self, VariableType::Genuine | VariableType::List)
55    }
56
57    pub fn is_shadow(&self) -> bool {
58        matches!(self, VariableType::Shadow(_))
59    }
60
61    pub fn is_list(&self) -> bool {
62        matches!(self, VariableType::List)
63    }
64
65    pub fn is_basic(&self) -> bool {
66        matches!(self, VariableType::Genuine)
67    }
68}
69
70impl ShadowVariableKind {
71    pub fn requires_listener(&self) -> bool {
72        matches!(
73            self,
74            ShadowVariableKind::Custom | ShadowVariableKind::Cascading
75        )
76    }
77
78    pub fn is_automatic(&self) -> bool {
79        matches!(
80            self,
81            ShadowVariableKind::InverseRelation
82                | ShadowVariableKind::Index
83                | ShadowVariableKind::NextElement
84                | ShadowVariableKind::PreviousElement
85        )
86    }
87
88    /// Returns true if this shadow variable piggybacks on another
89    /// shadow variable's listener rather than having its own.
90    pub fn is_piggyback(&self) -> bool {
91        matches!(self, ShadowVariableKind::Piggyback)
92    }
93}