71 lines
1.6 KiB
Java
71 lines
1.6 KiB
Java
|
|
package graph;
|
||
|
|
|
||
|
|
import java.util.Collections;
|
||
|
|
import java.util.Map;
|
||
|
|
|
||
|
|
import feature.Intersection;
|
||
|
|
import feature.StreetSegment;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Label-correcting shortest-path algorithm.
|
||
|
|
*/
|
||
|
|
public class LabelCorrectingAlgorithm extends AbstractShortestPathAlgorithm
|
||
|
|
{
|
||
|
|
private CandidateLabelManager labels;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Explicit value constructor.
|
||
|
|
*
|
||
|
|
* @param labels candidate label manager
|
||
|
|
*/
|
||
|
|
public LabelCorrectingAlgorithm(final CandidateLabelManager labels)
|
||
|
|
{
|
||
|
|
this.labels = labels;
|
||
|
|
}
|
||
|
|
|
||
|
|
@Override
|
||
|
|
public Map<String, StreetSegment> findPath(final int origin, final int destination,
|
||
|
|
final StreetNetwork net)
|
||
|
|
{
|
||
|
|
if (labels == null || net == null)
|
||
|
|
{
|
||
|
|
return Collections.emptyMap();
|
||
|
|
}
|
||
|
|
|
||
|
|
Label originLabel = labels.getLabel(origin);
|
||
|
|
if (originLabel == null)
|
||
|
|
{
|
||
|
|
return Collections.emptyMap();
|
||
|
|
}
|
||
|
|
originLabel.setValue(0.0);
|
||
|
|
|
||
|
|
Intersection originIntersection = net.getIntersection(origin);
|
||
|
|
if (originIntersection != null)
|
||
|
|
{
|
||
|
|
for (StreetSegment segment : originIntersection.getOutbound())
|
||
|
|
{
|
||
|
|
labels.adjustHeadValue(segment);
|
||
|
|
notifyStreetSegmentObservers(segment.getID());
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
Label current = labels.getCandidateLabel();
|
||
|
|
while (current != null)
|
||
|
|
{
|
||
|
|
Intersection intersection = net.getIntersection(current.getID());
|
||
|
|
if (intersection != null)
|
||
|
|
{
|
||
|
|
for (StreetSegment segment : intersection.getOutbound())
|
||
|
|
{
|
||
|
|
labels.adjustHeadValue(segment);
|
||
|
|
notifyStreetSegmentObservers(segment.getID());
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
current = labels.getCandidateLabel();
|
||
|
|
}
|
||
|
|
|
||
|
|
return buildPath(labels, origin, destination);
|
||
|
|
}
|
||
|
|
}
|