parthkvv / Carpool-graph

Efficient Carpool route algorithm

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Car-pool-algorithm

This project designed a min matching algorithm to match riders requesting carpool in Manhattan in order to save total travel distance.

Min Matching algorithm

We formed an undirected graph with nodes represent passengers and edges represent their sharing plan. Using maximum matching with minimum weight algorithm, we can find the best sharing plan with the minimum total distance.

Distance between passengers

Based on Manhattan distance (𝑋(π‘₯1, π‘₯2), π‘Œ(𝑦1, 𝑦2), 𝑑(𝑋, π‘Œ) = |π‘₯1 βˆ’ 𝑦1| + |π‘₯2 βˆ’ 𝑦2|), we defined the distance between each two passengers 𝑑(𝑋, π‘Œ)1 in five scenarios:


a. Pick up 𝑋 then pick up π‘Œ then drop off 𝑋 then drop up π‘Œ:
➒ 𝑑(π‘‹π‘Œ)=𝑑(1)=𝑑(𝑋1π‘Œ1)+𝑑(π‘Œ1𝑋2)+𝑑(𝑋2π‘Œ2)
b. Pick up 𝑋 then pick up π‘Œ then drop off π‘Œ then drop up 𝑋:
➒ 𝑑(π‘‹π‘Œ)=𝑑(2)=𝑑(𝑋1π‘Œ1)+𝑑(π‘Œ1π‘Œ2)+𝑑(π‘Œ2𝑋2)
c. Pick up π‘Œ then pick up 𝑋 then drop off 𝑋 then drop up π‘Œ:
➒ 𝑑(π‘‹π‘Œ)=𝑑(3)=𝑑(π‘Œ1𝑋1)+𝑑(𝑋1𝑋2)+𝑑(𝑋2π‘Œ2)
d. Pick up π‘Œ then pick up 𝑋 then drop off π‘Œ then drop up 𝑋:
➒ 𝑑(π‘‹π‘Œ)=𝑑(4)=𝑑(π‘Œ1𝑋1)+𝑑(𝑋1π‘Œ2)+𝑑(π‘Œ2𝑋2)
d.𝑋 and π‘Œ travels on his/her own:
➒ 𝑑(π‘‹π‘Œ)=𝑑(5)=𝑑(𝑋1𝑋2)+𝑑(π‘Œ1π‘Œ2)

Level of service

Passengers are not pooling with someone if the total travel distance he spends on a shared vehicle will exceed 25% more then traveling on his/her own. We call it β€œlevel of service” to guarantee the quality of vehicle sharing.

For passenger(𝑋):
if 𝑑(𝑋1π‘Œ1)+ 𝑑(π‘Œ1𝑋2)>1.25𝑑(π‘Œ1𝑋1):
set 𝑑(1) as +∝
if 𝑑(𝑋1π‘Œ1)+ 𝑑(π‘Œ1π‘Œ2)+ 𝑑(π‘Œ2𝑋2)>1.25𝑑(π‘Œ1𝑋1):
set 𝑑(2) as +∝
if 𝑑(𝑋1π‘Œ2) + 𝑑(π‘Œ2𝑋2) > 1.25𝑑(π‘Œ1𝑋1):
set 𝑑(4) as +∝


Repeat it for all passengers and output all the distance. The weight of two passengers is defined as:
𝑑(π‘‹π‘Œ) = min{𝑑(1), 𝑑(2), 𝑑(3), 𝑑(4), 𝑑(5)}.

Min Matching

After defining all the weight of edges, we formed a complete graph to represent passengers and their best way of pooling with each other.

As shown in the figure below, there are four passengers 𝐴, 𝐡, 𝐢 and 𝐷 with weights and way of pooling marked on edges. The maximum matching of all passengers with a minimum total weight is pair 𝐴 with 𝐷 using scenario 1 and pair 𝐡 with 𝐢 using scenario a.

alt text

About

Efficient Carpool route algorithm


Languages

Language:Python 100.0%