Skip to content

Commit

Permalink
Merge pull request #15 from ozgurakgun/the-abc-problem
Browse files Browse the repository at this point in the history
  • Loading branch information
ozgurakgun authored Oct 23, 2023
2 parents 98f1312 + e36ac05 commit 98af15e
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 39 deletions.
69 changes: 31 additions & 38 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 = []
96 changes: 96 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
use std::{cell::RefCell, rc::Rc};

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 = Rc::new(RefCell::new(DecisionVariable {
name: a,
domain: Domain::IntDomain(vec![Range::Bounded(1, 3)]),
}));
let b_decision_variable = Rc::new(RefCell::new(DecisionVariable {
name: b,
domain: Domain::IntDomain(vec![Range::Bounded(1, 3)]),
}));
let c_decision_variable = Rc::new(RefCell::new(DecisionVariable {
name: c,
domain: Domain::IntDomain(vec![Range::Bounded(1, 3)]),
}));

// find a,b,c : int(1..3)
// such that a + b + c = 4
// such that a >= b
let m = Model {
statements: vec![
Statement::Declaration(Rc::clone(&a_decision_variable)),
Statement::Declaration(Rc::clone(&b_decision_variable)),
Statement::Declaration(Rc::clone(&c_decision_variable)),
Statement::Constraint(Expression::Eq(
Box::from(Expression::Sum(vec![
Expression::Reference(Rc::clone(&a_decision_variable)),
Expression::Reference(Rc::clone(&b_decision_variable)),
Expression::Reference(Rc::clone(&c_decision_variable)),
])),
Box::from(Expression::ConstantInt(4)),
)),
Statement::Constraint(Expression::Geq(
Box::from(Expression::Reference(Rc::clone(&a_decision_variable))),
Box::from(Expression::Reference(Rc::clone(&b_decision_variable))),
)),
],
};

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

{
let mut decision_var_borrowed = a_decision_variable.borrow_mut();
decision_var_borrowed.domain = Domain::IntDomain(vec![Range::Bounded(1, 2)]);
}

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

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

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

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

#[derive(Debug)]
enum Statement {
Declaration(Rc<RefCell<DecisionVariable>>),
Constraint(Expression),
}

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

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

#[derive(Debug)]
enum Expression {
ConstantInt(i32),
Reference(Rc<RefCell<DecisionVariable>>),
Sum(Vec<Expression>),
Eq(Box<Expression>, Box<Expression>),
Geq(Box<Expression>, Box<Expression>),
}

0 comments on commit 98af15e

Please sign in to comment.