public class GraphPartition extends Object implements IPartition, IDynamicDecomposition, IDecompositionListener
GraphPartition partitions the bounding box of a graph into rectangles using the graph elements as
Obstacles.
All Obstacles used during the partitioning are created by
IGraphPartitionExtensions. IGraphPartitionExtensions have been registered
before using method IGraphPartitionExtension.preparePartition(PathSearchConfiguration, GraphPartition) which is
called during the initialization of a GraphPartition.
The core partitioning is delegated to an IObstaclePartition that is initialized
with these Obstacles.
If the IObstaclePartition is of type IDynamicDecomposition, GraphPartition re-dispatches the
decomposition notifications to its extensions.
IGraphPartitionExtension| Constructor and Description |
|---|
GraphPartition(IObstaclePartition partition)
Creates a new
GraphPartition instance using the given
delegate inner obstacle partition. |
| Modifier and Type | Method and Description |
|---|---|
void |
addDynamicDecompositionListener(IDecompositionListener listener)
Adds the given listener to the
GraphPartition. |
void |
clear()
Clears the
partition data such that the GraphPartition can be reused and initialized
with a new configuration. |
Obstacle |
createObstacle(YRectangle bounds,
Object data)
Creates and returns a new
Obstacle using the given bounds and data. |
YRectangle |
getBounds()
Gets the bounds of the original rectangular area that is being partitioned.
|
List<Object> |
getCells(Node node)
Returns all
PartitionCells that are completely covered by the bounds of the given node. |
List<Object> |
getCells(YRectangle rect)
Returns a list of all
PartitionCells that intersect or cover the given rectangle by delegating to the
corresponding method of the inner partition. |
List<Object> |
getNeighbors(PartitionCell cell)
Returns a list of all
PartitionCells that are neighbors of the given cell, i.e., those cells that have a common border segment
with the given cell. |
List<Object> |
getNodes(PartitionCell cell)
Returns a list of all
Nodes whose bounds intersect or cover the bounds of the given cell. |
Obstacle |
getObstacle(Object data)
Returns the
Obstacle that has been created earlier for the given data object. |
List<Object> |
getObstacles(PartitionCell cell)
Returns all
Obstacles covering the given PartitionCell by delegating to the corresponding method of the
inner partition. |
protected IObstaclePartition |
getPartition()
Gets the delegate inner obstacle partition.
|
void |
init(PathSearchConfiguration configuration)
Initializes the
GraphPartition with the given graph instance based on the given configuration
used by path search algorithms. |
void |
onCellCreated(PartitionCell createdCell)
Re-dispatches the event of the creation of a new
PartitionCell to all registered
IDecompositionListeners. |
void |
onCellFinalized(PartitionCell finalizedCell)
Re-dispatches the event of having completed the process of subdivisions of a given
PartitionCell to all
registered IDecompositionListeners. |
void |
onCellSubdivided(PartitionCell cell,
List<Object> subCells)
Re-dispatches the event of the subdivision of a given
PartitionCell into several sub-cells to all registered
IDecompositionListeners. |
void |
removeDynamicDecompositionListener(IDecompositionListener listener)
Removes the given listener from the
GraphPartition. |
public GraphPartition(IObstaclePartition partition)
GraphPartition instance using the given
delegate inner obstacle partition.partition - the delegate inner obstacle partitionpublic void addDynamicDecompositionListener(IDecompositionListener listener)
GraphPartition.
The listener will be notified upon dynamic decomposition events. If it is a IGraphPartitionExtension, method IGraphPartitionExtension.preparePartition(PathSearchConfiguration, GraphPartition)
is called during initialization.
addDynamicDecompositionListener in interface IDynamicDecompositionlistener - the listener to be addedpublic void clear()
partition data such that the GraphPartition can be reused and initialized
with a new configuration.
All IGraphPartitionExtensions are cleaned up; partition listeners and
obstacles are removed.
init(PathSearchConfiguration)public Obstacle createObstacle(YRectangle bounds, Object data)
Obstacle using the given bounds and data.
All obstacles created via this method are delegated to the inner partition upon
initialization.
bounds - the bounds of the obstacledata - the additional data that should be associated with the obstacleObstacle using the given bounds and datapublic YRectangle getBounds()
This method delegates to the corresponding method of the inner partition.
getBounds in interface IPartitionIPartition.getBounds()public List<Object> getCells(Node node)
PartitionCells that are completely covered by the bounds of the given node.IllegalArgumentException - if the node is unknownnode - the node for which the covered cells will be returnedPartitionCell instances that are completely covered by the bounds of the given nodepublic List<Object> getCells(YRectangle rect)
PartitionCells that intersect or cover the given rectangle by delegating to the
corresponding method of the inner partition.getCells in interface IPartitionrect - the rectangular area whose (partially) covered cells will be returnedPartitionCellsIPartition.getCells(YRectangle)public List<Object> getNeighbors(PartitionCell cell)
PartitionCells that are neighbors of the given cell, i.e., those cells that have a common border segment
with the given cell.getNeighbors in interface IPartitioncell - the cell whose neighbors will be returnedPartitionCells that are neighbors of the given cellpublic List<Object> getNodes(PartitionCell cell)
Nodes whose bounds intersect or cover the bounds of the given cell.cell - the cellNodes that are intersected by the given cellpublic Obstacle getObstacle(Object data)
Obstacle that has been created earlier for the given data object.data - the given data for which the obstacle will be returnedObstacle that has been created earlier for the given data objectpublic List<Object> getObstacles(PartitionCell cell)
Obstacles covering the given PartitionCell by delegating to the corresponding method of the
inner partition.cell - the cell whose obstacles will be returnedObstacles that cover the given cellIObstaclePartition.getObstacles(PartitionCell)protected IObstaclePartition getPartition()
public void init(PathSearchConfiguration configuration)
GraphPartition with the given graph instance based on the given configuration
used by path search algorithms.
Before calling this method, any old partitioning information must be cleared.
This initialization method calls IGraphPartitionExtension.preparePartition(PathSearchConfiguration, GraphPartition)
of all registered extensions. Then, the inner delegate partition is initialized passing all added
obstacles as well as the given graph's bounds extended by a small padding.
In the case where the delegate partition is of type IDynamicDecomposition, this GraphPartition
will also be added as IDecompositionListener to it.
configuration - the configuration used by path search algorithmsclear(),
IGraphPartitionExtension.preparePartition(PathSearchConfiguration, GraphPartition),
addDynamicDecompositionListener(IDecompositionListener)public void onCellCreated(PartitionCell createdCell)
PartitionCell to all registered
IDecompositionListeners.
This method is a callback after a PartitionCell has been created.
onCellCreated in interface IDecompositionListenercreatedCell - the newly created PartitionCellpublic void onCellFinalized(PartitionCell finalizedCell)
PartitionCell to all
registered IDecompositionListeners.
This method is a callback after a PartitionCell has been finalized and won't be further subdivided.
onCellFinalized in interface IDecompositionListenerfinalizedCell - the cell that has been finalizedpublic void onCellSubdivided(PartitionCell cell, List<Object> subCells)
PartitionCell into several sub-cells to all registered
IDecompositionListeners.
This method is a callback after a PartitionCell has been subdivided into several sub-cells.
onCellSubdivided in interface IDecompositionListenercell - the cell that has been subdividedsubCells - the sub-cells resulting from the subdivision of the given PartitionCellpublic void removeDynamicDecompositionListener(IDecompositionListener listener)
GraphPartition.
The listener will not be notified of dynamic decomposition events anymore.
removeDynamicDecompositionListener in interface IDynamicDecompositionlistener - the listener to be removed