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 /// Returns `true` for shadow variables.
58 pub fn is_shadow(&self) -> bool {
59 matches!(self, VariableType::Shadow(_))
60 }
61
62 /// Returns `true` for list variables.
63 pub fn is_list(&self) -> bool {
64 matches!(self, VariableType::List)
65 }
66
67 /// Returns `true` for genuine scalar variables.
68 pub fn is_basic(&self) -> bool {
69 matches!(self, VariableType::Genuine)
70 }
71}
72
73impl ShadowVariableKind {
74 /// Returns `true` for kinds updated by a listener (`Custom` and `Cascading`).
75 pub fn requires_listener(&self) -> bool {
76 matches!(
77 self,
78 ShadowVariableKind::Custom | ShadowVariableKind::Cascading
79 )
80 }
81
82 /// Returns `true` for kinds the solver maintains itself (`InverseRelation`,
83 /// `Index`, `NextElement`, `PreviousElement`).
84 pub fn is_automatic(&self) -> bool {
85 matches!(
86 self,
87 ShadowVariableKind::InverseRelation
88 | ShadowVariableKind::Index
89 | ShadowVariableKind::NextElement
90 | ShadowVariableKind::PreviousElement
91 )
92 }
93
94 /// Returns true if this shadow variable piggybacks on another
95 /// shadow variable's listener rather than having its own.
96 pub fn is_piggyback(&self) -> bool {
97 matches!(self, ShadowVariableKind::Piggyback)
98 }
99}