mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
relax API
This commit is contained in:
parent
7fd1f90164
commit
08bb31c4f5
21 changed files with 112 additions and 25 deletions
|
|
@ -22,7 +22,7 @@ package algorithms;
|
|||
|
||||
import basics.route.TourActivity;
|
||||
|
||||
interface MarginalsCalculus {
|
||||
interface ActivityInsertionCostCalculator {
|
||||
|
||||
class Marginals {
|
||||
|
||||
|
|
@ -51,5 +51,7 @@ interface MarginalsCalculus {
|
|||
}
|
||||
|
||||
Marginals calculate(InsertionContext iContext, TourActivity prevAct, TourActivity nextAct, TourActivity newAct, double depTimeAtPrevAct);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
package algorithms;
|
||||
|
||||
import basics.VehicleRoutingProblem;
|
||||
import algorithms.HardConstraints.HardActivityLevelConstraint;
|
||||
import algorithms.HardConstraints.HardRouteLevelConstraint;
|
||||
|
||||
public class BestInsertionBuilder implements InsertionStrategyBuilder{
|
||||
|
||||
private VehicleRoutingProblem vrp;
|
||||
|
||||
private StateManager stateManager;
|
||||
|
||||
public BestInsertionBuilder(VehicleRoutingProblem vrp, StateManager stateManager) {
|
||||
super();
|
||||
this.vrp = vrp;
|
||||
this.stateManager = stateManager;
|
||||
}
|
||||
|
||||
public void addConstraint(HardActivityLevelConstraint hardActvitiyLevelConstraint){};
|
||||
|
||||
public void addConstraint(HardRouteLevelConstraint hardRouteLevelConstraint){};
|
||||
|
||||
public void setRouteLevel(int forwardLooking, int memory){};
|
||||
|
||||
public void setLocalLevel(){};
|
||||
|
||||
public void setActivityInsertionCostCalculator(ActivityInsertionCostCalculator costCalc){};
|
||||
|
||||
@Override
|
||||
public InsertionStrategy build() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -16,7 +16,7 @@ import org.apache.log4j.Logger;
|
|||
|
||||
import util.Neighborhood;
|
||||
import algorithms.HardConstraints.HardRouteLevelConstraint;
|
||||
import algorithms.MarginalsCalculus.Marginals;
|
||||
import algorithms.ActivityInsertionCostCalculator.Marginals;
|
||||
import basics.Job;
|
||||
import basics.Service;
|
||||
import basics.costs.VehicleRoutingTransportCosts;
|
||||
|
|
@ -47,7 +47,7 @@ final class CalculatesServiceInsertion implements JobInsertionCalculator{
|
|||
}
|
||||
};
|
||||
|
||||
private MarginalsCalculus marginalCalculus;
|
||||
private ActivityInsertionCostCalculator marginalCalculus;
|
||||
|
||||
private VehicleRoutingTransportCosts transportCosts;
|
||||
|
||||
|
|
@ -58,7 +58,7 @@ final class CalculatesServiceInsertion implements JobInsertionCalculator{
|
|||
logger.info("initialise neighborhood " + neighborhood);
|
||||
}
|
||||
|
||||
public CalculatesServiceInsertion(VehicleRoutingTransportCosts routingCosts, MarginalsCalculus marginalsCalculus, HardRouteLevelConstraint hardRouteLevelConstraint) {
|
||||
public CalculatesServiceInsertion(VehicleRoutingTransportCosts routingCosts, ActivityInsertionCostCalculator marginalsCalculus, HardRouteLevelConstraint hardRouteLevelConstraint) {
|
||||
super();
|
||||
this.marginalCalculus = marginalsCalculus;
|
||||
this.hardRouteLevelConstraint = hardRouteLevelConstraint;
|
||||
|
|
|
|||
|
|
@ -219,7 +219,7 @@ class CalculatorBuilder {
|
|||
private CalculatorPlusListeners createStandardLocal(VehicleRoutingProblem vrp, StateManager statesManager){
|
||||
if(constraintManager == null) throw new IllegalStateException("constraint-manager is null");
|
||||
|
||||
MarginalsCalculus defaultCalc = new MarginalsCalculusTriangleInequality(vrp.getTransportCosts(), vrp.getActivityCosts(), constraintManager);
|
||||
ActivityInsertionCostCalculator defaultCalc = new MarginalsCalculusTriangleInequality(vrp.getTransportCosts(), vrp.getActivityCosts(), constraintManager);
|
||||
JobInsertionCalculator standardServiceInsertion = new CalculatesServiceInsertion(vrp.getTransportCosts(), defaultCalc, constraintManager);
|
||||
|
||||
((CalculatesServiceInsertion) standardServiceInsertion).setNeighborhood(vrp.getNeighborhood());
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ class EuclideanServiceDistance implements JobDistance {
|
|||
}
|
||||
|
||||
@Override
|
||||
public double calculateDistance(Job i, Job j) {
|
||||
public double getDistance(Job i, Job j) {
|
||||
double avgCost = 0.0;
|
||||
if (i instanceof Service && j instanceof Service) {
|
||||
if (i.equals(j)) {
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ import basics.route.VehicleRoute;
|
|||
*
|
||||
*/
|
||||
|
||||
interface InsertionStrategy {
|
||||
public interface InsertionStrategy {
|
||||
|
||||
class Insertion {
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
package algorithms;
|
||||
|
||||
public interface InsertionStrategyBuilder {
|
||||
|
||||
public InsertionStrategy build();
|
||||
|
||||
}
|
||||
|
|
@ -16,8 +16,8 @@ import basics.Job;
|
|||
|
||||
|
||||
|
||||
interface JobDistance {
|
||||
public interface JobDistance {
|
||||
|
||||
public double calculateDistance(Job i, Job j);
|
||||
public double getDistance(Job i, Job j);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ class JobDistanceAvgCosts implements JobDistance {
|
|||
* <p>If the distance between two jobs cannot be calculated with input-transport costs, it tries the euclidean distance between these jobs.
|
||||
*/
|
||||
@Override
|
||||
public double calculateDistance(Job i, Job j) {
|
||||
public double getDistance(Job i, Job j) {
|
||||
double avgCost = 0.0;
|
||||
if (i instanceof Service && j instanceof Service) {
|
||||
if (i.equals(j)) {
|
||||
|
|
@ -72,7 +72,7 @@ class JobDistanceAvgCosts implements JobDistance {
|
|||
// now try the euclidean distance between these two services
|
||||
}
|
||||
EuclideanServiceDistance euclidean = new EuclideanServiceDistance();
|
||||
distance = euclidean.calculateDistance(s_i, s_j);
|
||||
distance = euclidean.getDistance(s_i, s_j);
|
||||
return distance;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ class JobDistanceBeeline implements JobDistance {
|
|||
}
|
||||
|
||||
@Override
|
||||
public double calculateDistance(Job i, Job j) {
|
||||
public double getDistance(Job i, Job j) {
|
||||
double avgCost = 0.0;
|
||||
if (i instanceof Service && j instanceof Service) {
|
||||
if (i.equals(j)) {
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ import basics.costs.VehicleRoutingActivityCosts;
|
|||
import basics.costs.VehicleRoutingTransportCosts;
|
||||
import basics.route.TourActivity;
|
||||
|
||||
class MarginalsCalculusTriangleInequality implements MarginalsCalculus{
|
||||
class MarginalsCalculusTriangleInequality implements ActivityInsertionCostCalculator{
|
||||
|
||||
private HardActivityLevelConstraint hardConstraint;
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,22 @@
|
|||
package algorithms;
|
||||
|
||||
import basics.VehicleRoutingProblem;
|
||||
|
||||
public class RadialRuinStrategyFactory implements RuinStrategyFactory{
|
||||
|
||||
private double fraction;
|
||||
|
||||
private JobDistance jobDistance;
|
||||
|
||||
public RadialRuinStrategyFactory(double fraction, JobDistance jobDistance) {
|
||||
super();
|
||||
this.fraction = fraction;
|
||||
this.jobDistance = jobDistance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RuinStrategy createStrategy(VehicleRoutingProblem vrp) {
|
||||
return new RuinRadial(vrp,fraction,jobDistance);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
package algorithms;
|
||||
|
||||
import basics.VehicleRoutingProblem;
|
||||
|
||||
public class RandomRuinStrategyFactory implements RuinStrategyFactory{
|
||||
|
||||
private double fraction;
|
||||
|
||||
public RandomRuinStrategyFactory(double fraction) {
|
||||
super();
|
||||
this.fraction = fraction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RuinStrategy createStrategy(VehicleRoutingProblem vrp) {
|
||||
return new RuinRandom(vrp, fraction);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -30,7 +30,7 @@ import basics.algo.InsertionListener;
|
|||
import basics.algo.SearchStrategyModule;
|
||||
import basics.algo.SearchStrategyModuleListener;
|
||||
|
||||
class RuinAndRecreateModule implements SearchStrategyModule{
|
||||
public class RuinAndRecreateModule implements SearchStrategyModule{
|
||||
|
||||
private InsertionStrategy insertion;
|
||||
|
||||
|
|
@ -49,9 +49,13 @@ class RuinAndRecreateModule implements SearchStrategyModule{
|
|||
public VehicleRoutingProblemSolution runAndGetSolution(VehicleRoutingProblemSolution vrpSolution) {
|
||||
Collection<Job> ruinedJobs = ruin.ruin(vrpSolution.getRoutes());
|
||||
insertion.insertJobs(vrpSolution.getRoutes(), ruinedJobs);
|
||||
scoreSolution(vrpSolution);
|
||||
return vrpSolution;
|
||||
}
|
||||
|
||||
private void scoreSolution(VehicleRoutingProblemSolution vrpSolution) {
|
||||
double totalCost = RouteUtils.getTotalCost(vrpSolution.getRoutes());
|
||||
vrpSolution.setCost(totalCost);
|
||||
return vrpSolution;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -106,7 +106,7 @@ final class RuinRadial implements RuinStrategy {
|
|||
});
|
||||
distanceNodeTree.put(i.getId(), treeSet);
|
||||
for (Job j : vrp.getJobs().values()) {
|
||||
double distance = jobDistance.calculateDistance(i, j);
|
||||
double distance = jobDistance.getDistance(i, j);
|
||||
ReferencedJob refNode = new ReferencedJob(j, distance);
|
||||
treeSet.add(refNode);
|
||||
nuOfDistancesStored++;
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ import basics.route.VehicleRoute;
|
|||
*
|
||||
*/
|
||||
|
||||
interface RuinStrategy {
|
||||
public interface RuinStrategy {
|
||||
|
||||
/**
|
||||
* Listener that listens to the ruin-process. It informs whoever is interested about start, end and about a removal of a job.
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ package algorithms;
|
|||
|
||||
import basics.VehicleRoutingProblem;
|
||||
|
||||
interface RuinStrategyFactory {
|
||||
public interface RuinStrategyFactory {
|
||||
|
||||
public RuinStrategy createStrategy(VehicleRoutingProblem vrp);
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ package algorithms;
|
|||
import basics.route.TourActivity;
|
||||
import basics.route.VehicleRoute;
|
||||
|
||||
interface StateManager {
|
||||
public interface StateManager {
|
||||
|
||||
interface State {
|
||||
double toDouble();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue