scheduler
Class TravelDivisionsConnectionsFinder

java.lang.Object
  extended byscheduler.TravelDivisionsConnectionsFinder

public final class TravelDivisionsConnectionsFinder
extends java.lang.Object

A class used to find connections for the given set of travel parts.

Author:
Piotrek

Field Summary
private  ChangesJudger changesJudger
          A judger of changes.
private  boolean fRevert
          Indicates whether the search is performed with the arrival time limit (then everything is reverted).
private  ConnectionsTravelInfoProvider infoProvider
          A provider of the travel information on the world.
static int MAX_ALTER_CHANGE_CONNECTIONS_COUNT
          Defines a maximal number of change connections when searching for some other changes if there where none matching the travel constraints, but there are still some with a change time longer then the max change time.
static int MAX_LENGTH_TAXI_RESERVED_TIME
          Defines a minimal duration in minutes of the taxi travel part of the maximal possible length.
static int MAX_LENGTH_WALK_RESERVED_TIME
          Defines a minimal duration in minutes of the walk travel part of the maximal possible length.
static int MAX_STARTING_CONNECTIONS_COUNT
          Defines a maximal number of connections taken into account when starting the search for the connections leaving from the first station of the whole travel.
private  ConnectionsFinderTasksManager tasksManager
          A tasks manager.
private  TravelConstraints travelConstraint
          The travel constraint to be applied.
 
Constructor Summary
TravelDivisionsConnectionsFinder()
          Constructor.
 
Method Summary
private  void DropTasksBreakingConstraints(java.util.ArrayList tasksList)
          Removes from the given list of tasks those that break the constraints.
 java.util.ArrayList FindConnections(java.util.ArrayList travelDivisionsList, TravelConstraints travelConstraints)
          Finds connections for each of the given travel divisions.
private  void FindConnections(TravelPartsList travelPartsList, java.util.Date departureLimit, java.util.Date arrivalLimit, java.util.ArrayList resultsList)
          Finds out connections for the given division of the travel matching the given time limits and other constraints.
private  java.util.ArrayList GetChangeConnections(int meanOfTransportation, Station changeStation, Station destinationStation, java.util.Date changeStartTime, java.util.Date arrivalLimit, java.lang.Boolean fTooLongChangesExist)
          Gets a list of all connections leaving from the given station not before the given change time and holding the change constraints.
private  java.util.ArrayList GetDeparturingConnections(int meanOfTransportation, Station station, Station destinationStation, java.util.Date departureLimit, java.util.Date arrivalLimit, int connectionsCountLimit)
          Gets a list of at most connectionsCountLimit possible connections leaving from the given station not before the given time limit with the minimal time spans between the time limit and the departure time.
private static int GetTaxiDriveReservationTime(TravelPartConnectionChunk chunk)
          Gets an amount of time in minutes needed to be reserved for the given taxi connection chunk for the drive only.
private static int GetWalkReservationTime(TravelPartConnectionChunk chunk)
          Gets an amount of time in minutes needed to be reserved for the given walk connection chunk.
private  boolean IsDirectConnection(int currentStationIndex, int destinationStationIndex)
          Checks whether a connection is a driect connection basing on the indecies of the current and destination stations'.
private  void RemoveSimilarSolutions(java.util.ArrayList solutionsList)
          Removes from the given list of solutions similar ones (with the same routes and time of start and end, but with different times between the start and the end).
 void SetChangesJudger(ChangesJudger changesJudger)
          Sets the judger of changes.
 void SetTasksManager(ConnectionsFinderTasksManager tasksManager)
          Sets the tasks manager.
 void SetTravelInfoProvider(ConnectionsTravelInfoProvider infoProvider)
          Sets the provider of the travel information on the world.
private  void SolveUnsetDates(java.util.ArrayList tasksList, java.util.Date departureLimit, java.util.Date arrivalLimit)
          Sets the start and end dates for all the connection chunks with unset dates.
private  void UpdateTaxiConnectionChunksDates(java.util.ArrayList routes)
          Shortens the duration of the taxi connection chunks so there will be time for a change.
