Merge branch 'master' of https://git.etud.insa-toulouse.fr/rees/Graphes_REES_KOUTSODIMA
This commit is contained in:
		
						commit
						bd9d89eaf5
					
				
					 1 changed files with 16 additions and 3 deletions
				
			
		|  | @ -55,9 +55,19 @@ public class Path { | |||
|     public static Path createShortestPathFromNodes(Graph graph, List<Node> nodes) | ||||
|             throws IllegalArgumentException { | ||||
|         List<Arc> arcs = new ArrayList<Arc>(); | ||||
|         Arc candidat = null; | ||||
|         Node deb = nodes.remove(0);  | ||||
|         for(Node fin : nodes){ | ||||
|         List<Node> nodes2 = nodes; | ||||
|         Arc candidat = null; //arc candidat à être le plus court 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)){ | ||||
|             float dist = Float.MAX_VALUE; | ||||
|             for(Arc a : deb.getSuccessors()){ | ||||
|                 if(a.getDestination().equals(fin)&&dist>a.getLength()){ | ||||
|  | @ -65,12 +75,15 @@ public class Path { | |||
|                     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); | ||||
|     } | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue