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

XMLWriter : have choice to only display the best solution

This commit is contained in:
braktar 2016-05-26 10:58:02 +02:00
parent 7cb0c694c7
commit 5479cc8845

View file

@ -29,6 +29,8 @@ import com.graphhopper.jsprit.core.problem.solution.route.activity.TimeWindow;
import com.graphhopper.jsprit.core.problem.solution.route.activity.TourActivity; import com.graphhopper.jsprit.core.problem.solution.route.activity.TourActivity;
import com.graphhopper.jsprit.core.problem.vehicle.Vehicle; import com.graphhopper.jsprit.core.problem.vehicle.Vehicle;
import com.graphhopper.jsprit.core.problem.vehicle.VehicleType; import com.graphhopper.jsprit.core.problem.vehicle.VehicleType;
import com.graphhopper.jsprit.core.util.Solutions;
import org.apache.commons.configuration.ConfigurationException; import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.XMLConfiguration; import org.apache.commons.configuration.XMLConfiguration;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
@ -67,6 +69,14 @@ public class VrpXMLWriter {
private Collection<VehicleRoutingProblemSolution> solutions; private Collection<VehicleRoutingProblemSolution> solutions;
private boolean onlyBestSolution = false;
public VrpXMLWriter(VehicleRoutingProblem vrp, Collection<VehicleRoutingProblemSolution> solutions, boolean onlyBestSolution) {
this.vrp = vrp;
this.solutions = new ArrayList<VehicleRoutingProblemSolution>(solutions);
this.onlyBestSolution = onlyBestSolution;
}
public VrpXMLWriter(VehicleRoutingProblem vrp, Collection<VehicleRoutingProblemSolution> solutions) { public VrpXMLWriter(VehicleRoutingProblem vrp, Collection<VehicleRoutingProblemSolution> solutions) {
this.vrp = vrp; this.vrp = vrp;
this.solutions = solutions; this.solutions = solutions;
@ -102,6 +112,12 @@ public class VrpXMLWriter {
writeShipments(xmlConfig, jobs); writeShipments(xmlConfig, jobs);
writeInitialRoutes(xmlConfig); writeInitialRoutes(xmlConfig);
if(onlyBestSolution && solutions != null) {
VehicleRoutingProblemSolution solution = Solutions.bestOf(solutions);
solutions.clear();
solutions.add(solution);
}
writeSolutions(xmlConfig); writeSolutions(xmlConfig);