1
use std::fmt::Display;
2

            
3
use serde::{Deserialize, Serialize};
4

            
5
use crate::ast::domains::{Domain, Range};
6

            
7
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
8
pub struct DecisionVariable {
9
    pub domain: Domain,
10
}
11

            
12
impl DecisionVariable {
13
    pub fn new(domain: Domain) -> DecisionVariable {
14
        DecisionVariable { domain }
15
    }
16
}
17

            
18
impl Display for DecisionVariable {
19
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
20
        match &self.domain {
21
            Domain::BoolDomain => write!(f, "bool"),
22
            Domain::IntDomain(ranges) => {
23
                let mut first = true;
24
                for r in ranges {
25
                    if first {
26
                        first = false;
27
                    } else {
28
                        write!(f, " or ")?;
29
                    }
30
                    match r {
31
                        Range::Single(i) => write!(f, "{}", i)?,
32
                        Range::Bounded(i, j) => write!(f, "{}..{}", i, j)?,
33
                    }
34
                }
35
                Ok(())
36
            }
37
        }
38
    }
39
}