|
| 1 | +/* |
| 2 | + * To change this license header, choose License Headers in Project Properties. |
| 3 | + * To change this template file, choose Tools | Templates |
| 4 | + * and open the template in the editor. |
| 5 | + */ |
| 6 | +package com.route4me.sdk.examples.advancedconstraints; |
| 7 | + |
| 8 | +import com.route4me.sdk.exception.APIException; |
| 9 | +import com.route4me.sdk.services.routing.Address; |
| 10 | +import com.route4me.sdk.services.routing.AddressSource; |
| 11 | +import com.route4me.sdk.services.routing.Constants.AlgorithmType; |
| 12 | +import com.route4me.sdk.services.routing.Constants.DeviceType; |
| 13 | +import com.route4me.sdk.services.routing.Constants.DistanceUnit; |
| 14 | +import com.route4me.sdk.services.routing.Constants.OptimizationState; |
| 15 | +import com.route4me.sdk.services.routing.Constants.Optimize; |
| 16 | +import com.route4me.sdk.services.routing.Constants.TravelMode; |
| 17 | +import com.route4me.sdk.services.routing.DataObject; |
| 18 | +import com.route4me.sdk.services.routing.OptimizationParameters; |
| 19 | +import com.route4me.sdk.services.routing.Parameters; |
| 20 | +import com.route4me.sdk.services.routing.RoutingManager; |
| 21 | +import com.route4me.sdk.services.routing.SourceType; |
| 22 | +import com.route4me.sdk.services.routing.advancedconstraints.AdvancedConstraints; |
| 23 | +import java.util.ArrayList; |
| 24 | +import java.util.Arrays; |
| 25 | +import java.util.Iterator; |
| 26 | +import java.util.List; |
| 27 | + |
| 28 | + |
| 29 | +public class AdvancedConstraintsExample10 { |
| 30 | + |
| 31 | + public static void main(String[] args) { |
| 32 | + String apiKey = "11111111111111111111111111111111"; |
| 33 | + RoutingManager manager = new RoutingManager(apiKey); |
| 34 | + OptimizationParameters optParameters = new OptimizationParameters(); |
| 35 | + |
| 36 | + //********************************************************************** |
| 37 | + // TEST CASE: Retail Location |
| 38 | + //********************************************************************** |
| 39 | + |
| 40 | + |
| 41 | + Parameters parameters = new Parameters(); |
| 42 | + parameters.setAlgorithmType(AlgorithmType.ADVANCED_CVRP_TW.getValue()); |
| 43 | + parameters.setStoreRoute(Boolean.FALSE); |
| 44 | + parameters.setShareRoute(Boolean.FALSE); |
| 45 | + parameters.setRouteTime(0); |
| 46 | + parameters.setParts(20); |
| 47 | + parameters.setRouteMaxDuration(86400); |
| 48 | + parameters.setVehicleCapacity("100"); |
| 49 | + parameters.setVehicleMaxDistanceMi("10000"); |
| 50 | + parameters.setRouteName("Retail Location - Single Depot - Multiple Driver"); |
| 51 | + parameters.setOptimize(Optimize.DISTANCE.toString()); |
| 52 | + parameters.setDistanceUnit(DistanceUnit.MI.toString()); |
| 53 | + parameters.setDeviceType(DeviceType.WEB.toString()); |
| 54 | + parameters.setTravelMode(TravelMode.DRIVING.toString()); |
| 55 | + |
| 56 | + List<Address> addresses = new ArrayList<>(); |
| 57 | + // Depot |
| 58 | + addresses.add(new Address("1604 PARKRIDGE PKWY, Louisville, KY, 40214", true, 38.141598, -85.793846, 300)); |
| 59 | + // Stops |
| 60 | + Address address = new Address("1407 MCCOY, Louisville, KY, 40215", 38.202496, -85.786514, 300); |
| 61 | + addresses.add(address); |
| 62 | + address = new Address("4805 BELLEVUE AVE, Louisville, KY, 40215", 38.178844, -85.774864, 300); |
| 63 | + addresses.add(address); |
| 64 | + address = new Address("730 CECIL AVENUE, Louisville, KY, 40211", 38.248684, -85.821121, 300); |
| 65 | + addresses.add(address); |
| 66 | + address = new Address("650 SOUTH 29TH ST UNIT 315, Louisville, KY, 40211", 38.251923, -85.800034, 300); |
| 67 | + addresses.add(address); |
| 68 | + address = new Address("4629 HILLSIDE DRIVE, Louisville, KY, 40216", 38.176067, -85.824638, 300); |
| 69 | + addresses.add(address); |
| 70 | + address = new Address("4738 BELLEVUE AVE, Louisville, KY, 40215", 38.179806, -85.775558, 300); |
| 71 | + addresses.add(address); |
| 72 | + address = new Address("318 SO. 39TH STREET, Louisville, KY, 40212", 38.259335, -85.815094, 300); |
| 73 | + addresses.add(address); |
| 74 | + address = new Address("1324 BLUEGRASS AVE, Louisville, KY, 40215", 38.179253, -85.785118, 300); |
| 75 | + addresses.add(address); |
| 76 | + address = new Address("7305 ROYAL WOODS DR, Louisville, KY, 40214", 38.162472, -85.792854, 300); |
| 77 | + addresses.add(address); |
| 78 | + |
| 79 | + optParameters.setAddresses(addresses); |
| 80 | + |
| 81 | + // ADVANCED CONSTRAINT |
| 82 | + |
| 83 | + //Retail Location: "4738 BELLEVUE AVE, Louisville, KY, 40215" |
| 84 | + // Index 6 in the addresses list |
| 85 | + // We want that our Retail location is visited at the end of the route |
| 86 | + // So we use the special flag "" to indicate that before visiting retail location can be any stop. |
| 87 | + // We can have Different patternt that allow to have more than one retail location into the routes. |
| 88 | + AddressSource retailLocationSource = new AddressSource(6, SourceType.ADDRESSES); |
| 89 | + List <Object> locationsSequence = Arrays.asList("", retailLocationSource); |
| 90 | + |
| 91 | + |
| 92 | + // AdvancedConstraints 1 |
| 93 | + AdvancedConstraints advancedConstraint1 = new AdvancedConstraints(); |
| 94 | + advancedConstraint1.setMaxCapacity(200); |
| 95 | + advancedConstraint1.setMembersCount(10); |
| 96 | + List<List<Integer>> timeWindows1 = new ArrayList<>(); |
| 97 | + List<Integer> timeWindow1 = Arrays.asList(25200, 75000); |
| 98 | + timeWindows1.add(timeWindow1); |
| 99 | + advancedConstraint1.setAvailableTimeWindows(timeWindows1); |
| 100 | + advancedConstraint1.setLocationSequencePattern(locationsSequence); |
| 101 | + |
| 102 | + // AdvancedConstraints 2 |
| 103 | + AdvancedConstraints advancedConstraint2 = new AdvancedConstraints(); |
| 104 | + advancedConstraint2.setMaxCapacity(200); |
| 105 | + advancedConstraint2.setMembersCount(10); |
| 106 | + List<List<Integer>> timeWindows2 = new ArrayList<>(); |
| 107 | + List<Integer> timeWindow2 = Arrays.asList(45200, 95000); |
| 108 | + timeWindows2.add(timeWindow2); |
| 109 | + advancedConstraint2.setAvailableTimeWindows(timeWindows2); |
| 110 | + advancedConstraint2.setLocationSequencePattern(locationsSequence); |
| 111 | + |
| 112 | + |
| 113 | + List<AdvancedConstraints> advancedConstraints = Arrays.asList(advancedConstraint1, advancedConstraint2); |
| 114 | + |
| 115 | + parameters.setAdvancedConstraints(advancedConstraints); |
| 116 | + |
| 117 | + optParameters.setParameters(parameters); |
| 118 | + |
| 119 | + |
| 120 | + |
| 121 | + |
| 122 | + |
| 123 | + try { |
| 124 | + DataObject responseObject = manager.runOptimization(optParameters); |
| 125 | + System.out.println("Optimization Problem ID:" + responseObject.getOptimizationProblemId()); |
| 126 | + System.out.println("State:" + OptimizationState.get(responseObject.getState().intValue())); |
| 127 | + if (responseObject.getAddresses() != null) { |
| 128 | + for (Iterator<Address> it = responseObject.getAddresses().iterator(); it.hasNext();) { |
| 129 | + address = it.next(); |
| 130 | + System.out.println(address); |
| 131 | + } |
| 132 | + } |
| 133 | + } catch (APIException e) { |
| 134 | + //handle exception |
| 135 | + e.printStackTrace(); |
| 136 | + } |
| 137 | + } |
| 138 | + |
| 139 | + |
| 140 | + |
| 141 | +} |
0 commit comments