Conversation
The waypoint.py file was previously added in a commit, because it was rebased from another branch that used waypoint.py before it was removed from the repo.
| from .common.modules.position_global import PositionGlobal | ||
|
|
||
| # Earth radius in meters | ||
| EARTH_RADIUS = 6378137 |
There was a problem hiding this comment.
Good job breaking this out to a constant
|
|
||
|
|
||
| def waypoint_distance(point_1: PositionGlobal, point_2: PositionGlobal) -> "tuple[bool, float]": | ||
| """Return the great-circle distance of two points Earth, using Haversine's |
There was a problem hiding this comment.
TIL that we don't have an accepted format for docstrings 💀. Nothing to change here but just a quirk we didn't care to catch in prev PRs.
| if not success: | ||
| return False, None | ||
|
|
||
| for permutation in itertools.permutations(sorted_buckets): |
There was a problem hiding this comment.
If we're doing permutations why are we sorting the buckets
There was a problem hiding this comment.
oh LOL coming from C++ I thought the list must be sorted to iterate over all possible permutations.
There was a problem hiding this comment.
oh wait, no, I must sort them so that I return the smallest path, sorted based on (latitude, longitude)
There was a problem hiding this comment.
I don't think I follow? You check for every permutation whether the current path is the shortest, this would include the sorted permutation so we're going to cover that anyways.
like for example the lists [1, 2, 3] and [2, 3, 1] have the same permutations:
1, 2, 3 -- list one
1, 3, 2
2, 1, 3
2, 3, 1 -- list two
3, 1, 2
3, 2, 1
| buckets = [ | ||
| PositionGlobal.create(1, 1, 1)[1], | ||
| PositionGlobal.create(1.001, 1.001, 1)[1], | ||
| PositionGlobal.create(20, 20, 1)[1], |
There was a problem hiding this comment.
Make this way point negative (opposite direction of the first 2)
| @@ -0,0 +1,101 @@ | |||
| """ | |||
| Find the optimal itinerary if we wish to distribute water from a water source to | |||
There was a problem hiding this comment.
change docstring to match module name, also set up the bucket "analogy" if you want to continue using it for the rest of the module.
There was a problem hiding this comment.
Whoops, that's my bad. Sorry for the oversight.
| def find_optimal_path( | ||
| origin: PositionGlobal, buckets: "list[PositionGlobal]", buckets_at_once: int = 2 | ||
| ) -> "list[PositionGlobal]": | ||
| """Find an optimal itinerary of waypoints by going through all permutations |
There was a problem hiding this comment.
Make docstring general or set up bucket "analogy"
| assert path == [origin, buckets[0], buckets[1], buckets[2], origin] | ||
|
|
||
|
|
||
| def test_2_buckets_at_once() -> None: |
There was a problem hiding this comment.
This test fails when I run it locally, I will try to debug on my side but you should check it on your PC as well.
FAILED tests/unit/test_visit_waypoints_from_origin.py::test_2_buckets_at_once - AssertionError: assert [<class 'modules.common.modules.position_global.PositionGlobal'>: latitude: 43.47073179293396, longitude: -80.53501978862127, altitude: 1, <class 'modules.common.modules.position_global.PositionGlobal'>: latitude: 43.47076658531946, longitude: -80.54311788821606, altitude: 1, <class 'modules.common.modules.position_global.PositionGlobal'>: latitude: 43.4715312632625, longitude: -80.54211697668684, altitude: 1, <class 'modules.common.modules.position_global.PositionGlobal'>: latitude: 43.47073179293396, longitude: -80.53501978862127, altitude: 1, <class 'modules.common.modules.position_global.PositionGlobal'>: latitude: 43.46983001550084, longitude: -80.5422570409521, altitude: 1, <class 'modules.common.modules.position_global.PositionGlobal'>: latitude: 43.46834804571286, longitude: -80.54341048064786, altitude: 1, <class 'modules.common.modules.position_global.PositionGlobal'>: latitude: 43.47073179293396, longitude: -80.53501978862127, altitude: 1, <class 'modules.common.modules.position_global.PositionGlobal'>: latitude: 43.46925477790072, longitude: -80.54034107786745, altitude: 1, <class 'modules.common.modules.position_global.PositionGlobal'>: latitude: 43.47073179293396, longitude: -80.53501978862127, altitude: 1] == [<class 'modules.common.modules.position_global.PositionGlobal'>: latitude: 43.47073179293396, longitude: -80.53501978862127, altitude: 1, <class 'modules.common.modules.position_global.PositionGlobal'>: latitude: 43.47076658531946, longitude: -80.54311788821606, altitude: 1, <class 'modules.common.modules.position_global.PositionGlobal'>: latitude: 43.4715312632625, longitude: -80.54211697668684, altitude: 1, <class 'modules.common.modules.position_global.PositionGlobal'>: latitude: 43.47073179293396, longitude: -80.53501978862127, altitude: 1, <class 'modules.common.modules.position_global.PositionGlobal'>: latitude: 43.46834804571286, longitude: -80.54341048064786, altitude: 1, <class 'modules.common.modules.position_global.PositionGlobal'>: latitude: 43.46983001550084, longitude: -80.5422570409521, altitude: 1, <class 'modules.common.modules.position_global.PositionGlobal'>: latitude: 43.47073179293396, longitude: -80.53501978862127, altitude: 1, <class 'modules.common.modules.position_global.PositionGlobal'>: latitude: 43.46925477790072, longitude: -80.54034107786745, altitude: 1, <class 'modules.common.modules.position_global.PositionGlobal'>: latitude: 43.47073179293396, longitude: -80.53501978862127, altitude: 1]
At index 4 diff: <class 'modules.common.modules.position_global.PositionGlobal'>: latitude: 43.46983001550084, longitude: -80.5422570409521, altitude: 1 != <class 'modules.common.modules.position_global.PositionGlobal'>: latitude: 43.46834804571286, longitude: -80.54341048064786, altitude: 1
Full diff:
[
<class 'modules.common.modules.position_global.PositionGlobal'>: latitude: 43.47073179293396, longitude: -80.53501978862127, altitude: 1,
<class 'modules.common.modules.position_global.PositionGlobal'>: latitude: 43.47076658531946, longitude: -80.54311788821606, altitude: 1,
<class 'modules.common.modules.position_global.PositionGlobal'>: latitude: 43.4715312632625, longitude: -80.54211697668684, altitude: 1,
<class 'modules.common.modules.position_global.PositionGlobal'>: latitude: 43.47073179293396, longitude: -80.53501978862127, altitude: 1,
+ <class 'modules.common.modules.position_global.PositionGlobal'>: latitude: 43.46983001550084, longitude: -80.5422570409521, altitude: 1,
<class 'modules.common.modules.position_global.PositionGlobal'>: latitude: 43.46834804571286, longitude: -80.54341048064786, altitude: 1,
- <class 'modules.common.modules.position_global.PositionGlobal'>: latitude: 43.46983001550084, longitude: -80.5422570409521, altitude: 1,
<class 'modules.common.modules.position_global.PositionGlobal'>: latitude: 43.47073179293396, longitude: -80.53501978862127, altitude: 1,
<class 'modules.common.modules.position_global.PositionGlobal'>: latitude: 43.46925477790072, longitude: -80.54034107786745, altitude: 1,
<class 'modules.common.modules.position_global.PositionGlobal'>: latitude: 43.47073179293396, longitude: -80.53501978862127, altitude: 1,
]
Find the optimal itinerary, given an origin waypoint (the source of water) and a list of bucket waypoints. We can only visit a fixed number of buckets before we must return to the origin waypoint to fetch more water each time.
Finishes task https://app.asana.com/0/0/1209038151009011/f