de.upb.swtpra05.group03.shuttle
Class SpreadingControl

java.lang.Object
  extended byde.upb.swtpra05.group03.shuttle.SpreadingControl
All Implemented Interfaces:
Module, ShuttleModule

public class SpreadingControl
extends java.lang.Object
implements ShuttleModule

Controls the spreading of the shuttles of one company on the topology at simulation begin.

Version:
$Revision: 1.3 $

Nested Class Summary
(package private)  class SpreadingControl.SpreadingShuttleData
          spreading shuttle data
(package private)  class SpreadingControl.SpreadingStationData
          spreading station data
 
Field Summary
private  ShuttleControlInterface agent
           
private  boolean allowed
          Is this Shuttle allowed to do the Calculation and Spreading Control Only the Shuttle with the smallest ID is allowed to do that
private  java.util.Vector associateIDs
          Vector with all associated Shuttles in this Company
private  boolean associatesreceived
          are the associates received?
(package private)  java.util.HashMap CalculatedPositions
          Stores all Calculated Positions so they can be send to other Shuttles
private  ExecutionInterface execution
           
private static int HORIZONTAL
          Constant for sorting Horizontal
private  SpreadingControl.SpreadingStationData[] horizontalSortedStations
          Array of the Stations in horizontal Order
private  boolean isCalculating
          are we already calculating, or did we already calculate?
private static java.util.logging.Logger log
          Logger
private  int myID
          The ID of this Shuttle
private  NavigationInterface navigation
           
private  java.util.LinkedList needPositionIDs
          List with ShuttleIDs of wich we need the Positions
private  boolean positionMessageSent
          Indicates wheater the shuttle has sent its position to the SpreadingControl of the Mastershuttle
private  boolean positionsreceived
          the position of the other shuttles received?
private  java.util.HashMap ratedStations
          HashMap with the already rated Stations
private  java.util.HashMap ShuttleMap
          HashMap that stores SpreadingShuttleData Objects
private  java.util.LinkedList stations
          List of SpreadingStationObjects
private  StrategyControlInterface strategy
          The StrategyControl
private  boolean topologyreceived
          is the topology already received?
private static int VERTICAL
          Constant for sorting Vertical
private  SpreadingControl.SpreadingStationData[] verticalSortedStations
          Array of Stations in vertical Order
 
Constructor Summary
SpreadingControl()
          Constructor
 
Method Summary
private  void associatesreceived(de.upb.swtpra.kernel.message.ShuttleAssociates msg)
          Associates are received.
 void calculateOptimalPositions(java.util.HashMap shuttles)
          Calculates a good Station for every Shuttle.
private  void doCalculation()
           
private  void exchange(SpreadingControl.SpreadingStationData[] a, int m, int n)
          Exchange 2 SpreadingStationData Object in the give Array
private  de.upb.swtpra.kernel.id.ID[] getBestShuttleCombination(java.util.HashMap Shuttles)
          Determines the best Shuttle for each Region. if there is more than one shuttle for a region find a good solution.
 void init(ModuleContainerInterface manager)
          Initializes this module.
 void log(java.lang.String s)
          Write a String to the Log
 void newMessageReceived(de.upb.swtpra.kernel.message.Message msg)
          React on the received message of the shuttle or not.
private  void parseTopology(de.upb.swtpra.kernel.TopologyData td)
          Parses the Topology to find all adjacent Stations for each Station in the Topology.
private  int partition(SpreadingControl.SpreadingStationData[] a, int m, int n, int direction)
          Partition Method
private  void quicksort(SpreadingControl.SpreadingStationData[] a, int l, int r, int direction)
          quicksort Method
private  void rateRegion(SpreadingControl.SpreadingStationData[] data, int maindirection, int anf, int end, int RegionNumber)
          Rates the given Region by Coordinates
private  void rateStations(SpreadingControl.SpreadingStationData[] sortedstations, int direction, int numberofShuttles)
          Rates all Stations by Regions
 void sendPositions(java.util.HashMap positions)
          Sends Calculated Positions to Shuttles
private  void sort(SpreadingControl.SpreadingStationData[] data, int direction, int size)
          Sorts the given Array in the given Direction (Vertical/Horizontal)
private  void sortbydistance(SpreadingControl.SpreadingStationData[] data, int num, SpreadingControl.SpreadingShuttleData shuttle)
          Sorts the Array of Stations by the Distance to the given Shuttle
private  void sortStations()
          Sorts all Stations in Vertical and Horizontal Order Stores data in verticalSortedStations, horizontalSortedStations.
private  void trackdown(de.upb.swtpra.kernel.TopologyDataObject tdobject, java.util.LinkedList adjacent)
          Tracks down a given Track and adds all found Stations to the adjacent List.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private static final java.util.logging.Logger log
Logger


CalculatedPositions

java.util.HashMap CalculatedPositions
Stores all Calculated Positions so they can be send to other Shuttles


VERTICAL

private static final int VERTICAL
Constant for sorting Vertical

See Also:
Constant Field Values

HORIZONTAL

private static final int HORIZONTAL
Constant for sorting Horizontal

See Also:
Constant Field Values

allowed

private boolean allowed
Is this Shuttle allowed to do the Calculation and Spreading Control Only the Shuttle with the smallest ID is allowed to do that


