|
| 1 | +/* |
| 2 | + * The MIT License |
| 3 | + * |
| 4 | + * Copyright 2022 Route4Me. |
| 5 | + * |
| 6 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | + * of this software and associated documentation files (the "Software"), to deal |
| 8 | + * in the Software without restriction, including without limitation the rights |
| 9 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | + * copies of the Software, and to permit persons to whom the Software is |
| 11 | + * furnished to do so, subject to the following conditions: |
| 12 | + * |
| 13 | + * The above copyright notice and this permission notice shall be included in |
| 14 | + * all copies or substantial portions of the Software. |
| 15 | + * |
| 16 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 22 | + * THE SOFTWARE. |
| 23 | + */ |
| 24 | +package com.route4me.sdk.examples.bundling; |
| 25 | + |
| 26 | +import com.route4me.sdk.exception.APIException; |
| 27 | +import com.route4me.sdk.services.routing.Address; |
| 28 | +import com.route4me.sdk.services.routing.Bundling; |
| 29 | +import com.route4me.sdk.services.routing.BundlingEnum; |
| 30 | +import com.route4me.sdk.services.routing.Constants; |
| 31 | +import com.route4me.sdk.services.routing.DataObject; |
| 32 | +import com.route4me.sdk.services.routing.OptimizationParameters; |
| 33 | +import com.route4me.sdk.services.routing.Parameters; |
| 34 | +import com.route4me.sdk.services.routing.RoutingManager; |
| 35 | +import com.route4me.sdk.services.routing.ServiceTimeRules; |
| 36 | +import java.util.ArrayList; |
| 37 | +import java.util.Arrays; |
| 38 | +import java.util.List; |
| 39 | + |
| 40 | +/** |
| 41 | + * |
| 42 | + * @author route4me |
| 43 | + */ |
| 44 | +public class BundlingByAddressAndProrityConstraint { |
| 45 | + |
| 46 | + public static void main(String[] args) { |
| 47 | + String apiKey = System.getenv("R4M_API_KEY"); |
| 48 | + RoutingManager manager = new RoutingManager(apiKey, true); |
| 49 | + OptimizationParameters optParameters = new OptimizationParameters(); |
| 50 | + |
| 51 | + Parameters parameters = new Parameters(); |
| 52 | + parameters.setAlgorithmType(Constants.AlgorithmType.CVRP_TW_SD.getValue()); |
| 53 | + parameters.setStoreRoute(Boolean.FALSE); |
| 54 | + parameters.setShareRoute(Boolean.FALSE); |
| 55 | + parameters.setRouteName("Single Depot, Multiple Driver, Bundling by Address and having Priority Constraint"); |
| 56 | + parameters.setTravelMode(Constants.TravelMode.DRIVING.toString()); |
| 57 | + |
| 58 | + List<Address> addresses = new ArrayList<>(); |
| 59 | + // DEPOT |
| 60 | + addresses.add(new Address("1604 PARKRIDGE PKWY, Louisville, KY, 40214", true, 38.141598, -85.793846, 300)); |
| 61 | + |
| 62 | + // Addresses |
| 63 | + addresses.add(new Address("1407 MCCOY, Louisville, KY, 40215", 38.202496, -85.786514, 300)); |
| 64 | + addresses.add(new Address("730 CECIL AVENUE, Louisville, KY, 40211", 38.248684, -85.821121, 300)); |
| 65 | + addresses.add(new Address("650 SOUTH 29TH ST UNIT 315, Louisville, KY, 40211", 38.251923, -85.800034, 300)); |
| 66 | + addresses.add(new Address("4629 HILLSIDE DRIVE, Louisville, KY, 40216", 38.176067, -85.824638, 300)); |
| 67 | + |
| 68 | + // Bundling Addresses |
| 69 | + Address address; |
| 70 | + |
| 71 | + address = new Address("318 SO. 39TH STREET, Louisville, KY, 40212", 38.259335, -85.815094, 300); |
| 72 | + address.setPriority(1); |
| 73 | + addresses.add(address); |
| 74 | + address = new Address("318 SO. 39TH STREET, Louisville, KY, 40212", 38.259335, -85.815094, 300); |
| 75 | + address.setPriority(2); |
| 76 | + addresses.add(address); |
| 77 | + |
| 78 | + address = new Address("4629 HILLSIDE DRIVE, Louisville, KY, 40216", 38.176067, -85.824638, 300); |
| 79 | + address.setPriority(2); |
| 80 | + addresses.add(address); |
| 81 | + address = new Address("4629 HILLSIDE DRIVE, Louisville, KY, 40216", 38.176067, -85.824638, 300); |
| 82 | + address.setPriority(3); |
| 83 | + addresses.add(address); |
| 84 | + |
| 85 | + |
| 86 | + |
| 87 | + address = new Address("4738 BELLEVUE AVE, Louisville, KY, 40215", 38.179806, -85.775558, 300); |
| 88 | + address.setPriority(3); |
| 89 | + addresses.add(address); |
| 90 | + address = new Address("4738 BELLEVUE AVE, Louisville, KY, 40215", 38.179806, -85.775558, 300); |
| 91 | + address.setPriority(4); |
| 92 | + addresses.add(address); |
| 93 | + address = new Address("4738 BELLEVUE AVE, Louisville, KY, 40215", 38.179806, -85.775558, 300); |
| 94 | + address.setPriority(5); |
| 95 | + addresses.add(address); |
| 96 | + address = new Address("4738 BELLEVUE AVE, Louisville, KY, 40215", 38.179806, -85.775558, 300); |
| 97 | + address.setPriority(6); |
| 98 | + |
| 99 | + |
| 100 | + address = new Address("1324 BLUEGRASS AVE, Louisville, KY, 40215", 38.179253, -85.785118, 300); |
| 101 | + address.setPriority(4); |
| 102 | + addresses.add(address); |
| 103 | + address = new Address("1324 BLUEGRASS AVE, Louisville, KY, 40215", 38.179253, -85.785118, 300); |
| 104 | + address.setPriority(5); |
| 105 | + addresses.add(address); |
| 106 | + address = new Address("1324 BLUEGRASS AVE, Louisville, KY, 40215", 38.179253, -85.785118, 300); |
| 107 | + address.setPriority(6); |
| 108 | + addresses.add(address); |
| 109 | + address = new Address("1324 BLUEGRASS AVE, Louisville, KY, 40215", 38.179253, -85.785118, 300); |
| 110 | + address.setPriority(7); |
| 111 | + addresses.add(address); |
| 112 | + address = new Address("1324 BLUEGRASS AVE, Louisville, KY, 40215", 38.179253, -85.785118, 300); |
| 113 | + address.setPriority(8); |
| 114 | + addresses.add(address); |
| 115 | + address = new Address("1324 BLUEGRASS AVE, Louisville, KY, 40215", 38.179253, -85.785118, 300); |
| 116 | + address.setPriority(9); |
| 117 | + addresses.add(address); |
| 118 | + |
| 119 | + address = new Address("4805 BELLEVUE AVE, Louisville, KY, 40215", 38.162472, -85.792854, 300); |
| 120 | + address.setPriority(5); |
| 121 | + addresses.add(address); |
| 122 | + address = new Address("4805 BELLEVUE AVE, Louisville, KY, 40215", 38.162472, -85.792854, 300); |
| 123 | + address.setPriority(6); |
| 124 | + addresses.add(address); |
| 125 | + address = new Address("4805 BELLEVUE AVE, Louisville, KY, 40215", 38.162472, -85.792854, 300); |
| 126 | + address.setPriority(7); |
| 127 | + addresses.add(address); |
| 128 | + address = new Address("4805 BELLEVUE AVE, Louisville, KY, 40215", 38.162472, -85.792854, 300); |
| 129 | + address.setPriority(8); |
| 130 | + addresses.add(address); |
| 131 | + |
| 132 | + optParameters.setAddresses(addresses); |
| 133 | + |
| 134 | + Bundling bundling = new Bundling(); |
| 135 | + |
| 136 | + bundling.setMergeMode(BundlingEnum.BundledItemsMode.KEEP_AS_SEPARATE_DESTINATIONS.getValue()); |
| 137 | + |
| 138 | + bundling.setMode(BundlingEnum.BundlingMode.BUNDLING_BY_ADDRESS.getValue()); |
| 139 | + List<String> modeParams = Arrays.asList("custom_fields.BUNDLING_KEY", "custom_fields.LOCATION_ID"); |
| 140 | + bundling.setModeParams(modeParams); |
| 141 | + ServiceTimeRules serviceTimeRules = new ServiceTimeRules(); |
| 142 | + serviceTimeRules.setFirstItemMode(BundlingEnum.BundlingFirstItemMode.USE_CUSTOM_SERVICE_TIME.getValue()); |
| 143 | + serviceTimeRules.setAdditionalItemsMode(BundlingEnum.BundlingAdditionalItemMode.USE_CUSTOM_SERVICE_TIME_FOR_ADDITIONAL_ITEM.getValue()); |
| 144 | + ArrayList<Integer> firstItemModeParams = new ArrayList(); |
| 145 | + firstItemModeParams.add(900); |
| 146 | + ArrayList<Integer> additionalItemModeParams = new ArrayList(); |
| 147 | + additionalItemModeParams.add(200); |
| 148 | + serviceTimeRules.setFirstItemModeParams(firstItemModeParams); |
| 149 | + serviceTimeRules.setAdditionalItemsModeParams(additionalItemModeParams); |
| 150 | + bundling.setServiceTimeRules(serviceTimeRules); |
| 151 | + parameters.setBundling(bundling); |
| 152 | + |
| 153 | + optParameters.setParameters(parameters); |
| 154 | + |
| 155 | + try { |
| 156 | + DataObject responseObject = manager.runOptimization(optParameters); |
| 157 | + System.out.println("Optimization Problem ID:" + responseObject.getOptimizationProblemId()); |
| 158 | + System.out.println("State:" + Constants.OptimizationState.get(responseObject.getState().intValue())); |
| 159 | + } catch (APIException e) { |
| 160 | + //handle exception |
| 161 | + e.printStackTrace(); |
| 162 | + } |
| 163 | + |
| 164 | + } |
| 165 | + |
| 166 | +} |
0 commit comments