tp1
This commit is contained in:
		
							parent
							
								
									480b25bccc
								
							
						
					
					
						commit
						853637bb48
					
				
					 1 changed files with 22 additions and 4 deletions
				
			
		|  | @ -56,7 +56,22 @@ public class Path { | |||
|     public static Path createShortestPathFromNodes(Graph graph, List<Node> nodes) | ||||
|             throws IllegalArgumentException { | ||||
|         List<Arc> arcs = new ArrayList<Arc>(); | ||||
|         // TODO: | ||||
|         Arc candidat = null; | ||||
|         Node deb = nodes.remove(0);  | ||||
|         for(Node fin : nodes){ | ||||
|             float dist = Float.MAX_VALUE; | ||||
|             for(Arc a : deb.getSuccessors()){ | ||||
|                 if(a.getDestination().equals(fin)&&dist>a.getLength()){ | ||||
|                     dist = a.getLength(); | ||||
|                     candidat=a; | ||||
|                 }  | ||||
|             } | ||||
|             if(dist==Float.MAX_VALUE){ | ||||
|                     throw new IllegalArgumentException("Liste de noeuds non valide"); | ||||
|             } | ||||
|             arcs.add(candidat); | ||||
|             deb = fin; | ||||
|         } | ||||
|         return new Path(graph, arcs); | ||||
|     } | ||||
| 
 | ||||
|  | @ -175,7 +190,7 @@ public class Path { | |||
|         return this.origin == null; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|     /**speed | ||||
|      * Get the number of <b>nodes</b> in this path. | ||||
|      *  | ||||
|      * @return Number of nodes in this path. | ||||
|  | @ -228,8 +243,11 @@ public class Path { | |||
|      * @deprecated Need to be implemented. | ||||
|      */ | ||||
|     public double getTravelTime(double speed) { | ||||
|         // TODO: | ||||
|         return 0; | ||||
|         float res = 0; | ||||
|         for(Arc a : arcs){ | ||||
|             res+=a.getTravelTime(speed); | ||||
|         } | ||||
|         return res; | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue