Rename getInstance() -> getInputData(). Override getInputData() in solution classes to return correct type instead of abstract one.

This commit is contained in:
Holt59 2018-03-01 21:20:17 +01:00
parent 2fdaf30510
commit 4fae0e890c
8 changed files with 62 additions and 48 deletions

View File

@ -38,7 +38,7 @@ public abstract class AbstractAlgorithm<Observer> {
/**
* @return Instance corresponding to this algorithm.
*/
public AbstractData getInstance() { return instance; }
public AbstractData getInputData() { return instance; }
/**
* Run the algorithm and update the current solution.

View File

@ -43,7 +43,7 @@ public abstract class AbstractSolution {
/**
* @return Original instance for this solution.
*/
public AbstractData getInstance() { return instance; }
public AbstractData getInputData() { return instance; }
/**
* @return Status of this solution.

View File

@ -19,8 +19,8 @@ public abstract class StronglyConnectedComponentsAlgorithm extends AbstractAlgor
}
@Override
public StronglyConnectedComponentsData getInstance() {
return (StronglyConnectedComponentsData)super.getInstance();
public StronglyConnectedComponentsData getInputData() {
return (StronglyConnectedComponentsData)super.getInputData();
}
}

View File

@ -6,23 +6,30 @@ import org.insa.algo.AbstractSolution;
import org.insa.graph.Node;
public class StronglyConnectedComponentsSolution extends AbstractSolution {
// Components
private ArrayList<ArrayList<Node>> components;
protected StronglyConnectedComponentsSolution(StronglyConnectedComponentsData instance) {
super(instance);
}
protected StronglyConnectedComponentsSolution(StronglyConnectedComponentsData instance,
Status status, ArrayList<ArrayList<Node>> components) {
super(instance, status);
this.components = components;
}
/**
* @return Components of the solution, if any.
*/
public ArrayList<ArrayList<Node>> getComponents() { return components; }
// Components
private ArrayList<ArrayList<Node>> components;
protected StronglyConnectedComponentsSolution(StronglyConnectedComponentsData instance) {
super(instance);
}
protected StronglyConnectedComponentsSolution(StronglyConnectedComponentsData instance, Status status,
ArrayList<ArrayList<Node>> components) {
super(instance, status);
this.components = components;
}
@Override
public StronglyConnectedComponentsData getInputData() {
return (StronglyConnectedComponentsData) super.getInputData();
}
/**
* @return Components of the solution, if any.
*/
public ArrayList<ArrayList<Node>> getComponents() {
return components;
}
}

View File

@ -114,7 +114,7 @@ public class TarjanAlgorithm extends StronglyConnectedComponentsAlgorithm {
@Override
protected StronglyConnectedComponentsSolution doRun() {
Graph graph = getInstance().getGraph();
Graph graph = getInputData().getGraph();
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);
}
}

View File

@ -30,8 +30,8 @@ public class WeaklyConnectedComponentsAlgorithm extends AbstractAlgorithm<Weakly
}
@Override
public WeaklyConnectedComponentsData getInstance() {
return (WeaklyConnectedComponentsData) super.getInstance();
public WeaklyConnectedComponentsData getInputData() {
return (WeaklyConnectedComponentsData) super.getInputData();
}
/**
@ -73,13 +73,13 @@ public class WeaklyConnectedComponentsAlgorithm extends AbstractAlgorithm<Weakly
* graph.
*/
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);
for (int i = 0; i < nNodes; ++i) {
res.add(new HashSet<Integer>());
}
for (Node node: getInstance().getGraph().getNodes()) {
for (Node node: getInputData().getGraph().getNodes()) {
for (Arc arc: node.getSuccessors()) {
res.get(node.getId()).add(arc.getDestination().getId());
if (arc.getRoadInformation().isOneWay()) {
@ -101,7 +101,7 @@ public class WeaklyConnectedComponentsAlgorithm extends AbstractAlgorithm<Weakly
* @return
*/
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>();
// Using a queue because we are doing a BFS
@ -137,7 +137,7 @@ public class WeaklyConnectedComponentsAlgorithm extends AbstractAlgorithm<Weakly
@Override
protected WeaklyConnectedComponentsSolution doRun() {
Graph graph = getInstance().getGraph();
Graph graph = getInputData().getGraph();
ArrayList<HashSet<Integer>> ugraph = createUndirectedGraph();
boolean[] marked = new boolean[graph.getNodes().size()];
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);
}
}

View File

@ -6,23 +6,30 @@ import org.insa.algo.AbstractSolution;
import org.insa.graph.Node;
public class WeaklyConnectedComponentsSolution extends AbstractSolution {
// Components
private ArrayList<ArrayList<Node>> components;
protected WeaklyConnectedComponentsSolution(WeaklyConnectedComponentsData instance) {
super(instance);
}
protected WeaklyConnectedComponentsSolution(WeaklyConnectedComponentsData instance,
Status status, ArrayList<ArrayList<Node>> components) {
super(instance, status);
this.components = components;
}
/**
* @return Components of the solution, if any.
*/
public ArrayList<ArrayList<Node>> getComponents() { return components; }
// Components
private ArrayList<ArrayList<Node>> components;
protected WeaklyConnectedComponentsSolution(WeaklyConnectedComponentsData instance) {
super(instance);
}
protected WeaklyConnectedComponentsSolution(WeaklyConnectedComponentsData instance, Status status,
ArrayList<ArrayList<Node>> components) {
super(instance, status);
this.components = components;
}
@Override
public WeaklyConnectedComponentsData getInputData() {
return (WeaklyConnectedComponentsData) super.getInputData();
}
/**
* @return Components of the solution, if any.
*/
public ArrayList<ArrayList<Node>> getComponents() {
return components;
}
}

View File

@ -70,7 +70,7 @@ public class ShortestPathSolutionPanel extends JPanel implements DrawingChangeLi
* @return Data assocaited with this bundle.
*/
public ShortestPathData getData() {
return (ShortestPathData) this.solution.getInstance();
return this.solution.getInputData();
}
/**