fastest path
This commit is contained in:
		
							parent
							
								
									bd9d89eaf5
								
							
						
					
					
						commit
						4345b03ba0
					
				
					 1 changed files with 28 additions and 0 deletions
				
			
		|  | @ -36,6 +36,34 @@ public class Path { | |||
|             throws IllegalArgumentException { | ||||
|         List<Arc> arcs = new ArrayList<Arc>(); | ||||
|         // TODO: | ||||
|         List <Node> nodes2=nodes; | ||||
|         Arc candidat = null; //arc candidat à être le plus rapide entre deux nodes | ||||
|         if(nodes.size()==0){ | ||||
|             return new Path(graph); | ||||
|         } | ||||
|         else if(nodes.size()==1){ | ||||
|             return new Path(graph,nodes.get(0)); | ||||
|         } | ||||
|         else{ | ||||
|             Node deb = nodes2.get(0); | ||||
|             for(Node fin : nodes2){ | ||||
|                 if(!fin.equals(deb)){ | ||||
|                 double time = Float.MAX_VALUE; | ||||
|                 for(Arc a : deb.getSuccessors()){ | ||||
|                     if(a.getDestination().equals(fin)&&time>a.getMinimumTravelTime()){ | ||||
|                         time = a.getMinimumTravelTime(); | ||||
|                         candidat=a; | ||||
|                     }  | ||||
|                 } | ||||
|          | ||||
|                 if(time==Float.MAX_VALUE){ | ||||
|                         throw new IllegalArgumentException("Liste de noeuds non valide"); | ||||
|                 } | ||||
|                 arcs.add(candidat); | ||||
|                 deb = fin; | ||||
|             } | ||||
|             } | ||||
|             } | ||||
|         return new Path(graph, arcs); | ||||
|     } | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue