Skip to content

Commit 29fbdd6

Browse files
authored
Merge pull request graphhopper#348 from balage1541/master
graphhopper#347 - Custom properties
2 parents b9da9b9 + c109fe6 commit 29fbdd6

16 files changed

+592
-272
lines changed

jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/AbstractJob.java

+13
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626
public abstract class AbstractJob implements Job {
2727

2828
private int index;
29+
private Object userData;
2930

31+
@Override
3032
public int getIndex() {
3133
return index;
3234
}
@@ -35,4 +37,15 @@ protected void setIndex(int index) {
3537
this.index = index;
3638
}
3739

40+
/**
41+
* @return User-specific domain data associated by the job
42+
*/
43+
public Object getUserData() {
44+
return userData;
45+
}
46+
47+
protected void setUserData(Object userData) {
48+
this.userData = userData;
49+
}
50+
3851
}

jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/AbstractVehicle.java

+29-12
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public abstract static class AbstractTypeKey implements HasIndex {
3030

3131
private int index;
3232

33+
@Override
3334
public int getIndex() {
3435
return index;
3536
}
@@ -44,19 +45,35 @@ public void setIndex(int index) {
4445

4546
private VehicleTypeKey vehicleIdentifier;
4647

47-
public int getIndex() {
48-
return index;
49-
}
48+
private Object userData;
5049

51-
protected void setIndex(int index) {
52-
this.index = index;
53-
}
50+
/**
51+
* @return User-specific domain data associated with the vehicle
52+
*/
53+
@Override
54+
public Object getUserData() {
55+
return userData;
56+
}
5457

55-
public VehicleTypeKey getVehicleTypeIdentifier() {
56-
return vehicleIdentifier;
57-
}
58+
protected void setUserData(Object userData) {
59+
this.userData = userData;
60+
}
5861

59-
protected void setVehicleIdentifier(VehicleTypeKey vehicleTypeIdentifier) {
60-
this.vehicleIdentifier = vehicleTypeIdentifier;
61-
}
62+
@Override
63+
public int getIndex() {
64+
return index;
65+
}
66+
67+
protected void setIndex(int index) {
68+
this.index = index;
69+
}
70+
71+
@Override
72+
public VehicleTypeKey getVehicleTypeIdentifier() {
73+
return vehicleIdentifier;
74+
}
75+
76+
protected void setVehicleIdentifier(VehicleTypeKey vehicleTypeIdentifier) {
77+
this.vehicleIdentifier = vehicleTypeIdentifier;
78+
}
6279
}

jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/Location.java

+30
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,30 @@ public static class Builder {
6666

6767
private String name = "";
6868

69+
private Object userData;
70+
6971
public static Builder newInstance() {
7072
return new Builder();
7173
}
7274

75+
/**
76+
* Sets user specific domain data associated with the object.
77+
*
78+
* <p>
79+
* The user data is a black box for the framework, it only stores it,
80+
* but never interacts with it in any way.
81+
* </p>
82+
*
83+
* @param userData
84+
* any object holding the domain specific user data
85+
* associated with the object.
86+
* @return builder
87+
*/
88+
public Builder setUserData(Object userData) {
89+
this.userData = userData;
90+
return this;
91+
}
92+
7393
/**
7494
* Sets location index
7595
*
@@ -140,13 +160,23 @@ public Location build() {
140160

141161
private final String name;
142162

163+
private Object userData;
164+
143165
private Location(Builder builder) {
166+
this.userData = builder.userData;
144167
this.index = builder.index;
145168
this.coordinate = builder.coordinate;
146169
this.id = builder.id;
147170
this.name = builder.name;
148171
}
149172

173+
/**
174+
* @return User-specific domain data associated by the job
175+
*/
176+
public Object getUserData() {
177+
return userData;
178+
}
179+
150180
@Override
151181
public String getId() {
152182
return id;

jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/job/Service.java

+35-14
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
*/
1818
package com.graphhopper.jsprit.core.problem.job;
1919

20+
import java.util.Collection;
21+
2022
import com.graphhopper.jsprit.core.problem.AbstractJob;
2123
import com.graphhopper.jsprit.core.problem.Capacity;
2224
import com.graphhopper.jsprit.core.problem.Location;
@@ -26,8 +28,6 @@
2628
import com.graphhopper.jsprit.core.problem.solution.route.activity.TimeWindowsImpl;
2729
import com.graphhopper.jsprit.core.util.Coordinate;
2830

29-
import java.util.Collection;
30-
3131
/**
3232
* Service implementation of a job.
3333
* <p>
@@ -86,15 +86,16 @@ public static Builder newInstance(String id) {
8686

8787
protected TimeWindowsImpl timeWindows;
8888

89-
private boolean twAdded = false;
89+
private boolean twAdded = false;
9090

9191
private int priority = 2;
92+
protected Object userData;
9293

93-
Builder(String id){
94-
this.id = id;
95-
timeWindows = new TimeWindowsImpl();
96-
timeWindows.add(timeWindow);
97-
}
94+
Builder(String id){
95+
this.id = id;
96+
timeWindows = new TimeWindowsImpl();
97+
timeWindows.add(timeWindow);
98+
}
9899

99100
/**
100101
* Protected method to set the type-name of the service.
@@ -137,6 +138,24 @@ public Builder<T> setServiceTime(double serviceTime) {
137138
return this;
138139
}
139140

141+
/**
142+
* Sets user specific domain data associated with the object.
143+
*
144+
* <p>
145+
* The user data is a black box for the framework, it only stores it,
146+
* but never interacts with it in any way.
147+
* </p>
148+
*
149+
* @param userData
150+
* any object holding the domain specific user data
151+
* associated with the object.
152+
* @return builder
153+
*/
154+
public Builder<T> setUserData(Object userData) {
155+
this.userData = userData;
156+
return this;
157+
}
158+
140159
/**
141160
* Adds capacity dimension.
142161
*
@@ -247,7 +266,8 @@ public Builder<T> setPriority(int priority) {
247266

248267
private final int priority;
249268

250-
Service(Builder builder) {
269+
Service(Builder<?> builder) {
270+
setUserData(builder.userData);
251271
id = builder.id;
252272
serviceTime = builder.serviceTime;
253273
timeWindow = builder.timeWindow;
@@ -256,13 +276,13 @@ public Builder<T> setPriority(int priority) {
256276
skills = builder.skills;
257277
name = builder.name;
258278
location = builder.location;
259-
timeWindowManager = builder.timeWindows;
279+
timeWindowManager = builder.timeWindows;
260280
priority = builder.priority;
261-
}
281+
}
262282

263-
public Collection<TimeWindow> getTimeWindows(){
264-
return timeWindowManager.getTimeWindows();
265-
}
283+
public Collection<TimeWindow> getTimeWindows(){
284+
return timeWindowManager.getTimeWindows();
285+
}
266286

267287
@Override
268288
public String getId() {
@@ -367,6 +387,7 @@ public String getName() {
367387
*
368388
* @return priority
369389
*/
390+
@Override
370391
public int getPriority() {
371392
return priority;
372393
}

jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/job/Shipment.java

+26-3
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@
1717
*/
1818
package com.graphhopper.jsprit.core.problem.job;
1919

20+
import java.util.Collection;
21+
2022
import com.graphhopper.jsprit.core.problem.AbstractJob;
2123
import com.graphhopper.jsprit.core.problem.Capacity;
2224
import com.graphhopper.jsprit.core.problem.Location;
2325
import com.graphhopper.jsprit.core.problem.Skills;
2426
import com.graphhopper.jsprit.core.problem.solution.route.activity.TimeWindow;
2527
import com.graphhopper.jsprit.core.problem.solution.route.activity.TimeWindowsImpl;
2628

27-
import java.util.Collection;
28-
2929

3030
/**
3131
* Shipment is an implementation of Job and consists of a pickup and a delivery of something.
@@ -89,6 +89,8 @@ public static class Builder {
8989

9090
private int priority = 2;
9191

92+
public Object userData;
93+
9294
/**
9395
* Returns new instance of this builder.
9496
*
@@ -108,10 +110,29 @@ public static Builder newInstance(String id) {
108110
deliveryTimeWindows.add(deliveryTimeWindow);
109111
}
110112

113+
/**
114+
* Sets user specific domain data associated with the object.
115+
*
116+
* <p>
117+
* The user data is a black box for the framework, it only stores it,
118+
* but never interacts with it in any way.
119+
* </p>
120+
*
121+
* @param userData
122+
* any object holding the domain specific user data
123+
* associated with the object.
124+
* @return builder
125+
*/
126+
public Builder setUserData(Object userData) {
127+
this.userData = userData;
128+
return this;
129+
}
130+
111131
/**
112132
* Sets pickup location.
113133
*
114-
* @param pickupLocation pickup location
134+
* @param pickupLocation
135+
* pickup location
115136
* @return builder
116137
*/
117138
public Builder setPickupLocation(Location pickupLocation) {
@@ -311,6 +332,7 @@ public Builder setPriority(int priority) {
311332
private final int priority;
312333

313334
Shipment(Builder builder) {
335+
setUserData(builder.userData);
314336
this.id = builder.id;
315337
this.pickupServiceTime = builder.pickupServiceTime;
316338
this.pickupTimeWindow = builder.pickupTimeWindow;
@@ -438,6 +460,7 @@ public String getName() {
438460
*
439461
* @return priority
440462
*/
463+
@Override
441464
public int getPriority() {
442465
return priority;
443466
}

jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/vehicle/Vehicle.java

+8
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@ public interface Vehicle extends HasId, HasIndex {
7272
public abstract VehicleTypeKey getVehicleTypeIdentifier();
7373

7474
public abstract Skills getSkills();
75+
/**
76+
* @return User-specific domain data associated with the vehicle
77+
*/
78+
public Object getUserData();
7579

7680
public abstract Break getBreak();
81+
// Switch to this as soon as we switct to Java 8:
82+
// default Object getUserData() {
83+
// return null;
84+
// };
7785
}

0 commit comments

Comments
 (0)