Interview Question for Dev Leads Dev Leads
- 0of 0 votes
AnswersI have used my personal google API key here, you can use that or generate your own.
- kumar.prince6 December 22, 2014 in United States
The response id JSON:
{
"destination_addresses" : [ "Sector 15, Faridabad, Haryana, India" ],
"origin_addresses" : [ "GBN School, Sector 21D, Faridabad, Haryana 121001, India" ],
"rows" : [
{
"elements" : [
{
"distance" : {
"text" : "6.1 km",
"value" : 6054
},
"duration" : {
"text" : "12 mins",
"value" : 716
},
"status" : "OK"
}
]
}
],
"status" : "OK"
}
Base Algorithm or the rule engine for scheduling:
For the examples, let us assume pincode 121001, with 3 cabs cab1, cab2 & cab3.
The time slots are:
9:00 am to 10:30 am, 10:30 am to 12:00 pm, 12:00 pm to 1:30 pm, 2:30 pm to 4:00 pm, 4:00 pm to 5:30 pm and 5:30 pm to 7:00 pm
Non-real time scheduling
For an appointment of any time slot, say 4:00 pm to 5:30 pm, check the cabs allotted for adjacent slots, 2:30 pm to 4:00 pm and 5:30 pm to 7:00 pm for this example.
1) If no cabs are allotted for adjacent slots, then assign any random cab, say cab1.
2) Else, say cab2 is allotted to slot 2:30 pm to 4:00 pm and cab3 to 4:00 pm and 5:30 pm. Using google distance matrix api (referred to as gdm api from now on), find which cab is within x kms (x should be configurable, e.g 5 kms would be a good start) of the new appointment.
2.1) If one of the cabs is within x kms, assign it to this time slot.
2.2) If both cabs are within x kms, assign the one that is closer. If the difference is imperceptible, assign one randomly.
2.3) If both cabs are more than x kms, assign it to cab1
2.4) If cab1 was also allotted one of the adjacent time slots, then assign the nearest cab to this time slot. If the difference is imperceptible, assign one randomly.
Real time scheduling
This is applicable for appointments for the same day.
The same algorithm can be used, but use time to travel from the gdm api, instead of distance, since it accounts for traffic.
Feel free to discuss details or suggest changes in the rule engine.| Report Duplicate | Flag | PURGE
Dev Lead Dev Lead
any one can help me writting of above algorithm
- Anonymous December 28, 2014