implementation createfastestPathFromNodes()
Этот коммит содержится в:
родитель
61560998b8
коммит
cbca50bdd7
1 изменённых файлов: 27 добавлений и 3 удалений
|
|
@ -31,12 +31,36 @@ public class Path {
|
||||||
throws IllegalArgumentException {
|
throws IllegalArgumentException {
|
||||||
List<Arc> arcs = new ArrayList<Arc>();
|
List<Arc> arcs = new ArrayList<Arc>();
|
||||||
|
|
||||||
for(Node node : nodes)
|
if(nodes.size() == 1)
|
||||||
{
|
{
|
||||||
for( Arc arc : node.getSuccessors())
|
return new Path(graph, nodes.get(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int i = 0; i < nodes.size() - 1;i++)
|
||||||
|
{
|
||||||
|
Node origin = nodes.get(i);
|
||||||
|
Node destination = nodes.get(i+1);
|
||||||
|
|
||||||
|
List<Arc> successors = origin.getSuccessors();
|
||||||
|
Arc bestArc = null;
|
||||||
|
float speedMin = Float.MAX_VALUE;
|
||||||
|
for(Arc successor : successors)
|
||||||
{
|
{
|
||||||
|
double timeSuccessor = successor.getMinimumTravelTime();
|
||||||
|
if(successor.getDestination().equals(destination))
|
||||||
|
{
|
||||||
|
if (timeSuccessor < speedMin)
|
||||||
|
{
|
||||||
|
bestArc = successor;
|
||||||
|
speedMin = successor.getLength();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if (bestArc == null)
|
||||||
|
{
|
||||||
|
throw new IllegalArgumentException("No arc from " + origin.getId()+ "to " + destination.getId());
|
||||||
|
}
|
||||||
|
arcs.add(bestArc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Загрузка…
Сослаться в новой задаче