Instance -> Data.

This commit is contained in:
Mikael Capelle 2018-03-02 15:30:55 +01:00
parent e111b5f0e6
commit 4017577269
12 changed files with 288 additions and 276 deletions

View File

@ -6,17 +6,25 @@ import java.util.ArrayList;
public abstract class AbstractAlgorithm<Observer> {
protected AbstractData instance;
protected AbstractInputData data;
protected ArrayList<Observer> observers;
protected AbstractAlgorithm(AbstractData instance) {
this.instance = instance;
/**
* @param data
*/
protected AbstractAlgorithm(AbstractInputData data) {
this.data = data;
this.observers = new ArrayList<Observer>();
}
protected AbstractAlgorithm(AbstractData instance, ArrayList<Observer> observers) {
this.instance = instance;
this.observers = observers;;
/**
* @param data
* @param observers
*/
protected AbstractAlgorithm(AbstractInputData data, ArrayList<Observer> observers) {
this.data = data;
this.observers = observers;
;
}
/**
@ -38,7 +46,9 @@ public abstract class AbstractAlgorithm<Observer> {
/**
* @return Instance corresponding to this algorithm.
*/
public AbstractData getInputData() { return instance; }
public AbstractInputData getInputData() {
return data;
}
/**
* Run the algorithm and update the current solution.

View File

@ -1,20 +0,0 @@
package org.insa.algo;
import org.insa.graph.Graph;
public abstract class AbstractData {
protected Graph graph;
/**
* Create a new abstract instance with the given graph.
*
* @param graph
*/
protected AbstractData(Graph graph) {
this.graph = graph;
}
public Graph getGraph() { return graph; }
}

View File

@ -0,0 +1,22 @@
package org.insa.algo;
import org.insa.graph.Graph;
public abstract class AbstractInputData {
protected Graph graph;
/**
* Create a new AbstractInputData instance with the given graph.
*
* @param graph
*/
protected AbstractInputData(Graph graph) {
this.graph = graph;
}
public Graph getGraph() {
return graph;
}
}

View File

@ -9,51 +9,54 @@ public abstract class AbstractSolution {
*
*/
public enum Status {
UNKNOWN,
INFEASIBLE,
FEASIBLE,
OPTIMAL,
UNKNOWN, INFEASIBLE, FEASIBLE, OPTIMAL,
};
// Status of the solution.
Status status;
// Solving time for the solution
// Solving time for the solution.
Duration solvingTime;
// Original instance of the solution
AbstractData instance;
// Original input of the solution.
AbstractInputData data;
/**
* Create a new abstract solution with unknown status.
*
* @param instance
* @param data
*/
protected AbstractSolution(AbstractData instance) {
this.instance = instance;
protected AbstractSolution(AbstractInputData data) {
this.data = data;
this.solvingTime = Duration.ZERO;
this.status = Status.UNKNOWN;
}
protected AbstractSolution(AbstractData instance, Status status) {
this.instance = instance;
protected AbstractSolution(AbstractInputData data, Status status) {
this.data = data;
this.status = status;
}
/**
* @return Original instance for this solution.
* @return Original input for this solution.
*/
public AbstractData getInputData() { return instance; }
public AbstractInputData getInputData() {
return data;
}
/**
* @return Status of this solution.
*/
public Status getStatus() { return status; }
public Status getStatus() {
return status;
}
/**
* @return Solving time of this solution.
*/
public Duration getSolvingTime() { return solvingTime; }
public Duration getSolvingTime() {
return solvingTime;
}
/**
* Set the solving time of this solution.

View File

@ -2,15 +2,14 @@ package org.insa.algo.strongconnectivity ;
import org.insa.algo.AbstractAlgorithm;
public abstract class StronglyConnectedComponentsAlgorithm extends AbstractAlgorithm<StronglyConnectedComponentObserver> {
public abstract class StronglyConnectedComponentsAlgorithm
extends AbstractAlgorithm<StronglyConnectedComponentObserver> {
/**
*
* @param instance
* @param logOutput
* @param data
*/
public StronglyConnectedComponentsAlgorithm(StronglyConnectedComponentsData instance) {
super(instance);
public StronglyConnectedComponentsAlgorithm(StronglyConnectedComponentsData data) {
super(data);
}
@Override

View File

@ -1,9 +1,9 @@
package org.insa.algo.strongconnectivity;
import org.insa.algo.AbstractData;
import org.insa.algo.AbstractInputData;
import org.insa.graph.Graph;
public class StronglyConnectedComponentsData extends AbstractData {
public class StronglyConnectedComponentsData extends AbstractInputData {
/**
*

View File

@ -10,13 +10,13 @@ public class StronglyConnectedComponentsSolution extends AbstractSolution {
// Components
private ArrayList<ArrayList<Node>> components;
protected StronglyConnectedComponentsSolution(StronglyConnectedComponentsData instance) {
super(instance);
protected StronglyConnectedComponentsSolution(StronglyConnectedComponentsData data) {
super(data);
}
protected StronglyConnectedComponentsSolution(StronglyConnectedComponentsData instance, Status status,
ArrayList<ArrayList<Node>> components) {
super(instance, status);
protected StronglyConnectedComponentsSolution(StronglyConnectedComponentsData data,
Status status, ArrayList<ArrayList<Node>> components) {
super(data, status);
this.components = components;
}

View File

@ -27,8 +27,8 @@ public class TarjanAlgorithm extends StronglyConnectedComponentsAlgorithm {
// Array of strongly connected components
ArrayList<ArrayList<Node>> components;
public TarjanAlgorithm(StronglyConnectedComponentsData instance) {
super(instance);
public TarjanAlgorithm(StronglyConnectedComponentsData data) {
super(data);
}
/**

View File

@ -13,15 +13,14 @@ import org.insa.graph.Arc;
import org.insa.graph.Graph;
import org.insa.graph.Node;
public class WeaklyConnectedComponentsAlgorithm extends AbstractAlgorithm<WeaklyConnectedComponentObserver> {
public class WeaklyConnectedComponentsAlgorithm
extends AbstractAlgorithm<WeaklyConnectedComponentObserver> {
/**
*
* @param instance
* @param logOutput
* @param data
*/
public WeaklyConnectedComponentsAlgorithm(WeaklyConnectedComponentsData instance) {
super(instance);
public WeaklyConnectedComponentsAlgorithm(WeaklyConnectedComponentsData data) {
super(data);
}
@Override

View File

@ -1,9 +1,9 @@
package org.insa.algo.weakconnectivity;
import org.insa.algo.AbstractData;
import org.insa.algo.AbstractInputData;
import org.insa.graph.Graph;
public class WeaklyConnectedComponentsData extends AbstractData {
public class WeaklyConnectedComponentsData extends AbstractInputData {
/**
*

View File

@ -10,13 +10,13 @@ public class WeaklyConnectedComponentsSolution extends AbstractSolution {
// Components
private ArrayList<ArrayList<Node>> components;
protected WeaklyConnectedComponentsSolution(WeaklyConnectedComponentsData instance) {
super(instance);
protected WeaklyConnectedComponentsSolution(WeaklyConnectedComponentsData data) {
super(data);
}
protected WeaklyConnectedComponentsSolution(WeaklyConnectedComponentsData instance, Status status,
protected WeaklyConnectedComponentsSolution(WeaklyConnectedComponentsData data, Status status,
ArrayList<ArrayList<Node>> components) {
super(instance, status);
super(data, status);
this.components = components;
}

View File

@ -617,9 +617,8 @@ public class MainWindow extends JFrame {
wccItem.addActionListener(baf.createBlockingAction(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
WeaklyConnectedComponentsData instance = new WeaklyConnectedComponentsData(graph);
WeaklyConnectedComponentsAlgorithm algo = new WeaklyConnectedComponentsAlgorithm(
instance);
new WeaklyConnectedComponentsData(graph));
algo.addObserver(new WeaklyConnectedComponentGraphicObserver(drawing));
algo.addObserver(new WeaklyConnectedComponentTextObserver(printStream));
launchThread(new Runnable() {