scheduler
Class TravelSolutionsSorter

java.lang.Object
  extended byscheduler.TravelSolutionsSorter

public final class TravelSolutionsSorter
extends java.lang.Object

A class used to sort a given list of travel solutions (ConnectionsFinderTasks).

Author:
Piotrek

Nested Class Summary
private  class TravelSolutionsSorter.SortTag
          A tag used while sorting.
 
Field Summary
static int SORT_ON_AVERAGE_CHANGE_DURATION
          Used to indicate that sorting should be on the average duration of the change.
static int SORT_ON_CHANGES_COUNT
          Used to indicate that sorting should be on the number of changes.
static int SORT_ON_MAX_CHANGE_DURATION
          Used to indicate that sorting should be on the maximal duration of the change.
static int SORT_ON_SIMILARITIES_TO_HISTORY
          Used to indicate that sorting should be on the similarity level to the historical cases from the CRN.
static int SORT_ON_TOTAL_DISTANCE
          Used to indicate that sorting should be on the total distance of the travel.
static int SORT_ON_TOTAL_DURATION
          Used to indicate that sorting should be on the total duration of the travel.
(package private)  TravelSolutionsJudger travelSolutionsJudger
          The CRN manager used to judge the travel solutions when sorting on similarity to the history.
 
Constructor Summary
TravelSolutionsSorter(TravelSolutionsJudger travelSolutionsJudger)
          Constructor.
 
Method Summary
private  void AssignPropertyValues(java.util.ArrayList taggedList, int sortType)
          Assigns the values to the list of sort tags.
private  java.util.ArrayList GetTaggedList(java.util.ArrayList travelSolutions)
          Gets a list of the given travel solutions boxed within the sort tags.
private  java.util.ArrayList GetUntaggedList(java.util.ArrayList taggedList)
          Gets a list of travel tasks in the same order as in the given list of SortTags.
private  int Partition(java.util.ArrayList array, int begin, int end)
          Partitions the given range of elements in the given array using the SortTag in the middle as the pivot.
private  void QuickSort(java.util.ArrayList array, int begin, int end)
          Sorts the given range of SortTags on the given list.
 java.util.ArrayList SortTravelSolutions(java.util.ArrayList travelSolutions, int sortType)
          Sorts the given list of travel solutions on the given property.
private  void Swap(java.util.ArrayList array, int i, int j)
          Swaps two given element on the given list.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

travelSolutionsJudger

TravelSolutionsJudger travelSolutionsJudger
The CRN manager used to judge the travel solutions when sorting on similarity to the history.


SORT_ON_TOTAL_DURATION

public static final int SORT_ON_TOTAL_DURATION
Used to indicate that sorting should be on the total duration of the travel.

See Also:
Constant Field Values

SORT_ON_AVERAGE_CHANGE_DURATION

public static final int SORT_ON_AVERAGE_CHANGE_DURATION
Used to indicate that sorting should be on the average duration of the change.

See Also:
Constant Field Values

SORT_ON_MAX_CHANGE_DURATION

public static final int SORT_ON_MAX_CHANGE_DURATION
Used to indicate that sorting should be on the maximal duration of the change.

See Also:
Constant Field Values

SORT_ON_CHANGES_COUNT

public static final int SORT_ON_CHANGES_COUNT
Used to indicate that sorting should be on the number of changes.

See Also:
Constant Field Values

SORT_ON_SIMILARITIES_TO_HISTORY

public static final int SORT_ON_SIMILARITIES_TO_HISTORY
Used to indicate that sorting should be on the similarity level to the historical cases from the CRN.

See Also:
Constant Field Values

SORT_ON_TOTAL_DISTANCE

public static final int SORT_ON_TOTAL_DISTANCE
Used to indicate that sorting should be on the total distance of the travel.

See Also:
Constant Field Values
Constructor Detail

TravelSolutionsSorter

public TravelSolutionsSorter(TravelSolutionsJudger travelSolutionsJudger)
Constructor.

Parameters:
travelSolutionsJudger - The travel solutions judger.
Method Detail

SortTravelSolutions

public java.util.ArrayList SortTravelSolutions(java.util.ArrayList travelSolutions,
                                               int sortType)
Sorts the given list of travel solutions on the given property.

Parameters:
travelSolutions - A list of travel solutions to be sorted.
sortType - A property of a travel solution to sort on.
Returns:
A sorted list of travel solutions.
See Also:
SORT_ON_AVERAGE_CHANGE_DURATION, SORT_ON_CHANGES_COUNT, SORT_ON_MAX_CHANGE_DURATION, SORT_ON_SIMILARITIES_TO_HISTORY, SORT_ON_TOTAL_DISTANCE, SORT_ON_TOTAL_DURATION

GetUntaggedList

private java.util.ArrayList GetUntaggedList(java.util.ArrayList taggedList)
Gets a list of travel tasks in the same order as in the given list of SortTags.

Parameters:
taggedList - A list of SortTags.
Returns:
An list of travel task in the same order as the given list of SortTags.

Swap

private void Swap(java.util.ArrayList array,
                  int i,
                  int j)
Swaps two given element on the given list.

Parameters:
array - A list on which the given elements are swapped.
i - Index of the first of elements to be swapped.
j - Index of the second of elements to be swapped

Partition

private int Partition(java.util.ArrayList array,
                      int begin,
                      int end)
Partitions the given range of elements in the given array using the SortTag in the middle as the pivot.

Parameters:
array - An array part of which is to be partitioned.
begin - The first index of the range to be partitioned.
end - The last index of the range to be partitioned.
Returns:
An index of the pivot element after the partitioning.

QuickSort

private void QuickSort(java.util.ArrayList array,
                       int begin,
                       int end)
Sorts the given range of SortTags on the given list.

Parameters:
array - A list to be sorted.
begin - The first index to be sorted.
end - The last index to be sorted.

AssignPropertyValues

private void AssignPropertyValues(java.util.ArrayList taggedList,
                                  int sortType)
Assigns the values to the list of sort tags.

Parameters:
taggedList - A list of sort tags to be evalueted.
sortType - A property of a travel solution to sort on.
See Also:
SORT_ON_AVERAGE_CHANGE_DURATION, SORT_ON_CHANGES_COUNT, SORT_ON_MAX_CHANGE_DURATION, SORT_ON_SIMILARITIES_TO_HISTORY, SORT_ON_TOTAL_DISTANCE, SORT_ON_TOTAL_DURATION

GetTaggedList

private java.util.ArrayList GetTaggedList(java.util.ArrayList travelSolutions)
Gets a list of the given travel solutions boxed within the sort tags. It does not assign the values of the properties.

Parameters:
travelSolutions - A list of travel solutions to be boxed.
Returns:
A list of boxed travel solutions.