conjure_core/ast/
variables.rs

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