|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +# codebeat:disable[SIMILARITY, LOC, ABC] |
| 3 | + |
| 4 | +import argparse |
| 5 | + |
| 6 | +from route4me import Route4Me |
| 7 | + |
| 8 | +from route4me.constants import ( |
| 9 | + ALGORITHM_TYPE, |
| 10 | + OPTIMIZE, |
| 11 | + DEVICE_TYPE, |
| 12 | + TRAVEL_MODE, |
| 13 | + DISTANCE_UNIT, |
| 14 | +) |
| 15 | + |
| 16 | + |
| 17 | +def main(api_key): |
| 18 | + route4me = Route4Me(api_key) |
| 19 | + |
| 20 | + optimization = route4me.optimization |
| 21 | + address = route4me.address |
| 22 | + optimization.algorithm_type(ALGORITHM_TYPE.CVRP_TW_SD) |
| 23 | + optimization.share_route(0) |
| 24 | + optimization.store_route(0) |
| 25 | + optimization.route_time(0) |
| 26 | + optimization.rt(1) |
| 27 | + optimization.route_max_duration(86400) |
| 28 | + optimization.vehicle_max_distance_mi(10000) |
| 29 | + optimization.route_name('Single Depot Round Trip Orders Based') |
| 30 | + optimization.optimize(OPTIMIZE.TIME) |
| 31 | + optimization.distance_unit(DISTANCE_UNIT.MI) |
| 32 | + optimization.device_type(DEVICE_TYPE.WEB) |
| 33 | + optimization.travel_mode(TRAVEL_MODE.DRIVING) |
| 34 | + |
| 35 | + order_manager = route4me.order |
| 36 | + |
| 37 | + # Creating some Orders |
| 38 | + |
| 39 | + orders = [ |
| 40 | + { |
| 41 | + "address_1": "754 5th Ave New York, NY 10019, USA", |
| 42 | + "address_stop_type": "DELIVERY", |
| 43 | + "day_scheduled_for_YYMMDD": "2022-12-24", |
| 44 | + "EXT_FIELD_cost": 5, |
| 45 | + "EXT_FIELD_pieces": 1, |
| 46 | + "EXT_FIELD_custom_data": |
| 47 | + { |
| 48 | + "attached_barcode": "ORD0002ABC12301", |
| 49 | + } |
| 50 | + }, |
| 51 | + { |
| 52 | + "address_1": "717 5th Ave New York, NY 10022", |
| 53 | + "address_stop_type": "DELIVERY", |
| 54 | + "day_scheduled_for_YYMMDD": "2022-12-24", |
| 55 | + "EXT_FIELD_cost": 1, |
| 56 | + "EXT_FIELD_pieces": 1, |
| 57 | + "EXT_FIELD_custom_data": |
| 58 | + { |
| 59 | + "attached_barcode": "ORD0002ABC12302", |
| 60 | + } |
| 61 | + }, |
| 62 | + { |
| 63 | + "address_1": "888 Madison Ave New York, NY 10014", |
| 64 | + "address_stop_type": "DELIVERY", |
| 65 | + "day_scheduled_for_YYMMDD": "2022-12-24", |
| 66 | + "EXT_FIELD_cost": 2, |
| 67 | + "EXT_FIELD_pieces": 1, |
| 68 | + "EXT_FIELD_custom_data": |
| 69 | + { |
| 70 | + "attached_barcode": "ORD0002ABC12303", |
| 71 | + } |
| 72 | + }, |
| 73 | + { |
| 74 | + "address_1": "1011 Madison Ave New York, NY 10075", |
| 75 | + "address_stop_type": "DELIVERY", |
| 76 | + "day_scheduled_for_YYMMDD": "2022-12-24", |
| 77 | + "EXT_FIELD_cost": 6, |
| 78 | + "EXT_FIELD_pieces": 1, |
| 79 | + "EXT_FIELD_custom_data": |
| 80 | + { |
| 81 | + "attached_barcode": "ORD0002ABC12304", |
| 82 | + } |
| 83 | + }, |
| 84 | + { |
| 85 | + "address_1": "440 Columbus Ave New York, NY 10024", |
| 86 | + "address_stop_type": "DELIVERY", |
| 87 | + "day_scheduled_for_YYMMDD": "2022-12-24", |
| 88 | + "EXT_FIELD_cost": 3, |
| 89 | + "EXT_FIELD_pieces": 1, |
| 90 | + "EXT_FIELD_custom_data": |
| 91 | + { |
| 92 | + "attached_barcode": "ORD0002ABC12305", |
| 93 | + } |
| 94 | + }, |
| 95 | + |
| 96 | + ] |
| 97 | + |
| 98 | + for o in orders: |
| 99 | + new_order = order_manager.create_order(**o) |
| 100 | + address.add_address(order_id=new_order.get('order_id')) |
| 101 | + |
| 102 | + # Adding Depot |
| 103 | + |
| 104 | + address.add_address( |
| 105 | + address='57 W 57th St New York, NY 10019', |
| 106 | + lat=40.7558695, |
| 107 | + lng=-73.9862019, |
| 108 | + alias='Verizon Wireless', |
| 109 | + time=0, |
| 110 | + is_depot=True |
| 111 | + ) |
| 112 | + |
| 113 | + response = route4me.run_optimization() |
| 114 | + print('Optimization Link: {}'.format(response['links']['view'])) |
| 115 | + for i, route in enumerate(response['routes']): |
| 116 | + print('\t{0}\tRoute Link: {1}'.format(i + 1, route['links']['route'])) |
| 117 | + for address in route['addresses']: |
| 118 | + print('\t\t\tAddress: {0}'.format(address['address'])) |
| 119 | + |
| 120 | + |
| 121 | +if __name__ == '__main__': |
| 122 | + parser = argparse.ArgumentParser(description='Single Driver Round Trip') |
| 123 | + parser.add_argument('--api_key', dest='api_key', help='Route4Me API KEY', |
| 124 | + type=str, required=True) |
| 125 | + args = parser.parse_args() |
| 126 | + main(args.api_key) |
| 127 | + |
| 128 | +# codebeat:enable[SIMILARITY, LOC, ABC] |
0 commit comments