torressa / cspy

A collection of algorithms for the (Resource) Constrained Shortest Path problem in Python / C++ / C#
https://torressa.github.io/cspy/
MIT License
77 stars 24 forks source link

Get cost and consumed resources #23

Closed torressa closed 4 years ago

torressa commented 4 years ago

Is your feature request related to a problem? Please describe. I don't like that the algorithms only return the path in a list, I would like the path cost and total resource consumption.

Describe the solution you'd like I would like the option to get the total_cost attribute, and the consumed_resources attribute. I would like to access them as for e.g.

algorithm(args).run()
# Finds shortest path with resource constraints
algorithm.path
algorithm.total_cost
algorithm.consumed_resources

Describe alternatives you've considered Adding them as class attributes would mean implementing an appropriate destructor __del__ operator to avoid weird behaviour.

Additional context Similar to networkx's shortest_path and shortest_path_length

torressa commented 4 years ago

Created a branch for this, initially all should be alright except BiDirectional which requires some additional checks. Particularly both when getting the total resource usage of from a backward path https://github.com/torressa/cspy/blob/ef3e9663ce23d3e39d66ac6fcf1088ea3dde36d8/cspy/algorithms/bidirectional.py#L428 and when joining https://github.com/torressa/cspy/blob/ef3e9663ce23d3e39d66ac6fcf1088ea3dde36d8/cspy/algorithms/bidirectional.py#L480 Need to be extended to use the REF if provided