Instance -> Data.
This commit is contained in:
parent
e111b5f0e6
commit
4017577269
@ -1,4 +1,4 @@
|
|||||||
package org.insa.algo ;
|
package org.insa.algo;
|
||||||
|
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
@ -6,17 +6,25 @@ import java.util.ArrayList;
|
|||||||
|
|
||||||
public abstract class AbstractAlgorithm<Observer> {
|
public abstract class AbstractAlgorithm<Observer> {
|
||||||
|
|
||||||
protected AbstractData instance;
|
protected AbstractInputData data;
|
||||||
protected ArrayList<Observer> observers;
|
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>();
|
this.observers = new ArrayList<Observer>();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected AbstractAlgorithm(AbstractData instance, ArrayList<Observer> observers) {
|
/**
|
||||||
this.instance = instance;
|
* @param data
|
||||||
this.observers = observers;;
|
* @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.
|
* @return Instance corresponding to this algorithm.
|
||||||
*/
|
*/
|
||||||
public AbstractData getInputData() { return instance; }
|
public AbstractInputData getInputData() {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run the algorithm and update the current solution.
|
* Run the algorithm and update the current solution.
|
||||||
|
@ -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; }
|
|
||||||
|
|
||||||
}
|
|
22
src/main/org/insa/algo/AbstractInputData.java
Normal file
22
src/main/org/insa/algo/AbstractInputData.java
Normal 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -9,51 +9,54 @@ public abstract class AbstractSolution {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public enum Status {
|
public enum Status {
|
||||||
UNKNOWN,
|
UNKNOWN, INFEASIBLE, FEASIBLE, OPTIMAL,
|
||||||
INFEASIBLE,
|
|
||||||
FEASIBLE,
|
|
||||||
OPTIMAL,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Status of the solution.
|
// Status of the solution.
|
||||||
Status status;
|
Status status;
|
||||||
|
|
||||||
// Solving time for the solution
|
// Solving time for the solution.
|
||||||
Duration solvingTime;
|
Duration solvingTime;
|
||||||
|
|
||||||
// Original instance of the solution
|
// Original input of the solution.
|
||||||
AbstractData instance;
|
AbstractInputData data;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new abstract solution with unknown status.
|
* Create a new abstract solution with unknown status.
|
||||||
*
|
*
|
||||||
* @param instance
|
* @param data
|
||||||
*/
|
*/
|
||||||
protected AbstractSolution(AbstractData instance) {
|
protected AbstractSolution(AbstractInputData data) {
|
||||||
this.instance = instance;
|
this.data = data;
|
||||||
this.solvingTime = Duration.ZERO;
|
this.solvingTime = Duration.ZERO;
|
||||||
this.status = Status.UNKNOWN;
|
this.status = Status.UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected AbstractSolution(AbstractData instance, Status status) {
|
protected AbstractSolution(AbstractInputData data, Status status) {
|
||||||
this.instance = instance;
|
this.data = data;
|
||||||
this.status = status;
|
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.
|
* @return Status of this solution.
|
||||||
*/
|
*/
|
||||||
public Status getStatus() { return status; }
|
public Status getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Solving time of this solution.
|
* @return Solving time of this solution.
|
||||||
*/
|
*/
|
||||||
public Duration getSolvingTime() { return solvingTime; }
|
public Duration getSolvingTime() {
|
||||||
|
return solvingTime;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the solving time of this solution.
|
* Set the solving time of this solution.
|
||||||
|
@ -1,26 +1,25 @@
|
|||||||
package org.insa.algo.strongconnectivity ;
|
package org.insa.algo.strongconnectivity;
|
||||||
|
|
||||||
import org.insa.algo.AbstractAlgorithm;
|
import org.insa.algo.AbstractAlgorithm;
|
||||||
|
|
||||||
public abstract class StronglyConnectedComponentsAlgorithm extends AbstractAlgorithm<StronglyConnectedComponentObserver> {
|
public abstract class StronglyConnectedComponentsAlgorithm
|
||||||
|
extends AbstractAlgorithm<StronglyConnectedComponentObserver> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* @param data
|
||||||
* @param instance
|
|
||||||
* @param logOutput
|
|
||||||
*/
|
*/
|
||||||
public StronglyConnectedComponentsAlgorithm(StronglyConnectedComponentsData instance) {
|
public StronglyConnectedComponentsAlgorithm(StronglyConnectedComponentsData data) {
|
||||||
super(instance);
|
super(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StronglyConnectedComponentsSolution run() {
|
public StronglyConnectedComponentsSolution run() {
|
||||||
return (StronglyConnectedComponentsSolution)super.run();
|
return (StronglyConnectedComponentsSolution) super.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StronglyConnectedComponentsData getInputData() {
|
public StronglyConnectedComponentsData getInputData() {
|
||||||
return (StronglyConnectedComponentsData)super.getInputData();
|
return (StronglyConnectedComponentsData) super.getInputData();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
package org.insa.algo.strongconnectivity;
|
package org.insa.algo.strongconnectivity;
|
||||||
|
|
||||||
import org.insa.algo.AbstractData;
|
import org.insa.algo.AbstractInputData;
|
||||||
import org.insa.graph.Graph;
|
import org.insa.graph.Graph;
|
||||||
|
|
||||||
public class StronglyConnectedComponentsData extends AbstractData {
|
public class StronglyConnectedComponentsData extends AbstractInputData {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -10,13 +10,13 @@ public class StronglyConnectedComponentsSolution extends AbstractSolution {
|
|||||||
// Components
|
// Components
|
||||||
private ArrayList<ArrayList<Node>> components;
|
private ArrayList<ArrayList<Node>> components;
|
||||||
|
|
||||||
protected StronglyConnectedComponentsSolution(StronglyConnectedComponentsData instance) {
|
protected StronglyConnectedComponentsSolution(StronglyConnectedComponentsData data) {
|
||||||
super(instance);
|
super(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected StronglyConnectedComponentsSolution(StronglyConnectedComponentsData instance, Status status,
|
protected StronglyConnectedComponentsSolution(StronglyConnectedComponentsData data,
|
||||||
ArrayList<ArrayList<Node>> components) {
|
Status status, ArrayList<ArrayList<Node>> components) {
|
||||||
super(instance, status);
|
super(data, status);
|
||||||
this.components = components;
|
this.components = components;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,8 +27,8 @@ public class TarjanAlgorithm extends StronglyConnectedComponentsAlgorithm {
|
|||||||
// Array of strongly connected components
|
// Array of strongly connected components
|
||||||
ArrayList<ArrayList<Node>> components;
|
ArrayList<ArrayList<Node>> components;
|
||||||
|
|
||||||
public TarjanAlgorithm(StronglyConnectedComponentsData instance) {
|
public TarjanAlgorithm(StronglyConnectedComponentsData data) {
|
||||||
super(instance);
|
super(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -13,15 +13,14 @@ import org.insa.graph.Arc;
|
|||||||
import org.insa.graph.Graph;
|
import org.insa.graph.Graph;
|
||||||
import org.insa.graph.Node;
|
import org.insa.graph.Node;
|
||||||
|
|
||||||
public class WeaklyConnectedComponentsAlgorithm extends AbstractAlgorithm<WeaklyConnectedComponentObserver> {
|
public class WeaklyConnectedComponentsAlgorithm
|
||||||
|
extends AbstractAlgorithm<WeaklyConnectedComponentObserver> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* @param data
|
||||||
* @param instance
|
|
||||||
* @param logOutput
|
|
||||||
*/
|
*/
|
||||||
public WeaklyConnectedComponentsAlgorithm(WeaklyConnectedComponentsData instance) {
|
public WeaklyConnectedComponentsAlgorithm(WeaklyConnectedComponentsData data) {
|
||||||
super(instance);
|
super(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
package org.insa.algo.weakconnectivity;
|
package org.insa.algo.weakconnectivity;
|
||||||
|
|
||||||
import org.insa.algo.AbstractData;
|
import org.insa.algo.AbstractInputData;
|
||||||
import org.insa.graph.Graph;
|
import org.insa.graph.Graph;
|
||||||
|
|
||||||
public class WeaklyConnectedComponentsData extends AbstractData {
|
public class WeaklyConnectedComponentsData extends AbstractInputData {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -10,13 +10,13 @@ public class WeaklyConnectedComponentsSolution extends AbstractSolution {
|
|||||||
// Components
|
// Components
|
||||||
private ArrayList<ArrayList<Node>> components;
|
private ArrayList<ArrayList<Node>> components;
|
||||||
|
|
||||||
protected WeaklyConnectedComponentsSolution(WeaklyConnectedComponentsData instance) {
|
protected WeaklyConnectedComponentsSolution(WeaklyConnectedComponentsData data) {
|
||||||
super(instance);
|
super(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected WeaklyConnectedComponentsSolution(WeaklyConnectedComponentsData instance, Status status,
|
protected WeaklyConnectedComponentsSolution(WeaklyConnectedComponentsData data, Status status,
|
||||||
ArrayList<ArrayList<Node>> components) {
|
ArrayList<ArrayList<Node>> components) {
|
||||||
super(instance, status);
|
super(data, status);
|
||||||
this.components = components;
|
this.components = components;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -617,9 +617,8 @@ public class MainWindow extends JFrame {
|
|||||||
wccItem.addActionListener(baf.createBlockingAction(new ActionListener() {
|
wccItem.addActionListener(baf.createBlockingAction(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
WeaklyConnectedComponentsData instance = new WeaklyConnectedComponentsData(graph);
|
|
||||||
WeaklyConnectedComponentsAlgorithm algo = new WeaklyConnectedComponentsAlgorithm(
|
WeaklyConnectedComponentsAlgorithm algo = new WeaklyConnectedComponentsAlgorithm(
|
||||||
instance);
|
new WeaklyConnectedComponentsData(graph));
|
||||||
algo.addObserver(new WeaklyConnectedComponentGraphicObserver(drawing));
|
algo.addObserver(new WeaklyConnectedComponentGraphicObserver(drawing));
|
||||||
algo.addObserver(new WeaklyConnectedComponentTextObserver(printStream));
|
algo.addObserver(new WeaklyConnectedComponentTextObserver(printStream));
|
||||||
launchThread(new Runnable() {
|
launchThread(new Runnable() {
|
||||||
|
Loading…
Reference in New Issue
Block a user