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

add and test feature #127

This commit is contained in:
oblonski 2014-09-04 12:45:54 +02:00
parent ebff6ff50e
commit 9971d3d349
14 changed files with 397 additions and 177 deletions

View file

@ -1,20 +1,18 @@
/*******************************************************************************
* Copyright (c) 2014 Stefan Schroeder.
*
* Copyright (C) 2014 Stefan Schroeder
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
* Contributors:
* Stefan Schroeder - initial API and implementation
******************************************************************************/
package jsprit.core.problem.constraint;
@ -82,9 +80,8 @@ public class PickupAndDeliverShipmentLoadActivityLevelConstraint implements Hard
}
}
if(newAct instanceof DeliverShipment){
if(!Capacity.addup(loadAtPrevAct, Capacity.invert(newAct.getSize())).isLessOrEqual(iFacts.getNewVehicle().getType().getCapacityDimensions())){
return ConstraintsStatus.NOT_FULFILLED_BREAK;
}
if(!Capacity.addup(loadAtPrevAct, Capacity.invert(newAct.getSize())).isLessOrEqual(iFacts.getNewVehicle().getType().getCapacityDimensions()))
return ConstraintsStatus.NOT_FULFILLED_BREAK;
}
return ConstraintsStatus.FULFILLED;
}

View file

@ -1,16 +1,16 @@
/*******************************************************************************
* Copyright (C) 2013 Stefan Schroeder
*
* Copyright (C) 2014 Stefan Schroeder
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
@ -361,11 +361,15 @@ public class VrpXMLReader{
builder.addSizeDimension(index, value);
}
}
//name
String name = shipmentConfig.getString("name");
if(name != null) builder.setName(name);
//pickup-locationId
String pickupLocationId = shipmentConfig.getString("pickup.locationId");
if(pickupLocationId != null){
builder.setPickupLocation(pickupLocationId);
builder.setPickupLocationId(pickupLocationId);
}
//pickup-coord
@ -377,7 +381,7 @@ public class VrpXMLReader{
}
else{
// vrpBuilder.addLocation(pickupCoord.toString(),pickupCoord);
builder.setPickupLocation(pickupCoord.toString());
builder.setPickupLocationId(pickupCoord.toString());
}
}
@ -396,7 +400,7 @@ public class VrpXMLReader{
//delivery-locationId
String deliveryLocationId = shipmentConfig.getString("delivery.locationId");
if(deliveryLocationId != null){
builder.setDeliveryLocation(deliveryLocationId);
builder.setDeliveryLocationId(deliveryLocationId);
}
//delivery-coord
@ -408,7 +412,7 @@ public class VrpXMLReader{
}
else{
// vrpBuilder.addLocation(deliveryCoord.toString(),deliveryCoord);
builder.setDeliveryLocation(deliveryCoord.toString());
builder.setDeliveryLocationId(deliveryCoord.toString());
}
}
@ -479,6 +483,11 @@ public class VrpXMLReader{
builder.addSizeDimension(index, value);
}
}
//name
String name = serviceConfig.getString("name");
if(name != null) builder.setName(name);
String serviceLocationId = serviceConfig.getString("locationId");
if(serviceLocationId != null) builder.setLocationId(serviceLocationId);
Coordinate serviceCoord = getCoord(serviceConfig,"");

View file

@ -1,16 +1,16 @@
/*******************************************************************************
* Copyright (C) 2013 Stefan Schroeder
*
* Copyright (C) 2014 Stefan Schroeder
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
@ -237,6 +237,12 @@ public class VrpXMLWriter {
String skillString = getSkillString(service);
xmlConfig.setProperty(shipmentPathString + "("+counter+").requiredSkills", skillString);
//name
if(service.getName() != null){
if(!service.getName().equals("no-name")){
xmlConfig.setProperty(shipmentPathString + "("+counter+").name", service.getName());
}
}
counter++;
}
}
@ -249,7 +255,7 @@ public class VrpXMLWriter {
Shipment shipment = (Shipment) j;
xmlConfig.setProperty(shipmentPathString + "("+counter+")[@id]", shipment.getId());
// xmlConfig.setProperty(shipmentPathString + "("+counter+")[@type]", service.getType());
if(shipment.getPickupLocation() != null) xmlConfig.setProperty(shipmentPathString + "("+counter+").pickup.locationId", shipment.getPickupLocation());
if(shipment.getPickupLocationId() != null) xmlConfig.setProperty(shipmentPathString + "("+counter+").pickup.locationId", shipment.getPickupLocationId());
if(shipment.getPickupCoord() != null) {
xmlConfig.setProperty(shipmentPathString + "("+counter+").pickup.coord[@x]", shipment.getPickupCoord().getX());
xmlConfig.setProperty(shipmentPathString + "("+counter+").pickup.coord[@y]", shipment.getPickupCoord().getY());
@ -260,7 +266,7 @@ public class VrpXMLWriter {
xmlConfig.setProperty(shipmentPathString + "("+counter+").pickup.timeWindows.timeWindow(0).end", shipment.getPickupTimeWindow().getEnd());
if(shipment.getDeliveryLocation() != null) xmlConfig.setProperty(shipmentPathString + "("+counter+").delivery.locationId", shipment.getDeliveryLocation());
if(shipment.getDeliveryLocationId() != null) xmlConfig.setProperty(shipmentPathString + "("+counter+").delivery.locationId", shipment.getDeliveryLocationId());
if(shipment.getDeliveryCoord() != null) {
xmlConfig.setProperty(shipmentPathString + "("+counter+").delivery.coord[@x]", shipment.getDeliveryCoord().getX());
xmlConfig.setProperty(shipmentPathString + "("+counter+").delivery.coord[@y]", shipment.getDeliveryCoord().getY());
@ -279,6 +285,12 @@ public class VrpXMLWriter {
String skillString = getSkillString(shipment);
xmlConfig.setProperty(shipmentPathString + "("+counter+").requiredSkills", skillString);
//name
if(shipment.getName() != null){
if(!shipment.getName().equals("no-name")){
xmlConfig.setProperty(shipmentPathString + "("+counter+").name", shipment.getName());
}
}
counter++;
}
}

View file

@ -1,16 +1,16 @@
/*******************************************************************************
* Copyright (C) 2013 Stefan Schroeder
*
* Copyright (C) 2014 Stefan Schroeder
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
@ -32,11 +32,11 @@ public interface Job extends HasId, HasIndex {
/**
* Returns the unique identifier (id) of a job.
*
*
* @return id
*/
public String getId();
/**
* Returns size, i.e. capacity-demand, of this job which can consist of an arbitrary number of capacity dimensions.
*
@ -44,5 +44,12 @@ public interface Job extends HasId, HasIndex {
*/
public Capacity getSize();
Skills getRequiredSkills();
public Skills getRequiredSkills();
/**
* Returns name.
*
* @return name
*/
public String getName();
}