private  boolean WillBeBeforeDate(java.util.Date date, int shift, java.util.Date dateLimit)
          Checks if the given date shifted by the given number of minutes will be before the given date limit.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

infoProvider

private ConnectionsTravelInfoProvider infoProvider
A provider of the travel information on the world.


fRevert

private boolean fRevert
Indicates whether the search is performed with the arrival time limit (then everything is reverted).


travelConstraint

private TravelConstraints travelConstraint
The travel constraint to be applied.


changesJudger

private ChangesJudger changesJudger
A judger of changes.


tasksManager

private ConnectionsFinderTasksManager tasksManager
A tasks manager.


MAX_LENGTH_WALK_RESERVED_TIME

public static final int MAX_LENGTH_WALK_RESERVED_TIME
Defines a minimal duration in minutes of the walk travel part of the maximal possible length.

See Also:
Constant Field Values

MAX_LENGTH_TAXI_RESERVED_TIME

public static final int MAX_LENGTH_TAXI_RESERVED_TIME
Defines a minimal duration in minutes of the taxi travel part of the maximal possible length.

See Also:
Constant Field Values

MAX_STARTING_CONNECTIONS_COUNT

public static final int MAX_STARTING_CONNECTIONS_COUNT
Defines a maximal number of connections taken into account when starting the search for the connections leaving from the first station of the whole travel.

See Also:
Constant Field Values

MAX_ALTER_CHANGE_CONNECTIONS_COUNT

public static final int MAX_ALTER_CHANGE_CONNECTIONS_COUNT
Defines a maximal number of change connections when searching for some other changes if there where none matching the travel constraints, but there are still some with a change time longer then the max change time. Top MAX_ALTER_CHANGE_CONNECTIONS_COUNT of them will be taken (with the shortest change times).

See Also:
Constant Field Values
Constructor Detail

TravelDivisionsConnectionsFinder

public TravelDivisionsConnectionsFinder()
Constructor.

Method Detail

SetTravelInfoProvider

public void SetTravelInfoProvider(ConnectionsTravelInfoProvider infoProvider)
Sets the provider of the travel information on the world.

Parameters:
infoProvider - A provider to be set.

FindConnections

public java.util.ArrayList FindConnections(java.util.ArrayList travelDivisionsList,
                                           TravelConstraints travelConstraints)
Finds connections for each of the given travel divisions.

Parameters:
travelDivisionsList - A list of travel divisions to receive the results. It must be empty.
travelConstraints - The travel constraints to be applied.
Returns:
A list of connections for each of the travel divisions.

RemoveSimilarSolutions

private void RemoveSimilarSolutions(java.util.ArrayList solutionsList)
Removes from the given list of solutions similar ones (with the same routes and time of start and end, but with different times between the start and the end).

Parameters:
solutionsList - A list of solutions to be cleaned of similar solutions.

FindConnections

private void FindConnections(TravelPartsList travelPartsList,
                             java.util.Date departureLimit,
                             java.util.Date arrivalLimit,
                             java.util.ArrayList resultsList)
Finds out connections for the given division of the travel matching the given time limits and other constraints.

Parameters:
travelPartsList - A division of the travel to search for the connections for.
departureLimit - A departure time limit.
arrivalLimit - An arrival time limit. Set it to null if there is no arrival limit.
resultsList - A list to store all the results in.

UpdateTaxiConnectionChunksDates

private void UpdateTaxiConnectionChunksDates(java.util.ArrayList routes)
Shortens the duration of the taxi connection chunks so there will be time for a change.

Parameters:
routes - A list of tasks to be updated.

SetChangesJudger

public void SetChangesJudger(ChangesJudger changesJudger)
Sets the judger of changes.

Parameters:
changesJudger - A judger of changes to be used.

SetTasksManager

public void SetTasksManager(ConnectionsFinderTasksManager tasksManager)
Sets the tasks manager.

Parameters:
tasksManager - A tasks manager to be used.

DropTasksBreakingConstraints

private void DropTasksBreakingConstraints(java.util.ArrayList tasksList)
Removes from the given list of tasks those that break the constraints. If it would cause a removal of all the tasks, then none are removed.

Parameters:
tasksList - A list of tasks to be checked.

