Git Product home page Git Product logo

carpool-graph's Introduction

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.