Taxi sharing scheduling in neo4j

喜夏-厌秋 提交于 2019-12-13 01:05:49

问题


I would like to ask you some suggestions and ideas for my java application to compute a taxi scheduling with sharing ride.

Let's suppose that i have a taxi with two users (passengers). The users are going to share the trip, but both passengers are located in different places and are going to be picked up/dropped off at different times. The user model with its pick up and drop off locations, is:

(Grid1)<-[:PICK_UP {time:'10:30'}]-(user1)-[:DROP_OFF {time:'11:00'}]->(Grid9)
(Grid4)<-[:PICK_UP {time:'10:15'}]-(user2)-[:DROP_OFF {time:'10:45'}]->(Grid11)

Or even i can write all the properties inside a User Node e.g. user 1

pickUpLocation:'Grid1'
pickUpTime:'10:30'
dropOffLocation:'Grid9'
dropOffTime:'11:00'

Are both options okay?

I would like to compute the taxi path scheduling, in order to know which user has to be picked/dropped first/last, something like this:

Grid4 --- Grid1 --- Grid11 --- Grid9 
10:15     10:30     10:45      11:00
(pick      (pick    (drop       (drop
user2)     user1)    user2)      user1)

My idea is to get the pick up-time value for each user, and store it into a Collection(TreeSet), then do the same with the drop-times. So i can get an ordered collection. Is that a good idea??

But then, where should i store the Grid location (Grid4, Grid1, etc.)?? So then at the end, i can have all the information for the taxi, Where to go and at what time.

Any suggestions or ideas?

Thank you in advance!


回答1:


This all depends on your requirements of course, but I feel like you're missing an entity. I would probably call it Ride or `Reservation'. The following might make sense:

(:User)-[:BOOKED_RIDE]->(:Ride)
(:Ride)-[:STARTS_AT]->(:GridItem)
(:Ride)-[:ENDS_AT]->(:GridItem)

STARTS_AT could have a time property.

For two users the following Cypher might provide an example of how to query:

MATCH (user1:User), (user2:User)
MATCH
  (user1)-[:BOOKED_RIDE]->(ride1:Ride),
  (user2)-[:BOOKED_RIDE]->(ride2:Ride),
  (start1)<-[start_rel1:STARTS_AT]-(ride1)-[end_rel1:ENDS_AT]->(end1),
  (start2)<-[start_rel2:STARTS_AT]-(ride2)-[end_rel2:ENDS_AT]->(end2)
WITH 
  [
    {grid_item: start1, time: start_rel1.time},
    {grid_item: end1, time: end_rel1.time},
    {grid_item: start2, time: start_rel2.time},
    {grid_item: end2, time: end_rel2.time}
  ] AS stops
UNWIND stops AS stop
WITH stop
ORDER BY stop.time
RETURN collect(stop) AS stops

Of course there might be more logic to it (especially if you're using the Neo4j Java APIs), but that might be a rough start.



来源:https://stackoverflow.com/questions/33483757/taxi-sharing-scheduling-in-neo4j

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!