#[cfg(feature = "flatzinc")]
pub mod flatzinc;
use pindakaas::solver::propagation::ExternalPropagation;
use crate::{
IntVal,
lower::LoweringMap,
model::View,
solver::{
Solver,
branchers::{
BoolBrancher, DecisionSelection, DomainSelection, IntBrancher, WarmStartBrancher,
},
},
};
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
#[non_exhaustive]
pub enum AnyView {
Bool(View<bool>),
Int(View<IntVal>),
}
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
#[non_exhaustive]
pub enum Branching {
Bool(Vec<View<bool>>, DecisionSelection, DomainSelection),
Int(Vec<View<IntVal>>, DecisionSelection, DomainSelection),
Seq(Vec<Branching>),
WarmStart(Vec<View<bool>>),
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[non_exhaustive]
pub enum Goal<V> {
Minimize(V),
Maximize(V),
}
impl From<View<IntVal>> for AnyView {
fn from(value: View<IntVal>) -> Self {
Self::Int(value)
}
}
impl From<View<bool>> for AnyView {
fn from(value: View<bool>) -> Self {
Self::Bool(value)
}
}
impl Branching {
pub fn to_solver<Sat: ExternalPropagation>(&self, slv: &mut Solver<Sat>, map: &LoweringMap) {
match self {
Branching::Bool(vars, var_sel, val_sel) => {
let vars = vars.iter().map(|v| map.get(slv, *v)).collect();
BoolBrancher::new_in(slv, vars, *var_sel, *val_sel);
}
Branching::Int(v, var_sel, val_sel) => {
let vars: Vec<_> = v.iter().map(|v| map.get(slv, *v)).collect();
IntBrancher::new_in(slv, vars, *var_sel, *val_sel);
}
Branching::Seq(branchings) => {
for b in branchings {
b.to_solver(slv, map);
}
}
Branching::WarmStart(exprs) => {
let decisions = exprs.iter().map(|v| map.get(slv, *v)).collect();
WarmStartBrancher::new_in(slv, decisions);
}
}
}
}