mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
add problem modeling capabilities
This commit is contained in:
parent
31d9c4b069
commit
5399749cef
5 changed files with 152 additions and 8 deletions
|
|
@ -0,0 +1,12 @@
|
|||
package jsprit.core.algorithm;
|
||||
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
|
||||
public class VehicleRoutingAlgorithmBuilder {
|
||||
|
||||
public VehicleRoutingAlgorithmBuilder(VehicleRoutingProblem problem, String algorithmConfig) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
package jsprit.core.algorithm.recreate;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import jsprit.core.algorithm.recreate.listener.InsertionStartsListener;
|
||||
import jsprit.core.algorithm.recreate.listener.JobInsertedListener;
|
||||
import jsprit.core.problem.constraint.SoftRouteConstraint;
|
||||
import jsprit.core.problem.job.Job;
|
||||
import jsprit.core.problem.misc.JobInsertionContext;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.solution.route.state.RouteAndActivityStateGetter;
|
||||
|
||||
public class DellAmicoFixCostCalculator implements SoftRouteConstraint, InsertionStartsListener, JobInsertedListener{
|
||||
|
||||
private int nuOfJobsToRecreate;
|
||||
|
||||
private final JobInsertionConsideringFixCostsCalculator calculator;
|
||||
|
||||
private final int nuOfJobs;
|
||||
|
||||
public DellAmicoFixCostCalculator(final int nuOfJobs, final RouteAndActivityStateGetter stateGetter) {
|
||||
super();
|
||||
this.nuOfJobs=nuOfJobs;
|
||||
calculator = new JobInsertionConsideringFixCostsCalculator(null, stateGetter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getCosts(JobInsertionContext insertionContext) {// TODO Auto-generated method stub
|
||||
return calculator.getCosts(insertionContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void informInsertionStarts(Collection<VehicleRoute> routes, Collection<Job> unassignedJobs) {
|
||||
this.nuOfJobsToRecreate = unassignedJobs.size();
|
||||
double completenessRatio = (1-((double)nuOfJobsToRecreate/(double)nuOfJobs));
|
||||
calculator.setSolutionCompletenessRatio(completenessRatio);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void informJobInserted(Job job2insert, VehicleRoute inRoute, double additionalCosts, double additionalTime) {
|
||||
nuOfJobsToRecreate--;
|
||||
double completenessRatio = (1-((double)nuOfJobsToRecreate/(double)nuOfJobs));
|
||||
calculator.setSolutionCompletenessRatio(completenessRatio);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -18,8 +18,10 @@ package jsprit.core.algorithm.recreate;
|
|||
|
||||
import jsprit.core.algorithm.recreate.InsertionData.NoInsertionFound;
|
||||
import jsprit.core.problem.Capacity;
|
||||
import jsprit.core.problem.constraint.SoftRouteConstraint;
|
||||
import jsprit.core.problem.driver.Driver;
|
||||
import jsprit.core.problem.job.Job;
|
||||
import jsprit.core.problem.misc.JobInsertionContext;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.solution.route.state.RouteAndActivityStateGetter;
|
||||
import jsprit.core.problem.solution.route.state.StateFactory;
|
||||
|
|
@ -28,10 +30,7 @@ import jsprit.core.problem.vehicle.VehicleImpl.NoVehicle;
|
|||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
|
||||
|
||||
|
||||
final class JobInsertionConsideringFixCostsCalculator implements JobInsertionCostsCalculator{
|
||||
final class JobInsertionConsideringFixCostsCalculator implements JobInsertionCostsCalculator, SoftRouteConstraint{
|
||||
|
||||
private static final Logger logger = Logger.getLogger(JobInsertionConsideringFixCostsCalculator.class);
|
||||
|
||||
|
|
@ -52,10 +51,7 @@ final class JobInsertionConsideringFixCostsCalculator implements JobInsertionCos
|
|||
|
||||
@Override
|
||||
public InsertionData getInsertionData(final VehicleRoute currentRoute, final Job jobToInsert, final Vehicle newVehicle, double newVehicleDepartureTime, final Driver newDriver, final double bestKnownPrice) {
|
||||
double relFixCost = getDeltaRelativeFixCost(currentRoute, newVehicle, jobToInsert);
|
||||
double absFixCost = getDeltaAbsoluteFixCost(currentRoute, newVehicle, jobToInsert);
|
||||
double deltaFixCost = (1-solution_completeness_ratio)*relFixCost + solution_completeness_ratio*absFixCost;
|
||||
double fixcost_contribution = weight_deltaFixCost*solution_completeness_ratio*deltaFixCost;
|
||||
double fixcost_contribution = getFixCostContribution(currentRoute,jobToInsert, newVehicle);
|
||||
if(fixcost_contribution > bestKnownPrice){
|
||||
return InsertionData.createEmptyInsertionData();
|
||||
}
|
||||
|
|
@ -68,6 +64,15 @@ final class JobInsertionConsideringFixCostsCalculator implements JobInsertionCos
|
|||
insertionData.setVehicleDepartureTime(newVehicleDepartureTime);
|
||||
return insertionData;
|
||||
}
|
||||
|
||||
private double getFixCostContribution(final VehicleRoute currentRoute,
|
||||
final Job jobToInsert, final Vehicle newVehicle) {
|
||||
double relFixCost = getDeltaRelativeFixCost(currentRoute, newVehicle, jobToInsert);
|
||||
double absFixCost = getDeltaAbsoluteFixCost(currentRoute, newVehicle, jobToInsert);
|
||||
double deltaFixCost = (1-solution_completeness_ratio)*relFixCost + solution_completeness_ratio*absFixCost;
|
||||
double fixcost_contribution = weight_deltaFixCost*solution_completeness_ratio*deltaFixCost;
|
||||
return fixcost_contribution;
|
||||
}
|
||||
|
||||
public void setWeightOfFixCost(double weight){
|
||||
weight_deltaFixCost = weight;
|
||||
|
|
@ -120,4 +125,9 @@ final class JobInsertionConsideringFixCostsCalculator implements JobInsertionCos
|
|||
return stateGetter.getRouteState(route, StateFactory.MAXLOAD, Capacity.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getCosts(JobInsertionContext insertionContext) {
|
||||
return getFixCostContribution(insertionContext.getRoute(), insertionContext.getJob(), insertionContext.getNewVehicle());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,49 @@
|
|||
package jsprit.core.algorithm.recreate;
|
||||
|
||||
import jsprit.core.problem.constraint.SoftActivityConstraint;
|
||||
import jsprit.core.problem.cost.VehicleRoutingTransportCosts;
|
||||
import jsprit.core.problem.misc.JobInsertionContext;
|
||||
import jsprit.core.problem.solution.route.activity.End;
|
||||
import jsprit.core.problem.solution.route.activity.TourActivity;
|
||||
import jsprit.core.util.CalculationUtils;
|
||||
|
||||
public class VariableTransportCostCalculator implements SoftActivityConstraint{
|
||||
|
||||
private VehicleRoutingTransportCosts routingCosts;
|
||||
|
||||
public VariableTransportCostCalculator(VehicleRoutingTransportCosts routingCosts) {
|
||||
super();
|
||||
this.routingCosts = routingCosts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getCosts(JobInsertionContext iFacts, TourActivity prevAct,TourActivity newAct, TourActivity nextAct, double depTimeAtPrevAct) {
|
||||
double tp_costs_prevAct_newAct = routingCosts.getTransportCost(prevAct.getLocationId(), newAct.getLocationId(), depTimeAtPrevAct, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||
double tp_time_prevAct_newAct = routingCosts.getTransportTime(prevAct.getLocationId(), newAct.getLocationId(), depTimeAtPrevAct, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||
|
||||
double newAct_arrTime = depTimeAtPrevAct + tp_time_prevAct_newAct;
|
||||
double newAct_endTime = CalculationUtils.getActivityEndTime(newAct_arrTime, newAct);
|
||||
|
||||
//open routes
|
||||
if(nextAct instanceof End){
|
||||
if(!iFacts.getNewVehicle().isReturnToDepot()){
|
||||
return tp_costs_prevAct_newAct;
|
||||
}
|
||||
}
|
||||
|
||||
double tp_costs_newAct_nextAct = routingCosts.getTransportCost(newAct.getLocationId(), nextAct.getLocationId(), newAct_endTime, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||
double totalCosts = tp_costs_prevAct_newAct + tp_costs_newAct_nextAct;
|
||||
|
||||
double oldCosts;
|
||||
if(iFacts.getRoute().isEmpty()){
|
||||
double tp_costs_prevAct_nextAct = routingCosts.getTransportCost(prevAct.getLocationId(), nextAct.getLocationId(), depTimeAtPrevAct, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||
oldCosts = tp_costs_prevAct_nextAct;
|
||||
}
|
||||
else{
|
||||
double tp_costs_prevAct_nextAct = routingCosts.getTransportCost(prevAct.getLocationId(), nextAct.getLocationId(), prevAct.getEndTime(), iFacts.getRoute().getDriver(), iFacts.getRoute().getVehicle());
|
||||
oldCosts = tp_costs_prevAct_nextAct;
|
||||
}
|
||||
return totalCosts - oldCosts;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue