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

Merge remote-tracking branch 'origin/master'

This commit is contained in:
oblonski 2019-06-19 10:04:22 +02:00
commit a20db5e119
No known key found for this signature in database
GPG key ID: 179DE487285680D1
9 changed files with 72 additions and 41 deletions

View file

@ -572,28 +572,30 @@ public class GraphStreamViewer {
n.addAttribute("ui.label", "start");
}
for (TourActivity act : route.getActivities()) {
Job job = ((JobActivity) act).getJob();
String currIdentifier = makeId(job.getId(), act.getLocation().getId());
if (label.equals(Label.ACTIVITY)) {
Node actNode = g.getNode(currIdentifier);
actNode.addAttribute("ui.label", act.getName());
} else if (label.equals(Label.JOB_NAME)) {
Node actNode = g.getNode(currIdentifier);
actNode.addAttribute("ui.label", job.getName());
} else if (label.equals(Label.ARRIVAL_TIME)) {
Node actNode = g.getNode(currIdentifier);
actNode.addAttribute("ui.label", Time.parseSecondsToTime(act.getArrTime()));
} else if (label.equals(Label.DEPARTURE_TIME)) {
Node actNode = g.getNode(currIdentifier);
actNode.addAttribute("ui.label", Time.parseSecondsToTime(act.getEndTime()));
if (act instanceof JobActivity) {
Job job = ((JobActivity) act).getJob();
String currIdentifier = makeId(job.getId(), act.getLocation().getId());
if (label.equals(Label.ACTIVITY)) {
Node actNode = g.getNode(currIdentifier);
actNode.addAttribute("ui.label", act.getName());
} else if (label.equals(Label.JOB_NAME)) {
Node actNode = g.getNode(currIdentifier);
actNode.addAttribute("ui.label", job.getName());
} else if (label.equals(Label.ARRIVAL_TIME)) {
Node actNode = g.getNode(currIdentifier);
actNode.addAttribute("ui.label", Time.parseSecondsToTime(act.getArrTime()));
} else if (label.equals(Label.DEPARTURE_TIME)) {
Node actNode = g.getNode(currIdentifier);
actNode.addAttribute("ui.label", Time.parseSecondsToTime(act.getEndTime()));
}
g.addEdge(makeEdgeId(routeId, vehicle_edgeId), prevIdentifier, currIdentifier, true);
if (act instanceof PickupActivity) g.getNode(currIdentifier).addAttribute("ui.class", "pickupInRoute");
else if (act instanceof DeliveryActivity)
g.getNode(currIdentifier).addAttribute("ui.class", "deliveryInRoute");
prevIdentifier = currIdentifier;
vehicle_edgeId++;
sleep(renderDelay_in_ms);
}
g.addEdge(makeEdgeId(routeId, vehicle_edgeId), prevIdentifier, currIdentifier, true);
if (act instanceof PickupActivity) g.getNode(currIdentifier).addAttribute("ui.class", "pickupInRoute");
else if (act instanceof DeliveryActivity)
g.getNode(currIdentifier).addAttribute("ui.class", "deliveryInRoute");
prevIdentifier = currIdentifier;
vehicle_edgeId++;
sleep(renderDelay_in_ms);
}
if (route.getVehicle().isReturnToDepot()) {
String lastIdentifier = makeId(route.getVehicle().getId(), route.getVehicle().getEndLocation().getId());

View file

@ -302,6 +302,10 @@ public class Plotter {
final XYPlot plot = createPlot(problem, shipments, solution);
JFreeChart chart = new JFreeChart(title, plot);
plot.setBackgroundPaint(Color.WHITE);
plot.setDomainGridlinesVisible(false);
plot.setRangeGridlinesVisible(false);
LegendTitle legend = createLegend(routes, shipments, plot);
chart.removeLegend();
chart.addLegend(legend);

View file

@ -135,23 +135,28 @@ public class VehicleRoutingAlgorithm {
this.objectiveFunction = objectiveFunction;
}
/**
* Adds solution to the collection of initial solutions.
*
* @param solution the solution to be added
*/
public void addInitialSolution(VehicleRoutingProblemSolution solution) {
/**
* Adds solution to the collection of initial solutions.
*
* This method may lead to errors if tour activities in the solution are different to the
* ones in the VRP (including differences in indexing)
*
* @param solution the solution to be added
*/
public void addInitialSolution(VehicleRoutingProblemSolution solution) {
// We will make changes so let's make a copy
solution = VehicleRoutingProblemSolution.copyOf(solution);
verify(solution);
verifyAndAdaptSolution(solution);
initialSolutions.add(solution);
}
private void verify(VehicleRoutingProblemSolution solution) {
Set<Job> allJobs = new HashSet<Job>(problem.getJobs().values());
allJobs.removeAll(solution.getUnassignedJobs());
//this method may lead to errors if tour activities in the solution are different to the ones in the VRP
//(including differences in indexing)
private void verifyAndAdaptSolution(VehicleRoutingProblemSolution solution) {
Set<Job> jobsNotInSolution = new HashSet<Job>(problem.getJobs().values());
jobsNotInSolution.removeAll(solution.getUnassignedJobs());
for (VehicleRoute route : solution.getRoutes()) {
allJobs.removeAll(route.getTourActivities().getJobs());
jobsNotInSolution.removeAll(route.getTourActivities().getJobs());
if (route.getVehicle().getIndex() == 0)
throw new IllegalStateException("vehicle used in initial solution has no index. probably a vehicle is used that has not been added to the " +
" the VehicleRoutingProblem. only use vehicles that have already been added to the problem.");
@ -164,7 +169,9 @@ public class VehicleRoutingAlgorithm {
}
}
solution.getUnassignedJobs().addAll(allJobs);
//if solution is partial (not all jobs are considered), add these jobs to solution.unassignedJobs
solution.getUnassignedJobs().addAll(jobsNotInSolution);
//update the cost of solution (regardless if partial or not)
solution.setCost(getObjectiveFunction().getCosts(solution));
// if (nuJobs != problem.getJobs().values().size()) {

View file

@ -104,6 +104,10 @@ public final class RuinWorst extends AbstractRuinStrategy {
TourActivity actBefore = route.getStart();
TourActivity actToEval = null;
for (TourActivity act : route.getActivities()) {
if (!(act instanceof TourActivity.JobActivity)) {
continue;
}
if (actToEval == null) {
actToEval = act;
continue;
@ -119,6 +123,9 @@ public final class RuinWorst extends AbstractRuinStrategy {
actBefore = actToEval;
actToEval = act;
}
if (actToEval == null) {
continue;
}
double savings = savings(route, actBefore, actToEval, route.getEnd());
Job job = ((TourActivity.JobActivity) actToEval).getJob();
if (!savingsMap.containsKey(job)) {

View file

@ -414,6 +414,17 @@ public class VehicleRoutingProblem {
return this;
}
private final List<AbstractActivity> nonJobActivities = new ArrayList<>();
public Builder addNonJobActivities(Collection<? extends AbstractActivity> nonJobActivities) {
for (AbstractActivity act : nonJobActivities) {
act.setIndex(activityIndexCounter);
incActivityIndexCounter();
this.nonJobActivities.add(act);
}
return this;
}
/**
* Builds the {@link VehicleRoutingProblem}.
* <p>

View file

@ -78,8 +78,8 @@ public class MaxDistanceConstraint implements HardActivityConstraint {
double maxDistance = getMaxDistance(iFacts.getNewVehicle());
if (currentDistance > maxDistance) return ConstraintsStatus.NOT_FULFILLED_BREAK;
double distancePrevAct2NewAct = distanceCalculator.getDistance(prevAct.getLocation(), newAct.getLocation(), iFacts.getNewDepTime(), iFacts.getNewVehicle());
double distanceNewAct2nextAct = distanceCalculator.getDistance(newAct.getLocation(), nextAct.getLocation(), iFacts.getNewDepTime(), iFacts.getNewVehicle());
double distancePrevAct2NewAct = distanceCalculator.getDistance(prevAct.getLocation(), newAct.getLocation(), prevActDepTime, iFacts.getNewVehicle());
double distanceNewAct2nextAct = distanceCalculator.getDistance(newAct.getLocation(), nextAct.getLocation(), prevActDepTime, iFacts.getNewVehicle());
double distancePrevAct2NextAct = distanceCalculator.getDistance(prevAct.getLocation(), nextAct.getLocation(), prevActDepTime, iFacts.getNewVehicle());
if (prevAct instanceof Start && nextAct instanceof End) distancePrevAct2NextAct = 0;
if (nextAct instanceof End && !iFacts.getNewVehicle().isReturnToDepot()) {

View file

@ -398,9 +398,9 @@ public class Service extends AbstractJob {
}
/**
* Get priority of service. Only 1 = high priority, 2 = medium and 3 = low are allowed.
* Get priority of service. Only 1 (high) to 10 (low) are allowed.
* <p>
* Default is 2 = medium.
* Default is 2.
*
* @return priority
*/

View file

@ -318,7 +318,7 @@ public class Shipment extends AbstractJob {
/**
* Set priority to shipment. Only 1 (high) to 10 (low) are allowed.
* <p>
* Default is 2 = medium.
* Default is 2.
*
* @param priority
* @return builder
@ -505,9 +505,9 @@ public class Shipment extends AbstractJob {
}
/**
* Get priority of shipment. Only 1 = high priority, 2 = medium and 3 = low are allowed.
* Get priority of shipment. Only 1 (high) to 10 (low) are allowed.
* <p>
* Default is 2 = medium.
* Default is 2.
*
* @return priority
*/

View file

@ -367,7 +367,7 @@ public class VehicleRoute {
* @return list of tourActivities
*/
public List<TourActivity> getActivities() {
return Collections.unmodifiableList(tourActivities.getActivities());
return tourActivities.getActivities();
}
/**