Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c310660

Browse files
committedFeb 26, 2022
Added Balanced Routes Feature and example. Added missing parameter use_mixed_pickup_delivery_demands and new Pickup Dropoff Example
1 parent 57c4a06 commit c310660

File tree

7 files changed

+370
-4
lines changed

7 files changed

+370
-4
lines changed
 

‎pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>io.github.route4me</groupId>
66
<artifactId>route4me-java-sdk</artifactId>
7-
<version>1.6.9</version>
7+
<version>1.7.0</version>
88
<packaging>jar</packaging>
99
<properties>
1010
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
// codebeat:disable[SIMILARITY]
2+
package com.route4me.sdk.examples.balance;
3+
4+
import com.route4me.sdk.exception.APIException;
5+
import com.route4me.sdk.services.routing.Constants.*;
6+
import com.route4me.sdk.services.routing.*;
7+
import com.route4me.sdk.services.routing.balance.Balance;
8+
import com.route4me.sdk.services.routing.balance.BalanceMode;
9+
10+
import java.util.ArrayList;
11+
import java.util.List;
12+
13+
/**
14+
* @author route4me
15+
*/
16+
public class BalancedRoute {
17+
18+
public static void main(String[] args) {
19+
String apiKey = "11111111111111111111111111111111";
20+
RoutingManager manager = new RoutingManager(apiKey);
21+
OptimizationParameters optParameters = new OptimizationParameters();
22+
23+
Parameters parameters = new Parameters();
24+
parameters.setAlgorithmType(AlgorithmType.CVRP_TW_SD.getValue());
25+
parameters.setStoreRoute(Boolean.FALSE);
26+
parameters.setShareRoute(Boolean.FALSE);
27+
parameters.setRouteTime(0);
28+
parameters.setParts(3);
29+
parameters.setBalance(new Balance(BalanceMode.DESTINATIONS_COUNT.toString()));
30+
parameters.setRouteMaxDuration(86400);
31+
parameters.setVehicleCapacity("9999");
32+
parameters.setRouteName("Balanced Drivers");
33+
parameters.setOptimize(Optimize.DISTANCE.toString());
34+
parameters.setDistanceUnit(DistanceUnit.MI.toString());
35+
parameters.setDeviceType(DeviceType.WEB.toString());
36+
parameters.setTravelMode(TravelMode.DRIVING.toString());
37+
optParameters.setParameters(parameters);
38+
39+
List<Address> addresses = new ArrayList<>();
40+
addresses.add(new Address("455 S 4th St, Louisville, KY 40202", true, 38.251698, -85.757308, 300, 28800, 29400));
41+
addresses.add(new Address("1604 PARKRIDGE PKWY, Louisville, KY, 40214", 38.141598, -85.793846, 300, 29400, 30000));
42+
addresses.add(new Address("1407 MCCOY, Louisville, KY, 40215", 38.202496, -85.786514, 300, 30000, 30600));
43+
addresses.add(new Address("4805 BELLEVUE AVE, Louisville, KY, 40215", 38.178844, -85.774864, 300, 30600, 31200));
44+
addresses.add(new Address("730 CECIL AVENUE, Louisville, KY, 40211", 38.248684, -85.821121, 300, 31200, 31800));
45+
addresses.add(new Address("650 SOUTH 29TH ST UNIT 315, Louisville, KY, 40211", 38.251923, -85.800034, 300, 31800, 32400));
46+
addresses.add(new Address("4629 HILLSIDE DRIVE, Louisville, KY, 40216", 38.176067, -85.824638, 300, 32400, 33000));
47+
addresses.add(new Address("4738 BELLEVUE AVE, Louisville, KY, 40215", 38.179806, -85.775558, 300, 33000, 33600));
48+
addresses.add(new Address("318 SO. 39TH STREET, Louisville, KY, 40212", 38.259335, -85.815094, 300, 33600, 34200));
49+
addresses.add(new Address("1324 BLUEGRASS AVE, Louisville, KY, 40215", 38.179253, -85.785118, 300, 34200, 34800));
50+
addresses.add(new Address("7305 ROYAL WOODS DR, Louisville, KY, 40214", 38.162472, -85.792854, 300, 34800, 35400));
51+
addresses.add(new Address("1661 W HILL ST, Louisville, KY, 40210", 38.229584, -85.783966, 300, 35400, 36000));
52+
addresses.add(new Address("3222 KINGSWOOD WAY, Louisville, KY, 40216", 38.210606, -85.822594, 300, 36000, 36600));
53+
addresses.add(new Address("1922 PALATKA RD, Louisville, KY, 40214", 38.153767, -85.796783, 300, 36600, 37200));
54+
addresses.add(new Address("1314 SOUTH 26TH STREET, Louisville, KY, 40210", 38.235847, -85.796852, 300, 37200, 37800));
55+
addresses.add(new Address("2135 MCCLOSKEY AVENUE, Louisville, KY, 40210", 38.218662, -85.789032, 300, 37800, 38400));
56+
addresses.add(new Address("1409 PHYLLIS AVE, Louisville, KY, 40215", 38.206154, -85.781387, 300, 38400, 39000));
57+
addresses.add(new Address("4504 SUNFLOWER AVE, Louisville, KY, 40216", 38.187511, -85.839149, 300, 39000, 39600));
58+
addresses.add(new Address("2512 GREENWOOD AVE, Louisville, KY, 40210", 38.241405, -85.795059, 300, 39600, 40200));
59+
addresses.add(new Address("5500 WILKE FARM AVE, Louisville, KY, 40216", 38.166065, -85.863319, 300, 40200, 40800));
60+
addresses.add(new Address("3640 LENTZ AVE, Louisville, KY, 40215", 38.193283, -85.786201, 300, 40800, 41400));
61+
addresses.add(new Address("1020 BLUEGRASS AVE, Louisville, KY, 40215", 38.17952, -85.780037, 300, 41400, 42000));
62+
addresses.add(new Address("123 NORTH 40TH ST, Louisville, KY, 40212", 38.26498, -85.814156, 300, 42000, 42600));
63+
addresses.add(new Address("7315 ST ANDREWS WOODS CIRCLE UNIT 104, Louisville, KY, 40214", 38.151072, -85.802867, 300, 42600, 43200));
64+
addresses.add(new Address("3210 POPLAR VIEW DR, Louisville, KY, 40216", 38.182594, -85.849937, 300, 43200, 43800));
65+
addresses.add(new Address("4519 LOUANE WAY, Louisville, KY, 40216", 38.1754, -85.811447, 300, 43800, 44400));
66+
addresses.add(new Address("6812 MANSLICK RD, Louisville, KY, 40214", 38.161839, -85.798279, 300, 44400, 45000));
67+
addresses.add(new Address("1524 HUNTOON AVENUE, Louisville, KY, 40215", 38.172031, -85.788353, 300, 45000, 45600));
68+
addresses.add(new Address("1307 LARCHMONT AVE, Louisville, KY, 40215", 38.209663, -85.779816, 300, 45600, 46200));
69+
addresses.add(new Address("434 N 26TH STREET #2, Louisville, KY, 40212", 38.26844, -85.791962, 300, 46200, 46800));
70+
addresses.add(new Address("678 WESTLAWN ST, Louisville, KY, 40211", 38.250397, -85.80629, 300, 46800, 47400));
71+
addresses.add(new Address("2308 W BROADWAY, Louisville, KY, 40211", 38.248882, -85.790421, 300, 47400, 48000));
72+
addresses.add(new Address("2332 WOODLAND AVE, Louisville, KY, 40210", 38.233579, -85.794257, 300, 48000, 48600));
73+
addresses.add(new Address("1706 WEST ST. CATHERINE, Louisville, KY, 40210", 38.239697, -85.783928, 300, 48600, 49200));
74+
addresses.add(new Address("1699 WATHEN LN, Louisville, KY, 40216", 38.216465, -85.792397, 300, 49200, 49800));
75+
addresses.add(new Address("2416 SUNSHINE WAY, Louisville, KY, 40216", 38.186245, -85.831787, 300, 49800, 50400));
76+
addresses.add(new Address("6925 MANSLICK RD, Louisville, KY, 40214", 38.158466, -85.798355, 300, 50400, 51000));
77+
addresses.add(new Address("2707 7TH ST, Louisville, KY, 40215", 38.212438, -85.785082, 300, 51000, 51600));
78+
addresses.add(new Address("2014 KENDALL LN, Louisville, KY, 40216", 38.179394, -85.826668, 300, 51600, 52200));
79+
addresses.add(new Address("612 N 39TH ST, Louisville, KY, 40212", 38.273354, -85.812012, 300, 52200, 52800));
80+
addresses.add(new Address("2215 ROWAN ST, Louisville, KY, 40212", 38.261703, -85.786781, 300, 52800, 53400));
81+
addresses.add(new Address("1826 W. KENTUCKY ST, Louisville, KY, 40210", 38.241611, -85.78653, 300, 53400, 54000));
82+
addresses.add(new Address("1810 GREGG AVE, Louisville, KY, 40210", 38.224716, -85.796211, 300, 54000, 54600));
83+
addresses.add(new Address("4103 BURRRELL DRIVE, Louisville, KY, 40216", 38.191753, -85.825836, 300, 54600, 55200));
84+
addresses.add(new Address("359 SOUTHWESTERN PKWY, Louisville, KY, 40212", 38.259903, -85.823463, 300, 55200, 55800));
85+
addresses.add(new Address("2407 W CHESTNUT ST, Louisville, KY, 40211", 38.252781, -85.792109, 300, 55800, 56400));
86+
addresses.add(new Address("225 S 22ND ST, Louisville, KY, 40212", 38.257616, -85.786658, 300, 56400, 57000));
87+
addresses.add(new Address("1404 MCCOY AVE, Louisville, KY, 40215", 38.202122, -85.786072, 300, 57000, 57600));
88+
addresses.add(new Address("117 FOUNT LANDING CT, Louisville, KY, 40212", 38.270061, -85.799438, 300, 57600, 58200));
89+
addresses.add(new Address("5504 SHOREWOOD DRIVE, Louisville, KY, 40214", 38.145851, -85.7798, 300, 58200, 58800));
90+
optParameters.setAddresses(addresses);
91+
92+
try {
93+
DataObject responseObject = manager.runOptimization(optParameters);
94+
System.out.println("Optimization Problem ID:" + responseObject.getOptimizationProblemId());
95+
System.out.println("State:" + OptimizationState.get(responseObject.getState().intValue()));
96+
if (responseObject.getAddresses() != null) {
97+
for (Address address : responseObject.getAddresses()) {
98+
System.out.println(address);
99+
}
100+
}
101+
} catch (APIException e) {
102+
//handle exception
103+
e.printStackTrace();
104+
}
105+
}
106+
}
107+
// codebeat:enable[SIMILARITY]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
// codebeat:disable[SIMILARITY]
2+
package com.route4me.sdk.examples.pickupdropoff;
3+
4+
import com.route4me.sdk.exception.APIException;
5+
import com.route4me.sdk.services.routing.Address;
6+
import com.route4me.sdk.services.routing.Constants.*;
7+
import com.route4me.sdk.services.routing.DataObject;
8+
import com.route4me.sdk.services.routing.OptimizationParameters;
9+
import com.route4me.sdk.services.routing.Parameters;
10+
import com.route4me.sdk.services.routing.RoutingManager;
11+
12+
import java.util.ArrayList;
13+
import java.util.List;
14+
15+
/**
16+
* @author route4me
17+
*/
18+
public class PickupDropoffPriority {
19+
20+
public static void main(String[] args) {
21+
String apiKey = "11111111111111111111111111111111";
22+
RoutingManager manager = new RoutingManager(apiKey, false);
23+
OptimizationParameters optParameters = new OptimizationParameters();
24+
25+
Parameters parameters = new Parameters();
26+
parameters.setAlgorithmType(AlgorithmType.CVRP_TW_SD.getValue());
27+
parameters.setStoreRoute(Boolean.FALSE);
28+
parameters.setShareRoute(Boolean.FALSE);
29+
parameters.setRouteTime((8 + 5) * 3600); // 8:00 am East Time
30+
parameters.setParts(99);
31+
parameters.setLeftTurn(LeftTurn.LEFTTURN_FORBID.getValue());
32+
parameters.setUTurn(UTurn.UTURN_DEPART_TO_RIGHT.getValue());
33+
parameters.setVehicleCapacity("4");
34+
parameters.isUseMixedPickupDeliveryDemands(false);
35+
parameters.setRouteName("Pickup Dropoff Example");
36+
parameters.setOptimize(Optimize.TIME.toString());
37+
parameters.setDistanceUnit(DistanceUnit.MI.toString());
38+
parameters.setTravelMode(TravelMode.DRIVING.toString());
39+
optParameters.setParameters(parameters);
40+
41+
List<Address> addresses = new ArrayList<>();
42+
// Depot
43+
Address depotAddress = new Address("455 S 4th St, Louisville, KY 40202", true, "DEPOT", 38.251698, -85.757308, 0);
44+
addresses.add(depotAddress);
45+
46+
// Pickups
47+
48+
Address pickupAddress;
49+
50+
pickupAddress = new Address("1604 PARKRIDGE PKWY, Louisville, KY, 40214", "STORAGE FACILITY", 38.141598, -85.793846, 840 * 7);
51+
pickupAddress.setPickUp("PDA001");
52+
pickupAddress.setAddressStopType(AddressStopType.PICKUP.toString());
53+
pickupAddress.setPriority(1);
54+
pickupAddress.setPieces(1);
55+
pickupAddress.addCustomField("GOOD_TYPE", "TYPE0001");
56+
addresses.add(pickupAddress);
57+
pickupAddress = new Address("1604 PARKRIDGE PKWY, Louisville, KY, 40214", "STORAGE FACILITY", 38.141598, -85.793846, 0);
58+
pickupAddress.setPickUp("PDA002");
59+
pickupAddress.setAddressStopType(AddressStopType.PICKUP.toString());
60+
pickupAddress.setPriority(1);
61+
pickupAddress.setPieces(1);
62+
pickupAddress.addCustomField("GOOD_TYPE", "TYPE0002");
63+
addresses.add(pickupAddress);
64+
pickupAddress = new Address("1604 PARKRIDGE PKWY, Louisville, KY, 40214", "STORAGE FACILITY", 38.141598, -85.793846, 0);
65+
pickupAddress.setPickUp("PDA003");
66+
pickupAddress.setAddressStopType(AddressStopType.PICKUP.toString());
67+
pickupAddress.setPriority(1);
68+
pickupAddress.setPieces(1);
69+
pickupAddress.addCustomField("GOOD_TYPE", "TYPE0003");
70+
addresses.add(pickupAddress);
71+
pickupAddress = new Address("1604 PARKRIDGE PKWY, Louisville, KY, 40214", "STORAGE FACILITY", 38.141598, -85.793846, 0);
72+
pickupAddress.setPickUp("PDA004");
73+
pickupAddress.setAddressStopType(AddressStopType.PICKUP.toString());
74+
pickupAddress.setPriority(1);
75+
pickupAddress.setPieces(1);
76+
pickupAddress.addCustomField("GOOD_TYPE", "TYPE0004");
77+
addresses.add(pickupAddress);
78+
pickupAddress = new Address("1604 PARKRIDGE PKWY, Louisville, KY, 40214", "STORAGE FACILITY", 38.141598, -85.793846, 0);
79+
pickupAddress.setPickUp("PDA005");
80+
pickupAddress.setAddressStopType(AddressStopType.PICKUP.toString());
81+
pickupAddress.setPriority(1);
82+
pickupAddress.setPieces(1);
83+
pickupAddress.addCustomField("GOOD_TYPE", "TYPE0005");
84+
addresses.add(pickupAddress);
85+
pickupAddress = new Address("1604 PARKRIDGE PKWY, Louisville, KY, 40214", "STORAGE FACILITY", 38.141598, -85.793846, 0);
86+
pickupAddress.setPickUp("PDA006");
87+
pickupAddress.setAddressStopType(AddressStopType.PICKUP.toString());
88+
pickupAddress.setPriority(1);
89+
pickupAddress.setPieces(1);
90+
pickupAddress.addCustomField("GOOD_TYPE", "TYPE0006");
91+
addresses.add(pickupAddress);
92+
pickupAddress = new Address("1604 PARKRIDGE PKWY, Louisville, KY, 40214", "STORAGE FACILITY", 38.141598, -85.793846, 0);
93+
pickupAddress.setPickUp("PDA007");
94+
pickupAddress.setAddressStopType(AddressStopType.PICKUP.toString());
95+
pickupAddress.setPriority(1);
96+
pickupAddress.setPieces(1);
97+
pickupAddress.addCustomField("GOOD_TYPE", "TYPE0007");
98+
addresses.add(pickupAddress);
99+
100+
101+
//Dropoffs
102+
Address dropoffAddress;
103+
dropoffAddress = new Address("1407 MCCOY, Louisville, KY, 40215", "Customer 001", 38.202496, -85.786514, 840);
104+
dropoffAddress.setDropOff("PDA001");
105+
dropoffAddress.setAddressStopType(AddressStopType.DELIVERY.toString());
106+
dropoffAddress.setPieces(1);
107+
dropoffAddress.addCustomField("GOOD_TYPE", "TYPE0001");
108+
addresses.add(dropoffAddress);
109+
dropoffAddress = new Address("4805 BELLEVUE AVE, Louisville, KY, 40215", "Customer 002", 38.178844, -85.774864, 840);
110+
dropoffAddress.setDropOff("PDA002");
111+
dropoffAddress.setAddressStopType(AddressStopType.DELIVERY.toString());
112+
dropoffAddress.setPieces(1);
113+
dropoffAddress.addCustomField("GOOD_TYPE", "TYPE0002");
114+
addresses.add(dropoffAddress);
115+
dropoffAddress = new Address("730 CECIL AVENUE, Louisville, KY, 40211", "Customer 003", 38.248684, -85.821121, 840);
116+
dropoffAddress.setDropOff("PDA003");
117+
dropoffAddress.setAddressStopType(AddressStopType.DELIVERY.toString());
118+
dropoffAddress.setPieces(1);
119+
dropoffAddress.addCustomField("GOOD_TYPE", "TYPE0003");
120+
addresses.add(dropoffAddress);
121+
dropoffAddress = new Address("650 SOUTH 29TH ST UNIT 315, Louisville, KY, 40211", "Customer 004", 38.251923, -85.800034, 840);
122+
dropoffAddress.setDropOff("PDA004");
123+
dropoffAddress.setAddressStopType(AddressStopType.DELIVERY.toString());
124+
dropoffAddress.setPieces(1);
125+
dropoffAddress.addCustomField("GOOD_TYPE", "TYPE0004");
126+
addresses.add(dropoffAddress);
127+
dropoffAddress = new Address("4629 HILLSIDE DRIVE, Louisville, KY, 40216", "Customer 005", 38.176067, -85.824638, 840);
128+
dropoffAddress.setDropOff("PDA005");
129+
dropoffAddress.setAddressStopType(AddressStopType.DELIVERY.toString());
130+
dropoffAddress.addCustomField("GOOD_TYPE", "TYPE0005");
131+
dropoffAddress.setPieces(1);
132+
addresses.add(dropoffAddress);
133+
dropoffAddress = new Address("4738 BELLEVUE AVE, Louisville, KY, 40215", "Customer 006", 38.179806, -85.775558, 840);
134+
dropoffAddress.setDropOff("PDA006");
135+
dropoffAddress.setAddressStopType(AddressStopType.DELIVERY.toString());
136+
dropoffAddress.setPieces(1);
137+
dropoffAddress.addCustomField("GOOD_TYPE", "TYPE0006");
138+
addresses.add(dropoffAddress);
139+
dropoffAddress = new Address("318 SO. 39TH STREET, Louisville, KY, 40212", "Customer 007", 38.259335, -85.815094, 840);
140+
dropoffAddress.setDropOff("PDA007");
141+
dropoffAddress.setAddressStopType(AddressStopType.DELIVERY.toString());
142+
dropoffAddress.setPieces(1);
143+
dropoffAddress.addCustomField("GOOD_TYPE", "TYPE0007");
144+
addresses.add(dropoffAddress);
145+
optParameters.setAddresses(addresses);
146+
147+
try {
148+
DataObject responseObject = manager.runOptimization(optParameters);
149+
System.out.println("Optimization Problem ID:" + responseObject.getOptimizationProblemId());
150+
System.out.println("State:" + OptimizationState.get(responseObject.getState().intValue()));
151+
} catch (APIException e) {
152+
//handle exception
153+
e.printStackTrace();
154+
}
155+
}
156+
}
157+
// codebeat:enable[SIMILARITY]

