Skip to content
This repository was archived by the owner on Nov 13, 2025. It is now read-only.

visit water buckets 2#79

Open
Evang264 wants to merge 6 commits intomainfrom
visit-water-buckets-2
Open

visit water buckets 2#79
Evang264 wants to merge 6 commits intomainfrom
visit-water-buckets-2

Conversation

@Evang264
Copy link
Copy Markdown
Contributor

@Evang264 Evang264 commented Feb 8, 2025

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

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.
@Evang264 Evang264 mentioned this pull request Feb 8, 2025
Comment thread modules/visit_water_buckets.py Outdated
from .common.modules.position_global import PositionGlobal

# Earth radius in meters
EARTH_RADIUS = 6378137
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good job breaking this out to a constant

Comment thread modules/visit_water_buckets.py Outdated


def waypoint_distance(point_1: PositionGlobal, point_2: PositionGlobal) -> "tuple[bool, float]":
"""Return the great-circle distance of two points Earth, using Haversine's
Copy link
Copy Markdown
Contributor

@BalajiLeninrajan BalajiLeninrajan Feb 9, 2025

Choose a reason for hiding this comment

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

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.

Comment thread modules/visit_water_buckets.py Outdated
Comment thread modules/visit_water_buckets.py Outdated
Comment thread modules/visit_water_buckets.py Outdated
Comment thread modules/visit_water_buckets.py Outdated
Comment thread tests/unit/test_waypoint_distance.py Outdated
Comment thread modules/visit_water_buckets.py Outdated
Comment thread modules/visit_water_buckets.py Outdated
if not success:
return False, None

for permutation in itertools.permutations(sorted_buckets):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If we're doing permutations why are we sorting the buckets

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

oh LOL coming from C++ I thought the list must be sorted to iterate over all possible permutations.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

oh wait, no, I must sort them so that I return the smallest path, sorted based on (latitude, longitude)

Copy link
Copy Markdown
Contributor

@BalajiLeninrajan BalajiLeninrajan Feb 11, 2025

Choose a reason for hiding this comment

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

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

Comment thread tests/unit/test_visit_water_buckets.py
buckets = [
PositionGlobal.create(1, 1, 1)[1],
PositionGlobal.create(1.001, 1.001, 1)[1],
PositionGlobal.create(20, 20, 1)[1],
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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,
    ]

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants