Skip to content

Conversation

@ppinchuk
Copy link
Collaborator

@ppinchuk ppinchuk commented Dec 6, 2025

One functionality we have in reVX that wasn't in reVRt yet is to have layers that don't get scaled by the distanced traversed in each cell.

For example, imagine you are moving a cable from underwater to above-ground. There is a one-time cost you must pay for that transition along the coast. This cost should not be scaled by the distance in the cell - it's juts a transition cost.

In this PR, I added functionality to the CostFunction to handle such layers. This includes a few new tests as well as fixing up older tests that were marked as dead code.

@ppinchuk ppinchuk added this to the 0.2.0 - Python MVP milestone Dec 6, 2025
@ppinchuk ppinchuk self-assigned this Dec 6, 2025
@ppinchuk ppinchuk requested a review from castelao as a code owner December 6, 2025 01:37
Copilot AI review requested due to automatic review settings December 6, 2025 01:37
@ppinchuk ppinchuk added enhancement Update to logic or general code improvements new computation Update that adds a new computation method p-high Priority: high topic-rust-routing Issues/pull requests related to rust routing code labels Dec 6, 2025
@codecov-commenter
Copy link

codecov-commenter commented Dec 6, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (6d4ddce) to head (8bcd342).

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #173   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           17        17           
  Lines         1392      1392           
  Branches       168       168           
=========================================
  Hits          1392      1392           
Flag Coverage Δ
unittests 100.00% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds support for length-invariant cost layers in reVRt's routing engine. These layers represent one-time transition costs that don't scale with the distance traveled through a cell (e.g., a fixed cost for transitioning from underwater to above-ground cable routes along a coastline).

Key Changes:

  • Extended CostLayer struct with an is_invariant field to mark layers as distance-independent
  • Refactored cost calculation to compute and store both invariant and distance-dependent costs in separate layers (/cost_invariant and /cost)
  • Updated neighbor cost retrieval to combine averaged distance-dependent costs with unscaled invariant costs
  • Activated and updated previously dead tests, adding comprehensive test coverage for the new invariant layer functionality

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
crates/revrt/src/dataset/lazy_subset.rs Fixed spelling errors in documentation ("unecessary" → "unnecessary", "assumtions" → "assumptions")
crates/revrt/src/dataset.rs Core implementation: added dual-layer cost storage, refactored cost calculation to handle both invariant and distance-scaled layers, extracted add_layer_to_data and get_neighbor_costs helper functions, and updated tests to verify correct behavior
crates/revrt/src/cost.rs Extended CostLayer with is_invariant field, updated compute method to filter layers by type, refactored layer building logic into separate function, and returns zero-filled arrays when no matching layers exist

@ppinchuk
Copy link
Collaborator Author

ppinchuk commented Dec 6, 2025

@castelao this is ready for review

Copy link
Member

@castelao castelao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ppinchuk , thanks for moving this ahead. Just to be clear, I'm aware that some of my comments are related with inherited code that I did it myself, i.e. I'm aware that it was my own fault. I would do a couple of things differently, but let's move this ahead and we can handle in smaller components in future PRs once I'm able to get back to this. Now that this system is a little bit better split in components, it will be easier to progress in small parts.

Thanks!

}
}

fn add_layer_to_data(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function should return a Result, so we could replace .unwrap() for ?. When parallelizing, we don't want that one failure to crash everything.

That said, there is so much still to improve that is totaly fine to leave it as it is for now and we will handle that later.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added here: 1188678

let cost_function =
CostFunction::from_json(r#"{"cost_layers": [{"layer_name": "A"}]}"#).unwrap();
let dataset =
Dataset::open(path, cost_function, 250_000_000).expect("Error opening dataset");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It shouldn't reach ~250MB, but since it is a test, let's play on the safe side and reduce this a lot?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added here: 0dd2217

@ppinchuk
Copy link
Collaborator Author

To saver time, I will merge now and add these suggestions into the other PR

@ppinchuk ppinchuk merged commit 5babf28 into main Dec 11, 2025
29 checks passed
@ppinchuk ppinchuk deleted the pp/update_cost_function branch December 11, 2025 23:15
@ppinchuk ppinchuk mentioned this pull request Dec 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Update to logic or general code improvements new computation Update that adds a new computation method p-high Priority: high topic-rust-routing Issues/pull requests related to rust routing code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants