Skip to content

Commit

Permalink
an initial go at representing a model
Browse files Browse the repository at this point in the history
  • Loading branch information
ozgurakgun committed Oct 18, 2023
1 parent 45ea0b7 commit f323e51
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 43 deletions.
77 changes: 35 additions & 42 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
[workspace]
[package]
name = "conjure-oxide"
version = "0.0.1"
edition = "2021"

[workspace]
members = ["solvers/kissat", "solvers/minion", "solvers/chuffed"]
exclude = []
80 changes: 80 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
fn main() {
let a = Name::UserName(String::from("a"));
let b = Name::UserName(String::from("b"));
let c = Name::UserName(String::from("c"));

let a_decision_variable = DecisionVariable {
name: a,
domain: Domain::IntDomain(vec![Range::Bounded(1, 3)]),
};
let a_reference = Expression::Reference(&a_decision_variable);

let b_decision_variable = DecisionVariable {
name: b,
domain: Domain::IntDomain(vec![Range::Bounded(1, 3)]),
};
let b_reference = Expression::Reference(&b_decision_variable);

let c_decision_variable = DecisionVariable {
name: c,
domain: Domain::IntDomain(vec![Range::Bounded(1, 3)]),
};
let c_reference = Expression::Reference(&c_decision_variable);

let m = Model {
statements: vec![
Statement::Declaration(&a_decision_variable),
Statement::Declaration(&b_decision_variable),
Statement::Declaration(&c_decision_variable),
Statement::Constraint(Expression::Eq(
Box::from(Expression::Sum(vec![a_reference, b_reference, c_reference])),
Box::from(Expression::ConstantInt(4)),
)),
],
};

println!("{:#?}", m);
}

#[derive(Debug)]
enum Name {
UserName(String),
MachineName(i32),
}

#[derive(Debug)]
struct Model<'a> {
statements: Vec<Statement<'a>>,
}

#[derive(Debug)]
struct DecisionVariable {
name: Name,
domain: Domain,
}

#[derive(Debug)]
enum Statement<'a> {
Declaration(&'a DecisionVariable),
Constraint(Expression<'a>),
}

#[derive(Debug)]
enum Domain {
BoolDomain,
IntDomain(Vec<Range<i32>>),
}

#[derive(Debug)]
enum Range<A> {
Single(A),
Bounded(A, A),
}

#[derive(Debug)]
enum Expression<'a> {
ConstantInt(i32),
Reference(&'a DecisionVariable),
Sum(Vec<Expression<'a>>),
Eq(Box<Expression<'a>>, Box<Expression<'a>>),
}

0 comments on commit f323e51

Please sign in to comment.