topologyreceived

private boolean topologyreceived
is the topology already received?


associatesreceived

private boolean associatesreceived
are the associates received?


positionsreceived

private boolean positionsreceived
the position of the other shuttles received?


isCalculating

private boolean isCalculating
are we already calculating, or did we already calculate?


needPositionIDs

private java.util.LinkedList needPositionIDs
List with ShuttleIDs of wich we need the Positions


ShuttleMap

private java.util.HashMap ShuttleMap
HashMap that stores SpreadingShuttleData Objects


stations

private java.util.LinkedList stations
List of SpreadingStationObjects


ratedStations

private java.util.HashMap ratedStations
HashMap with the already rated Stations


horizontalSortedStations

private SpreadingControl.SpreadingStationData[] horizontalSortedStations
Array of the Stations in horizontal Order


verticalSortedStations

private SpreadingControl.SpreadingStationData[] verticalSortedStations
Array of Stations in vertical Order


associateIDs

private java.util.Vector associateIDs
Vector with all associated Shuttles in this Company


myID

private int myID
The ID of this Shuttle


agent

private ShuttleControlInterface agent

execution

private ExecutionInterface execution

navigation

private NavigationInterface navigation

strategy

private StrategyControlInterface strategy
The StrategyControl


positionMessageSent

private boolean positionMessageSent
Indicates wheater the shuttle has sent its position to the SpreadingControl of the Mastershuttle

Constructor Detail

SpreadingControl

public SpreadingControl()
Constructor

Method Detail

init

public void init(ModuleContainerInterface manager)
Description copied from interface: Module
Initializes this module. References to other modules should be set here to avoid circle dependencies.

Specified by:
init in interface Module
Parameters:
manager - The module manager which contain all modules

log

public void log(java.lang.String s)
Write a String to the Log

Parameters:
s -

exchange

private void exchange(SpreadingControl.SpreadingStationData[] a,
                      int m,
                      int n)
Exchange 2 SpreadingStationData Object in the give Array

Parameters:
a -
m -
n -

partition

private int partition(SpreadingControl.SpreadingStationData[] a,
                      int m,
                      int n,
                      int direction)
Partition Method

Parameters:
a -
m -
n -
direction -
Returns:
int

quicksort

private void quicksort(SpreadingControl.SpreadingStationData[] a,
                       int l,
                       int r,
                       int direction)
quicksort Method

Parameters:
a -
l -
r -
direction -

sort

private void sort(SpreadingControl.SpreadingStationData[] data,
                  int direction,
                  int size)
Sorts the given Array in the given Direction (Vertical/Horizontal)

Parameters:
data -
direction -
size -

rateRegion

private void rateRegion(SpreadingControl.SpreadingStationData[] data,
                        int maindirection,
                        int anf,
                        int end,
                        int RegionNumber)
Rates the given Region by Coordinates

Parameters:
data -
maindirection -
anf -
end -
RegionNumber -

rateStations

private void rateStations(SpreadingControl.SpreadingStationData[] sortedstations,
                          int direction,
                          int numberofShuttles)
Rates all Stations by Regions

Parameters:
sortedstations -
direction -
numberofShuttles -

sortStations

private void sortStations()
Sorts all Stations in Vertical and Horizontal Order Stores data in verticalSortedStations, horizontalSortedStations.


calculateOptimalPositions

public void calculateOptimalPositions(java.util.HashMap shuttles)
Calculates a good Station for every Shuttle. If the Shuttle isn't already at the calculated Station, the Shuttle will be send there.

Parameters:
shuttles -

sortbydistance

private void sortbydistance(SpreadingControl.SpreadingStationData[] data,
                            int num,
                            SpreadingControl.SpreadingShuttleData shuttle)
Sorts the Array of Stations by the Distance to the given Shuttle

Parameters:
data -
num -
shuttle -

getBestShuttleCombination

private de.upb.swtpra.kernel.id.ID[] getBestShuttleCombination(java.util.HashMap Shuttles)
Determines the best Shuttle for each Region. if there is more than one shuttle for a region find a good solution. Doesnt return the optimum but a good approach.

Parameters:
Shuttles -
Returns:
int[]

trackdown

private void trackdown(de.upb.swtpra.kernel.TopologyDataObject tdobject,
                       java.util.LinkedList adjacent)
Tracks down a given Track and adds all found Stations to the adjacent List.

Parameters:
tdobject -
adjacent -

parseTopology

private void parseTopology(de.upb.swtpra.kernel.TopologyData td)
Parses the Topology to find all adjacent Stations for each Station in the Topology.

Parameters:
td -

associatesreceived

private void associatesreceived(de.upb.swtpra.kernel.message.ShuttleAssociates msg)
Associates are received.

Parameters:
msg -

newMessageReceived

public void newMessageReceived(de.upb.swtpra.kernel.message.Message msg)
Description copied from interface: ShuttleModule
React on the received message of the shuttle or not.

Specified by:
newMessageReceived in interface ShuttleModule
Parameters:
msg - The received message of the shuttle

doCalculation

private void doCalculation()

sendPositions

public void sendPositions(java.util.HashMap positions)
Sends Calculated Positions to Shuttles

Parameters:
positions -