mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
Merge branch 'master' into driver-breaks
This commit is contained in:
commit
11a320c2e4
19 changed files with 259 additions and 77 deletions
|
|
@ -35,6 +35,8 @@ import java.util.concurrent.Executors;
|
||||||
|
|
||||||
public class Jsprit {
|
public class Jsprit {
|
||||||
|
|
||||||
|
private final ActivityInsertionCostsCalculator activityInsertion;
|
||||||
|
|
||||||
public enum Construction {
|
public enum Construction {
|
||||||
|
|
||||||
BEST_INSERTION("best_insertion"), REGRET_INSERTION("regret_insertion");
|
BEST_INSERTION("best_insertion"), REGRET_INSERTION("regret_insertion");
|
||||||
|
|
@ -132,6 +134,8 @@ public class Jsprit {
|
||||||
|
|
||||||
private Random random = RandomNumberGeneration.newInstance();
|
private Random random = RandomNumberGeneration.newInstance();
|
||||||
|
|
||||||
|
private ActivityInsertionCostsCalculator activityInsertionCalculator;
|
||||||
|
|
||||||
public static Builder newInstance(VehicleRoutingProblem vrp) {
|
public static Builder newInstance(VehicleRoutingProblem vrp) {
|
||||||
return new Builder(vrp);
|
return new Builder(vrp);
|
||||||
}
|
}
|
||||||
|
|
@ -225,6 +229,11 @@ public class Jsprit {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Builder setActivityInsertionCalculator(ActivityInsertionCostsCalculator activityInsertionCalculator){
|
||||||
|
this.activityInsertionCalculator = activityInsertionCalculator;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public VehicleRoutingAlgorithm buildAlgorithm() {
|
public VehicleRoutingAlgorithm buildAlgorithm() {
|
||||||
return new Jsprit(this).create(vrp);
|
return new Jsprit(this).create(vrp);
|
||||||
}
|
}
|
||||||
|
|
@ -294,6 +303,7 @@ public class Jsprit {
|
||||||
this.properties = builder.properties;
|
this.properties = builder.properties;
|
||||||
this.objectiveFunction = builder.objectiveFunction;
|
this.objectiveFunction = builder.objectiveFunction;
|
||||||
this.random = builder.random;
|
this.random = builder.random;
|
||||||
|
this.activityInsertion = builder.activityInsertionCalculator;
|
||||||
}
|
}
|
||||||
|
|
||||||
private VehicleRoutingAlgorithm create(final VehicleRoutingProblem vrp) {
|
private VehicleRoutingAlgorithm create(final VehicleRoutingProblem vrp) {
|
||||||
|
|
@ -403,6 +413,7 @@ public class Jsprit {
|
||||||
.setConcurrentMode(es, noThreads)
|
.setConcurrentMode(es, noThreads)
|
||||||
.considerFixedCosts(toDouble(getProperty(Parameter.FIXED_COST_PARAM.toString())))
|
.considerFixedCosts(toDouble(getProperty(Parameter.FIXED_COST_PARAM.toString())))
|
||||||
.setAllowVehicleSwitch(toBoolean(getProperty(Parameter.VEHICLE_SWITCH.toString())))
|
.setAllowVehicleSwitch(toBoolean(getProperty(Parameter.VEHICLE_SWITCH.toString())))
|
||||||
|
.setActivityInsertionCostCalculator(activityInsertion)
|
||||||
.build();
|
.build();
|
||||||
scorer = getRegretScorer(vrp);
|
scorer = getRegretScorer(vrp);
|
||||||
regretInsertion.setScoringFunction(scorer);
|
regretInsertion.setScoringFunction(scorer);
|
||||||
|
|
@ -412,6 +423,7 @@ public class Jsprit {
|
||||||
.setInsertionStrategy(InsertionBuilder.Strategy.REGRET)
|
.setInsertionStrategy(InsertionBuilder.Strategy.REGRET)
|
||||||
.setAllowVehicleSwitch(toBoolean(getProperty(Parameter.VEHICLE_SWITCH.toString())))
|
.setAllowVehicleSwitch(toBoolean(getProperty(Parameter.VEHICLE_SWITCH.toString())))
|
||||||
.considerFixedCosts(toDouble(getProperty(Parameter.FIXED_COST_PARAM.toString())))
|
.considerFixedCosts(toDouble(getProperty(Parameter.FIXED_COST_PARAM.toString())))
|
||||||
|
.setActivityInsertionCostCalculator(activityInsertion)
|
||||||
.build();
|
.build();
|
||||||
scorer = getRegretScorer(vrp);
|
scorer = getRegretScorer(vrp);
|
||||||
regretInsertion.setScoringFunction(scorer);
|
regretInsertion.setScoringFunction(scorer);
|
||||||
|
|
@ -425,6 +437,7 @@ public class Jsprit {
|
||||||
.setInsertionStrategy(InsertionBuilder.Strategy.BEST)
|
.setInsertionStrategy(InsertionBuilder.Strategy.BEST)
|
||||||
.considerFixedCosts(Double.valueOf(properties.getProperty(Parameter.FIXED_COST_PARAM.toString())))
|
.considerFixedCosts(Double.valueOf(properties.getProperty(Parameter.FIXED_COST_PARAM.toString())))
|
||||||
.setAllowVehicleSwitch(toBoolean(getProperty(Parameter.VEHICLE_SWITCH.toString())))
|
.setAllowVehicleSwitch(toBoolean(getProperty(Parameter.VEHICLE_SWITCH.toString())))
|
||||||
|
.setActivityInsertionCostCalculator(activityInsertion)
|
||||||
.build();
|
.build();
|
||||||
best = bestInsertion;
|
best = bestInsertion;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -433,6 +446,7 @@ public class Jsprit {
|
||||||
.considerFixedCosts(Double.valueOf(properties.getProperty(Parameter.FIXED_COST_PARAM.toString())))
|
.considerFixedCosts(Double.valueOf(properties.getProperty(Parameter.FIXED_COST_PARAM.toString())))
|
||||||
.setAllowVehicleSwitch(toBoolean(getProperty(Parameter.VEHICLE_SWITCH.toString())))
|
.setAllowVehicleSwitch(toBoolean(getProperty(Parameter.VEHICLE_SWITCH.toString())))
|
||||||
.setConcurrentMode(es, noThreads)
|
.setConcurrentMode(es, noThreads)
|
||||||
|
.setActivityInsertionCostCalculator(activityInsertion)
|
||||||
.build();
|
.build();
|
||||||
best = bestInsertion;
|
best = bestInsertion;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -77,9 +77,7 @@ public class AlgorithmConfigXmlReader {
|
||||||
try {
|
try {
|
||||||
algorithmConfig.getXMLConfiguration().load();
|
algorithmConfig.getXMLConfiguration().load();
|
||||||
} catch (ConfigurationException e) {
|
} catch (ConfigurationException e) {
|
||||||
log.error(e);
|
throw new RuntimeException(e);
|
||||||
e.printStackTrace();
|
|
||||||
System.exit(1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -519,7 +519,6 @@ public class VehicleRoutingAlgorithms {
|
||||||
@Override
|
@Override
|
||||||
public void uncaughtException(Thread arg0, Throwable arg1) {
|
public void uncaughtException(Thread arg0, Throwable arg1) {
|
||||||
System.err.println(arg1.toString());
|
System.err.println(arg1.toString());
|
||||||
System.exit(0);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Runtime.getRuntime().addShutdownHook(new Thread() {
|
Runtime.getRuntime().addShutdownHook(new Thread() {
|
||||||
|
|
|
||||||
|
|
@ -130,9 +130,7 @@ public final class BestInsertionConcurrent extends AbstractInsertionStrategy {
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
} catch (ExecutionException e) {
|
} catch (ExecutionException e) {
|
||||||
e.printStackTrace();
|
throw new RuntimeException(e);
|
||||||
logger.error("Exception", e);
|
|
||||||
System.exit(1);
|
|
||||||
}
|
}
|
||||||
VehicleRoute newRoute = VehicleRoute.emptyRoute();
|
VehicleRoute newRoute = VehicleRoute.emptyRoute();
|
||||||
InsertionData newIData = bestInsertionCostCalculator.getInsertionData(newRoute, unassignedJob, NO_NEW_VEHICLE_YET, NO_NEW_DEPARTURE_TIME_YET, NO_NEW_DRIVER_YET, bestInsertionCost);
|
InsertionData newIData = bestInsertionCostCalculator.getInsertionData(newRoute, unassignedJob, NO_NEW_VEHICLE_YET, NO_NEW_DEPARTURE_TIME_YET, NO_NEW_DRIVER_YET, bestInsertionCost);
|
||||||
|
|
|
||||||
|
|
@ -259,6 +259,11 @@ public class RegretInsertion extends AbstractInsertionStrategy {
|
||||||
if(scoredJob.getScore() > bestScoredJob.getScore()){
|
if(scoredJob.getScore() > bestScoredJob.getScore()){
|
||||||
bestScoredJob = scoredJob;
|
bestScoredJob = scoredJob;
|
||||||
}
|
}
|
||||||
|
else if (scoredJob.getScore() == bestScoredJob.getScore()){
|
||||||
|
if(scoredJob.getJob().getId().compareTo(bestScoredJob.getJob().getId()) <= 0){
|
||||||
|
bestScoredJob = scoredJob;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return bestScoredJob;
|
return bestScoredJob;
|
||||||
|
|
|
||||||
|
|
@ -136,6 +136,11 @@ public class RegretInsertionConcurrent extends AbstractInsertionStrategy {
|
||||||
} else if (sJob.getScore() > bestScoredJob.getScore()) {
|
} else if (sJob.getScore() > bestScoredJob.getScore()) {
|
||||||
bestScoredJob = sJob;
|
bestScoredJob = sJob;
|
||||||
}
|
}
|
||||||
|
else if (sJob.getScore() == bestScoredJob.getScore()){
|
||||||
|
if(sJob.getJob().getId().compareTo(bestScoredJob.getJob().getId()) <= 0){
|
||||||
|
bestScoredJob = sJob;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ public class Skills {
|
||||||
* @return builder
|
* @return builder
|
||||||
*/
|
*/
|
||||||
public Builder addSkill(String skill) {
|
public Builder addSkill(String skill) {
|
||||||
skills.add(skill.toLowerCase());
|
skills.add(skill.trim().toLowerCase());
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -163,9 +163,7 @@ public class VrpXMLReader {
|
||||||
try {
|
try {
|
||||||
xmlConfig.load();
|
xmlConfig.load();
|
||||||
} catch (ConfigurationException e) {
|
} catch (ConfigurationException e) {
|
||||||
logger.error("Exception:", e);
|
throw new RuntimeException(e);
|
||||||
e.printStackTrace();
|
|
||||||
System.exit(1);
|
|
||||||
}
|
}
|
||||||
readProblemType(xmlConfig);
|
readProblemType(xmlConfig);
|
||||||
readVehiclesAndTheirTypes(xmlConfig);
|
readVehiclesAndTheirTypes(xmlConfig);
|
||||||
|
|
|
||||||
|
|
@ -117,9 +117,7 @@ public class VrpXMLWriter {
|
||||||
element.setAttribute("xsi:schemaLocation", "http://www.w3schools.com vrp_xml_schema.xsd");
|
element.setAttribute("xsi:schemaLocation", "http://www.w3schools.com vrp_xml_schema.xsd");
|
||||||
|
|
||||||
} catch (ConfigurationException e) {
|
} catch (ConfigurationException e) {
|
||||||
logger.error("Exception:", e);
|
throw new RuntimeException(e);
|
||||||
e.printStackTrace();
|
|
||||||
System.exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
@ -128,9 +126,7 @@ public class VrpXMLWriter {
|
||||||
serializer.serialize(xmlConfig.getDocument());
|
serializer.serialize(xmlConfig.getDocument());
|
||||||
out.close();
|
out.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.error("Exception:", e);
|
throw new RuntimeException(e);
|
||||||
e.printStackTrace();
|
|
||||||
System.exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -187,6 +187,7 @@ public class VehicleImpl extends AbstractVehicle {
|
||||||
* @return this builder
|
* @return this builder
|
||||||
*/
|
*/
|
||||||
public Builder setEarliestStart(double earliest_startTime) {
|
public Builder setEarliestStart(double earliest_startTime) {
|
||||||
|
if(earliest_startTime < 0) throw new IllegalArgumentException("earliest start of vehicle " + id + " must not be negative");
|
||||||
this.earliestStart = earliest_startTime;
|
this.earliestStart = earliest_startTime;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
@ -198,6 +199,7 @@ public class VehicleImpl extends AbstractVehicle {
|
||||||
* @return this builder
|
* @return this builder
|
||||||
*/
|
*/
|
||||||
public Builder setLatestArrival(double latest_arrTime) {
|
public Builder setLatestArrival(double latest_arrTime) {
|
||||||
|
if(latest_arrTime < 0) throw new IllegalArgumentException("latest arrival time of vehicle " + id + " must not be negative");
|
||||||
this.latestArrival = latest_arrTime;
|
this.latestArrival = latest_arrTime;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
@ -224,6 +226,7 @@ public class VehicleImpl extends AbstractVehicle {
|
||||||
* or (endLocationId!=null AND returnToDepot=false)
|
* or (endLocationId!=null AND returnToDepot=false)
|
||||||
*/
|
*/
|
||||||
public VehicleImpl build() {
|
public VehicleImpl build() {
|
||||||
|
if(latestArrival < earliestStart) throw new IllegalStateException("latest arrival of vehicle " + id + " must not be smaller than its start time");
|
||||||
if (startLocation != null && endLocation != null) {
|
if (startLocation != null && endLocation != null) {
|
||||||
if (!startLocation.getId().equals(endLocation.getId()) && !returnToDepot)
|
if (!startLocation.getId().equals(endLocation.getId()) && !returnToDepot)
|
||||||
throw new IllegalStateException("this must not be. you specified both endLocationId and open-routes. this is contradictory. <br>" +
|
throw new IllegalStateException("this must not be. you specified both endLocationId and open-routes. this is contradictory. <br>" +
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,8 @@ package jsprit.core.algorithm.box;
|
||||||
import jsprit.core.algorithm.SearchStrategy;
|
import jsprit.core.algorithm.SearchStrategy;
|
||||||
import jsprit.core.algorithm.VehicleRoutingAlgorithm;
|
import jsprit.core.algorithm.VehicleRoutingAlgorithm;
|
||||||
import jsprit.core.algorithm.listener.StrategySelectedListener;
|
import jsprit.core.algorithm.listener.StrategySelectedListener;
|
||||||
|
import jsprit.core.algorithm.recreate.InsertionData;
|
||||||
|
import jsprit.core.algorithm.recreate.listener.BeforeJobInsertionListener;
|
||||||
import jsprit.core.algorithm.recreate.listener.JobInsertedListener;
|
import jsprit.core.algorithm.recreate.listener.JobInsertedListener;
|
||||||
import jsprit.core.algorithm.ruin.listener.RuinListener;
|
import jsprit.core.algorithm.ruin.listener.RuinListener;
|
||||||
import jsprit.core.problem.Location;
|
import jsprit.core.problem.Location;
|
||||||
|
|
@ -185,6 +187,51 @@ public class JspritTest {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void strategyDrawShouldBeReproducibleV2() {
|
||||||
|
Service s = Service.Builder.newInstance("s1").setLocation(Location.newInstance(1, 1)).build();
|
||||||
|
Service s2 = Service.Builder.newInstance("s2").setLocation(Location.newInstance(1, 2)).build();
|
||||||
|
Service s3 = Service.Builder.newInstance("s3").setLocation(Location.newInstance(1, 2)).build();
|
||||||
|
Service s4 = Service.Builder.newInstance("s4").setLocation(Location.newInstance(1, 2)).build();
|
||||||
|
|
||||||
|
VehicleImpl v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0, 0)).build();
|
||||||
|
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(s4).addJob(s3).addVehicle(v).addJob(s2).addJob(s).build();
|
||||||
|
VehicleRoutingAlgorithm vra = Jsprit.Builder.newInstance(vrp).setProperty(Jsprit.Parameter.THREADS,"4").buildAlgorithm();
|
||||||
|
vra.setMaxIterations(100);
|
||||||
|
final List<String> firstRecord = new ArrayList<String>();
|
||||||
|
vra.addListener(new StrategySelectedListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void informSelectedStrategy(SearchStrategy.DiscoveredSolution discoveredSolution, VehicleRoutingProblem vehicleRoutingProblem, Collection<VehicleRoutingProblemSolution> vehicleRoutingProblemSolutions) {
|
||||||
|
firstRecord.add(discoveredSolution.getStrategyId());
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
vra.searchSolutions();
|
||||||
|
|
||||||
|
RandomNumberGeneration.reset();
|
||||||
|
VehicleRoutingAlgorithm second = Jsprit.Builder.newInstance(vrp).setProperty(Jsprit.Parameter.THREADS,"2").buildAlgorithm();
|
||||||
|
second.setMaxIterations(100);
|
||||||
|
final List<String> secondRecord = new ArrayList<String>();
|
||||||
|
second.addListener(new StrategySelectedListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void informSelectedStrategy(SearchStrategy.DiscoveredSolution discoveredSolution, VehicleRoutingProblem vehicleRoutingProblem, Collection<VehicleRoutingProblemSolution> vehicleRoutingProblemSolutions) {
|
||||||
|
secondRecord.add(discoveredSolution.getStrategyId());
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
second.searchSolutions();
|
||||||
|
|
||||||
|
for (int i = 0; i < 100; i++) {
|
||||||
|
if (!firstRecord.get(i).equals(secondRecord.get(i))) {
|
||||||
|
org.junit.Assert.assertFalse(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
org.junit.Assert.assertTrue(true);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void ruinedJobsShouldBeReproducible() {
|
public void ruinedJobsShouldBeReproducible() {
|
||||||
Service s = Service.Builder.newInstance("s1").setLocation(Location.newInstance(1, 1)).build();
|
Service s = Service.Builder.newInstance("s1").setLocation(Location.newInstance(1, 1)).build();
|
||||||
|
|
@ -192,6 +239,72 @@ public class JspritTest {
|
||||||
Service s3 = Service.Builder.newInstance("s3").setLocation(Location.newInstance(1, 2)).build();
|
Service s3 = Service.Builder.newInstance("s3").setLocation(Location.newInstance(1, 2)).build();
|
||||||
Service s4 = Service.Builder.newInstance("s4").setLocation(Location.newInstance(1, 2)).build();
|
Service s4 = Service.Builder.newInstance("s4").setLocation(Location.newInstance(1, 2)).build();
|
||||||
|
|
||||||
|
VehicleImpl v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0, 0)).build();
|
||||||
|
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(s4).addJob(s3).addVehicle(v).addJob(s2).addJob(s).build();
|
||||||
|
VehicleRoutingAlgorithm vra = Jsprit.Builder.newInstance(vrp)
|
||||||
|
.setProperty(Jsprit.Strategy.WORST_REGRET,"0.")
|
||||||
|
.setProperty(Jsprit.Strategy.WORST_BEST, "0.")
|
||||||
|
.setProperty(Jsprit.Parameter.THREADS, "2").buildAlgorithm();
|
||||||
|
vra.setMaxIterations(100);
|
||||||
|
final List<String> firstRecord = new ArrayList<String>();
|
||||||
|
vra.addListener(new RuinListener() {
|
||||||
|
@Override
|
||||||
|
public void ruinStarts(Collection<VehicleRoute> routes) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void ruinEnds(Collection<VehicleRoute> routes, Collection<Job> unassignedJobs) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removed(Job job, VehicleRoute fromRoute) {
|
||||||
|
firstRecord.add(job.getId());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
vra.searchSolutions();
|
||||||
|
|
||||||
|
VehicleRoutingAlgorithm second = Jsprit.Builder.newInstance(vrp).setProperty(Jsprit.Parameter.THREADS, "4")
|
||||||
|
.setProperty(Jsprit.Strategy.WORST_REGRET, "0.")
|
||||||
|
.setProperty(Jsprit.Strategy.WORST_BEST, "0.")
|
||||||
|
.buildAlgorithm();
|
||||||
|
second.setMaxIterations(100);
|
||||||
|
final List<String> secondRecord = new ArrayList<String>();
|
||||||
|
second.addListener(new RuinListener() {
|
||||||
|
@Override
|
||||||
|
public void ruinStarts(Collection<VehicleRoute> routes) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void ruinEnds(Collection<VehicleRoute> routes, Collection<Job> unassignedJobs) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removed(Job job, VehicleRoute fromRoute) {
|
||||||
|
secondRecord.add(job.getId());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
second.searchSolutions();
|
||||||
|
|
||||||
|
Assert.assertEquals(secondRecord.size(), firstRecord.size());
|
||||||
|
for (int i = 0; i < firstRecord.size(); i++) {
|
||||||
|
if (!firstRecord.get(i).equals(secondRecord.get(i))) {
|
||||||
|
Assert.assertFalse(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Assert.assertTrue(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void ruinedJobsShouldBeReproducibleV2() {
|
||||||
|
Service s = Service.Builder.newInstance("s1").setLocation(Location.newInstance(1, 1)).build();
|
||||||
|
Service s2 = Service.Builder.newInstance("s2").setLocation(Location.newInstance(1, 2)).build();
|
||||||
|
Service s3 = Service.Builder.newInstance("s3").setLocation(Location.newInstance(1, 2)).build();
|
||||||
|
Service s4 = Service.Builder.newInstance("s4").setLocation(Location.newInstance(1, 2)).build();
|
||||||
|
|
||||||
VehicleImpl v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0, 0)).build();
|
VehicleImpl v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0, 0)).build();
|
||||||
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(s4).addJob(s3).addVehicle(v).addJob(s2).addJob(s).build();
|
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(s4).addJob(s3).addVehicle(v).addJob(s2).addJob(s).build();
|
||||||
VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp);
|
VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp);
|
||||||
|
|
@ -286,5 +399,73 @@ public class JspritTest {
|
||||||
Assert.assertTrue(true);
|
Assert.assertTrue(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void insertionShouldBeReproducibleV2() {
|
||||||
|
Service s = Service.Builder.newInstance("s1").setLocation(Location.newInstance(1, 1)).build();
|
||||||
|
Service s2 = Service.Builder.newInstance("s2").setLocation(Location.newInstance(1, 1)).build();
|
||||||
|
Service s3 = Service.Builder.newInstance("s3").setLocation(Location.newInstance(1, 3)).build();
|
||||||
|
Service s4 = Service.Builder.newInstance("s4").setLocation(Location.newInstance(1, 4)).build();
|
||||||
|
|
||||||
|
VehicleImpl v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0, 0)).build();
|
||||||
|
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().setFleetSize(VehicleRoutingProblem.FleetSize.FINITE).addJob(s4).addJob(s3).addVehicle(v).addJob(s2).addJob(s).build();
|
||||||
|
|
||||||
|
VehicleRoutingAlgorithm vra = Jsprit.Builder.newInstance(vrp)
|
||||||
|
.setProperty(Jsprit.Strategy.WORST_REGRET,"0.")
|
||||||
|
.setProperty(Jsprit.Strategy.WORST_BEST, "0.")
|
||||||
|
.setProperty(Jsprit.Parameter.THREADS, "4").buildAlgorithm();
|
||||||
|
vra.setMaxIterations(100);
|
||||||
|
final List<String> firstRecord = new ArrayList<String>();
|
||||||
|
final List<Double> firstRecordCosts = new ArrayList<Double>();
|
||||||
|
vra.addListener(new BeforeJobInsertionListener() {
|
||||||
|
@Override
|
||||||
|
public void informBeforeJobInsertion(Job job, InsertionData data, VehicleRoute route) {
|
||||||
|
String id = job.getId();
|
||||||
|
firstRecordCosts.add(data.getInsertionCost());
|
||||||
|
firstRecord.add(id);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
vra.searchSolutions();
|
||||||
|
|
||||||
|
VehicleRoutingAlgorithm second = Jsprit.Builder.newInstance(vrp)
|
||||||
|
.setProperty(Jsprit.Strategy.WORST_REGRET,"0.")
|
||||||
|
.setProperty(Jsprit.Strategy.WORST_BEST, "0.")
|
||||||
|
.setProperty(Jsprit.Parameter.THREADS, "5").buildAlgorithm();
|
||||||
|
second.setMaxIterations(100);
|
||||||
|
final List<String> secondRecord = new ArrayList<String>();
|
||||||
|
final List<Double> secondRecordCosts = new ArrayList<Double>();
|
||||||
|
second.addListener(new BeforeJobInsertionListener() {
|
||||||
|
@Override
|
||||||
|
public void informBeforeJobInsertion(Job job, InsertionData data, VehicleRoute route) {
|
||||||
|
secondRecord.add(job.getId());
|
||||||
|
secondRecordCosts.add(data.getInsertionCost());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
second.searchSolutions();
|
||||||
|
|
||||||
|
// for(int i=0;i<firstRecord.size();i++){
|
||||||
|
// System.out.print(firstRecord.get(i) + " (" + ((int)(firstRecordCosts.get(i)*100.))/100. + "), ");
|
||||||
|
// }
|
||||||
|
// System.out.println();
|
||||||
|
// for(int i=0;i<secondRecord.size();i++){
|
||||||
|
// System.out.print(secondRecord.get(i) + " (" + ((int)(firstRecordCosts.get(i)*100.))/100. + "), ");
|
||||||
|
// }
|
||||||
|
|
||||||
|
Assert.assertEquals(secondRecord.size(), firstRecord.size());
|
||||||
|
for (int i = 0; i < firstRecord.size(); i++) {
|
||||||
|
if (!firstRecord.get(i).equals(secondRecord.get(i))) {
|
||||||
|
Assert.assertFalse(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Assert.assertTrue(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void compare(){
|
||||||
|
String s1 = "s2234";
|
||||||
|
String s2 = "s1";
|
||||||
|
int c = s1.compareTo(s2);
|
||||||
|
Assert.assertEquals(1,c);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -63,4 +63,30 @@ public class SkillsTest {
|
||||||
assertTrue(skills.containsSkill("skill2"));
|
assertTrue(skills.containsSkill("skill2"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenSkillsAddedPrecedingWhitespaceShouldNotMatter() {
|
||||||
|
Set<String> skillSet = new HashSet<String>();
|
||||||
|
skillSet.add(" skill1");
|
||||||
|
skillSet.add("Skill2");
|
||||||
|
Skills skills = Skills.Builder.newInstance().addAllSkills(skillSet).build();
|
||||||
|
assertTrue(skills.containsSkill("skill1"));
|
||||||
|
assertTrue(skills.containsSkill("skill2"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenSkillsAddedTrailingWhitespaceShouldNotMatter() {
|
||||||
|
Set<String> skillSet = new HashSet<String>();
|
||||||
|
skillSet.add("skill1 ");
|
||||||
|
skillSet.add("Skill2");
|
||||||
|
Skills skills = Skills.Builder.newInstance().addAllSkills(skillSet).build();
|
||||||
|
assertTrue(skills.containsSkill("skill1"));
|
||||||
|
assertTrue(skills.containsSkill("skill2"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenSkillsAddedTrailingWhitespaceShouldNotMatter2() {
|
||||||
|
Skills skills = Skills.Builder.newInstance().addSkill("skill1 ").build();
|
||||||
|
assertTrue(skills.containsSkill("skill1"));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -107,9 +107,7 @@ public class ChristofidesReader {
|
||||||
try {
|
try {
|
||||||
reader.close();
|
reader.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
throw new RuntimeException(e);
|
||||||
logger.error("Exception:", e);
|
|
||||||
System.exit(1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -117,10 +115,7 @@ public class ChristofidesReader {
|
||||||
try {
|
try {
|
||||||
return reader.readLine();
|
return reader.readLine();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
throw new RuntimeException(e);
|
||||||
logger.error("Exception:", e);
|
|
||||||
System.exit(1);
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -135,9 +130,7 @@ public class ChristofidesReader {
|
||||||
try {
|
try {
|
||||||
reader = new BufferedReader(new FileReader(solomonFile));
|
reader = new BufferedReader(new FileReader(solomonFile));
|
||||||
} catch (FileNotFoundException e1) {
|
} catch (FileNotFoundException e1) {
|
||||||
e1.printStackTrace();
|
throw new RuntimeException(e1);
|
||||||
logger.error("Exception:", e1);
|
|
||||||
System.exit(1);
|
|
||||||
}
|
}
|
||||||
return reader;
|
return reader;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -136,9 +136,7 @@ public class CordeauReader {
|
||||||
try {
|
try {
|
||||||
reader.close();
|
reader.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
throw new RuntimeException(e);
|
||||||
logger.error("Exception:", e);
|
|
||||||
System.exit(1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -146,10 +144,7 @@ public class CordeauReader {
|
||||||
try {
|
try {
|
||||||
return reader.readLine();
|
return reader.readLine();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
throw new RuntimeException(e);
|
||||||
logger.error("Exception:", e);
|
|
||||||
System.exit(1);
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -164,9 +159,7 @@ public class CordeauReader {
|
||||||
try {
|
try {
|
||||||
reader = new BufferedReader(new FileReader(solomonFile));
|
reader = new BufferedReader(new FileReader(solomonFile));
|
||||||
} catch (FileNotFoundException e1) {
|
} catch (FileNotFoundException e1) {
|
||||||
e1.printStackTrace();
|
throw new RuntimeException(e1);
|
||||||
logger.error("Exception:", e1);
|
|
||||||
System.exit(1);
|
|
||||||
}
|
}
|
||||||
return reader;
|
return reader;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -142,9 +142,7 @@ public class LiLimReader {
|
||||||
try {
|
try {
|
||||||
reader = new BufferedReader(new FileReader(file));
|
reader = new BufferedReader(new FileReader(file));
|
||||||
} catch (FileNotFoundException e1) {
|
} catch (FileNotFoundException e1) {
|
||||||
e1.printStackTrace();
|
throw new RuntimeException(e1);
|
||||||
logger.error("Exception:", e1);
|
|
||||||
System.exit(1);
|
|
||||||
}
|
}
|
||||||
return reader;
|
return reader;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -86,9 +86,7 @@ public class LopezIbanezBlumReader {
|
||||||
try {
|
try {
|
||||||
reader.close();
|
reader.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
throw new RuntimeException(e);
|
||||||
logger.error("Exception:", e);
|
|
||||||
System.exit(1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -96,10 +94,7 @@ public class LopezIbanezBlumReader {
|
||||||
try {
|
try {
|
||||||
return reader.readLine();
|
return reader.readLine();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
throw new RuntimeException(e);
|
||||||
logger.error("Exception:", e);
|
|
||||||
System.exit(1);
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -108,9 +103,7 @@ public class LopezIbanezBlumReader {
|
||||||
try {
|
try {
|
||||||
reader = new BufferedReader(new FileReader(solomonFile));
|
reader = new BufferedReader(new FileReader(solomonFile));
|
||||||
} catch (FileNotFoundException e1) {
|
} catch (FileNotFoundException e1) {
|
||||||
e1.printStackTrace();
|
throw new RuntimeException(e1);
|
||||||
logger.error("Exception:", e1);
|
|
||||||
System.exit(1);
|
|
||||||
}
|
}
|
||||||
return reader;
|
return reader;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -149,9 +149,7 @@ public class LuiShenReader {
|
||||||
try {
|
try {
|
||||||
reader.close();
|
reader.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
throw new RuntimeException(e);
|
||||||
logger.error("Exception:", e);
|
|
||||||
System.exit(1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -159,10 +157,7 @@ public class LuiShenReader {
|
||||||
try {
|
try {
|
||||||
return reader.readLine();
|
return reader.readLine();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
throw new RuntimeException(e);
|
||||||
logger.error("Exception:", e);
|
|
||||||
System.exit(1);
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -177,9 +172,7 @@ public class LuiShenReader {
|
||||||
try {
|
try {
|
||||||
reader = new BufferedReader(new FileReader(solomonFile));
|
reader = new BufferedReader(new FileReader(solomonFile));
|
||||||
} catch (FileNotFoundException e1) {
|
} catch (FileNotFoundException e1) {
|
||||||
e1.printStackTrace();
|
throw new RuntimeException(e1);
|
||||||
logger.error("Exception:", e1);
|
|
||||||
System.exit(1);
|
|
||||||
}
|
}
|
||||||
return reader;
|
return reader;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -127,9 +127,7 @@ public class SolomonReader {
|
||||||
try {
|
try {
|
||||||
reader.close();
|
reader.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
throw new RuntimeException(e);
|
||||||
logger.error("Exception:", e);
|
|
||||||
System.exit(1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -137,10 +135,7 @@ public class SolomonReader {
|
||||||
try {
|
try {
|
||||||
return reader.readLine();
|
return reader.readLine();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
throw new RuntimeException(e);
|
||||||
logger.error("Exception:", e);
|
|
||||||
System.exit(1);
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -155,9 +150,7 @@ public class SolomonReader {
|
||||||
try {
|
try {
|
||||||
reader = new BufferedReader(new FileReader(solomonFile));
|
reader = new BufferedReader(new FileReader(solomonFile));
|
||||||
} catch (FileNotFoundException e1) {
|
} catch (FileNotFoundException e1) {
|
||||||
e1.printStackTrace();
|
throw new RuntimeException(e1);
|
||||||
logger.error("Exception:", e1);
|
|
||||||
System.exit(1);
|
|
||||||
}
|
}
|
||||||
return reader;
|
return reader;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -138,8 +138,7 @@ public class VrphGoldenReader {
|
||||||
try {
|
try {
|
||||||
reader.close();
|
reader.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
throw new RuntimeException(e);
|
||||||
System.exit(1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -148,8 +147,7 @@ public class VrphGoldenReader {
|
||||||
try {
|
try {
|
||||||
readLine = reader.readLine();
|
readLine = reader.readLine();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
throw new RuntimeException(e);
|
||||||
System.exit(1);
|
|
||||||
}
|
}
|
||||||
return readLine;
|
return readLine;
|
||||||
}
|
}
|
||||||
|
|
@ -160,10 +158,8 @@ public class VrphGoldenReader {
|
||||||
bufferedReader = new BufferedReader(new FileReader(new File(filename)));
|
bufferedReader = new BufferedReader(new FileReader(new File(filename)));
|
||||||
return bufferedReader;
|
return bufferedReader;
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
e.printStackTrace();
|
throw new RuntimeException(e);
|
||||||
System.exit(1);
|
|
||||||
}
|
}
|
||||||
return bufferedReader;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue