RuCos is an extremely high-performance parallel constraint solver implemented by Rust.
RustMIT
Rust Constraint Solver(RuCos)
RuCos is an extremely high-performance parallel constraint solver implemented by Rust.
RuCos is implemented by safe, elegant and lower-level code with zero-cost abstraction.
RuCos is a total Test-Driven developed open source solver.
I have implemented an XCSP3 parser whose repo is xcsp3-rust.
I will implement the main part of the solver and some typical types of constraints first.
The process of implementing the solver could take years, but I will keep updating....
Usage
define the problem
you can define the problem with the following code:
fnmain(){let problem = Problem::new();}
or the following code:
fnmain(){let problem = Default::default();}
or the following code:
fnmain(){let problem = problem!();}
define the variables
fnmain(){let problem = problem!();
problem += var!("var1"; 1=> 10);
problem += var!("var2";1=> 10);
problem += var!("var3";1=> 10);
problem += all_different!(
&problem["var1"],
&problem["var2"],
&problem["var3"]);}
you can define the variables with following code:
fnmain(){letmut problem = problem!();let v1 = var!(&mut problem; "v1"; domain![7, 43, 22, 33, 2234]);let v2 = var!(&mut problem; "v2"; domain![7, 43, 22, 33, 2234, 43]);let v3 = var!(&mut problem; "v3"; 7, 43, 22, 33, 2234, 43);let v4 = var!(&mut problem; "v4"; 1=>100);let v4 = var!(&mut problem; "v5"; domain![1=>1000]);
problem += var!("v4"; 7=> 43);
problem += var!("v5";7, 54, 65, 43);
problem += var!("v6"; 7=> 43);
problem += bool!("v5");
problem += bool!("v6");
problem += bool!("vbool_1");
problem += bool!("vbool_2");
problem += bool!();// you can get the variables by following code:println!("{}",problem["v1"]);println!("{}",problem["v4"]);println!("{}",problem["v5"]);println!("{}",problem[0]);}
define the constraints
you can define the constraint with following code:
fnmain(){letmut problem = problem!();for i in0..n {
problem += var!(&format!("row_{}"; &i), 0=>(n asi32));}
problem += all_different!(
&problem[format!("row_{}", i).as_str()],
&problem[i],
);}
the n-queen problem(may not n-queen😃) can be modelled by following code:
fnn_queens(n:usize) -> Problem{letmut problem = problem!();for i in0..n {
problem += var!(&format!("row_{}"; &i), 0=>(n asi32));}for i in0..n {for j in i + 1..n {
problem += all_different!(
&problem[format!("row_{}", i).as_str()],
&problem[j]);}}
problem
}