Builder first iteration: bool constraints
This commit is contained in:
committed by
Guillaume P
parent
adcc1d638b
commit
86cca97c1e
@@ -1,40 +1,19 @@
|
||||
use cp_sat::proto::{
|
||||
constraint_proto::Constraint, AllDifferentConstraintProto, ConstraintProto, CpModelProto,
|
||||
IntegerVariableProto,
|
||||
};
|
||||
|
||||
fn main() {
|
||||
let model = CpModelProto {
|
||||
variables: vec![
|
||||
IntegerVariableProto {
|
||||
name: "x".into(),
|
||||
domain: vec![0, 2],
|
||||
},
|
||||
IntegerVariableProto {
|
||||
name: "y".into(),
|
||||
domain: vec![0, 2],
|
||||
},
|
||||
IntegerVariableProto {
|
||||
name: "z".into(),
|
||||
domain: vec![0, 2],
|
||||
},
|
||||
],
|
||||
constraints: vec![ConstraintProto {
|
||||
constraint: Some(Constraint::AllDiff(AllDifferentConstraintProto {
|
||||
vars: vec![0, 1, 2],
|
||||
})),
|
||||
..Default::default()
|
||||
}],
|
||||
..Default::default()
|
||||
};
|
||||
let mut model = cp_sat::builder::CpModelBuilder::default();
|
||||
let x = model.new_int_var_with_name([(0, 2)], "x");
|
||||
let y = model.new_int_var_with_name([(0, 2)], "y");
|
||||
let z = model.new_int_var_with_name([(0, 2)], "z");
|
||||
model.add_all_different([x, y, z]);
|
||||
println!("{:#?}", model);
|
||||
|
||||
println!("model stats: {}", cp_sat::cp_model_stats(&model));
|
||||
|
||||
let response = cp_sat::solve(&model);
|
||||
println!("model stats: {}", model.stats());
|
||||
let response = model.solve();
|
||||
println!("{:#?}", response);
|
||||
println!(
|
||||
"response stats: {}",
|
||||
cp_sat::cp_solver_response_stats(&response, false)
|
||||
);
|
||||
assert_eq!(response.status(), cp_sat::proto::CpSolverStatus::Optimal);
|
||||
assert!(x.solution_value(&response) != y.solution_value(&response));
|
||||
assert!(x.solution_value(&response) != z.solution_value(&response));
|
||||
assert!(y.solution_value(&response) != z.solution_value(&response));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user