Initial commit.

This commit is contained in:
Mikael Capelle
2018-01-29 12:35:24 +01:00
commit 65c81b9921
34 changed files with 2193 additions and 0 deletions

View 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();
}

View 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; }
}

View 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;
}
}

View File

@@ -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;
}
}

View File

@@ -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);
}
}

View File

@@ -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:
}
}