Skip to content

Commit

Permalink
because it is sometimes useful, the transition cost function now has …
Browse files Browse the repository at this point in the history
…an access to the target node that is reached
  • Loading branch information
xgillard committed Feb 22, 2024
1 parent 1752b1e commit d5adf2e
Show file tree
Hide file tree
Showing 23 changed files with 41 additions and 41 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ddo/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ddo"
version = "1.2.0"
version = "2.0.0"
authors = ["Xavier Gillard <xavier.gillard@uclouvain.be>"]
edition = "2021"
description = "DDO a generic and efficient framework for MDD-based optimization."
Expand Down
2 changes: 1 addition & 1 deletion ddo/examples/alp/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ impl Problem for Alp {
}
}

fn transition_cost(&self, state: &Self::State, decision: ddo::Decision) -> isize {
fn transition_cost(&self, state: &Self::State, _: &Self::State, decision: ddo::Decision) -> isize {
if decision.value == DUMMY {
0
} else {
Expand Down
2 changes: 1 addition & 1 deletion ddo/examples/golomb/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl Problem for Golomb {
}

// compute the cost of the decision from the given state
fn transition_cost(&self, state: &Self::State, dec: Decision) -> isize {
fn transition_cost(&self, state: &Self::State, _: &Self::State, dec: Decision) -> isize {
// distance between the new mark and the previous one
-(dec.value - state.last_mark) // put a minus to turn objective into maximization (ddo requirement)
}
Expand Down
2 changes: 1 addition & 1 deletion ddo/examples/knapsack/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl Problem for Knapsack {
}
ret
}
fn transition_cost(&self, _state: &Self::State, dec: Decision) -> isize {
fn transition_cost(&self, _state: &Self::State, _: &Self::State, dec: Decision) -> isize {
self.profit[dec.variable.id()] * dec.value
}

Expand Down
2 changes: 1 addition & 1 deletion ddo/examples/lcs/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ impl Problem for Lcs {
LcsState { position }
}

fn transition_cost(&self, _: &Self::State, decision: ddo::Decision) -> isize {
fn transition_cost(&self, _: &Self::State, _: &Self::State, decision: ddo::Decision) -> isize {
match decision.value {
GO_TO_END_OF_STRINGS => 0,
_ => 1,
Expand Down
2 changes: 1 addition & 1 deletion ddo/examples/max2sat/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ impl Problem for Max2Sat {
ret
}

fn transition_cost(&self, state: &State, d: Decision) -> isize {
fn transition_cost(&self, state: &State, _: &Self::State, d: Decision) -> isize {
let k = d.variable;
let vars = self.varset(state);
if d.value == F {
Expand Down
2 changes: 1 addition & 1 deletion ddo/examples/mcp/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl Problem for Mcp {
McpState {depth: 1 + state.depth, benef: benefits}
}

fn transition_cost(&self, state: &McpState, d: Decision) -> isize {
fn transition_cost(&self, state: &McpState, _: &Self::State, d: Decision) -> isize {
match d.value {
S => if state.depth == 0 { 0 } else { self.branch_on_s(state, d) },
T => if state.depth == 0 { 0 } else { self.branch_on_t(state, d) },
Expand Down
2 changes: 1 addition & 1 deletion ddo/examples/misp/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl Problem for Misp {
res
}

fn transition_cost(&self, _: &Self::State, decision: Decision) -> isize {
fn transition_cost(&self, _: &Self::State, _: &Self::State, decision: Decision) -> isize {
if decision.value == NO {
0
} else {
Expand Down
2 changes: 1 addition & 1 deletion ddo/examples/psp/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl Problem for Psp {
ret
}

fn transition_cost(&self, state: &Self::State, decision: ddo::Decision) -> isize {
fn transition_cost(&self, state: &Self::State, _: &Self::State, decision: ddo::Decision) -> isize {
if decision.value == IDLE {
0
} else {
Expand Down
2 changes: 1 addition & 1 deletion ddo/examples/sop/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ impl Problem for Sop {
next
}

fn transition_cost(&self, state: &SopState, d: Decision) -> isize {
fn transition_cost(&self, state: &SopState, _: &Self::State, d: Decision) -> isize {
// Sop is a minimization problem but the solver works with a
// maximization perspective. So we have to negate the cost.

Expand Down
2 changes: 1 addition & 1 deletion ddo/examples/srflp/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ impl Problem for Srflp {
}
}

fn transition_cost(&self, state: &SrflpState, d: Decision) -> isize {
fn transition_cost(&self, state: &SrflpState, _: &Self::State, d: Decision) -> isize {
let d = d.value as usize;

let mut cut = 0;
Expand Down
2 changes: 1 addition & 1 deletion ddo/examples/talentsched/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ impl Problem for TalentSched {
ret
}

fn transition_cost(&self, state: &Self::State, decision: ddo::Decision) -> isize {
fn transition_cost(&self, state: &Self::State, _: &Self::State, decision: ddo::Decision) -> isize {
let scene = decision.value as usize;

let pay = self.get_present(state).diff(self.actors[scene]);
Expand Down
2 changes: 1 addition & 1 deletion ddo/examples/tsptw/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ impl Problem for Tsptw {
}
}

fn transition_cost(&self, state: &TsptwState, d: Decision) -> isize {
fn transition_cost(&self, state: &TsptwState, _: &Self::State, d: Decision) -> isize {
// Tsptw is a minimization problem but the solver works with a
// maximization perspective. So we have to negate the min if we want to
// yield a lower bound.
Expand Down
2 changes: 1 addition & 1 deletion ddo/examples/visualisation/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl Problem for Knapsack {
}
ret
}
fn transition_cost(&self, _state: &Self::State, dec: Decision) -> isize {
fn transition_cost(&self, _state: &Self::State, _: &Self::State, dec: Decision) -> isize {
self.profit[dec.variable.id()] as isize * dec.value
}

Expand Down
4 changes: 2 additions & 2 deletions ddo/src/abstraction/dp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub trait Problem {
fn transition(&self, state: &Self::State, decision: Decision) -> Self::State;
/// This method is an implementation of the transition cost function mentioned
/// in the mathematical model of a DP formulation for some problem.
fn transition_cost(&self, state: &Self::State, decision: Decision) -> isize;
fn transition_cost(&self, source: &Self::State, dest: &Self::State, decision: Decision) -> isize;
/// Any problem needs to be able to specify an ordering on the variables
/// in order to decide which variable should be assigned next. This choice
/// is an **heuristic** choice. The variable ordering does not need to be
Expand Down Expand Up @@ -165,7 +165,7 @@ mod tests {
fn transition(&self, _: &Self::State, _: Decision) -> Self::State {
todo!()
}
fn transition_cost(&self, _: &Self::State, _: Decision) -> isize {
fn transition_cost(&self, _: &Self::State, _: &Self::State, _: Decision) -> isize {
todo!()
}
fn next_variable(&self, _: usize, _: &mut dyn Iterator<Item = &Self::State>)
Expand Down
4 changes: 2 additions & 2 deletions ddo/src/implementation/heuristics/cutoff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ use crate::Cutoff;
/// # }
/// # ret
/// # }
/// # fn transition_cost(&self, _state: &Self::State, dec: Decision) -> isize {
/// # fn transition_cost(&self, _state: &Self::State, _next: &Self::State, dec: Decision) -> isize {
/// # self.profit[dec.variable.id()] as isize * dec.value
/// # }
/// # fn next_variable(&self, depth: usize, next_layer: &mut dyn Iterator<Item = &Self::State>) -> Option<Variable> {
Expand Down Expand Up @@ -212,7 +212,7 @@ impl Cutoff for NoCutoff {
/// # }
/// # ret
/// # }
/// # fn transition_cost(&self, _state: &Self::State, dec: Decision) -> isize {
/// # fn transition_cost(&self, _state: &Self::State, _: &Self::State, dec: Decision) -> isize {
/// # self.profit[dec.variable.id()] as isize * dec.value
/// # }
/// # fn next_variable(&self, depth: usize, _: &mut dyn Iterator<Item = &Self::State>) -> Option<Variable> {
Expand Down
14 changes: 7 additions & 7 deletions ddo/src/implementation/heuristics/width.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ use crate::{WidthHeuristic, SubProblem};
/// # }
/// # ret
/// # }
/// # fn transition_cost(&self, _state: &Self::State, dec: Decision) -> isize {
/// # fn transition_cost(&self, _state: &Self::State, _next: &Self::State, dec: Decision) -> isize {
/// # self.profit[dec.variable.id()] as isize * dec.value
/// # }
/// # fn next_variable(&self, depth: usize, next_layer: &mut dyn Iterator<Item = &Self::State>) -> Option<Variable> {
Expand Down Expand Up @@ -223,7 +223,7 @@ impl <X> WidthHeuristic<X> for FixedWidth {
/// # }
/// # ret
/// # }
/// # fn transition_cost(&self, _state: &Self::State, dec: Decision) -> isize {
/// # fn transition_cost(&self, _state: &Self::State, _next: &Self::State, dec: Decision) -> isize {
/// # self.profit[dec.variable.id()] as isize * dec.value
/// # }
/// # fn next_variable(&self, depth: usize, _: &mut dyn Iterator<Item = &Self::State>) -> Option<Variable> {
Expand Down Expand Up @@ -312,7 +312,7 @@ impl <X> WidthHeuristic<X> for FixedWidth {
/// # }
/// # ret
/// # }
/// # fn transition_cost(&self, _state: &Self::State, dec: Decision) -> isize {
/// # fn transition_cost(&self, _state: &Self::State, _next: &Self::State, dec: Decision) -> isize {
/// # self.profit[dec.variable.id()] as isize * dec.value
/// # }
/// # fn next_variable(&self, depth: usize, _: &mut dyn Iterator<Item = &Self::State>) -> Option<Variable> {
Expand Down Expand Up @@ -462,7 +462,7 @@ impl <X> WidthHeuristic<X> for NbUnassignedWidth {
/// # }
/// # ret
/// # }
/// # fn transition_cost(&self, _state: &Self::State, dec: Decision) -> isize {
/// # fn transition_cost(&self, _state: &Self::State, _next: &Self::State, dec: Decision) -> isize {
/// # self.profit[dec.variable.id()] as isize * dec.value
/// # }
/// # fn next_variable(&self, depth: usize, next_layer: &mut dyn Iterator<Item = &Self::State>) -> Option<Variable> {
Expand Down Expand Up @@ -551,7 +551,7 @@ impl <X> WidthHeuristic<X> for NbUnassignedWidth {
/// # }
/// # ret
/// # }
/// # fn transition_cost(&self, _state: &Self::State, dec: Decision) -> isize {
/// # fn transition_cost(&self, _state: &Self::State, _next: &Self::State, dec: Decision) -> isize {
/// # self.profit[dec.variable.id()] as isize * dec.value
/// # }
/// # fn next_variable(&self, depth: usize, next_layer: &mut dyn Iterator<Item = &Self::State>) -> Option<Variable> {
Expand Down Expand Up @@ -702,7 +702,7 @@ impl <S, X: WidthHeuristic<S>> WidthHeuristic<S> for Times<X> {
/// # }
/// # ret
/// # }
/// # fn transition_cost(&self, _state: &Self::State, dec: Decision) -> isize {
/// # fn transition_cost(&self, _state: &Self::State, _next: &Self::State, dec: Decision) -> isize {
/// # self.profit[dec.variable.id()] as isize * dec.value
/// # }
/// # fn next_variable(&self, depth: usize, _: &mut dyn Iterator<Item = &Self::State>) -> Option<Variable> {
Expand Down Expand Up @@ -791,7 +791,7 @@ impl <S, X: WidthHeuristic<S>> WidthHeuristic<S> for Times<X> {
/// # }
/// # ret
/// # }
/// # fn transition_cost(&self, _state: &Self::State, dec: Decision) -> isize {
/// # fn transition_cost(&self, _state: &Self::State, _next: &Self::State, dec: Decision) -> isize {
/// # self.profit[dec.variable.id()] as isize * dec.value
/// # }
/// # fn next_variable(&self, depth: usize, _: &mut dyn Iterator<Item = &Self::State>) -> Option<Variable> {
Expand Down
8 changes: 4 additions & 4 deletions ddo/src/implementation/mdd/clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ where
) {
let state = get!(node from_id, self).state.as_ref();
let next_state = Arc::new(problem.transition(state, decision));
let cost = problem.transition_cost(state, decision);
let cost = problem.transition_cost(state, next_state.as_ref(), decision);

match self.next_l.entry(next_state.clone()) {
Entry::Vacant(e) => {
Expand Down Expand Up @@ -2128,7 +2128,7 @@ mod test_default_mdd {
}
}

fn transition_cost(&self, _: &char, d: Decision) -> isize {
fn transition_cost(&self, _: &char, _: &Self::State, d: Decision) -> isize {
d.value
}
}
Expand Down Expand Up @@ -2567,7 +2567,7 @@ mod test_default_mdd {
}
}

fn transition_cost(&self, _: &Self::State, decision: crate::Decision) -> isize {
fn transition_cost(&self, _: &Self::State, _: &Self::State, decision: crate::Decision) -> isize {
decision.value
}

Expand Down Expand Up @@ -2608,7 +2608,7 @@ mod test_default_mdd {
}
}

fn transition_cost(&self, _: &Self::State, decision: crate::Decision) -> isize {
fn transition_cost(&self, _: &Self::State, _: &Self::State, decision: crate::Decision) -> isize {
decision.value
}

Expand Down
8 changes: 4 additions & 4 deletions ddo/src/implementation/mdd/pooled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ where
) {
let state = get!(node from_id, self).state.as_ref();
let next_state = Arc::new(problem.transition(state, decision));
let cost = problem.transition_cost(state, decision);
let cost = problem.transition_cost(state, next_state.as_ref(), decision);

match self.pool.entry(next_state.clone()) {
Entry::Vacant(e) => {
Expand Down Expand Up @@ -2045,7 +2045,7 @@ mod test_default_mdd {
}
}

fn transition_cost(&self, _: &char, d: Decision) -> isize {
fn transition_cost(&self, _: &char, _: &Self::State, d: Decision) -> isize {
d.value
}
}
Expand Down Expand Up @@ -2423,7 +2423,7 @@ mod test_default_mdd {
}
}

fn transition_cost(&self, _: &Self::State, decision: crate::Decision) -> isize {
fn transition_cost(&self, _: &Self::State, _: &Self::State, decision: crate::Decision) -> isize {
decision.value
}

Expand Down Expand Up @@ -2464,7 +2464,7 @@ mod test_default_mdd {
}
}

fn transition_cost(&self, _: &Self::State, decision: crate::Decision) -> isize {
fn transition_cost(&self, _: &Self::State, _: &Self::State, decision: crate::Decision) -> isize {
decision.value
}

Expand Down
4 changes: 2 additions & 2 deletions ddo/src/implementation/solver/parallel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ enum WorkLoad<T> {
/// # }
/// # ret
/// # }
/// # fn transition_cost(&self, _state: &Self::State, dec: Decision) -> isize {
/// # fn transition_cost(&self, _state: &Self::State, _next: &Self::State, dec: Decision) -> isize {
/// # self.profit[dec.variable.id()] as isize * dec.value
/// # }
/// # fn next_variable(&self, depth: usize, _: &mut dyn Iterator<Item = &Self::State>) -> Option<Variable> {
Expand Down Expand Up @@ -1281,7 +1281,7 @@ mod test_solver {
}
ret
}
fn transition_cost(&self, _state: &Self::State, dec: Decision) -> isize {
fn transition_cost(&self, _state: &Self::State, _: &Self::State, dec: Decision) -> isize {
self.profit[dec.variable.id()] as isize * dec.value
}
fn next_variable(&self, depth: usize, _: &mut dyn Iterator<Item = &Self::State>) -> Option<Variable> {
Expand Down
4 changes: 2 additions & 2 deletions ddo/src/implementation/solver/sequential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ enum WorkLoad<T> {
/// # }
/// # ret
/// # }
/// # fn transition_cost(&self, _state: &Self::State, dec: Decision) -> isize {
/// # fn transition_cost(&self, _state: &Self::State, _next: &Self::State, dec: Decision) -> isize {
/// # self.profit[dec.variable.id()] as isize * dec.value
/// # }
/// # fn next_variable(&self, depth: usize, _: &mut dyn Iterator<Item = &Self::State>) -> Option<Variable> {
Expand Down Expand Up @@ -1035,7 +1035,7 @@ mod test_solver {
}
ret
}
fn transition_cost(&self, _state: &Self::State, dec: Decision) -> isize {
fn transition_cost(&self, _state: &Self::State, _: &Self::State, dec: Decision) -> isize {
self.profit[dec.variable.id()] as isize * dec.value
}
fn next_variable(&self, depth: usize, _: &mut dyn Iterator<Item = &Self::State>) -> Option<Variable> {
Expand Down
6 changes: 3 additions & 3 deletions ddo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
//! // This method is analogous to the transition function. But instead to returning
//! // the next state when a decision is made, it returns the "cost", that is the
//! // impact of making that decision on the objective function.
//! fn transition_cost(&self, _state: &Self::State, dec: Decision) -> isize {
//! fn transition_cost(&self, _state: &Self::State, _next: &Self::State, dec: Decision) -> isize {
//! self.profit[dec.variable.id()] as isize * dec.value
//! }
//! // This method is used to determine the order in which the variables will be branched
Expand Down Expand Up @@ -225,7 +225,7 @@
//! # }
//! # ret
//! # }
//! # fn transition_cost(&self, _state: &Self::State, dec: Decision) -> isize {
//! # fn transition_cost(&self, _state: &Self::State, _next: &Self::State, dec: Decision) -> isize {
//! # self.profit[dec.variable.id()] as isize * dec.value
//! # }
//! # fn next_variable(&self, depth: usize, _: &mut dyn Iterator<Item = &Self::State>) -> Option<Variable> {
Expand Down Expand Up @@ -349,7 +349,7 @@
//! # }
//! # ret
//! # }
//! # fn transition_cost(&self, _state: &Self::State, dec: Decision) -> isize {
//! # fn transition_cost(&self, _state: &Self::State, _next: &Self::State, dec: Decision) -> isize {
//! # self.profit[dec.variable.id()] as isize * dec.value
//! # }
//! # fn next_variable(&self, depth: usize, _: &mut dyn Iterator<Item = &Self::State>) -> Option<Variable> {
Expand Down

0 comments on commit d5adf2e

Please sign in to comment.