View file

@ -1,16 +1,16 @@
/*******************************************************************************
* Copyright (C) 2013 Stefan Schroeder
*
* Copyright (C) 2014 Stefan Schroeder
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
@ -35,15 +35,19 @@ import jsprit.core.util.Coordinate;
*/
public class Service extends AbstractJob {
/**
/**
* Builder that builds a service.
*
* @author schroeder
*
*/
public static class Builder {
/**
/**
* Returns a new instance of builder that builds a service.
*
* @param id the id of the service
@ -73,6 +77,8 @@ public class Service extends AbstractJob {
protected Skills skills;
private String name = "no-name";
Builder(String id){
this.id = id;
}
@ -178,6 +184,11 @@ public class Service extends AbstractJob {
skillBuilder.addSkill(skill);
return this;
}
public Builder setName(String name) {
this.name = name;
return this;
}
}
@ -197,6 +208,8 @@ public class Service extends AbstractJob {
private final Skills skills;
private final String name;
Service(Builder builder){
id = builder.id;
locationId = builder.locationId;
@ -206,6 +219,7 @@ public class Service extends AbstractJob {
type = builder.type;
size = builder.capacity;
skills = builder.skills;
name = builder.name;
}
@Override
@ -306,4 +320,9 @@ public class Service extends AbstractJob {
return skills;
}
@Override
public String getName() {
return name;
}
}

View file

@ -1,20 +1,18 @@
/*******************************************************************************
* Copyright (c) 2014 Stefan Schroeder.
*
* Copyright (C) 2014 Stefan Schroeder
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
* Contributors:
* Stefan Schroeder - initial API and implementation
******************************************************************************/
package jsprit.core.problem.job;
@ -43,7 +41,9 @@ import jsprit.core.util.Coordinate;
*/
public class Shipment extends AbstractJob{
/**
/**
* Builder that builds the shipment.
*
* @author schroeder
@ -77,6 +77,8 @@ public class Shipment extends AbstractJob{
private Skills skills;
private String name = "no-name";
/**
* Returns new instance of this builder.
*
@ -91,14 +93,29 @@ public class Shipment extends AbstractJob{
if(id == null) throw new IllegalArgumentException("id must not be null");
this.id = id;
}
/**
* Sets pickup-location id.
*
* @param pickupLocationId the location id of shipment's pickup
* @return builder
* @throws IllegalArgumentException if location is null
*/
public Builder setPickupLocationId(String pickupLocationId){
if(pickupLocationId == null) throw new IllegalArgumentException("location must not be null");
this.pickupLocation = pickupLocationId;
return this;
}
/**
* Sets pickup-location.
* Sets pickup-location id.
*
* @param pickupLocationId the location id of shipment's pickup
* @return builder
* @throws IllegalArgumentException if location is null
* @deprecated use .setPickupLocationId(locationId) instead
*/
@Deprecated
public Builder setPickupLocation(String pickupLocationId){
if(pickupLocationId == null) throw new IllegalArgumentException("location must not be null");
this.pickupLocation = pickupLocationId;
@ -148,14 +165,29 @@ public class Shipment extends AbstractJob{
this.pickupTimeWindow = timeWindow;
return this;
}
/**
/**
* Sets the delivery-location.
*
* @param deliveryLocationId the delivery location id
* @return builder
* @throws IllegalArgumentException if location is null
*/
public Builder setDeliveryLocationId(String deliveryLocationId){
if(deliveryLocationId == null) throw new IllegalArgumentException("delivery location must not be null");
this.deliveryLocation = deliveryLocationId;
return this;
}
/**
* Sets the delivery-location.
*
* @param deliveryLocation the delivery location id
* @return builder
* @throws IllegalArgumentException if location is null
* @deprecated use .setDeliveryLocationId(deliveryLocationId)
*/
@Deprecated
public Builder setDeliveryLocation(String deliveryLocation){
if(deliveryLocation == null) throw new IllegalArgumentException("delivery location must not be null");
this.deliveryLocation = deliveryLocation;
@ -247,6 +279,11 @@ public class Shipment extends AbstractJob{
skillBuilder.addSkill(skill);
return this;
}
public Builder setName(String name) {
this.name = name;
return this;
}
}
private final String id;
@ -271,6 +308,8 @@ public class Shipment extends AbstractJob{
private final Skills skills;
private String name;
Shipment(Builder builder){
this.id = builder.id;
this.pickupLocation = builder.pickupLocation;
@ -283,6 +322,7 @@ public class Shipment extends AbstractJob{
this.deliveryTimeWindow = builder.deliveryTimeWindow;
this.capacity = builder.capacity;
this.skills = builder.skills;
this.name = builder.name;
}
@Override
@ -294,11 +334,22 @@ public class Shipment extends AbstractJob{
* Returns the pickup-location.
*
* @return pickup-location
* @deprecated use .getPickupLocationId() instead
*/
@Deprecated
public String getPickupLocation() {
return pickupLocation;
}
/**
* Returns the pickup-location.
*
* @return pickup-location
*/
public String getPickupLocationId() {
return pickupLocation;
}
/**
* Returns the pickup-coordinate.
*
@ -323,11 +374,22 @@ public class Shipment extends AbstractJob{
* Returns delivery-location.
*
* @return delivery-location
* @deprecated use .getDeliveryLocationId() instead
*/
@Deprecated
public String getDeliveryLocation() {
return deliveryLocation;
}
/**
* Returns delivery-location.
*
* @return delivery-location
*/
public String getDeliveryLocationId() {
return deliveryLocation;
}
/**
* Returns coordinate of the delivery.
*
@ -404,5 +466,10 @@ public class Shipment extends AbstractJob{
return skills;
}
@Override
public String getName() {
return name;
}
}

View file

@ -1,6 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.w3schools.com"
<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~ Copyright (C) 2014 Stefan Schroeder
~
~ This library is free software; you can redistribute it and/or
~ modify it under the terms of the GNU Lesser General Public
~ License as published by the Free Software Foundation; either
~ version 3.0 of the License, or (at your option) any later version.
~
~ This library is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
~ Lesser General Public License for more details.
~
~ You should have received a copy of the GNU Lesser General Public
~ License along with this library. If not, see <http://www.gnu.org/licenses/>.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.w3schools.com"
xmlns="http://www.w3schools.com" elementFormDefault="qualified">
<xs:element name="problem">
@ -124,6 +141,7 @@
<xs:all>
<xs:element name="locationId" type="xs:string" minOccurs="0" maxOccurs="1"/>
<xs:element name="coord" type="coordType" minOccurs="0" maxOccurs="1"/>
<xs:element name="name" type="xs:string" minOccurs="0" maxOccurs="1"/>
<xs:element name="capacity-demand" type="xs:integer" minOccurs="0" maxOccurs="1" default="0"/>
<xs:element name="capacity-dimensions" minOccurs="0" maxOccurs="1">
<xs:complexType>
@ -163,7 +181,7 @@
<xs:sequence>
<xs:element name="shipment" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:all>
<xs:element name="pickup" minOccurs="1" maxOccurs="1">
<xs:complexType>
<xs:all>
@ -213,7 +231,8 @@
</xs:complexType>
</xs:element>
<xs:element name="requiredSkills" type="xs:string" minOccurs="0" maxOccurs="1"/>
</xs:sequence>
<xs:element name="name" type="xs:string" minOccurs="0" maxOccurs="1"/>
</xs:all>
<xs:attribute name="id" type="xs:string" use="required" />
</xs:complexType>
</xs:element>