Skip to content

Commit

Permalink
minion: rename things
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasdewally committed Oct 30, 2023
1 parent cc1e6b7 commit 3e3e0a9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
14 changes: 8 additions & 6 deletions solvers/minion/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,19 @@ pub enum Var {

pub enum Constant {
Bool(bool),
Discrete(i32),
Integer(i32),
}

#[derive(Copy, Clone)]
pub enum VarType {
Bounded(i32, i32),
pub enum VarDomain {
Bound(i32, i32),
Discrete(i32, i32),
SparseBound(i32, i32),
Bool(bool),
}

pub struct SymbolTable {
table: HashMap<VarName, VarType>,
table: HashMap<VarName, VarDomain>,

// for now doubles both as Minion's SearchOrder and print order
var_order: Vec<VarName>,
Expand All @@ -63,7 +65,7 @@ impl SymbolTable {

/// Creates a new variable and adds it to the symbol table.
/// If a variable already exists with the given name, an error is thrown.
pub fn add_var(&mut self, name: VarName, vartype: VarType) -> Option<()> {
pub fn add_var(&mut self, name: VarName, vartype: VarDomain) -> Option<()> {
if self.table.contains_key(&name) {
return None;
}
Expand All @@ -74,7 +76,7 @@ impl SymbolTable {
return Some(());
}

pub fn get_vartype(&self, name: VarName) -> Option<VarType> {
pub fn get_vartype(&self, name: VarName) -> Option<VarDomain> {
match self.table.get(&name) {
Some(m) => Some(*m),
None => None,
Expand Down
12 changes: 6 additions & 6 deletions solvers/minion/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ unsafe fn convert_model_to_raw(model: &Model) -> *mut ProbSpec_CSPInstance {
.expect("");

let (vartype_raw, domain_low, domain_high) = match vartype {
VarType::Bounded(a, b) => (VariableType_VAR_BOUND, a, b),
VarDomain::Bound(a, b) => (VariableType_VAR_BOUND, a, b),
_ => panic!("NOT IMPLEMENTED"),
};

Expand Down Expand Up @@ -183,7 +183,7 @@ unsafe fn read_const(raw_constraint: *mut ProbSpec_ConstraintBlob, constant: &Co
let raw_consts = Scoped::new(vec_int_new(), |x| vec_var_free(x as _));

let val = match constant {
Constant::Discrete(n) => n,
Constant::Integer(n) => n,
_ => panic!("NOT IMPLEMENTED"),
};

Expand All @@ -205,13 +205,13 @@ mod tests {
let mut model = Model::new();
model
.named_variables
.add_var("x".to_owned(), VarType::Bounded(1, 3));
.add_var("x".to_owned(), VarDomain::Bound(1, 3));
model
.named_variables
.add_var("y".to_owned(), VarType::Bounded(2, 4));
.add_var("y".to_owned(), VarDomain::Bound(2, 4));
model
.named_variables
.add_var("z".to_owned(), VarType::Bounded(1, 5));
.add_var("z".to_owned(), VarDomain::Bound(1, 5));

let leq = Constraint::SumLeq(
vec![
Expand All @@ -234,7 +234,7 @@ mod tests {
let ineq = Constraint::Ineq(
Var::NameRef("x".to_owned()),
Var::NameRef("y".to_owned()),
Constant::Discrete(-1),
Constant::Integer(-1),
);

model.constraints.push(leq);
Expand Down

0 comments on commit 3e3e0a9

Please sign in to comment.