SolveUnsetDates

private void SolveUnsetDates(java.util.ArrayList tasksList,
                             java.util.Date departureLimit,
                             java.util.Date arrivalLimit)
Sets the start and end dates for all the connection chunks with unset dates.

Parameters:
tasksList - A list of tasks for which to set dates for its connection tasks.
departureLimit - A departure date limit.
arrivalLimit - An arrival date limit. Set it to null if there is no limit.

GetWalkReservationTime

private static int GetWalkReservationTime(TravelPartConnectionChunk chunk)
Gets an amount of time in minutes needed to be reserved for the given walk connection chunk.

Parameters:
chunk - A connection chunk for which the time is being reserved.
Returns:
An amount of time in minutes to be reserved.

GetTaxiDriveReservationTime

private static int GetTaxiDriveReservationTime(TravelPartConnectionChunk chunk)
Gets an amount of time in minutes needed to be reserved for the given taxi connection chunk for the drive only.

Parameters:
chunk - A connection chunk for which the time is being reserved.
Returns:
An amount of time in minutes to be reserved.

GetDeparturingConnections

private java.util.ArrayList GetDeparturingConnections(int meanOfTransportation,
                                                      Station station,
                                                      Station destinationStation,
                                                      java.util.Date departureLimit,
                                                      java.util.Date arrivalLimit,
                                                      int connectionsCountLimit)
Gets a list of at most connectionsCountLimit possible connections leaving from the given station not before the given time limit with the minimal time spans between the time limit and the departure time.

Parameters:
meanOfTransportation - A mean of transportation the connections are to be taken by.
station - An origin station the connections are to leave from.
destinationStation - A destination station. If there are direct connections the will be, each of them will be on the list even if that would mean breaking the count limit.
departureLimit - A departure date limit. Connections must not depart from the given station before / after (depends on reverting) this date.
arrivalLimit - An arrival time limit. Connections must not depart from the given station before this date. Set it to null if not reverting.
connectionsCountLimit - A maximal number of connections to be returned.
Returns:
A list of all possible connections matching all the given constraints. Each of the connections is added as a task. If there are no possibilities an empty list is returned.

WillBeBeforeDate

private boolean WillBeBeforeDate(java.util.Date date,
                                 int shift,
                                 java.util.Date dateLimit)
Checks if the given date shifted by the given number of minutes will be before the given date limit.

Parameters:
date - A date to be shifted. The given parameter will not be modified.
shift - A number of minutes to shift the date by. It must not be positive.
dateLimit - A date that is limiting the result date from below.
Returns:
A number of minutes to be added to the shift paramter. Zero means the date is latter then the given time limit.

GetChangeConnections

private java.util.ArrayList GetChangeConnections(int meanOfTransportation,
                                                 Station changeStation,
                                                 Station destinationStation,
                                                 java.util.Date changeStartTime,
                                                 java.util.Date arrivalLimit,
                                                 java.lang.Boolean fTooLongChangesExist)
Gets a list of all connections leaving from the given station not before the given change time and holding the change constraints. This method does not test if the returned connections are in line with the changes rules (like do not change to the local train if very far away from the destination).

Parameters:
meanOfTransportation - A mean of transportation the connections are to be taken by.
changeStation - A station the connections are to leave from.
destinationStation - A destination station. The best direct change that does not hold the change time constraints will be added to the list of changes unless some other direct change holding the constrains will be added.
changeStartTime - A time since when the change connections may leave.
arrivalLimit - An arrival limit. Set it only if reverting.
fTooLongChangesExist - After a call to this method this will hold a boolean value indicating whether there were changes with the change time longer then the one allowed by the constraints.
Returns:
A list of all possible connections matching all the given constraints. Each of the connections is added as a task. If there are no possibilities an empty list is returned.

IsDirectConnection

private boolean IsDirectConnection(int currentStationIndex,
                                   int destinationStationIndex)
Checks whether a connection is a driect connection basing on the indecies of the current and destination stations'.

Parameters:
currentStationIndex - An index of the cuurent station within a connection.
destinationStationIndex - An index of the destination station within a connection.
Returns:
A boolean value indicating whether it is a direct connection.