‎src/main/java/com/route4me/sdk/services/routing/Address.java

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.google.gson.annotations.SerializedName;
55
import com.route4me.sdk.queryconverter.QueryParameter;
66
import com.route4me.sdk.services.notes.Note;
7+
import java.util.HashMap;
78
import java.util.List;
89
import java.util.Map;
910
import lombok.Data;
@@ -217,6 +218,9 @@ public Address(String address, String alias, double lat, double lng, long time)
217218
}
218219

219220
public void addCustomField(String key, Object value) {
221+
if (this.custom_fields == null) {
222+
this.custom_fields = new HashMap<>();
223+
}
220224
this.custom_fields.put(key, value);
221225
}
222226
}

‎src/main/java/com/route4me/sdk/services/routing/Parameters.java

+12-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.google.gson.annotations.SerializedName;
44
import com.route4me.sdk.queryconverter.QueryParameter;
55
import com.route4me.sdk.services.routing.advancedconstraints.AdvancedConstraints;
6+
import com.route4me.sdk.services.routing.balance.Balance;
67
import java.util.List;
78
import lombok.Data;
89

@@ -69,6 +70,8 @@ public class Parameters {
6970
private Boolean hasTrailer;
7071
@SerializedName("parts")
7172
private Number parts;
73+
@SerializedName("parts_min")
74+
private Number partsMin;
7275
@SerializedName("trailer_weight_t")
7376
private Number trailerWeightT;
7477
@SerializedName("limited_weight_t")
@@ -111,9 +114,15 @@ public class Parameters {
111114
private Boolean isDynamicStartTime;
112115
@SerializedName("depots")
113116
private List<Object> depots;
114-
115-
117+
@QueryParameter("use_mixed_pickup_delivery_demands")
118+
@SerializedName("use_mixed_pickup_delivery_demands")
119+
private boolean useMixedPickupDeliveryDemands;
120+
@QueryParameter("balance")
121+
@SerializedName("balance")
122+
private Balance balance;
116123

124+
public void isUseMixedPickupDeliveryDemands(boolean useMixedPickupDeliveryDemands) {
125+
this.useMixedPickupDeliveryDemands = useMixedPickupDeliveryDemands;
126+
}
117127

118-
119128
}
There was a problem loading the remainder of the diff.

0 commit comments

Comments
 (0)
Please sign in to comment.