Skip to content

Commit

Permalink
add and test feature #127
Browse files Browse the repository at this point in the history
  • Loading branch information
oblonski committed Sep 4, 2014
1 parent ebff6ff commit 9971d3d
Show file tree
Hide file tree
Showing 14 changed files with 397 additions and 177 deletions.
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -82,9 +80,8 @@ public ConstraintsStatus fulfilled(JobInsertionContext iFacts, TourActivity prev
}
}
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;
}
Expand Down
29 changes: 19 additions & 10 deletions jsprit-core/src/main/java/jsprit/core/problem/io/VrpXMLReader.java
Original file line number Diff line number Diff line change
@@ -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/>.
******************************************************************************/
Expand Down Expand Up @@ -361,11 +361,15 @@ private void readShipments(XMLConfiguration config){
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
Expand All @@ -377,7 +381,7 @@ private void readShipments(XMLConfiguration config){
}
else{
// vrpBuilder.addLocation(pickupCoord.toString(),pickupCoord);
builder.setPickupLocation(pickupCoord.toString());
builder.setPickupLocationId(pickupCoord.toString());
}
}

Expand All @@ -396,7 +400,7 @@ private void readShipments(XMLConfiguration config){
//delivery-locationId
String deliveryLocationId = shipmentConfig.getString("delivery.locationId");
if(deliveryLocationId != null){
builder.setDeliveryLocation(deliveryLocationId);
builder.setDeliveryLocationId(deliveryLocationId);
}

//delivery-coord
Expand All @@ -408,7 +412,7 @@ private void readShipments(XMLConfiguration config){
}
else{
// vrpBuilder.addLocation(deliveryCoord.toString(),deliveryCoord);
builder.setDeliveryLocation(deliveryCoord.toString());
builder.setDeliveryLocationId(deliveryCoord.toString());
}
}

Expand Down Expand Up @@ -479,6 +483,11 @@ private void readServices(XMLConfiguration vrpProblem) {
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,"");
Expand Down
26 changes: 19 additions & 7 deletions jsprit-core/src/main/java/jsprit/core/problem/io/VrpXMLWriter.java
Original file line number Diff line number Diff line change
@@ -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/>.
******************************************************************************/
Expand Down Expand Up @@ -237,6 +237,12 @@ private void writeServices(XMLConf xmlConfig, List<Job> jobs) {
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++;
}
}
Expand All @@ -249,7 +255,7 @@ private void writeShipments(XMLConf xmlConfig, List<Job> jobs) {
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());
Expand All @@ -260,7 +266,7 @@ private void writeShipments(XMLConf xmlConfig, List<Job> jobs) {
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());
Expand All @@ -279,6 +285,12 @@ private void writeShipments(XMLConf xmlConfig, List<Job> jobs) {
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++;
}
}
Expand Down
23 changes: 15 additions & 8 deletions jsprit-core/src/main/java/jsprit/core/problem/job/Job.java
Original file line number Diff line number Diff line change
@@ -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/>.
******************************************************************************/
Expand All @@ -32,17 +32,24 @@ 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.
*
* @return Capacity
*/
public Capacity getSize();

Skills getRequiredSkills();
public Skills getRequiredSkills();

/**
* Returns name.
*
* @return name
*/
public String getName();
}
35 changes: 27 additions & 8 deletions jsprit-core/src/main/java/jsprit/core/problem/job/Service.java
Original file line number Diff line number Diff line change
@@ -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/>.
******************************************************************************/
Expand All @@ -35,15 +35,19 @@
*/
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
Expand Down Expand Up @@ -73,6 +77,8 @@ public static Builder newInstance(String id){

protected Skills skills;

private String name = "no-name";

Builder(String id){
this.id = id;
}
Expand Down Expand Up @@ -178,6 +184,11 @@ public Builder addRequiredSkill(String skill) {
skillBuilder.addSkill(skill);
return this;
}

public Builder setName(String name) {
this.name = name;
return this;
}
}


Expand All @@ -197,6 +208,8 @@ public Builder addRequiredSkill(String skill) {

private final Skills skills;

private final String name;

Service(Builder builder){
id = builder.id;
locationId = builder.locationId;
Expand All @@ -206,6 +219,7 @@ public Builder addRequiredSkill(String skill) {
type = builder.type;
size = builder.capacity;
skills = builder.skills;
name = builder.name;
}

@Override
Expand Down Expand Up @@ -306,4 +320,9 @@ public Skills getRequiredSkills() {
return skills;
}

@Override
public String getName() {
return name;
}

}
Loading

0 comments on commit 9971d3d

Please sign in to comment.