mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
make Plotter plot initial routes
This commit is contained in:
parent
d11e11fc8d
commit
b8ef9a55a1
1 changed files with 120 additions and 95 deletions
|
|
@ -142,6 +142,9 @@ public class Plotter {
|
||||||
if(plotSolutionAsWell){
|
if(plotSolutionAsWell){
|
||||||
plotSolutionAsPNG(vrp, routes, filename, plotTitle);
|
plotSolutionAsPNG(vrp, routes, filename, plotTitle);
|
||||||
}
|
}
|
||||||
|
else if(!(vrp.getInitialVehicleRoutes().isEmpty())){
|
||||||
|
plotSolutionAsPNG(vrp, vrp.getInitialVehicleRoutes(), filename, plotTitle);
|
||||||
|
}
|
||||||
else{
|
else{
|
||||||
plotVrpAsPNG(vrp, filename, plotTitle);
|
plotVrpAsPNG(vrp, filename, plotTitle);
|
||||||
}
|
}
|
||||||
|
|
@ -240,10 +243,9 @@ public class Plotter {
|
||||||
problemRenderer.setBaseItemLabelPaint(Color.BLACK);
|
problemRenderer.setBaseItemLabelPaint(Color.BLACK);
|
||||||
|
|
||||||
NumberAxis xAxis = new NumberAxis();
|
NumberAxis xAxis = new NumberAxis();
|
||||||
|
NumberAxis yAxis = new NumberAxis();
|
||||||
|
|
||||||
xAxis.setRangeWithMargins(getDomainRange(problem));
|
xAxis.setRangeWithMargins(getDomainRange(problem));
|
||||||
|
|
||||||
NumberAxis yAxis = new NumberAxis();
|
|
||||||
yAxis.setRangeWithMargins(getRange(problem));
|
yAxis.setRangeWithMargins(getRange(problem));
|
||||||
|
|
||||||
plot.setDataset(0, problem);
|
plot.setDataset(0, problem);
|
||||||
|
|
@ -297,16 +299,10 @@ public class Plotter {
|
||||||
problemRenderer.setBaseItemLabelsVisible(true);
|
problemRenderer.setBaseItemLabelsVisible(true);
|
||||||
problemRenderer.setBaseItemLabelPaint(Color.BLACK);
|
problemRenderer.setBaseItemLabelPaint(Color.BLACK);
|
||||||
|
|
||||||
NumberAxis xAxis = new NumberAxis();
|
|
||||||
xAxis.setRangeWithMargins(getDomainRange(solutionColl));
|
|
||||||
|
|
||||||
NumberAxis yAxis = new NumberAxis();
|
|
||||||
yAxis.setRangeWithMargins(getRange(solutionColl));
|
|
||||||
|
|
||||||
plot.setDataset(0, problem);
|
plot.setDataset(0, problem);
|
||||||
plot.setRenderer(0, problemRenderer);
|
plot.setRenderer(0, problemRenderer);
|
||||||
plot.setDomainAxis(0, xAxis);
|
// plot.setDomainAxis(0, xAxis);
|
||||||
plot.setRangeAxis(0, yAxis);
|
// plot.setRangeAxis(0, yAxis);
|
||||||
// plot.mapDatasetToDomainAxis(0, 0);
|
// plot.mapDatasetToDomainAxis(0, 0);
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -336,6 +332,24 @@ public class Plotter {
|
||||||
// plot.setDomainAxis(2, xAxis);
|
// plot.setDomainAxis(2, xAxis);
|
||||||
// plot.setRangeAxis(2, yAxis);
|
// plot.setRangeAxis(2, yAxis);
|
||||||
|
|
||||||
|
|
||||||
|
NumberAxis xAxis = new NumberAxis();
|
||||||
|
NumberAxis yAxis = new NumberAxis();
|
||||||
|
|
||||||
|
if(boundingBox == null){
|
||||||
|
xAxis.setRangeWithMargins(Math.min(problem.getDomainLowerBound(true), solutionColl.getDomainLowerBound(true)),
|
||||||
|
Math.max(problem.getDomainUpperBound(true), solutionColl.getDomainUpperBound(true)));
|
||||||
|
yAxis.setRangeWithMargins(Math.min(problem.getRangeLowerBound(true), solutionColl.getRangeLowerBound(true)),
|
||||||
|
Math.max(problem.getRangeUpperBound(true), solutionColl.getRangeUpperBound(true)));
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
xAxis.setRangeWithMargins(new Range(boundingBox.minX, boundingBox.maxX));
|
||||||
|
yAxis.setRangeWithMargins(new Range(boundingBox.minY, boundingBox.maxY));
|
||||||
|
}
|
||||||
|
|
||||||
|
plot.setDomainAxis(xAxis);
|
||||||
|
plot.setRangeAxis(yAxis);
|
||||||
|
|
||||||
return plot;
|
return plot;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -421,42 +435,12 @@ public class Plotter {
|
||||||
XYSeries pickupSeries = new XYSeries("pickup", false, true);
|
XYSeries pickupSeries = new XYSeries("pickup", false, true);
|
||||||
XYSeries deliverySeries = new XYSeries("delivery", false, true);
|
XYSeries deliverySeries = new XYSeries("delivery", false, true);
|
||||||
for(Job job : jobs){
|
for(Job job : jobs){
|
||||||
if(job instanceof Shipment){
|
addJob(labels, serviceSeries, pickupSeries, deliverySeries, job);
|
||||||
Shipment s = (Shipment)job;
|
}
|
||||||
XYDataItem dataItem = new XYDataItem(s.getPickupCoord().getX(), s.getPickupCoord().getY());
|
for(VehicleRoute r : vrp.getInitialVehicleRoutes()){
|
||||||
pickupSeries.add(dataItem);
|
for(Job job : r.getTourActivities().getJobs()){
|
||||||
addLabel(labels, s, dataItem);
|
addJob(labels, serviceSeries, pickupSeries, deliverySeries, job);
|
||||||
|
|
||||||
XYDataItem dataItem2 = new XYDataItem(s.getDeliveryCoord().getX(), s.getDeliveryCoord().getY());
|
|
||||||
deliverySeries.add(dataItem2);
|
|
||||||
addLabel(labels, s, dataItem2);
|
|
||||||
}
|
}
|
||||||
else if(job instanceof Pickup){
|
|
||||||
Pickup service = (Pickup)job;
|
|
||||||
Coordinate coord = service.getCoord();
|
|
||||||
XYDataItem dataItem = new XYDataItem(coord.getX(), coord.getY());
|
|
||||||
pickupSeries.add(dataItem);
|
|
||||||
addLabel(labels, service, dataItem);
|
|
||||||
|
|
||||||
}
|
|
||||||
else if(job instanceof Delivery){
|
|
||||||
Delivery service = (Delivery)job;
|
|
||||||
Coordinate coord = service.getCoord();
|
|
||||||
XYDataItem dataItem = new XYDataItem(coord.getX(), coord.getY());
|
|
||||||
deliverySeries.add(dataItem);
|
|
||||||
addLabel(labels, service, dataItem);
|
|
||||||
}
|
|
||||||
else if(job instanceof Service){
|
|
||||||
Service service = (Service)job;
|
|
||||||
Coordinate coord = service.getCoord();
|
|
||||||
XYDataItem dataItem = new XYDataItem(coord.getX(), coord.getY());
|
|
||||||
serviceSeries.add(dataItem);
|
|
||||||
addLabel(labels, service, dataItem);
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
throw new IllegalStateException("job instanceof " + job.getClass().toString() + ". this is not supported.");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
if(!serviceSeries.isEmpty()) coll.addSeries(serviceSeries);
|
if(!serviceSeries.isEmpty()) coll.addSeries(serviceSeries);
|
||||||
if(!pickupSeries.isEmpty()) coll.addSeries(pickupSeries);
|
if(!pickupSeries.isEmpty()) coll.addSeries(pickupSeries);
|
||||||
|
|
@ -464,6 +448,45 @@ public class Plotter {
|
||||||
return coll;
|
return coll;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void addJob(Map<XYDataItem, String> labels, XYSeries serviceSeries,
|
||||||
|
XYSeries pickupSeries, XYSeries deliverySeries, Job job) {
|
||||||
|
if(job instanceof Shipment){
|
||||||
|
Shipment s = (Shipment)job;
|
||||||
|
XYDataItem dataItem = new XYDataItem(s.getPickupCoord().getX(), s.getPickupCoord().getY());
|
||||||
|
pickupSeries.add(dataItem);
|
||||||
|
addLabel(labels, s, dataItem);
|
||||||
|
|
||||||
|
XYDataItem dataItem2 = new XYDataItem(s.getDeliveryCoord().getX(), s.getDeliveryCoord().getY());
|
||||||
|
deliverySeries.add(dataItem2);
|
||||||
|
addLabel(labels, s, dataItem2);
|
||||||
|
}
|
||||||
|
else if(job instanceof Pickup){
|
||||||
|
Pickup service = (Pickup)job;
|
||||||
|
Coordinate coord = service.getCoord();
|
||||||
|
XYDataItem dataItem = new XYDataItem(coord.getX(), coord.getY());
|
||||||
|
pickupSeries.add(dataItem);
|
||||||
|
addLabel(labels, service, dataItem);
|
||||||
|
|
||||||
|
}
|
||||||
|
else if(job instanceof Delivery){
|
||||||
|
Delivery service = (Delivery)job;
|
||||||
|
Coordinate coord = service.getCoord();
|
||||||
|
XYDataItem dataItem = new XYDataItem(coord.getX(), coord.getY());
|
||||||
|
deliverySeries.add(dataItem);
|
||||||
|
addLabel(labels, service, dataItem);
|
||||||
|
}
|
||||||
|
else if(job instanceof Service){
|
||||||
|
Service service = (Service)job;
|
||||||
|
Coordinate coord = service.getCoord();
|
||||||
|
XYDataItem dataItem = new XYDataItem(coord.getX(), coord.getY());
|
||||||
|
serviceSeries.add(dataItem);
|
||||||
|
addLabel(labels, service, dataItem);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
throw new IllegalStateException("job instanceof " + job.getClass().toString() + ". this is not supported.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void addLabel(Map<XYDataItem, String> labels, Job job, XYDataItem dataItem) {
|
private void addLabel(Map<XYDataItem, String> labels, Job job, XYDataItem dataItem) {
|
||||||
if(this.label.equals(Label.SIZE)){
|
if(this.label.equals(Label.SIZE)){
|
||||||
labels.put(dataItem, getSizeString(job));
|
labels.put(dataItem, getSizeString(job));
|
||||||
|
|
@ -496,56 +519,58 @@ public class Plotter {
|
||||||
}
|
}
|
||||||
|
|
||||||
private Locations retrieveLocations(VehicleRoutingProblem vrp) throws NoLocationFoundException {
|
private Locations retrieveLocations(VehicleRoutingProblem vrp) throws NoLocationFoundException {
|
||||||
final Map<String, Coordinate> locs = new HashMap<String, Coordinate>();
|
return vrp.getLocations();
|
||||||
for(Vehicle v : vrp.getVehicles()){
|
// final Map<String, Coordinate> locs = new HashMap<String, Coordinate>();
|
||||||
String startLocationId = v.getStartLocationId();
|
//
|
||||||
if(startLocationId == null) throw new NoLocationFoundException();
|
// for(Vehicle v : vrp.getVehicles()){
|
||||||
Coordinate startCoord = v.getStartLocationCoordinate();
|
// String startLocationId = v.getStartLocationId();
|
||||||
if(startCoord == null) throw new NoLocationFoundException();
|
// if(startLocationId == null) throw new NoLocationFoundException();
|
||||||
locs.put(startLocationId, startCoord);
|
// Coordinate startCoord = v.getStartLocationCoordinate();
|
||||||
|
// if(startCoord == null) throw new NoLocationFoundException();
|
||||||
String endLocationId = v.getEndLocationId();
|
// locs.put(startLocationId, startCoord);
|
||||||
if(!startLocationId.equals(endLocationId)){
|
//
|
||||||
Coordinate endCoord = v.getEndLocationCoordinate();
|
// String endLocationId = v.getEndLocationId();
|
||||||
if(endCoord == null) throw new NoLocationFoundException();
|
// if(!startLocationId.equals(endLocationId)){
|
||||||
locs.put(endLocationId, endCoord);
|
// Coordinate endCoord = v.getEndLocationCoordinate();
|
||||||
}
|
// if(endCoord == null) throw new NoLocationFoundException();
|
||||||
}
|
// locs.put(endLocationId, endCoord);
|
||||||
for(Job j : vrp.getJobs().values()){
|
// }
|
||||||
if(j instanceof Service){
|
// }
|
||||||
String locationId = ((Service) j).getLocationId();
|
// for(Job j : vrp.getJobs().values()){
|
||||||
if(locationId == null) throw new NoLocationFoundException();
|
// if(j instanceof Service){
|
||||||
Coordinate coord = ((Service) j).getCoord();
|
// String locationId = ((Service) j).getLocationId();
|
||||||
if(coord == null) throw new NoLocationFoundException();
|
// if(locationId == null) throw new NoLocationFoundException();
|
||||||
locs.put(locationId, coord);
|
// Coordinate coord = ((Service) j).getCoord();
|
||||||
}
|
// if(coord == null) throw new NoLocationFoundException();
|
||||||
else if(j instanceof Shipment){
|
// locs.put(locationId, coord);
|
||||||
{
|
// }
|
||||||
String locationId = ((Shipment) j).getPickupLocation();
|
// else if(j instanceof Shipment){
|
||||||
if(locationId == null) throw new NoLocationFoundException();
|
// {
|
||||||
Coordinate coord = ((Shipment) j).getPickupCoord();
|
// String locationId = ((Shipment) j).getPickupLocation();
|
||||||
if(coord == null) throw new NoLocationFoundException();
|
// if(locationId == null) throw new NoLocationFoundException();
|
||||||
locs.put(locationId, coord);
|
// Coordinate coord = ((Shipment) j).getPickupCoord();
|
||||||
}
|
// if(coord == null) throw new NoLocationFoundException();
|
||||||
{
|
// locs.put(locationId, coord);
|
||||||
String locationId = ((Shipment) j).getDeliveryLocation();
|
// }
|
||||||
if(locationId == null) throw new NoLocationFoundException();
|
// {
|
||||||
Coordinate coord = ((Shipment) j).getDeliveryCoord();
|
// String locationId = ((Shipment) j).getDeliveryLocation();
|
||||||
if(coord == null) throw new NoLocationFoundException();
|
// if(locationId == null) throw new NoLocationFoundException();
|
||||||
locs.put(locationId, coord);
|
// Coordinate coord = ((Shipment) j).getDeliveryCoord();
|
||||||
}
|
// if(coord == null) throw new NoLocationFoundException();
|
||||||
}
|
// locs.put(locationId, coord);
|
||||||
else{
|
// }
|
||||||
throw new IllegalStateException("job is neither a service nor a shipment. this is not supported yet.");
|
// }
|
||||||
}
|
// else{
|
||||||
}
|
// throw new IllegalStateException("job is neither a service nor a shipment. this is not supported yet.");
|
||||||
return new Locations() {
|
// }
|
||||||
|
// }
|
||||||
@Override
|
// return new Locations() {
|
||||||
public Coordinate getCoord(String id) {
|
//
|
||||||
return locs.get(id);
|
// @Override
|
||||||
}
|
// public Coordinate getCoord(String id) {
|
||||||
};
|
// return locs.get(id);
|
||||||
|
// }
|
||||||
|
// };
|
||||||
}
|
}
|
||||||
|
|
||||||
public void plotShipments(boolean plotShipments) {
|
public void plotShipments(boolean plotShipments) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue