Skip to content

Commit

Permalink
fix(up): Add missing substitution of duration bounds in constraints.
Browse files Browse the repository at this point in the history
  • Loading branch information
Shi-Raida committed Feb 22, 2023
1 parent 917d259 commit 1722ccc
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
4 changes: 2 additions & 2 deletions planning/grpc/server/src/chronicles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1033,9 +1033,9 @@ fn read_action(
.as_ref()
.with_context(|| "Duration without an upper bound")?;

// cannot use try_into() because the denom is set to 1
// FIXME (Roland) The default try_into() method use a denom of 1. The TIME_SCALE constant is not is the scope of model, so it is not accessible in the try_into().
let atom_to_fatom = |value| match value {
Atom::Int(i) => Ok(FAtom::new((i.shift * TIME_SCALE).into(), TIME_SCALE)),
Atom::Int(i) => Ok(FAtom::new(i, TIME_SCALE)),
Atom::Fixed(f) => Ok(f),
_ => bail!("Cannot convert {value:?} into a FAtom"),
};
Expand Down
11 changes: 4 additions & 7 deletions planning/planners/src/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -534,11 +534,10 @@ pub fn encode(pb: &FiniteProblem, metric: Option<Metric>) -> anyhow::Result<(Mod
ConstraintType::Lt => match constraint.variables.as_slice() {
&[a, b] => {
let into_fatom = |value: Atom| match value {
// FIXME (Roland) The default try_into() method use a denom of 1.
// The TIME_SCALE constant is not is the scope of model, so it is not accessible in the try_into().
// FIXME (Roland) The default try_into() method use a denom of 1. The TIME_SCALE constant is not is the scope of model, so it is not accessible in the try_into().
Atom::Int(i) => Ok(FAtom::new(i, TIME_SCALE)),
Atom::Fixed(f) => Ok(f),
_ => bail!("Only IAtom and FAtom can be converted into FAtom"),
_ => bail!("Cannot convert {value:?} into a FAtom"),
};
let a: FAtom = into_fatom(a)?;
let b: FAtom = into_fatom(b)?;
Expand All @@ -565,10 +564,8 @@ pub fn encode(pb: &FiniteProblem, metric: Option<Metric>) -> anyhow::Result<(Mod
model.bind(neq(constraint.variables[0], constraint.variables[1]), value);
}
ConstraintType::Duration(dur) => {
let build_term = |val: FAtom, f: i32| LinearTerm::new(f, val.num.var, true);
let build_sum = |start, end, dur| {
LinearSum::of(vec![build_term(start, -1), build_term(end, 1), build_term(dur, -1)])
};
let build_term = |val: FAtom| LinearTerm::new(1, val.num.var, true);
let build_sum = |s, e, d| LinearSum::of(vec![-build_term(s), build_term(e), -build_term(d)]);

let start = instance.chronicle.start;
let end = instance.chronicle.end;
Expand Down
2 changes: 1 addition & 1 deletion planning/planners/src/solver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub fn solve(
deadline: Option<Instant>,
) -> Result<SolverResult<(Arc<FiniteProblem>, Arc<Domains>)>> {
println!("===== Preprocessing ======");
aries_planning::chronicles::preprocessing::preprocess(&mut base_problem);
// aries_planning::chronicles::preprocessing::preprocess(&mut base_problem);
println!("==========================");

let start = Instant::now();
Expand Down
15 changes: 14 additions & 1 deletion planning/planning/src/chronicles/constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl Substitute for Constraint {
fn substitute(&self, substitution: &impl Substitution) -> Self {
Constraint {
variables: self.variables.iter().map(|i| substitution.sub(*i)).collect(),
tpe: self.tpe.clone(),
tpe: self.tpe.substitute(substitution),
value: self.value.map(|v| substitution.sub_lit(v)),
}
}
Expand All @@ -102,6 +102,19 @@ pub enum ConstraintType {
Or,
}

impl Substitute for ConstraintType {
fn substitute(&self, substitution: &impl Substitution) -> Self {
match self {
Duration(Duration::Fixed(f)) => ConstraintType::Duration(Duration::Fixed(substitution.fsub(*f))),
Duration(Duration::Bounded { lb, ub }) => ConstraintType::Duration(Duration::Bounded {
lb: substitution.fsub(*lb),
ub: substitution.fsub(*ub),
}),
InTable(_) | Lt | Eq | Neq | Or => self.clone(), // no variables in those variants
}
}
}

/// A set of tuples, representing the allowed values in a table constraint.
#[derive(Clone)]
#[allow(dead_code)]
Expand Down

0 comments on commit 1722ccc

Please sign in to comment.