1
0
Fork 0
mirror of https://github.com/graphhopper/jsprit.git synced 2020-01-24 07:45:05 +01:00

fix algorithmSearchProgress...Listener - reset it when algorithm starts,

deprecate setters VehicleRoutingProblem to make it immutable in the next
release, add Example
This commit is contained in:
Stefan Schroeder 2013-06-11 09:57:48 +02:00
parent a113a6cf18
commit bc6c1e23b5
5 changed files with 114 additions and 38 deletions

View file

@ -123,6 +123,7 @@ public class VehicleRoutingAlgorithm {
logger.info("algorithm starts");
double now = System.currentTimeMillis();
verify();
int nuOfIterationsThisAlgoIsRunning = nOfIterations;
counter.reset();
Collection<VehicleRoutingProblemSolution> solutions = new ArrayList<VehicleRoutingProblemSolution>(initialSolutions);
algorithmStarts(problem,solutions);
@ -138,11 +139,12 @@ public class VehicleRoutingAlgorithm {
else iterWithoutImprovement++;
if(iterWithoutImprovement > prematureBreak){
logger.info("premature break at iteration "+ (i+1));
nuOfIterationsThisAlgoIsRunning = (i+1);
break;
}
iterationEnds(i+1,problem,solutions);
}
logger.info("iterations end at " + nOfIterations + " iterations");
logger.info("iterations end at " + nuOfIterationsThisAlgoIsRunning + " iterations");
algorithmEnds(problem,solutions);
logger.info("total time: " + ((System.currentTimeMillis()-now)/1000.0) + "s");
logger.info("done");

View file

@ -142,6 +142,7 @@ public class VehicleRoutingProblem {
this.transportCosts = costs;
return this;
}
/**
* Sets the type of fleetSize.
@ -153,9 +154,6 @@ public class VehicleRoutingProblem {
*/
public Builder setFleetSize(FleetSize fleetSize){
this.fleetSize = fleetSize;
// if(fleetSize.equals(FleetSize.INFINITE)){
// fleetSizeIsInfinite=true;
// }
return this;
}
@ -198,20 +196,10 @@ public class VehicleRoutingProblem {
if(job instanceof Service) {
addService((Service) job);
}
// else if(job instanceof Shipment){
// addShipment((Shipment)job);
// }
else throw new IllegalStateException("job can only be a shipment or a service, but is instance of " + job.getClass());
return this;
}
// private void addShipment(Shipment job) {
// coordinates.put(job.getFromId(),job.getFromCoord());
// coordinates.put(job.getToId(), job.getToCoord());
// if(jobs.containsKey(job.getId())){ logger.warn("service " + job + " already in job list. overrides existing job."); }
// jobs.put(job.getId(),job);
//
// }
/**
* Adds a vehicle.
@ -221,7 +209,6 @@ public class VehicleRoutingProblem {
* @return
*/
public Builder addVehicle(Vehicle vehicle) {
// fleetSizeIsFinite = true;
vehicles.add(vehicle);
if(!vehicleTypes.contains(vehicle.getType())){
vehicleTypes.add(vehicle.getType());
@ -262,7 +249,6 @@ public class VehicleRoutingProblem {
logger.warn("set routing costs crowFlyDistance.");
transportCosts = new CrowFlyCosts(getLocations());
}
return new VehicleRoutingProblem(this);
}
@ -380,10 +366,6 @@ public class VehicleRoutingProblem {
return fleetComposition;
}
public void setFleetComposition(FleetComposition fleetComposition){
this.fleetComposition = fleetComposition;
}
/**
* Returns type of fleetSize, either INFINITE or FINITE.
*
@ -395,10 +377,6 @@ public class VehicleRoutingProblem {
return fleetSize;
}
public void setFleetSize(FleetSize fleetSize){
this.fleetSize = fleetSize;
}
/**
* Returns the unmodifiable job map.
*
@ -440,17 +418,6 @@ public class VehicleRoutingProblem {
return transportCosts;
}
/**
* Sets routing costs.
*
* @param costs
* @see VehicleRoutingTransportCosts
*/
public void setTransportCosts(VehicleRoutingTransportCosts costs) {
this.transportCosts = costs;
logger.info("transport costs set to " + costs.getClass());
}
/**
* Returns activityCosts.
*/
@ -459,8 +426,38 @@ public class VehicleRoutingProblem {
}
/**
* Sets activityCosts.
* Is deprecated and is not going to be supported any longer. Use the builder instead.
*/
@Deprecated
public void setFleetComposition(FleetComposition fleetComposition){
this.fleetComposition = fleetComposition;
}
/**
* Is deprecated and is not going to be supported any longer. Use the builder instead.
*/
@Deprecated
public void setFleetSize(FleetSize fleetSize){
this.fleetSize = fleetSize;
}
/**
* Sets routing costs.
* Is deprecated and is not going to be supported any longer. Use the builder instead.
*
* @param costs
* @see VehicleRoutingTransportCosts
*/
@Deprecated
public void setTransportCosts(VehicleRoutingTransportCosts costs) {
this.transportCosts = costs;
logger.info("transport costs set to " + costs.getClass());
}
/**
* Is deprecated and is not going to be supported any longer. Use the builder instead.
*/
@Deprecated
public void setActivityCosts(VehicleRoutingActivityCosts activityCosts){
this.activityCosts = activityCosts;
logger.info("activtiy costs set to " + activityCosts.getClass());