Initial commit.
This commit is contained in:
59
src/main/org/insa/algo/AbstractAlgorithm.java
Normal file
59
src/main/org/insa/algo/AbstractAlgorithm.java
Normal file
@@ -0,0 +1,59 @@
|
||||
package org.insa.algo ;
|
||||
|
||||
import java.io.* ;
|
||||
|
||||
public abstract class AbstractAlgorithm {
|
||||
|
||||
protected PrintStream output;
|
||||
protected AbstractInstance instance;
|
||||
protected AbstractSolution solution;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param instance
|
||||
* @param logOutput
|
||||
*/
|
||||
protected AbstractAlgorithm(AbstractInstance instance, PrintStream logOutput) {
|
||||
this.instance = instance;
|
||||
this.output = logOutput;
|
||||
this.solution = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the current solution.
|
||||
*
|
||||
* @param solution New solution, or null to unset the current solution.
|
||||
*
|
||||
*/
|
||||
protected void updateLastSolution(AbstractSolution solution) {
|
||||
this.solution = solution;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Instance corresponding to this algorithm.
|
||||
*/
|
||||
public AbstractInstance getInstance() { return instance; }
|
||||
|
||||
/**
|
||||
* @return Last solution, or null if no solution was stored.
|
||||
*/
|
||||
public AbstractSolution getLastSolution() { return solution; }
|
||||
|
||||
/**
|
||||
* Run the algorithm and update the current solution.
|
||||
*
|
||||
* @return true if a feasible solution was found (even non-optimal).
|
||||
*/
|
||||
public boolean run() {
|
||||
this.solution = this.doRun();
|
||||
return this.solution != null && this.solution.isFeasible();
|
||||
}
|
||||
|
||||
/**
|
||||
* Abstract method that should be implemented by child class.
|
||||
*
|
||||
* @return A solution, if one was found, or null.
|
||||
*/
|
||||
protected abstract AbstractSolution doRun();
|
||||
|
||||
}
|
20
src/main/org/insa/algo/AbstractInstance.java
Normal file
20
src/main/org/insa/algo/AbstractInstance.java
Normal file
@@ -0,0 +1,20 @@
|
||||
package org.insa.algo;
|
||||
|
||||
import org.insa.graph.Graph;
|
||||
|
||||
public abstract class AbstractInstance {
|
||||
|
||||
protected Graph graph;
|
||||
|
||||
/**
|
||||
* Create a new abstract instance with the given graph.
|
||||
*
|
||||
* @param graph
|
||||
*/
|
||||
protected AbstractInstance(Graph graph) {
|
||||
this.graph = graph;
|
||||
}
|
||||
|
||||
public Graph getGraph() { return graph; }
|
||||
|
||||
}
|
67
src/main/org/insa/algo/AbstractSolution.java
Normal file
67
src/main/org/insa/algo/AbstractSolution.java
Normal file
@@ -0,0 +1,67 @@
|
||||
package org.insa.algo;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
public abstract class AbstractSolution {
|
||||
|
||||
/**
|
||||
* Possible status for a solution.
|
||||
*
|
||||
*/
|
||||
public enum Status {
|
||||
UNKNOWN,
|
||||
INFEASIBLE,
|
||||
FEASIBLE,
|
||||
OPTIMAL,
|
||||
};
|
||||
|
||||
// Status of the solution.
|
||||
Status status;
|
||||
|
||||
// Solving time for the solution
|
||||
Duration solvingTime;
|
||||
|
||||
// Original instance of the solution
|
||||
AbstractInstance instance;
|
||||
|
||||
/**
|
||||
* Create a new abstract solution with unknown status.
|
||||
*
|
||||
* @param instance
|
||||
*/
|
||||
protected AbstractSolution(AbstractInstance instance) {
|
||||
this.instance = instance;
|
||||
this.solvingTime = Duration.ZERO;
|
||||
this.status = Status.UNKNOWN;
|
||||
}
|
||||
|
||||
protected AbstractSolution(AbstractInstance instance,
|
||||
Duration solvingTime, Status status) {
|
||||
this.instance = instance;
|
||||
this.solvingTime = solvingTime;
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Original instance for this solution.
|
||||
*/
|
||||
public AbstractInstance getInstance() { return instance; }
|
||||
|
||||
/**
|
||||
* @return Status of this solution.
|
||||
*/
|
||||
public Status getStatus() { return status; }
|
||||
|
||||
/**
|
||||
* @return Solving time of this solution.
|
||||
*/
|
||||
public Duration getSolvingTime() { return solvingTime; }
|
||||
|
||||
/**
|
||||
* @return true if the solution is feasible or optimal.
|
||||
*/
|
||||
public boolean isFeasible() {
|
||||
return status == Status.FEASIBLE || status == Status.OPTIMAL;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,30 @@
|
||||
package org.insa.algo.connectivity ;
|
||||
|
||||
import java.io.* ;
|
||||
|
||||
import org.insa.algo.AbstractAlgorithm;
|
||||
import org.insa.algo.AbstractSolution;
|
||||
|
||||
public class ConnectivityAlgorithm extends AbstractAlgorithm {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param instance
|
||||
* @param logOutput
|
||||
*/
|
||||
public ConnectivityAlgorithm(ConnectivityInstance instance, PrintStream logOutput) {
|
||||
super(instance, logOutput);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
protected AbstractSolution doRun() {
|
||||
ConnectivityInstance instance = (ConnectivityInstance)getInstance();
|
||||
ConnectivitySolution solution = null;
|
||||
// TODO:
|
||||
return solution;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,16 @@
|
||||
package org.insa.algo.connectivity;
|
||||
|
||||
import org.insa.algo.AbstractInstance;
|
||||
import org.insa.graph.Graph;
|
||||
|
||||
public class ConnectivityInstance extends AbstractInstance {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param graph
|
||||
*/
|
||||
public ConnectivityInstance(Graph graph) {
|
||||
super(graph);
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,20 @@
|
||||
package org.insa.algo.connectivity;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
import org.insa.algo.AbstractSolution;
|
||||
|
||||
public class ConnectivitySolution extends AbstractSolution {
|
||||
|
||||
protected ConnectivitySolution(ConnectivityInstance instance) {
|
||||
super(instance);
|
||||
}
|
||||
|
||||
protected ConnectivitySolution(ConnectivityInstance instance,
|
||||
Duration solvingTime, Status status) {
|
||||
super(instance, solvingTime, status);
|
||||
|
||||
// TODO:
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user