1

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!

marhg
  • 659
  • 1
  • 17
  • 30

1 Answers1

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.

Brian Underwood
  • 10,746
  • 1
  • 22
  • 34
  • thank you! very good explanation i'm going to try it out. Some observations, the :Ride node; i don't know what properties should it have, or i can just create the node, without properties. Also, could you please give me some advices about how should i store the time in neo4j. I asked before http://stackoverflow.com/questions/33463882/how-to-store-time-data-type-in-neo4j but i would like your advice as well. So i can run the query properly. Thank you – marhg Nov 03 '15 at 13:22
  • It's totally fine to have the `Ride` nodes without properties. You can think of the three relationships coming to/from it as data, of a sort. I think the answers on the question about time are quite good, though it always comes down to how you're going to use it. The first question I'd ask yourself is if you're ever going to do calculations in Cypher or in your programming language of choice – Brian Underwood Nov 03 '15 at 13:51
  • Thank you again, i already tried your query with the format time HH:mm and it works! You're right, about the time it all depends of my needs. So, may be at some point i need to use another format. Thank you – marhg Nov 03 '15 at 14:36
  • With the given query result, for computing which user has to be picked up first given the time. Could you give me some suggestions or ideas for computing the shortest weighted path between the set of nodes. E.g. Let's suppose that the query result is Grid 4 (10:15) - Grid 1(10:30) - G 11(10:45) - G 9(11:00) but then i need to compute the shortes path btw Grid4 with Grid1, then from Grid 1 to Grid 11, and so on and so forth. Is there a simple way to do that either via cyhper or code. Thank you – marhg Nov 07 '15 at 11:28
  • Check out the documentation for `shortestPath` and `allShortestPaths`. If you still have questions post a SO question and we'll see what we can do – Brian Underwood Nov 07 '15 at 12:56
  • Ok! Thank you, i will ;) – marhg Nov 07 '15 at 15:05