Click here to Skip to main content
15,125,104 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Python
pd = pd.DataFrame({'Priority order':[1,2,3,4,5],
      'bike_id':[11,12,13,14,15],
      'lat':[13.027514,13.037857,12.937877,13.091736,12.959291],
      'long':[77.723228,77.705032,77.751419,77.564781,77.727295]})

pd1 = pd.DataFrame({'Priority':[1,2,3,4,5],
      'drop hex lat':[13.084574,13.083513,13.089918,12.977496,13.078991],
      'drop hex long':[77.485690,77.482666,77.483974,77.570524,77.580048],
      'avg_daily_sessions/supply':[122.071429,112.857143,110.500000,90.571429,85.571429]})


What I have tried:

Need to assign riders from pd to drop locations in pd1 based on following conditions:

if the avg daily sessions/supply > 120 can assign min 6 and max 8 bikes
if between 100-120 can assign min 2 and max 4 bikes
if between 50-100 can assign min 2 and max 3 bikes
if between 30-50 can assign min 1 and max 2 bikes
if between 20-30 can assign min 1 and max 1 bikes
if between 10-20 can assign min 0 and max 1 bikes

Need to always aim to assign maximum bikes to be dropped but if haversine distance more than 4 you have to choose a different hex location.

Always aim that a high-priority bike should be assigned to a high-priority drop location. But if haversine distance is more than 4 it should move on to the next available hex location within the parameters.

Overall haversine distance (total bike drop distance/no of bikes) can go max up to ~2km.

I have already cross joined the two tables then calculated the haversine distance for each of the resulting rows. And then started filtering based on the given conditions and after selecting the rows started appending them to a new dataframe. I am actually having issues with the first criteria. how do I get to know that I have assigned the max available slots at a specific location so that automatically the next best location is selected
Posted
Updated 1-Sep-21 22:20pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900