|
||||||||||
| PREV CLASS Documentation homepage NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectilog.views.graphlayout.labellayout.IlvLabelLayout
ilog.views.graphlayout.labellayout.annealing.IlvAnnealingLabelLayout
public class IlvAnnealingLabelLayout
The main class for the Simulated Annealing Label Layout algorithm.
This performs a simulated annealing label positioning algorithm.
Each label is moved according to its label descriptor, such that the
overlaps among labels, and between labels and obstacles is small.
The label descriptor defines the area where a label can be placed.
For instance, to specify an area close to a given point, use the
IlvAnnealingPointLabelDescriptor (see
setLabelDescriptor), or to specify an area
along a polyline,
use the IlvAnnealingPolylineLabelDescriptor.
In the following sample drawings, the labels were placed by the
Annealing Label Layout algorithm.
They show point labeling with the
IlvAnnealingPointLabelDescriptor to place the labels
at nodes of a network or at cities of a map.
The following are two sample drawings that show link/line labeling with the
IlvAnnealingPolylineLabelDescriptor. Many options are provided
to tailor the placement. In the left drawing, the "Start Label", "End Label"
and "Center Label" were specified to be at the start, end, center,
respectively, of the corresponding link. The right drawing shows a link
with multiple labels. It is possible to specify the side of the link where
labels are placed.
Simulated annealing is a quality controlled, randomized iterative heuristic. The labels are placed according to a temperature scheme, and the quality of the placement increases when the temperature decreases. The quality is defined by the amount of overlaps between pairs of labels and between labels and obstacles. The fewer overlaps the higher the quality. Simulated annealing, as randomized algorithm, does not guarantee a placement of the labels without overlaps. However, it produces a quality layout with a high probability. The more iterations the higher the probability of high quality.
See the corresponding chapter of the User's Manual for details on the algorithm, the features and limitations, code samples, and so on.
Note that the initial position of the labels (at the moment you start the layout) does not affect the resulting layout.
| Field Summary |
|---|
| Fields inherited from class ilog.views.graphlayout.labellayout.IlvLabelLayout |
|---|
INVERSE_VIEW_COORDINATES, MANAGER_COORDINATES, VIEW_COORDINATES |
| Constructor Summary | |
|---|---|
IlvAnnealingLabelLayout()
Creates a new instance of the Annealing Layout algorithm. |
|
IlvAnnealingLabelLayout(IlvAnnealingLabelLayout source)
Creates a new label layout instance by copying an existing one. |
|
| Method Summary | |
|---|---|
void |
cleanLabel(IlvLabelingModel labelingModel,
Object label)
Cleans a label. |
void |
cleanObstacle(IlvLabelingModel labelingModel,
Object obstacle)
Cleans an obstacle. |
void |
contentsChanged(LabelingModelEvent event)
Overridden version of the base class method to allow the layout to automatically update the label positions when a related obstacle is moved. |
IlvLabelLayout |
copy()
Copies the layout instance. |
void |
copyParameters(IlvLabelLayout source)
Copies the parameters from a given layout instance. |
protected IlvLabelLayoutLabelProperty |
createLayoutLabelProperty(String name,
IlvGraphic label,
boolean withDefaults)
Returns a new instance of IlvAnnealingLabelLayoutLabelProperty
that stores the parameter settings of this layout class for labels. |
protected IlvLabelLayoutManagerProperty |
createLayoutManagerProperty(String name,
boolean withDefaults)
Returns a new instance of IlvAnnealingLabelLayoutManagerProperty
that stores the parameter settings of this layout class. |
void |
detach()
Detaches the labeling model from the layout instance. |
int |
getAllowedNumberOfIterations()
Returns the maximal allowed number of iterations of the layout algorithm. |
IlvAutoLayoutHandler |
getAutoLayoutHandler()
Returns the auto layout handler. |
IlvAnnealingLabelDescriptor |
getLabelDescriptor(Object label)
Returns the descriptor of the label. |
IlvLabelMovementPolicy |
getLabelMovementPolicy()
Returns the label movement policy used during layout. |
float |
getLabelOffset()
Returns the minimal offset between labels. |
Enumeration |
getLabelsOfObstacle(Object obstacle)
Returns the labels associated with an obstacle. |
int |
getMaxNumberOfFailIterations()
Returns the maximal number of iterations that doesn't improve the layout quality before the layout algorithm stops. |
float |
getMinImprovementPercentageToContinue()
Returns the minimal required percentage the layout needs to improve over a couple of rounds before the layout algorithm stops. |
int |
getNumberIterationsForMinImprovement()
Returns the number of iterations performed to reach the minimal required percentage of layout quality improvement. |
float |
getObstacleOffset()
Returns the global minimal offset between a label and an unrelated obstacle. |
IlvObstacleOffsetInterface |
getObstacleOffsetInterface()
Returns the obstacle offset interface used during layout. |
protected void |
init()
Initializes instance variables. |
boolean |
isAutoUpdate()
Returns true if the automatic update of labels on geometry
changes is enabled. |
boolean |
isUseQuadtree()
Returns true if the quadtree is enabled. |
protected void |
layout(boolean redraw)
Computes the layout using the Annealing Layout algorithm. |
void |
refreshAllLabelsOfObstacles()
Refreshes all the labels associated with obstacles. |
void |
refreshLabelsOfObstacle(Object obstacle)
Refreshes the labels associated with an obstacle. |
void |
setAllowedNumberOfIterations(int iterations)
Sets the maximal allowed number of iterations of the layout algorithm. |
void |
setAutoLayoutHandler(IlvAutoLayoutHandler handler)
Sets the auto layout handler. |
void |
setAutoUpdate(boolean flag)
Enables the automatic update of labels on geometry changes. |
void |
setLabelDescriptor(Object label,
IlvAnnealingLabelDescriptor descriptor)
Sets the descriptor of the label. |
void |
setLabelMovementPolicy(IlvLabelMovementPolicy policy)
Allows you to install a label movement policy, that is, an object that allows or prohibits a label being moved by the layout algorithm. |
void |
setLabelOffset(float offset)
Sets the minimal offset between the border of neighbored labels. |
void |
setMaxNumberOfFailIterations(int iterations)
Sets the maximal number of iterations that doesn't improve the layout quality before the layout algorithm stops. |
void |
setMinImprovementPercentageToContinue(float percentage)
Sets the minimal required percentage the layout needs to improve over a couple of rounds before the layout algorithm stops. |
void |
setNumberIterationsForMinImprovement(int iterations)
Sets the number of iterations performed to reach the minimal required percentage of layout quality improvement specified by setMinImprovementPercentageToContinue(float). |
void |
setObstacleOffset(float offset)
Sets the global minimal offset between a label and an unrelated obstacle. |
void |
setObstacleOffsetInterface(IlvObstacleOffsetInterface ifc)
Allows you to install an obstacle offset interface, that is, an object that allows selecting specific minimal offsets between certain label/obstacle pairs. |
void |
setUseQuadtree(boolean flag)
Enables the quadtree. |
boolean |
supportsAllowedTime()
Indicates that this layout class can stop the layout computation when the user-defined allowed time is exceeded. |
boolean |
supportsPercentageComplete()
Indicates that this layout class can estimate the percentage of completion during the run of layout. |
boolean |
supportsRandomGenerator()
Indicates that this layout class uses randomly-generated numbers that can be initialized with a user-defined seed value. |
boolean |
supportsSaveParametersToNamedProperties()
Indicates whether the layout class can transfer the layout parameters to named properties. |
boolean |
supportsStopImmediately()
Indicates that this layout class can interrupt the current run of the layout immediately in a controlled way. |
void |
updateLabelPosition(Object label,
boolean redraw)
Update the position of the input label when the related obstacle has moved. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public IlvAnnealingLabelLayout()
attach(IlvManager).
attach(IlvLabelingModel).
performLayout.
IlvLabelLayout.attach(ilog.views.IlvManager),
IlvLabelLayout.attach(IlvLabelingModel),
IlvLabelLayout.performLayout()public IlvAnnealingLabelLayout(IlvAnnealingLabelLayout source)
copy() method.
Any subclass should provide a copy constructor.
Note that layout parameters which are specific to a label or obstacle are not copied. Global layout parameters are copied.
source - The layout instance that is copied.| Method Detail |
|---|
protected void init()
You should not call this method directly. The method is called internally by the constructor without arguments and by the copy constructor. The method must be overridden by subclasses that need to initialize additional instance variables.
init in class IlvLabelLayoutpublic IlvLabelLayout copy()
This method copies the layout instance by calling the copy constructor.
copy in class IlvLabelLayoutIlvAnnealingLabelLayout(IlvAnnealingLabelLayout),
copyParameters(ilog.views.graphlayout.labellayout.IlvLabelLayout)public void copyParameters(IlvLabelLayout source)
Note that layout parameters which are specific to a label or obstacle are not copied. Global layout parameters are copied.
copyParameters in class IlvLabelLayoutsource - The layout instance from which the parameters are copied.copy()public void detach()
When a new labeling model is attached to the layout instance, it is not
necessary to detach the previously attached labeling model because this
is done automatically when the method IlvLabelLayout.attach(ilog.views.IlvManager) is called.
This method performs cleaning operations on the labeling model. In addition to the cleaning operations in the base class, Annealing Label Layout removes the label descriptors per label.
Note that you must call this method when you no longer need the layout instance; otherwise, some objects may not be garbage collected.
detach in class IlvLabelLayoutIlvLabelLayout.attach(ilog.views.IlvManager),
setLabelDescriptor(Object, IlvAnnealingLabelDescriptor)
public void cleanLabel(IlvLabelingModel labelingModel,
Object label)
cleanLabel in class IlvLabelLayoutlabelingModel - The graph model the label belongs tolabel - The label to be cleaneddetach()
public void cleanObstacle(IlvLabelingModel labelingModel,
Object obstacle)
cleanObstacle in class IlvLabelLayoutlabelingModel - The graph model the obstacle belongs toobstacle - The obstacle to be cleaneddetach()public void contentsChanged(LabelingModelEvent event)
If the auto update is enabled (that is, isAutoUpdate() returns
true) the method checks whether an auto layout handler is
installed. If a handler is installed, it calls
IlvAutoLayoutHandler.performAutoLayout(Object, Vector),
passing this as layout and the vector of changed objects.
Otherwise it simply calls the method
updateLabelPosition in order
to reposition the labels accordingly.
contentsChanged in interface LabelingModelListenercontentsChanged in class IlvLabelLayoutevent - The labeling model event that contains information about the
type of change that happens in the labeling model.setAutoUpdate(boolean),
setAutoLayoutHandler(ilog.views.graphlayout.IlvAutoLayoutHandler),
updateLabelPosition(Object, boolean)public void setAutoLayoutHandler(IlvAutoLayoutHandler handler)
getAutoLayoutHandler(),
setAutoUpdate(boolean),
contentsChanged(ilog.views.graphlayout.labellayout.LabelingModelEvent)public IlvAutoLayoutHandler getAutoLayoutHandler()
setAutoLayoutHandler(ilog.views.graphlayout.IlvAutoLayoutHandler),
setAutoUpdate(boolean),
contentsChanged(ilog.views.graphlayout.labellayout.LabelingModelEvent)
public void updateLabelPosition(Object label,
boolean redraw)
The normal usage of this method is to install a listener on the related object of the label that gets notified about the object movements. When notified, the listener should call this method to update the label position depending on the new position of the related object.
LabelingModelListener,
contentsChanged(LabelingModelEvent),
setAutoUpdate(boolean)protected void layout(boolean redraw)
IlvLabelLayout.performLayout().
layout in class IlvLabelLayoutredraw - If true, the attached labeling model will be
asked to redraw the manager after layout.
When the layout algorithm moves the labels, it is
required to pass the value of the redraw
argument to the method IlvLabelingModel.moveLabel(java.lang.Object, float, float, boolean).IlvLabelLayout.performLayout()public Enumeration getLabelsOfObstacle(Object obstacle)
IlvAnnealingLabelDescriptor.getRelatedObstacle()public void refreshLabelsOfObstacle(Object obstacle)
getLabelsOfObstacle(java.lang.Object) returns the correct associated labels.
getLabelsOfObstacle(java.lang.Object),
refreshAllLabelsOfObstacles()public void refreshAllLabelsOfObstacles()
getLabelsOfObstacle(java.lang.Object) returns the correct associated labels.
getLabelsOfObstacle(java.lang.Object),
refreshLabelsOfObstacle(Object)
public void setLabelDescriptor(Object label,
IlvAnnealingLabelDescriptor descriptor)
For instance, to specify that a label should move close to an
IlvGraphic that represents a city on a geographic map,
use an IlvAnnealingPointLabelDescriptor.
In order to specify that a label should be placed on a link, use an
IlvAnnealingLinkLabelDescriptor.
Label descriptors cannot be shared. You have to allocate a different label descriptor for each label.
label - The label.descriptor - The label descriptor.getLabelDescriptor(java.lang.Object),
IlvAnnealingLabelDescriptor,
IlvAnnealingPointLabelDescriptor,
IlvAnnealingPolylineLabelDescriptorpublic IlvAnnealingLabelDescriptor getLabelDescriptor(Object label)
label - The label.
setLabelDescriptor(Object, IlvAnnealingLabelDescriptor)public final void setLabelOffset(float offset)
Very large minimal offsets may slow down the layout considerably.
The default value is 0.
getLabelOffset()public final float getLabelOffset()
setLabelOffset(float)public final void setObstacleOffset(float offset)
setObstacleOffsetInterface(ilog.views.graphlayout.labellayout.annealing.IlvObstacleOffsetInterface).
The minimal offset is not used for the related obstacle of the
label, if any
(see IlvAnnealingPointLabelDescriptor.getRelatedObstacle()
and IlvAnnealingLabelDescriptor.considerObstacle(java.lang.Object)).
Simulated annealing is a quality controlled iterative heuristic. It will not always satisfy the minimal offset, but it will include the minimal offset in the calculation of the quality after each iteration step; hence, the majority of labels will most likely preserve the minimal offset at the end of layout.
Very large minimal offsets may slow down the layout considerably.
It is not recommended to set the global obstacle offset to an
unreasonably high value such as Float.MAX_VALUE, because this
causes computational problems inside quadtree operations (see
setUseQuadtree(boolean)).
The default value is 0.
offset - The offset value to set.getObstacleOffset(),
setObstacleOffsetInterface(ilog.views.graphlayout.labellayout.annealing.IlvObstacleOffsetInterface)public final float getObstacleOffset()
setObstacleOffset(float)public final void setObstacleOffsetInterface(IlvObstacleOffsetInterface ifc)
setObstacleOffset(float)) specifies globally the minimal offset
between labels and unrelated obstacles. The obstacle offset interface
can be used to make this minimal offset smaller for specific
label/obstacle pairs, hence allowing the label to move closer to the
corresponding obstacle than specified by the global obstacle offset.
The obstacle offset is not used for the related obstacle of the label, if
any (see IlvAnnealingPointLabelDescriptor.getRelatedObstacle()
and IlvAnnealingLabelDescriptor.considerObstacle(java.lang.Object)).
If an obstacle offset interface is installed, the effective minimal
offset between a label and an obstacle is the minimum of the value
provided by getObstacleOffset() and the value provided by
the obstacle interface. As an example, assume the labels in general must be
at least 10 units apart from unrelated obstacles, except for a specific
label "X" that can move as close as 3 units to specific obstacles "A"
and "B". You specify this by setting the global obstacle offset to 10,
and by installing an obstacle offset interface that returns 3 for the call
getOffset(model, X, A) and for the call
getOffset(model, X, B), while it returns
Float.MAX_VALUE for all other combinations of labels and
obstacles.
The obstacle offset interface cannot be used to make a minimal obstacle offset larger than the global obstacle offset. The global obstacle offset is always the upper limit, that is, if the obstacle offset interface returns larger values than the global obstacle offset, then the global offset is used.
ifc - The obstacle offset interface to set.getObstacleOffsetInterface(),
IlvObstacleOffsetInterfacepublic final IlvObstacleOffsetInterface getObstacleOffsetInterface()
null if none is specified.
setObstacleOffsetInterface(ilog.views.graphlayout.labellayout.annealing.IlvObstacleOffsetInterface)public final void setAllowedNumberOfIterations(int iterations)
Simulated annealing is a quality controlled, randomized iterative heuristic. It does not guarantee a placement of the labels without overlaps. However, the more iterations, the higher the probability that the heuristic ends up with a high quality layout without overlaps.
getAllowedNumberOfIterations()public final int getAllowedNumberOfIterations()
setAllowedNumberOfIterations(int)public final void setMaxNumberOfFailIterations(int iterations)
Simulated annealing is a quality controlled, randomized iterative heuristic. If after the specified number of iterations, the quality did not improve, the algorithm gives up. Hence, setting the maximal number to a high value avoids that the layout algorithm gives up too early, resulting in a better quality of the layout. Setting the maximal number to a low value speeds up the algorithm.
The default value is 20.
getMaxNumberOfFailIterations()public final int getMaxNumberOfFailIterations()
setMaxNumberOfFailIterations(int)public final void setMinImprovementPercentageToContinue(float percentage)
Simulated annealing is a quality controlled, randomized iterative heuristic. If, after the specified number of iterations, the quality did not improve at least by the specified percentage, the algorithm gives up. Hence, setting the percentage to 0 avoids that the layout algorithm gives up too early, resulting in a better quality of the layout. Setting the percentage to a high number speeds up the algorithm. Useful percentage values are between 0 and 5%.
The default value is 0.5%.
By default, the algorithm performs five iterations to reach at least 0.5%
improvement of the quality.
The number of iterations that are taken to reach the minimal percentage
of improvement can be set by setNumberIterationsForMinImprovement(int).
percentage - The minimal improvement value, as a percentage.getMinImprovementPercentageToContinue(),
setNumberIterationsForMinImprovement(int)public final float getMinImprovementPercentageToContinue()
setMinImprovementPercentageToContinue(float)public final void setNumberIterationsForMinImprovement(int iterations)
setMinImprovementPercentageToContinue(float).
Simulated annealing is a quality controlled, randomized iterative heuristic. If, after the specified number of iterations, the quality did not improve at least by the specified percentage, the algorithm gives up. Hence, setting the number of iterations to a high value avoids the layout algorithm giving up too early, resulting in a better quality of the layout. Setting the number of iterations to a small number speeds up the algorithm. Useful values are between 1 and 30.
The default value is 5.
iterations - The number of iterations to reach the minimal
improvement.getNumberIterationsForMinImprovement(),
setMinImprovementPercentageToContinue(float)public final int getNumberIterationsForMinImprovement()
setNumberIterationsForMinImprovement(int)public final void setUseQuadtree(boolean flag)
The quadtree is enabled by default.
isUseQuadtree(),
IlvLabelingModel.isBoundingBoxDependent()public final boolean isUseQuadtree()
true if the quadtree is enabled.
setUseQuadtree(boolean)public final void setLabelMovementPolicy(IlvLabelMovementPolicy policy)
An example of a label movement policy is an application that has its
own preprocessing phase for the label positions, so that the label layout
should treat only the remaining labels that the preprocessing phase could
not handle. For instance, the movement policy could check which labels
overlap with other labels and obstacles, and then move only these
overlapping labels, and keep those labels fixed that are initially
overlap-free. (This particular policy is available by the class
IlvOverlappingLabelMovementPolicy).
policy - The label movement policy.getLabelMovementPolicy()public final IlvLabelMovementPolicy getLabelMovementPolicy()
null if none is specified.
setLabelMovementPolicy(ilog.views.graphlayout.labellayout.IlvLabelMovementPolicy)public final void setAutoUpdate(boolean flag)
updateLabelPosition(Object, boolean)
for each label that has a point label descriptor or polyline label
descriptor with a related obstacle that was moved or resized.
It is disabled by default.
It is designed to automatically update the labels during interactions. Hence, it is optimized for speed: It does not perform a full layout and does not try to avoid overlaps.
If the default labeling model is used, the automatic update is not always
performed on zoom level changes. This may lead to undesired results
with nonzoomable objects (see IlvGraphic.zoomable()). We recommend
to use zoomable objects.
IlvAnnealingPointLabelDescriptor,
IlvAnnealingPolylineLabelDescriptor,
IlvDefaultLabelingModel,
isAutoUpdate(),
setAutoLayoutHandler(ilog.views.graphlayout.IlvAutoLayoutHandler)public final boolean isAutoUpdate()
true if the automatic update of labels on geometry
changes is enabled.
setAutoUpdate(boolean)public final boolean supportsPercentageComplete()
supportsPercentageComplete in class IlvLabelLayouttrue.IlvLabelLayout.increasePercentageComplete(int),
IlvLabelLayoutReport.getPercentageComplete()public final boolean supportsRandomGenerator()
useSeedValueForRandomGenerator with
a true argument.
supportsRandomGenerator in class IlvLabelLayouttrue.IlvLabelLayout.setSeedValueForRandomGenerator(long),
IlvLabelLayout.getSeedValueForRandomGenerator(),
IlvLabelLayout.setUseSeedValueForRandomGenerator(boolean),
IlvLabelLayout.isUseSeedValueForRandomGenerator()public final boolean supportsAllowedTime()
IlvLabelLayoutReport.STOPPED_AND_VALID in this case,
if all labels were moved at least once to a better position,
and IlvLabelLayoutReport.STOPPED_AND_INVALID otherwise.
supportsAllowedTime in class IlvLabelLayouttrue.IlvLabelLayout.setAllowedTime(long),
IlvLabelLayout.getAllowedTime(),
IlvLabelLayoutReport.getCode()public boolean supportsStopImmediately()
IlvLabelLayoutReport.STOPPED_AND_VALID in this case,
if all labels were moved at least once to a better position,
and IlvLabelLayoutReport.STOPPED_AND_INVALID otherwise.
supportsStopImmediately in class IlvLabelLayouttrue.IlvLabelLayout.stopImmediately(),
IlvLabelLayout.isStoppedImmediately(),
IlvLabelLayoutReport.getCode()public boolean supportsSaveParametersToNamedProperties()
.ivl file.
supportsSaveParametersToNamedProperties in class IlvLabelLayouttrue.IlvDefaultLabelingModel.saveParametersToNamedProperties(ilog.views.graphlayout.labellayout.IlvLabelLayout, boolean),
IlvDefaultLabelingModel.loadParametersFromNamedProperties(ilog.views.graphlayout.labellayout.IlvLabelLayout),
IlvDefaultLabelingModel.removeParametersFromNamedProperties()
protected IlvLabelLayoutManagerProperty createLayoutManagerProperty(String name,
boolean withDefaults)
IlvAnnealingLabelLayoutManagerProperty
that stores the parameter settings of this layout class.
The method is used by
IlvDefaultLabelingModel.saveParametersToNamedProperties(IlvLabelLayout, boolean)
to create a named property that contains parameter settings of this layout
instance.
createLayoutManagerProperty in class IlvLabelLayoutIlvLabelLayoutManagerProperty,
IlvDefaultLabelingModel.saveParametersToNamedProperties(ilog.views.graphlayout.labellayout.IlvLabelLayout, boolean),
IlvDefaultLabelingModel.loadParametersFromNamedProperties(ilog.views.graphlayout.labellayout.IlvLabelLayout),
IlvDefaultLabelingModel.removeParametersFromNamedProperties()
protected IlvLabelLayoutLabelProperty createLayoutLabelProperty(String name,
IlvGraphic label,
boolean withDefaults)
IlvAnnealingLabelLayoutLabelProperty
that stores the parameter settings of this layout class for labels.
The method is used by
IlvDefaultLabelingModel.saveParametersToNamedProperties(IlvLabelLayout, boolean)
to create a named property for a label that contains parameter settings
of a layout instance for this label.
createLayoutLabelProperty in class IlvLabelLayoutsupportsSaveParametersToNamedProperties(),
IlvLabelLayoutLabelProperty,
IlvDefaultLabelingModel.saveParametersToNamedProperties(ilog.views.graphlayout.labellayout.IlvLabelLayout, boolean),
IlvDefaultLabelingModel.loadParametersFromNamedProperties(ilog.views.graphlayout.labellayout.IlvLabelLayout),
IlvDefaultLabelingModel.removeParametersFromNamedProperties()
|
||||||||||
| PREV CLASS Documentation homepage NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||