mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
add buildFastCVRP test
This commit is contained in:
parent
f7ff7aeeca
commit
75c54103ad
2 changed files with 21 additions and 10 deletions
|
|
@ -2,6 +2,7 @@ package algorithms;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
|
import algorithms.StateManager.StateImpl;
|
||||||
import basics.Job;
|
import basics.Job;
|
||||||
import basics.algo.InsertionEndsListener;
|
import basics.algo.InsertionEndsListener;
|
||||||
import basics.algo.InsertionStartsListener;
|
import basics.algo.InsertionStartsListener;
|
||||||
|
|
@ -28,6 +29,9 @@ class UdateCostsAtRouteLevel implements JobInsertedListener, InsertionStartsList
|
||||||
@Override
|
@Override
|
||||||
public void informJobInserted(Job job2insert, VehicleRoute inRoute, double additionalCosts, double additionalTime) {
|
public void informJobInserted(Job job2insert, VehicleRoute inRoute, double additionalCosts, double additionalTime) {
|
||||||
// inRoute.getVehicleRouteCostCalculator().addTransportCost(additionalCosts);
|
// inRoute.getVehicleRouteCostCalculator().addTransportCost(additionalCosts);
|
||||||
|
double oldCosts = states.getRouteState(inRoute, StateTypes.COSTS).toDouble();
|
||||||
|
oldCosts += additionalCosts;
|
||||||
|
states.putRouteState(inRoute, StateTypes.COSTS, new StateImpl(oldCosts));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -42,10 +46,15 @@ class UdateCostsAtRouteLevel implements JobInsertedListener, InsertionStartsList
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void informInsertionEnds(Collection<VehicleRoute> vehicleRoutes) {
|
public void informInsertionEnds(Collection<VehicleRoute> vehicleRoutes) {
|
||||||
IterateRouteForwardInTime forwardInTime = new IterateRouteForwardInTime(tpCosts);
|
|
||||||
forwardInTime.addListener(new UpdateCostsAtAllLevels(actCosts, tpCosts, states));
|
// IterateRouteForwardInTime forwardInTime = new IterateRouteForwardInTime(tpCosts);
|
||||||
|
// forwardInTime.addListener(new UpdateCostsAtAllLevels(actCosts, tpCosts, states));
|
||||||
for(VehicleRoute route : vehicleRoutes){
|
for(VehicleRoute route : vehicleRoutes){
|
||||||
forwardInTime.iterate(route);
|
if(route.isEmpty()) continue;
|
||||||
|
route.getVehicleRouteCostCalculator().reset();
|
||||||
|
route.getVehicleRouteCostCalculator().addOtherCost(states.getRouteState(route, StateTypes.COSTS).toDouble());
|
||||||
|
route.getVehicleRouteCostCalculator().price(route.getVehicle());
|
||||||
|
// forwardInTime.iterate(route);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,13 @@
|
||||||
package algorithms;
|
package algorithms;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import util.Solutions;
|
import util.Solutions;
|
||||||
|
|
||||||
import algorithms.HardConstraints.HardActivityLevelConstraint;
|
import algorithms.HardConstraints.HardActivityLevelConstraint;
|
||||||
import algorithms.acceptors.AcceptNewIfBetterThanWorst;
|
import algorithms.acceptors.AcceptNewIfBetterThanWorst;
|
||||||
import algorithms.selectors.SelectBest;
|
import algorithms.selectors.SelectBest;
|
||||||
|
|
@ -45,12 +46,10 @@ public class BuildFastCVRPAlgoTest {
|
||||||
VehicleFleetManager fleetManager = new InfiniteVehicles(vrp.getVehicles());
|
VehicleFleetManager fleetManager = new InfiniteVehicles(vrp.getVehicles());
|
||||||
JobInsertionCalculator finalServiceInsertion = new CalculatesVehTypeDepServiceInsertion(fleetManager, serviceInsertion);
|
JobInsertionCalculator finalServiceInsertion = new CalculatesVehTypeDepServiceInsertion(fleetManager, serviceInsertion);
|
||||||
|
|
||||||
// UpdateStates stateUpdater = new UpdateStates(stateManager, vrp.getTransportCosts(), vrp.getActivityCosts());
|
|
||||||
|
|
||||||
BestInsertion bestInsertion = new BestInsertion(finalServiceInsertion);
|
BestInsertion bestInsertion = new BestInsertion(finalServiceInsertion);
|
||||||
|
|
||||||
RuinRadial radial = new RuinRadial(vrp, 0.3, new JobDistanceAvgCosts(vrp.getTransportCosts()));
|
RuinRadial radial = new RuinRadial(vrp, 0.15, new JobDistanceAvgCosts(vrp.getTransportCosts()));
|
||||||
RuinRandom random = new RuinRandom(vrp, 0.5);
|
RuinRandom random = new RuinRandom(vrp, 0.25);
|
||||||
|
|
||||||
SearchStrategy randomStrategy = new SearchStrategy(new SelectBest(), new AcceptNewIfBetterThanWorst(1));
|
SearchStrategy randomStrategy = new SearchStrategy(new SelectBest(), new AcceptNewIfBetterThanWorst(1));
|
||||||
RuinAndRecreateModule randomModule = new RuinAndRecreateModule("randomRuin_bestInsertion", bestInsertion, random);
|
RuinAndRecreateModule randomModule = new RuinAndRecreateModule("randomRuin_bestInsertion", bestInsertion, random);
|
||||||
|
|
@ -81,17 +80,20 @@ public class BuildFastCVRPAlgoTest {
|
||||||
vra.getSearchStrategyManager().addSearchStrategyModuleListener(new UpdateLoadAtRouteLevel(stateManager));
|
vra.getSearchStrategyManager().addSearchStrategyModuleListener(new UpdateLoadAtRouteLevel(stateManager));
|
||||||
|
|
||||||
VehicleRoutingProblemSolution iniSolution = new CreateInitialSolution(bestInsertion).createInitialSolution(vrp);
|
VehicleRoutingProblemSolution iniSolution = new CreateInitialSolution(bestInsertion).createInitialSolution(vrp);
|
||||||
System.out.println("ini: costs="+iniSolution.getCost()+";#routes="+iniSolution.getRoutes().size());
|
// System.out.println("ini: costs="+iniSolution.getCost()+";#routes="+iniSolution.getRoutes().size());
|
||||||
vra.addInitialSolution(iniSolution);
|
vra.addInitialSolution(iniSolution);
|
||||||
|
|
||||||
vra.setNuOfIterations(1000);
|
vra.setNuOfIterations(1000);
|
||||||
vra.setPrematureBreak(200);
|
vra.setPrematureBreak(200);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testVRA(){
|
public void testVRA(){
|
||||||
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
|
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
|
||||||
System.out.println("costs="+Solutions.getBest(solutions).getCost()+";#routes="+Solutions.getBest(solutions).getRoutes().size());
|
// System.out.println("costs="+Solutions.getBest(solutions).getCost()+";#routes="+Solutions.getBest(solutions).getRoutes().size());
|
||||||
|
assertEquals(530.0, Solutions.getBest(solutions).getCost(),15.0);
|
||||||
|
assertEquals(5, Solutions.getBest(solutions).getRoutes().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue