Possible number of combinations for return routes
My math is bad, very bad. So bad that I am struggling to formulate this question, but here.
The situation is a train of trains and you have four arrays to work with.
Leaving_Stations Arriving_Stations
Leaving_Dates Returning_Dates
So, say that you are only interested in one route and need to figure out how many route combinations there are. It would be (I think)
possible_routes = (leaving_stations x arriving_stations) x leaving_dates
But how can I figure out how many combinations there are if I want to go back?
UPDATE ::
or will this work?
possible_routes = ((leave_stations x arriving_stations) x leave_dates) x (leave_dates x return_dates)
a source to share
Ok, the answer is not entirely clear from your array names.
Assuming we have 4 arrays:
- End dates
- Return dates
- Outgoing stations
- Arriving stations
Then we can explain a little here. Let the notation | x | to represent the cardinality (number of elements) of array [x], so | Outgoing dates | this is the total number of dates you could keep.
Then | Outgoing dates | * | Remaining stations | * | Arriving stations | translate, choose a date to get off, then choose a station to leave, and then choose a station to arrive, and do it in every possible way. So it looks like this is what you are asking for for one-way trips.
Now, practically, I'm going to assume that this is a real world problem, so let me say that we decided to leave Southampton for Yorkshire on June 20th, on the way back, that we are allowed to choose at this point should be a return date (which means, which I assume you want to go home).
So the total number of ways we can plan the round trip will be the first one-way trip plan as above and then choose the return date, which will be | * | Remaining stations | * | Arriving stations | * | Return date |. The first three conditions select a one-way trip as above, and the last term selects a return date from all possible dates. Of course, if we had the opportunity to return to a different station than the one we left, then the equation would be (| Leaving Dates | * | Remaining Stations | * | Arriving Stations |) * (| Return Date | * | Leaving Stations |), or if we could even leave from a different arrival station than the one we first arrived at,will become (| Departing dates | * | Leaving stations | * | Arriving stations |) * (| Returning dates | * | Arriving stations | * | Departing stations |).
a source to share
I'm not sure if I'm getting it right, but this seems to be a typical problem in graph-routing theory . You can look at Minimum Path or A * algorithms.
a source to share
firstly, AA routes are the wrong thing, so:
possible_routes = ( leaving_stations x arriving_stations - (leaving_stations [intersection] arrivig_stations) ) x leaving_dates
intersection operation is elements belonging to both arrays
secondly, if you need 2 route routes, the following combinations:
possible_2way_routes =
(
leaving_stations x arriving_stations -
(leaving_stations [intersection] arrivig_stations)
) x
leaving_dates x
(return_dates that later than leaving dates+route time)
'leave_dates x (return_dates, which is later than leaving dates + route times)' is a weird thing, so it might be easier to calculate a high score - a number that is no less than the possible_2way_routes anyway. the highest score will be when all returned_dates are later than left_dates, so:
possible_2way_routes <=
(
leaving_stations x arriving_stations -
(leaving_stations [intersection] arrivig_stations)
) x leaving_dates x return_dates
Oh, I remembered how to calculate 'return_dates, which is later than leaving the dates + times of the route'. this is:
for each element of leaving_dates {
sum=sum+return_dates that later than ith leaving date+route time}
there is still a "route time" issue though ...
a source to share