Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rust/bambam/src/model/frontier/multimodal/constraint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl MultimodalFrontierConstraint {
})?;
let n_legs = match active_mode {
Some(active_mode) if active_mode != edge_mode => n_existing_legs + 1,
_ => 0,
_ => n_existing_legs,
};
let is_valid = n_legs <= *max_legs;
Ok(is_valid)
Expand Down
38 changes: 38 additions & 0 deletions rust/bambam/src/model/frontier/multimodal/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -871,4 +871,42 @@
.expect("test failed");
assert!(!is_valid); // Should be invalid as this would create a second leg
}

#[test]
fn test_max_trip_legs_same_mode_continuation_at_limit() {

Check warning on line 876 in rust/bambam/src/model/frontier/multimodal/model.rs

View workflow job for this annotation

GitHub Actions / cargo test

Diff in /home/runner/work/bambam/bambam/rust/bambam/src/model/frontier/multimodal/model.rs
// Test that continuing with the same mode when at the limit is still invalid
// This tests the bug fix where same-mode continuation was always returning 0 legs

// max_trip_legs is the state buffer size, constraint is the actual limit
let max_trip_legs = 2; // State buffer can hold 2 legs
let constraint_limit = 1; // But we only allow 1 leg

let (bike_mtm, bike_mfm, state_model, mut state) = test_setup(
vec![MultimodalFrontierConstraint::MaxTripLegs(constraint_limit)],
"bike", // FrontierModel for bike edges
&["walk", "bike"],
&[],
max_trip_legs,
);

// Set up state with 2 legs: walk then bike (exceeds constraint_limit of 1)
inject_trip_legs(
&["walk", "bike"],
&mut state,
&state_model,
&bike_mtm.mode_to_state,
max_trip_legs,
);

// Test continuing with bike-mode edge (same as active mode)
// edge.edge_list_id doesn't matter since we're just checking constraints, not traversal
// The important thing is that bike_mfm has mode="bike" which matches active_mode="bike"
// Before the fix, this would incorrectly return n_legs=0 and be valid
// After the fix, this should correctly use n_existing_legs=2 and be invalid
let bike_edge = Edge::new(0, 0, 0, 1, Length::new::<uom::si::length::meter>(1000.0));
let is_valid = bike_mfm
.valid_frontier(&bike_edge, None, &state, &state_model)
.expect("test failed");
assert!(!is_valid); // Should be invalid as we already have 2 legs, which exceeds constraint_limit of 1
}
}
Loading