Rename getInstance() -> getInputData(). Override getInputData() in solution classes to return correct type instead of abstract one.
This commit is contained in:
		
							parent
							
								
									2fdaf30510
								
							
						
					
					
						commit
						4fae0e890c
					
				
					 8 changed files with 62 additions and 48 deletions
				
			
		|  | @ -38,7 +38,7 @@ public abstract class AbstractAlgorithm<Observer> { | ||||||
|     /** |     /** | ||||||
|      * @return Instance corresponding to this algorithm. |      * @return Instance corresponding to this algorithm. | ||||||
|      */ |      */ | ||||||
|     public AbstractData getInstance() { return instance; } |     public AbstractData getInputData() { return instance; } | ||||||
|          |          | ||||||
|     /** |     /** | ||||||
|      * Run the algorithm and update the current solution. |      * Run the algorithm and update the current solution. | ||||||
|  |  | ||||||
|  | @ -43,7 +43,7 @@ public abstract class AbstractSolution { | ||||||
| 	/** | 	/** | ||||||
| 	 * @return Original instance for this solution. | 	 * @return Original instance for this solution. | ||||||
| 	 */ | 	 */ | ||||||
| 	public AbstractData getInstance() { return instance; } | 	public AbstractData getInputData() { return instance; } | ||||||
| 	 | 	 | ||||||
| 	/** | 	/** | ||||||
| 	 * @return Status of this solution. | 	 * @return Status of this solution. | ||||||
|  |  | ||||||
|  | @ -19,8 +19,8 @@ public abstract class StronglyConnectedComponentsAlgorithm extends AbstractAlgor | ||||||
| 	} | 	} | ||||||
| 	 | 	 | ||||||
| 	@Override | 	@Override | ||||||
| 	public StronglyConnectedComponentsData getInstance() { | 	public StronglyConnectedComponentsData getInputData() { | ||||||
| 		return (StronglyConnectedComponentsData)super.getInstance(); | 		return (StronglyConnectedComponentsData)super.getInputData(); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -7,22 +7,29 @@ import org.insa.graph.Node; | ||||||
| 
 | 
 | ||||||
| public class StronglyConnectedComponentsSolution extends AbstractSolution { | public class StronglyConnectedComponentsSolution extends AbstractSolution { | ||||||
| 
 | 
 | ||||||
| 	// Components |     // Components | ||||||
| 	private ArrayList<ArrayList<Node>> components; |     private ArrayList<ArrayList<Node>> components; | ||||||
| 
 | 
 | ||||||
| 	protected StronglyConnectedComponentsSolution(StronglyConnectedComponentsData instance) { |     protected StronglyConnectedComponentsSolution(StronglyConnectedComponentsData instance) { | ||||||
| 		super(instance); |         super(instance); | ||||||
| 	} |     } | ||||||
| 
 | 
 | ||||||
| 	protected StronglyConnectedComponentsSolution(StronglyConnectedComponentsData instance,  |     protected StronglyConnectedComponentsSolution(StronglyConnectedComponentsData instance, Status status, | ||||||
| 					   Status status, ArrayList<ArrayList<Node>> components) { |             ArrayList<ArrayList<Node>> components) { | ||||||
| 		super(instance, status); |         super(instance, status); | ||||||
| 		this.components = components; |         this.components = components; | ||||||
| 	} |     } | ||||||
| 
 | 
 | ||||||
| 	/** |     @Override | ||||||
| 	 * @return Components of the solution, if any. |     public StronglyConnectedComponentsData getInputData() { | ||||||
| 	 */ |         return (StronglyConnectedComponentsData) super.getInputData(); | ||||||
| 	public ArrayList<ArrayList<Node>> getComponents() { return components; } |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * @return Components of the solution, if any. | ||||||
|  |      */ | ||||||
|  |     public ArrayList<ArrayList<Node>> getComponents() { | ||||||
|  |         return components; | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -114,7 +114,7 @@ public class TarjanAlgorithm extends StronglyConnectedComponentsAlgorithm { | ||||||
| 
 | 
 | ||||||
| 	@Override | 	@Override | ||||||
| 	protected StronglyConnectedComponentsSolution doRun() { | 	protected StronglyConnectedComponentsSolution doRun() { | ||||||
| 		Graph graph = getInstance().getGraph(); | 		Graph graph = getInputData().getGraph(); | ||||||
| 		 | 		 | ||||||
| 		components = new ArrayList<ArrayList<Node>>(); | 		components = new ArrayList<ArrayList<Node>>(); | ||||||
| 		 | 		 | ||||||
|  | @ -138,7 +138,7 @@ public class TarjanAlgorithm extends StronglyConnectedComponentsAlgorithm { | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 		 | 		 | ||||||
| 		return new StronglyConnectedComponentsSolution(getInstance(), Status.OPTIMAL, components); | 		return new StronglyConnectedComponentsSolution(getInputData(), Status.OPTIMAL, components); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -30,8 +30,8 @@ public class WeaklyConnectedComponentsAlgorithm extends AbstractAlgorithm<Weakly | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @Override |     @Override | ||||||
|     public WeaklyConnectedComponentsData getInstance() { |     public WeaklyConnectedComponentsData getInputData() { | ||||||
|         return (WeaklyConnectedComponentsData) super.getInstance(); |         return (WeaklyConnectedComponentsData) super.getInputData(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|  | @ -73,13 +73,13 @@ public class WeaklyConnectedComponentsAlgorithm extends AbstractAlgorithm<Weakly | ||||||
|      *         graph. |      *         graph. | ||||||
|      */ |      */ | ||||||
|     protected ArrayList<HashSet<Integer>> createUndirectedGraph() { |     protected ArrayList<HashSet<Integer>> createUndirectedGraph() { | ||||||
|         int nNodes = getInstance().getGraph().getNodes().size(); |         int nNodes = getInputData().getGraph().getNodes().size(); | ||||||
|         ArrayList<HashSet<Integer>> res = new ArrayList<HashSet<Integer>>(nNodes); |         ArrayList<HashSet<Integer>> res = new ArrayList<HashSet<Integer>>(nNodes); | ||||||
|         for (int i = 0; i < nNodes; ++i) { |         for (int i = 0; i < nNodes; ++i) { | ||||||
|             res.add(new HashSet<Integer>()); |             res.add(new HashSet<Integer>()); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         for (Node node: getInstance().getGraph().getNodes()) { |         for (Node node: getInputData().getGraph().getNodes()) { | ||||||
|             for (Arc arc: node.getSuccessors()) { |             for (Arc arc: node.getSuccessors()) { | ||||||
|                 res.get(node.getId()).add(arc.getDestination().getId()); |                 res.get(node.getId()).add(arc.getDestination().getId()); | ||||||
|                 if (arc.getRoadInformation().isOneWay()) { |                 if (arc.getRoadInformation().isOneWay()) { | ||||||
|  | @ -101,7 +101,7 @@ public class WeaklyConnectedComponentsAlgorithm extends AbstractAlgorithm<Weakly | ||||||
|      * @return |      * @return | ||||||
|      */ |      */ | ||||||
|     protected ArrayList<Node> bfs(ArrayList<HashSet<Integer>> ugraph, boolean[] marked, int cur) { |     protected ArrayList<Node> bfs(ArrayList<HashSet<Integer>> ugraph, boolean[] marked, int cur) { | ||||||
|         List<Node> nodes = getInstance().getGraph().getNodes(); |         List<Node> nodes = getInputData().getGraph().getNodes(); | ||||||
|         ArrayList<Node> component = new ArrayList<Node>(); |         ArrayList<Node> component = new ArrayList<Node>(); | ||||||
| 
 | 
 | ||||||
|         // Using a queue because we are doing a BFS |         // Using a queue because we are doing a BFS | ||||||
|  | @ -137,7 +137,7 @@ public class WeaklyConnectedComponentsAlgorithm extends AbstractAlgorithm<Weakly | ||||||
|     @Override |     @Override | ||||||
|     protected WeaklyConnectedComponentsSolution doRun() { |     protected WeaklyConnectedComponentsSolution doRun() { | ||||||
| 
 | 
 | ||||||
|         Graph graph = getInstance().getGraph(); |         Graph graph = getInputData().getGraph(); | ||||||
|         ArrayList<HashSet<Integer>> ugraph = createUndirectedGraph(); |         ArrayList<HashSet<Integer>> ugraph = createUndirectedGraph(); | ||||||
|         boolean[] marked = new boolean[graph.getNodes().size()]; |         boolean[] marked = new boolean[graph.getNodes().size()]; | ||||||
|         Arrays.fill(marked, false); |         Arrays.fill(marked, false); | ||||||
|  | @ -155,7 +155,7 @@ public class WeaklyConnectedComponentsAlgorithm extends AbstractAlgorithm<Weakly | ||||||
|                 ; |                 ; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         return new WeaklyConnectedComponentsSolution(getInstance(), Status.OPTIMAL, components); |         return new WeaklyConnectedComponentsSolution(getInputData(), Status.OPTIMAL, components); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -7,22 +7,29 @@ import org.insa.graph.Node; | ||||||
| 
 | 
 | ||||||
| public class WeaklyConnectedComponentsSolution extends AbstractSolution { | public class WeaklyConnectedComponentsSolution extends AbstractSolution { | ||||||
| 
 | 
 | ||||||
| 	// Components |     // Components | ||||||
| 	private ArrayList<ArrayList<Node>> components; |     private ArrayList<ArrayList<Node>> components; | ||||||
| 
 | 
 | ||||||
| 	protected WeaklyConnectedComponentsSolution(WeaklyConnectedComponentsData instance) { |     protected WeaklyConnectedComponentsSolution(WeaklyConnectedComponentsData instance) { | ||||||
| 		super(instance); |         super(instance); | ||||||
| 	} |     } | ||||||
| 
 | 
 | ||||||
| 	protected WeaklyConnectedComponentsSolution(WeaklyConnectedComponentsData instance,  |     protected WeaklyConnectedComponentsSolution(WeaklyConnectedComponentsData instance, Status status, | ||||||
| 					   Status status, ArrayList<ArrayList<Node>> components) { |             ArrayList<ArrayList<Node>> components) { | ||||||
| 		super(instance, status); |         super(instance, status); | ||||||
| 		this.components = components; |         this.components = components; | ||||||
| 	} |     } | ||||||
| 
 | 
 | ||||||
| 	/** |     @Override | ||||||
| 	 * @return Components of the solution, if any. |     public WeaklyConnectedComponentsData getInputData() { | ||||||
| 	 */ |         return (WeaklyConnectedComponentsData) super.getInputData(); | ||||||
| 	public ArrayList<ArrayList<Node>> getComponents() { return components; } |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * @return Components of the solution, if any. | ||||||
|  |      */ | ||||||
|  |     public ArrayList<ArrayList<Node>> getComponents() { | ||||||
|  |         return components; | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -70,7 +70,7 @@ public class ShortestPathSolutionPanel extends JPanel implements DrawingChangeLi | ||||||
|          * @return Data assocaited with this bundle. |          * @return Data assocaited with this bundle. | ||||||
|          */ |          */ | ||||||
|         public ShortestPathData getData() { |         public ShortestPathData getData() { | ||||||
|             return (ShortestPathData) this.solution.getInstance(); |             return this.solution.getInputData(); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         /** |         /** | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue