Skip to content

Commit

Permalink
chore(cargo): fmt and clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
Shi-Raida committed Nov 20, 2023
1 parent 331b504 commit a0a8815
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 23 deletions.
16 changes: 12 additions & 4 deletions planning/planners/src/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1029,8 +1029,12 @@ fn encode_resource_constraints(

// Force the new assigned values to be in the state variable domain.
for &&(_, prez, eff) in &assignments {
let Type::Int { lb, ub } = eff.state_var.fluent.return_type() else { unreachable!() };
let EffectOp::Assign(val) = eff.operation else { unreachable!() };
let Type::Int { lb, ub } = eff.state_var.fluent.return_type() else {
unreachable!()
};
let EffectOp::Assign(val) = eff.operation else {
unreachable!()
};
let val: IAtom = val.try_into().expect("Not integer assignment to an int state variable");
solver.enforce(geq(val, lb), [prez]);
solver.enforce(leq(val, ub), [prez]);
Expand All @@ -1046,7 +1050,9 @@ fn encode_resource_constraints(
"Only instantaneous effects are supported"
);
// Get the bounds of the state variable.
let Type::Int { lb, ub } = eff.state_var.fluent.return_type() else { unreachable!() };
let Type::Int { lb, ub } = eff.state_var.fluent.return_type() else {
unreachable!()
};
// Create a new variable with those bounds.
let var = solver
.model
Expand Down Expand Up @@ -1150,7 +1156,9 @@ fn encode_resource_constraints(
debug_assert!(solver.model.entails(solver.model.presence_literal(li_lit.variable())));

// Get the `ci_j*` value.
let EffectOp::Increase(eff_val) = eff.operation.clone() else { unreachable!() };
let EffectOp::Increase(eff_val) = eff.operation.clone() else {
unreachable!()
};
(li_lit, eff_val)
})
.collect::<Vec<_>>()
Expand Down
2 changes: 1 addition & 1 deletion planning/planners/src/search/causal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl SearchControl<VarLabel> for ManualCausalSearch {
.collect();

for &(tag, lig) in &self.encoding.tags {
let Tag::Support(cond, eff) = tag else {continue };
let Tag::Support(cond, eff) = tag else { continue };
if !pending_conditions.contains(&cond) {
continue;
}
Expand Down
1 change: 1 addition & 0 deletions planning/unified/deps/planning-test-cases
Submodule planning-test-cases added at b76281
6 changes: 3 additions & 3 deletions solver/src/core/state/domains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ impl Domains {
self.implications.add_implication(from, to);
if self.entails(from) {
let prop_result = self.set_impl(to, DirectOrigin::ImplicationPropagation(from));
assert!(matches!(prop_result, Ok(_)), "{}", "Inconsistency on the addition of implies({from:?}, {to:?}");
assert!(prop_result.is_ok(), "{}", "Inconsistency on the addition of implies({from:?}, {to:?}");
}
if self.entails(!to) {
let prop_result = self.set_impl(!from, DirectOrigin::ImplicationPropagation(!to));
assert!(matches!(prop_result, Ok(_)), "{}", "Inconsistency on the addition of implies({from:?}, {to:?}");
assert!(prop_result.is_ok(), "{}", "Inconsistency on the addition of implies({from:?}, {to:?}");
}
}

Expand Down Expand Up @@ -980,6 +980,6 @@ mod tests {
assert_eq!(model.set_ub(x, 5, Cause::Decision), Ok(true));

model.save_state();
assert!(matches!(model.set_lb(i, 6, Cause::Decision), Err(_)));
assert!(model.set_lb(i, 6, Cause::Decision).is_err());
}
}
8 changes: 3 additions & 5 deletions solver/src/model/lang/linear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,7 @@ mod tests {

#[test]
fn test_sum_set_denom() {
let terms = vec![
let terms = [
LinearTerm::constant_rational(5, 28, Lit::TRUE),
LinearTerm::constant_rational(10, 77, Lit::TRUE),
];
Expand Down Expand Up @@ -1020,8 +1020,7 @@ mod tests {
assert_eq!(sum.denom, 100);

// Terms could have been reorganized
let expected_terms = vec![
// Constant terms without true lit, should be grouped
let expected_terms = [
LinearTerm::new(45, IVar::ONE, lit1, denom),
// Other variable terms no specificities, should be grouped by lit
LinearTerm::new(105, var1, lit0, denom),
Expand Down Expand Up @@ -1224,8 +1223,7 @@ mod tests {
assert_eq!(obj.upper_bound, -20);

// Terms could have been reorganized
let expected_sum = vec![
// Constant terms without true lit, should be grouped
let expected_sum = [
item(45, VarRef::ONE, lit1),
// Other variable terms no specificities, should be grouped by lit
item(105, var1, lit0),
Expand Down
2 changes: 1 addition & 1 deletion solver/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ mod tests {
println!("{x:?}");
}

let xs = vec!["x1", "x2"];
let xs = ["x1", "x2"];
let it = enumerate(vec![xs.iter()]);
assert_eq!(it.count(), 2);

Expand Down
2 changes: 1 addition & 1 deletion validator/src/interfaces/unified_planning/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1183,7 +1183,7 @@ mod tests {

#[test]
fn test_is_temporal() {
let features = vec![Feature::ContinuousTime, Feature::DiscreteTime];
let features = [Feature::ContinuousTime, Feature::DiscreteTime];
for (i, &feature) in features.iter().enumerate() {
let mut p = problem::mock_nontemporal();
assert!(!is_continuous_time(&p));
Expand Down
10 changes: 2 additions & 8 deletions validator/src/procedures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,11 @@ use anyhow::{bail, ensure, Context, Result};
pub type Procedure<E> = fn(&Env<E>, Vec<E>) -> Result<Value>;

pub fn and<E: Interpreter>(env: &Env<E>, args: Vec<E>) -> Result<Value> {
args.iter().fold(Ok(true.into()), |r, a| match r {
Ok(b) => b & a.eval(env)?,
Err(e) => Err(e),
})
args.iter().try_fold(true.into(), |r, a| r & a.eval(env)?)
}

pub fn or<E: Interpreter>(env: &Env<E>, args: Vec<E>) -> Result<Value> {
args.iter().fold(Ok(false.into()), |r, a| match r {
Ok(b) => b | a.eval(env)?,
Err(e) => Err(e),
})
args.iter().try_fold(false.into(), |r, a| r | a.eval(env)?)
}

pub fn not<E: Interpreter>(env: &Env<E>, args: Vec<E>) -> Result<Value> {
Expand Down

0 comments on commit a0a8815

Please sign in to comment.