Esempio n. 1
0
        /// <summary>
        /// Change a route depot.
        /// </summary>
        public void ChangeRouteDepote()
        {
            var route4Me = new Route4MeManager(ActualApiKey);

            RunSingleDriverRoundTrip();
            OptimizationsToRemove = new List <string>()
            {
                SDRT_optimization_problem_id
            };

            string routeId = SDRT_route_id;

            var initialRoute = R4MeUtils.ObjectDeepClone <DataObjectRoute>(SDRT_route);

            SDRT_route.Addresses[0].IsDepot = false;
            int?addressId0 = SDRT_route.Addresses[0].RouteDestinationId;

            SDRT_route.Addresses[0].Alias   = addressId0.ToString();
            initialRoute.Addresses[0].Alias = addressId0.ToString();

            SDRT_route.Addresses[1].IsDepot = true;
            int?addressId1 = SDRT_route.Addresses[1].RouteDestinationId;

            SDRT_route.Addresses[1].Alias   = addressId1.ToString();
            initialRoute.Addresses[1].Alias = addressId1.ToString();

            var dataObject = route4Me.UpdateRoute(
                SDRT_route,
                initialRoute,
                out string errorString
                );

            #region Print Results

            PrintExampleRouteResult(dataObject, errorString);

            var address0 = dataObject.Addresses
                           .Where(x => x.Alias == addressId0.ToString())
                           .FirstOrDefault();

            PrintExampleDestination(address0);

            var address1 = dataObject.Addresses
                           .Where(x => x.Alias == addressId1.ToString())
                           .FirstOrDefault();

            PrintExampleDestination(address1);

            #endregion

            RemoveTestOptimizations();
        }
        /// <summary>
        /// Update an address book contact by sending whole modified contact object.
        /// </summary>
        public void UpdateWholeAddressBookContact()
        {
            var route4Me = new Route4MeManager(ActualApiKey);

            CreateTestContacts();

            // Create contact clone in the memory
            var contactClone = R4MeUtils.ObjectDeepClone <AddressBookContact>(contact1);

            // Modify the parameters of the contactClone
            contactClone.address_group      = "Updated";
            contactClone.schedule_blacklist = new string[] { "2020-03-14", "2020-03-15" };

            contactClone.address_custom_data = new Dictionary <string, string>
            {
                { "key1", "value1" }, { "key2", "value2" }
            };

            contactClone.local_time_window_start = R4MeUtils.DDHHMM2Seconds("7:05", out _);
            contactClone.local_time_window_end   = R4MeUtils.DDHHMM2Seconds("7:22", out _);
            contactClone.AddressCube             = 5;
            contactClone.AddressPieces           = 6;
            contactClone.AddressRevenue          = 700;
            contactClone.AddressWeight           = 80;
            contactClone.AddressPriority         = 9;

            var sched1 = new Schedule("daily", false)
            {
                Enabled = true,
                Mode    = "daily",
                Daily   = new ScheduleDaily(1)
            };

            contactClone.schedule = new List <Schedule>()
            {
                sched1
            };

            contact1 = route4Me.UpdateAddressBookContact(contactClone, contact1, out string errorString);

            PrintExampleContact(contact1, 0, errorString);

            RemoveTestContacts();
        }
Esempio n. 3
0
        /// <summary>
        /// Update a contact by modifying the specified parameters.
        /// </summary>
        /// <param name="contact">Initial address book contact</param>
        public void UpdateAddressBookContact(AddressBookContact contact = null)
        {
            // Create the manager with the api key
            var route4Me = new Route4MeManager(ActualApiKey);

            CreateTestContacts();

            if (contact != null)
            {
                contact1 = contact;
            }

            contact1.address_group       = "Updated";
            contact1.schedule_blacklist  = new string[] { "2020-03-14", "2020-03-15" };
            contact1.address_custom_data = new Dictionary <string, string>
            {
                { "key1", "value1" }, { "key2", "value2" }
            };
            contact1.local_time_window_start = R4MeUtils.DDHHMM2Seconds("7:03", out _);
            contact1.local_time_window_end   = R4MeUtils.DDHHMM2Seconds("7:37", out _);
            contact1.AddressCube             = 5;
            contact1.AddressPieces           = 6;
            contact1.AddressRevenue          = 700;
            contact1.AddressWeight           = 80;
            contact1.AddressPriority         = 9;

            var updatableProperties = new List <string>()
            {
                "address_id", "address_group", "schedule_blacklist",
                "address_custom_data", "local_time_window_start", "local_time_window_end",
                "AddressCube", "AddressPieces", "AddressRevenue", "AddressWeight", "AddressPriority", "ConvertBooleansToInteger"
            };

            // Run the query
            var updatedContact = route4Me.UpdateAddressBookContact(
                contact1,
                updatableProperties,
                out string errorString);

            PrintExampleContact(updatedContact, 0, errorString);

            RemoveTestContacts();
        }
Esempio n. 4
0
        public DataObject MultipleDepotMultipleDriverTimeWindow()
        {
            // Create the manager with the api key
            Route4MeManager route4Me = new Route4MeManager(c_ApiKey);

            // Prepare the addresses
            Address[] addresses = new Address[]
            {
                #region Addresses

                new Address()
                {
                    AddressString   = "455 S 4th St, Louisville, KY 40202",
                    IsDepot         = true,
                    Latitude        = 38.251698,
                    Longitude       = -85.757308,
                    Time            = 300,
                    TimeWindowStart = 28800,
                    TimeWindowEnd   = 30477
                },

                new Address()
                {
                    AddressString   = "1604 PARKRIDGE PKWY, Louisville, KY, 40214",
                    Latitude        = 38.141598,
                    Longitude       = -85.793846,
                    Time            = 300,
                    TimeWindowStart = 30477,
                    TimeWindowEnd   = 33406
                },

                new Address()
                {
                    AddressString   = "1407 א53MCCOY, Louisville, KY, 40215",
                    Latitude        = 38.202496,
                    Longitude       = -85.786514,
                    Time            = 300,
                    TimeWindowStart = 33406,
                    TimeWindowEnd   = 36228
                },
                new Address()
                {
                    AddressString   = "4805 BELLEVUE AVE, Louisville, KY, 40215",
                    Latitude        = 38.178844,
                    Longitude       = -85.774864,
                    Time            = 300,
                    TimeWindowStart = 36228,
                    TimeWindowEnd   = 37518
                },

                new Address()
                {
                    AddressString   = "730 CECIL AVENUE, Louisville, KY, 40211",
                    Latitude        = 38.248684,
                    Longitude       = -85.821121,
                    Time            = 300,
                    TimeWindowStart = 37518,
                    TimeWindowEnd   = 39550
                },

                new Address()
                {
                    AddressString   = "650 SOUTH 29TH ST UNIT 315, Louisville, KY, 40211",
                    Latitude        = 38.251923,
                    Longitude       = -85.800034,
                    Time            = 300,
                    TimeWindowStart = 39550,
                    TimeWindowEnd   = 41348
                },

                new Address()
                {
                    AddressString   = "4629 HILLSIDE DRIVE, Louisville, KY, 40216",
                    Latitude        = 38.176067,
                    Longitude       = -85.824638,
                    Time            = 300,
                    TimeWindowStart = 41348,
                    TimeWindowEnd   = 42261
                },

                new Address()
                {
                    AddressString   = "4738 BELLEVUE AVE, Louisville, KY, 40215",
                    Latitude        = 38.179806,
                    Longitude       = -85.775558,
                    Time            = 300,
                    TimeWindowStart = 42261,
                    TimeWindowEnd   = 45195
                },

                new Address()
                {
                    AddressString   = "318 SO. 39TH STREET, Louisville, KY, 40212",
                    Latitude        = 38.259335,
                    Longitude       = -85.815094,
                    Time            = 300,
                    TimeWindowStart = 45195,
                    TimeWindowEnd   = 46549
                },

                new Address()
                {
                    AddressString   = "1324 BLUEGRASS AVE, Louisville, KY, 40215",
                    Latitude        = 38.179253,
                    Longitude       = -85.785118,
                    Time            = 300,
                    TimeWindowStart = 46549,
                    TimeWindowEnd   = 47353
                },

                new Address()
                {
                    AddressString   = "7305 ROYAL WOODS DR, Louisville, KY, 40214",
                    Latitude        = 38.162472,
                    Longitude       = -85.792854,
                    Time            = 300,
                    TimeWindowStart = 47353,
                    TimeWindowEnd   = 50924
                },

                new Address()
                {
                    AddressString   = "1661 W HILL ST, Louisville, KY, 40210",
                    Latitude        = 38.229584,
                    Longitude       = -85.783966,
                    Time            = 300,
                    TimeWindowStart = 50924,
                    TimeWindowEnd   = 51392
                },

                new Address()
                {
                    AddressString   = "3222 KINGSWOOD WAY, Louisville, KY, 40216",
                    Latitude        = 38.210606,
                    Longitude       = -85.822594,
                    Time            = 300,
                    TimeWindowStart = 51392,
                    TimeWindowEnd   = 52451
                },

                new Address()
                {
                    AddressString   = "1922 PALATKA RD, Louisville, KY, 40214",
                    Latitude        = 38.153767,
                    Longitude       = -85.796783,
                    Time            = 300,
                    TimeWindowStart = 52451,
                    TimeWindowEnd   = 55631
                },

                new Address()
                {
                    AddressString   = "1314 SOUTH 26TH STREET, Louisville, KY, 40210",
                    Latitude        = 38.235847,
                    Longitude       = -85.796852,
                    Time            = 300,
                    TimeWindowStart = 55631,
                    TimeWindowEnd   = 58516
                },

                new Address()
                {
                    AddressString   = "2135 MCCLOSKEY AVENUE, Louisville, KY, 40210",
                    Latitude        = 38.218662,
                    Longitude       = -85.789032,
                    Time            = 300,
                    TimeWindowStart = 58516,
                    TimeWindowEnd   = 61080
                },

                new Address()
                {
                    AddressString   = "1409 PHYLLIS AVE, Louisville, KY, 40215",
                    Latitude        = 38.206154,
                    Longitude       = -85.781387,
                    Time            = 100,
                    TimeWindowStart = 61080,
                    TimeWindowEnd   = 61504
                },

                new Address()
                {
                    AddressString   = "4504 SUNFLOWER AVE, Louisville, KY, 40216",
                    Latitude        = 38.187511,
                    Longitude       = -85.839149,
                    Time            = 300,
                    TimeWindowStart = 61504,
                    TimeWindowEnd   = 62061
                },

                new Address()
                {
                    AddressString   = "2512 GREENWOOD AVE, Louisville, KY, 40210",
                    Latitude        = 38.241405,
                    Longitude       = -85.795059,
                    Time            = 300,
                    TimeWindowStart = 62061,
                    TimeWindowEnd   = 65012
                },

                new Address()
                {
                    AddressString   = "5500 WILKE FARM AVE, Louisville, KY, 40216",
                    Latitude        = 38.166065,
                    Longitude       = -85.863319,
                    Time            = 300,
                    TimeWindowStart = 65012,
                    TimeWindowEnd   = 67541
                },

                new Address()
                {
                    AddressString   = "3640 LENTZ AVE, Louisville, KY, 40215",
                    Latitude        = 38.193283,
                    Longitude       = -85.786201,
                    Time            = 300,
                    TimeWindowStart = 67541,
                    TimeWindowEnd   = 69120
                },

                new Address()
                {
                    AddressString   = "1020 BLUEGRASS AVE, Louisville, KY, 40215",
                    Latitude        = 38.17952,
                    Longitude       = -85.780037,
                    Time            = 300,
                    TimeWindowStart = 69120,
                    TimeWindowEnd   = 70572
                },

                new Address()
                {
                    AddressString   = "123 NORTH 40TH ST, Louisville, KY, 40212",
                    Latitude        = 38.26498,
                    Longitude       = -85.814156,
                    Time            = 300,
                    TimeWindowStart = 70572,
                    TimeWindowEnd   = 73177
                },

                new Address()
                {
                    AddressString   = "7315 ST ANDREWS WOODS CIRCLE UNIT 104, Louisville, KY, 40214",
                    Latitude        = 38.151072,
                    Longitude       = -85.802867,
                    Time            = 300,
                    TimeWindowStart = 73177,
                    TimeWindowEnd   = 75231
                },

                new Address()
                {
                    AddressString   = "3210 POPLAR VIEW DR, Louisville, KY, 40216",
                    Latitude        = 38.182594,
                    Longitude       = -85.849937,
                    Time            = 300,
                    TimeWindowStart = 75231,
                    TimeWindowEnd   = 77663
                },

                new Address()
                {
                    AddressString   = "4519 LOUANE WAY, Louisville, KY, 40216",
                    Latitude        = 38.1754,
                    Longitude       = -85.811447,
                    Time            = 300,
                    TimeWindowStart = 77663,
                    TimeWindowEnd   = 79796
                },

                new Address()
                {
                    AddressString   = "6812 MANSLICK RD, Louisville, KY, 40214",
                    Latitude        = 38.161839,
                    Longitude       = -85.798279,
                    Time            = 300,
                    TimeWindowStart = 79796,
                    TimeWindowEnd   = 80813
                },

                new Address()
                {
                    AddressString   = "1524 HUNTOON AVENUE, Louisville, KY, 40215",
                    Latitude        = 38.172031,
                    Longitude       = -85.788353,
                    Time            = 300,
                    TimeWindowStart = 80813,
                    TimeWindowEnd   = 83956
                },

                new Address()
                {
                    AddressString   = "1307 LARCHMONT AVE, Louisville, KY, 40215",
                    Latitude        = 38.209663,
                    Longitude       = -85.779816,
                    Time            = 300,
                    TimeWindowStart = 83956,
                    TimeWindowEnd   = 84365
                },

                new Address()
                {
                    AddressString   = "434 N 26TH STREET #2, Louisville, KY, 40212",
                    Latitude        = 38.26844,
                    Longitude       = -85.791962,
                    Time            = 300,
                    TimeWindowStart = 84365,
                    TimeWindowEnd   = 85367
                },

                new Address()
                {
                    AddressString   = "678 WESTLAWN ST, Louisville, KY, 40211",
                    Latitude        = 38.250397,
                    Longitude       = -85.80629,
                    Time            = 300,
                    TimeWindowStart = 85367,
                    TimeWindowEnd   = 86400
                },

                new Address()
                {
                    AddressString   = "2308 W BROADWAY, Louisville, KY, 40211",
                    Latitude        = 38.248882,
                    Longitude       = -85.790421,
                    Time            = 300,
                    TimeWindowStart = 86400,
                    TimeWindowEnd   = 88703
                },

                new Address()
                {
                    AddressString   = "2332 WOODLAND AVE, Louisville, KY, 40210",
                    Latitude        = 38.233579,
                    Longitude       = -85.794257,
                    Time            = 300,
                    TimeWindowStart = 88703,
                    TimeWindowEnd   = 89320
                },

                new Address()
                {
                    AddressString   = "1706 WEST ST. CATHERINE, Louisville, KY, 40210",
                    Latitude        = 38.239697,
                    Longitude       = -85.783928,
                    Time            = 300,
                    TimeWindowStart = 89320,
                    TimeWindowEnd   = 90054
                },

                new Address()
                {
                    AddressString   = "1699 WATHEN LN, Louisville, KY, 40216",
                    Latitude        = 38.216465,
                    Longitude       = -85.792397,
                    Time            = 300,
                    TimeWindowStart = 90054,
                    TimeWindowEnd   = 91150
                },

                new Address()
                {
                    AddressString   = "2416 SUNSHINE WAY, Louisville, KY, 40216",
                    Latitude        = 38.186245,
                    Longitude       = -85.831787,
                    Time            = 300,
                    TimeWindowStart = 91150,
                    TimeWindowEnd   = 91915
                },

                new Address()
                {
                    AddressString   = "6925 MANSLICK RD, Louisville, KY, 40214",
                    Latitude        = 38.158466,
                    Longitude       = -85.798355,
                    Time            = 300,
                    TimeWindowStart = 91915,
                    TimeWindowEnd   = 93407
                },

                new Address()
                {
                    AddressString   = "2707 7TH ST, Louisville, KY, 40215",
                    Latitude        = 38.212438,
                    Longitude       = -85.785082,
                    Time            = 300,
                    TimeWindowStart = 93407,
                    TimeWindowEnd   = 95992
                },

                new Address()
                {
                    AddressString   = "2014 KENDALL LN, Louisville, KY, 40216",
                    Latitude        = 38.179394,
                    Longitude       = -85.826668,
                    Time            = 300,
                    TimeWindowStart = 95992,
                    TimeWindowEnd   = 99307
                },

                new Address()
                {
                    AddressString   = "612 N 39TH ST, Louisville, KY, 40212",
                    Latitude        = 38.273354,
                    Longitude       = -85.812012,
                    Time            = 300,
                    TimeWindowStart = 99307,
                    TimeWindowEnd   = 102906
                },

                new Address()
                {
                    AddressString   = "2215 ROWAN ST, Louisville, KY, 40212",
                    Latitude        = 38.261703,
                    Longitude       = -85.786781,
                    Time            = 300,
                    TimeWindowStart = 102906,
                    TimeWindowEnd   = 106021
                },

                new Address()
                {
                    AddressString   = "1826 W. KENTUCKY ST, Louisville, KY, 40210",
                    Latitude        = 38.241611,
                    Longitude       = -85.78653,
                    Time            = 300,
                    TimeWindowStart = 106021,
                    TimeWindowEnd   = 107276
                },

                new Address()
                {
                    AddressString   = "1810 GREGG AVE, Louisville, KY, 40210",
                    Latitude        = 38.224716,
                    Longitude       = -85.796211,
                    Time            = 300,
                    TimeWindowStart = 107276,
                    TimeWindowEnd   = 107948
                },

                new Address()
                {
                    AddressString   = "4103 BURRRELL DRIVE, Louisville, KY, 40216",
                    Latitude        = 38.191753,
                    Longitude       = -85.825836,
                    Time            = 300,
                    TimeWindowStart = 107948,
                    TimeWindowEnd   = 108414
                },

                new Address()
                {
                    AddressString   = "359 SOUTHWESTERN PKWY, Louisville, KY, 40212",
                    Latitude        = 38.259903,
                    Longitude       = -85.823463,
                    Time            = 200,
                    TimeWindowStart = 108414,
                    TimeWindowEnd   = 108685
                },

                new Address()
                {
                    AddressString   = "2407 W CHESTNUT ST, Louisville, KY, 40211",
                    Latitude        = 38.252781,
                    Longitude       = -85.792109,
                    Time            = 300,
                    TimeWindowStart = 108685,
                    TimeWindowEnd   = 110109
                },

                new Address()
                {
                    AddressString   = "225 S 22ND ST, Louisville, KY, 40212",
                    Latitude        = 38.257616,
                    Longitude       = -85.786658,
                    Time            = 300,
                    TimeWindowStart = 110109,
                    TimeWindowEnd   = 111375
                },

                new Address()
                {
                    AddressString   = "1404 MCCOY AVE, Louisville, KY, 40215",
                    Latitude        = 38.202122,
                    Longitude       = -85.786072,
                    Time            = 300,
                    TimeWindowStart = 111375,
                    TimeWindowEnd   = 112120
                },

                new Address()
                {
                    AddressString   = "117 FOUNT LANDING CT, Louisville, KY, 40212",
                    Latitude        = 38.270061,
                    Longitude       = -85.799438,
                    Time            = 300,
                    TimeWindowStart = 112120,
                    TimeWindowEnd   = 114095
                },

                new Address()
                {
                    AddressString   = "5504 SHOREWOOD DRIVE, Louisville, KY, 40214",
                    Latitude        = 38.145851,
                    Longitude       = -85.7798,
                    Time            = 300,
                    TimeWindowStart = 114095,
                    TimeWindowEnd   = 115743
                },

                new Address()
                {
                    AddressString   = "1406 CENTRAL AVE, Louisville, KY, 40208",
                    Latitude        = 38.211025,
                    Longitude       = -85.780251,
                    Time            = 300,
                    TimeWindowStart = 115743,
                    TimeWindowEnd   = 117716
                },

                new Address()
                {
                    AddressString   = "901 W WHITNEY AVE, Louisville, KY, 40215",
                    Latitude        = 38.194115,
                    Longitude       = -85.77494,
                    Time            = 300,
                    TimeWindowStart = 117716,
                    TimeWindowEnd   = 119078
                },

                new Address()
                {
                    AddressString   = "2109 SCHAFFNER AVE, Louisville, KY, 40210",
                    Latitude        = 38.219699,
                    Longitude       = -85.779363,
                    Time            = 300,
                    TimeWindowStart = 119078,
                    TimeWindowEnd   = 121147
                },

                new Address()
                {
                    AddressString   = "2906 DIXIE HWY, Louisville, KY, 40216",
                    Latitude        = 38.209278,
                    Longitude       = -85.798653,
                    Time            = 300,
                    TimeWindowStart = 121147,
                    TimeWindowEnd   = 124281
                },

                new Address()
                {
                    AddressString   = "814 WWHITNEY AVE, Louisville, KY, 40215",
                    Latitude        = 38.193596,
                    Longitude       = -85.773521,
                    Time            = 300,
                    TimeWindowStart = 124281,
                    TimeWindowEnd   = 124675
                },

                new Address()
                {
                    AddressString   = "1610 ALGONQUIN PWKY, Louisville, KY, 40210",
                    Latitude        = 38.222153,
                    Longitude       = -85.784187,
                    Time            = 300,
                    TimeWindowStart = 124675,
                    TimeWindowEnd   = 127148
                },

                new Address()
                {
                    AddressString   = "3524 WHEELER AVE, Louisville, KY, 40215",
                    Latitude        = 38.195293,
                    Longitude       = -85.788643,
                    Time            = 300,
                    TimeWindowStart = 127148,
                    TimeWindowEnd   = 130667
                },

                new Address()
                {
                    AddressString   = "5009 NEW CUT RD, Louisville, KY, 40214",
                    Latitude        = 38.165905,
                    Longitude       = -85.779701,
                    Time            = 300,
                    TimeWindowStart = 130667,
                    TimeWindowEnd   = 131980
                },

                new Address()
                {
                    AddressString   = "3122 ELLIOTT AVE, Louisville, KY, 40211",
                    Latitude        = 38.251213,
                    Longitude       = -85.804199,
                    Time            = 300,
                    TimeWindowStart = 131980,
                    TimeWindowEnd   = 134402
                },

                new Address()
                {
                    AddressString   = "911 GAGEL AVE, Louisville, KY, 40216",
                    Latitude        = 38.173512,
                    Longitude       = -85.807854,
                    Time            = 300,
                    TimeWindowStart = 134402,
                    TimeWindowEnd   = 136787
                },

                new Address()
                {
                    AddressString   = "4020 GARLAND AVE #lOOA, Louisville, KY, 40211",
                    Latitude        = 38.246181,
                    Longitude       = -85.818901,
                    Time            = 300,
                    TimeWindowStart = 136787,
                    TimeWindowEnd   = 138073
                },

                new Address()
                {
                    AddressString   = "5231 MT HOLYOKE DR, Louisville, KY, 40216",
                    Latitude        = 38.169369,
                    Longitude       = -85.85704,
                    Time            = 300,
                    TimeWindowStart = 138073,
                    TimeWindowEnd   = 141407
                },

                new Address()
                {
                    AddressString   = "1339 28TH S #2, Louisville, KY, 40211",
                    Latitude        = 38.235275,
                    Longitude       = -85.800156,
                    Time            = 300,
                    TimeWindowStart = 141407,
                    TimeWindowEnd   = 143561
                },

                new Address()
                {
                    AddressString   = "836 S 36TH ST, Louisville, KY, 40211",
                    Latitude        = 38.24651,
                    Longitude       = -85.811234,
                    Time            = 300,
                    TimeWindowStart = 143561,
                    TimeWindowEnd   = 145941
                },

                new Address()
                {
                    AddressString   = "2132 DUNCAN STREET, Louisville, KY, 40212",
                    Latitude        = 38.262135,
                    Longitude       = -85.785172,
                    Time            = 300,
                    TimeWindowStart = 145941,
                    TimeWindowEnd   = 148296
                },

                new Address()
                {
                    AddressString   = "3529 WHEELER AVE, Louisville, KY, 40215",
                    Latitude        = 38.195057,
                    Longitude       = -85.787949,
                    Time            = 300,
                    TimeWindowStart = 148296,
                    TimeWindowEnd   = 150177
                },

                new Address()
                {
                    AddressString   = "2829 DE MEL #11, Louisville, KY, 40214",
                    Latitude        = 38.171662,
                    Longitude       = -85.807271,
                    Time            = 300,
                    TimeWindowStart = 150177,
                    TimeWindowEnd   = 150981
                },

                new Address()
                {
                    AddressString   = "1325 EARL AVENUE, Louisville, KY, 40215",
                    Latitude        = 38.204556,
                    Longitude       = -85.781555,
                    Time            = 300,
                    TimeWindowStart = 150981,
                    TimeWindowEnd   = 151854
                },

                new Address()
                {
                    AddressString   = "3632 MANSLICK RD #10, Louisville, KY, 40215",
                    Latitude        = 38.193542,
                    Longitude       = -85.801147,
                    Time            = 300,
                    TimeWindowStart = 151854,
                    TimeWindowEnd   = 152613
                },

                new Address()
                {
                    AddressString   = "637 S 41ST ST, Louisville, KY, 40211",
                    Latitude        = 38.253632,
                    Longitude       = -85.81897,
                    Time            = 300,
                    TimeWindowStart = 152613,
                    TimeWindowEnd   = 156131
                },

                new Address()
                {
                    AddressString   = "3420 VIRGINIA AVENUE, Louisville, KY, 40211",
                    Latitude        = 38.238693,
                    Longitude       = -85.811386,
                    Time            = 300,
                    TimeWindowStart = 156131,
                    TimeWindowEnd   = 157212
                },

                new Address()
                {
                    AddressString   = "3501 MALIBU CT APT 6, Louisville, KY, 40216",
                    Latitude        = 38.166481,
                    Longitude       = -85.825928,
                    Time            = 300,
                    TimeWindowStart = 157212,
                    TimeWindowEnd   = 158655
                },

                new Address()
                {
                    AddressString   = "4912 DIXIE HWY, Louisville, KY, 40216",
                    Latitude        = 38.170728,
                    Longitude       = -85.826817,
                    Time            = 300,
                    TimeWindowStart = 158655,
                    TimeWindowEnd   = 159145
                },

                new Address()
                {
                    AddressString   = "7720 DINGLEDELL RD, Louisville, KY, 40214",
                    Latitude        = 38.162472,
                    Longitude       = -85.792854,
                    Time            = 300,
                    TimeWindowStart = 159145,
                    TimeWindowEnd   = 161831
                },

                new Address()
                {
                    AddressString   = "2123 RATCLIFFE AVE, Louisville, KY, 40210",
                    Latitude        = 38.21978,
                    Longitude       = -85.797615,
                    Time            = 300,
                    TimeWindowStart = 161831,
                    TimeWindowEnd   = 163705
                },

                new Address()
                {
                    AddressString   = "1321 OAKWOOD AVE, Louisville, KY, 40215",
                    Latitude        = 38.17704,
                    Longitude       = -85.783829,
                    Time            = 300,
                    TimeWindowStart = 163705,
                    TimeWindowEnd   = 164953
                },

                new Address()
                {
                    AddressString   = "2223 WEST KENTUCKY STREET, Louisville, KY, 40210",
                    Latitude        = 38.242516,
                    Longitude       = -85.790695,
                    Time            = 300,
                    TimeWindowStart = 164953,
                    TimeWindowEnd   = 166189
                },

                new Address()
                {
                    AddressString   = "8025 GLIMMER WAY #3308, Louisville, KY, 40214",
                    Latitude        = 38.131981,
                    Longitude       = -85.77935,
                    Time            = 300,
                    TimeWindowStart = 166189,
                    TimeWindowEnd   = 166640
                },

                new Address()
                {
                    AddressString   = "1155 S 28TH ST, Louisville, KY, 40211",
                    Latitude        = 38.238621,
                    Longitude       = -85.799911,
                    Time            = 300,
                    TimeWindowStart = 166640,
                    TimeWindowEnd   = 168147
                },

                new Address()
                {
                    AddressString   = "840 IROQUOIS AVE, Louisville, KY, 40214",
                    Latitude        = 38.166355,
                    Longitude       = -85.779396,
                    Time            = 300,
                    TimeWindowStart = 168147,
                    TimeWindowEnd   = 170385
                },

                new Address()
                {
                    AddressString   = "5573 BRUCE AVE, Louisville, KY, 40214",
                    Latitude        = 38.145222,
                    Longitude       = -85.779205,
                    Time            = 300,
                    TimeWindowStart = 170385,
                    TimeWindowEnd   = 171096
                },

                new Address()
                {
                    AddressString   = "1727 GALLAGHER, Louisville, KY, 40210",
                    Latitude        = 38.239334,
                    Longitude       = -85.784882,
                    Time            = 300,
                    TimeWindowStart = 171096,
                    TimeWindowEnd   = 171951
                },

                new Address()
                {
                    AddressString   = "1309 CATALPA ST APT 204, Louisville, KY, 40211",
                    Latitude        = 38.236524,
                    Longitude       = -85.801619,
                    Time            = 300,
                    TimeWindowStart = 171951,
                    TimeWindowEnd   = 172393
                },

                new Address()
                {
                    AddressString   = "1330 ALGONQUIN PKWY, Louisville, KY, 40208",
                    Latitude        = 38.219846,
                    Longitude       = -85.777344,
                    Time            = 300,
                    TimeWindowStart = 172393,
                    TimeWindowEnd   = 175337
                },

                new Address()
                {
                    AddressString   = "823 SUTCLIFFE, Louisville, KY, 40211",
                    Latitude        = 38.246956,
                    Longitude       = -85.811569,
                    Time            = 300,
                    TimeWindowStart = 175337,
                    TimeWindowEnd   = 176867
                },

                new Address()
                {
                    AddressString   = "4405 CHURCHMAN AVENUE #2, Louisville, KY, 40215",
                    Latitude        = 38.177768,
                    Longitude       = -85.792545,
                    Time            = 300,
                    TimeWindowStart = 176867,
                    TimeWindowEnd   = 178051
                },

                new Address()
                {
                    AddressString   = "3211 DUMESNIL ST #1, Louisville, KY, 40211",
                    Latitude        = 38.237789,
                    Longitude       = -85.807968,
                    Time            = 300,
                    TimeWindowStart = 178051,
                    TimeWindowEnd   = 179083
                },

                new Address()
                {
                    AddressString   = "3904 WEWOKA AVE, Louisville, KY, 40212",
                    Latitude        = 38.270367,
                    Longitude       = -85.813118,
                    Time            = 300,
                    TimeWindowStart = 179083,
                    TimeWindowEnd   = 181543
                },

                new Address()
                {
                    AddressString   = "660 SO. 42ND STREET, Louisville, KY, 40211",
                    Latitude        = 38.252865,
                    Longitude       = -85.822624,
                    Time            = 300,
                    TimeWindowStart = 181543,
                    TimeWindowEnd   = 184193
                },

                new Address()
                {
                    AddressString   = "3619  LENTZ  AVE, Louisville, KY, 40215",
                    Latitude        = 38.193249,
                    Longitude       = -85.785492,
                    Time            = 300,
                    TimeWindowStart = 184193,
                    TimeWindowEnd   = 185853
                },

                new Address()
                {
                    AddressString   = "4305  STOLTZ  CT, Louisville, KY, 40215",
                    Latitude        = 38.178707,
                    Longitude       = -85.787292,
                    Time            = 300,
                    TimeWindowStart = 185853,
                    TimeWindowEnd   = 187252
                }

                #endregion
            };

            // Set parameters
            RouteParameters parameters = new RouteParameters()
            {
                AlgorithmType = AlgorithmType.CVRP_TW_MD,
                RouteName     = "Multiple Depot, Multiple Driver, Time Window",
                StoreRoute    = false,

                RouteDate            = R4MeUtils.ConvertToUnixTimestamp(DateTime.UtcNow.Date.AddDays(1)),
                RouteTime            = 60 * 60 * 7,
                RT                   = true,
                RouteMaxDuration     = 86400 * 3,
                VehicleCapacity      = "99",
                VehicleMaxDistanceMI = "99999",

                Optimize     = Optimize.Time.Description(),
                DistanceUnit = DistanceUnit.MI.Description(),
                DeviceType   = DeviceType.Web.Description(),
                TravelMode   = TravelMode.Driving.Description(),
                Metric       = Metric.Geodesic
            };

            OptimizationParameters optimizationParameters = new OptimizationParameters()
            {
                Addresses  = addresses,
                Parameters = parameters
            };

            // Run the query
            string     errorString;
            DataObject dataObject = route4Me.RunOptimization(optimizationParameters, out errorString);

            // Output the result
            PrintExampleOptimizationResult("MultipleDepotMultipleDriverTimeWindow", dataObject, errorString);

            return(dataObject);
        }
        /// <summary>
        /// Get Device History from Time Range
        /// </summary>
        public void GetDeviceHistoryTimeRange()
        {
            // Create the manager with the api key
            var route4Me = new Route4MeManager(ActualApiKey);

            #region Create GPS event record

            var      tsp2days = new TimeSpan(2, 0, 0, 0);
            DateTime dtNow    = DateTime.Now;

            RunOptimizationSingleDriverRoute10Stops();
            OptimizationsToRemove = new List <string>();
            OptimizationsToRemove.Add(SD10Stops_optimization_problem_id);

            double lat = SD10Stops_route.Addresses.Length > 1
                ? SD10Stops_route.Addresses[1].Latitude
                : 33.14384;
            double lng = SD10Stops_route.Addresses.Length > 1
                ? SD10Stops_route.Addresses[1].Longitude
                : -83.22466;

            var gpsParameters = new GPSParameters
            {
                Format          = Format.Csv.Description(),
                RouteId         = SD10Stops_route_id,
                Latitude        = lat,
                Longitude       = lng,
                Course          = 1,
                Speed           = 120,
                DeviceType      = DeviceType.IPhone.Description(),
                MemberId        = (int)SD10Stops_route.Addresses[1].MemberId,
                DeviceGuid      = "TEST_GPS",
                DeviceTimestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
            };

            var response = route4Me.SetGPS(gpsParameters, out string errorString);

            if (!string.IsNullOrEmpty(errorString))
            {
                Console.WriteLine("SetGps error: {0}", errorString);
                return;
            }

            Console.WriteLine("SetGps response: {0}", response.Status.ToString());

            #endregion

            var trParameters = new GPSParameters
            {
                Format     = "json",
                RouteId    = SD10Stops_route_id,
                TimePeriod = "custom",
                StartDate  = R4MeUtils.ConvertToUnixTimestamp(dtNow - tsp2days),
                EndDate    = R4MeUtils.ConvertToUnixTimestamp(dtNow + tsp2days)
            };

            var result = route4Me.GetDeviceLocationHistory(trParameters, out errorString);

            Console.WriteLine(
                result != null && result.GetType() == typeof(DeviceLocationHistoryResponse)
                    ? "GetDeviceHistoryTimeRangeTest executed successfully"
                    : "GetDeviceHistoryTimeRangeTest failed. " + errorString
                );

            if (result != null && result.GetType() == typeof(DeviceLocationHistoryResponse))
            {
                Console.WriteLine("");

                var locationHistoryResul = (DeviceLocationHistoryResponse)result;

                if ((locationHistoryResul.data?.Length ?? 0) > 0)
                {
                    foreach (var locationHistory in locationHistoryResul.data)
                    {
                        Console.WriteLine("Location: {0}, {1}", locationHistory.Latitude, locationHistory.Longitude);
                    }
                }
            }

            RemoveTestOptimizations();
        }
        /// <summary>
        /// The example referes to the process of creating an optimization
        /// with bundled addresses.
        /// </summary>
        public void BundledAddresses()
        {
            var route4Me = new Route4MeManager(ActualApiKey);

            if (!route4Me.MemberHasCommercialCapability(ActualApiKey, DemoApiKey, out string errorString0))
            {
                return;
            }

            // Prepare the addresses
            var addresses = new Address[]
            {
                #region Addresses

                new Address()
                {
                    AddressString = "3634 W Market St, Fairlawn, OH 44333",
                    //all possible originating locations are depots, should be marked as true
                    //stylistically we recommend all depots should be at the top of the destinations list
                    IsDepot   = true,
                    Latitude  = 41.135762259364,
                    Longitude = -81.629313826561,

                    TimeWindowStart  = null,
                    TimeWindowEnd    = null,
                    TimeWindowStart2 = null,
                    TimeWindowEnd2   = null,
                    Time             = null
                },

                new Address()
                {
                    AddressString = "1218 Ruth Ave, Cuyahoga Falls, OH 44221",
                    Latitude      = 41.135762259364,
                    Longitude     = -81.629313826561,

                    //together these two specify the time window of a destination
                    //seconds offset relative to the route start time for the open availability of a destination
                    TimeWindowStart = 6 * 3600 + 00 * 60,
                    //seconds offset relative to the route end time for the open availability of a destination
                    TimeWindowEnd = 6 * 3600 + 30 * 60,

                    // Second 'TimeWindowStart'
                    TimeWindowStart2 = 7 * 3600 + 00 * 60,
                    // Second 'TimeWindowEnd'
                    TimeWindowEnd2 = 7 * 3600 + 20 * 60,

                    //the number of seconds at destination
                    Time = 300
                },

                new Address()
                {
                    AddressString    = "512 Florida Pl, Barberton, OH 44203",
                    Latitude         = 41.003671512008,
                    Longitude        = -81.598461046815,
                    TimeWindowStart  = 7 * 3600 + 30 * 60,
                    TimeWindowEnd    = 7 * 3600 + 40 * 60,
                    TimeWindowStart2 = 8 * 3600 + 00 * 60,
                    TimeWindowEnd2   = 8 * 3600 + 10 * 60,
                    Time             = 300
                },

                new Address()
                {
                    AddressString    = "512 Florida Pl, Barberton, OH 44203",
                    Latitude         = 41.003671512008,
                    Longitude        = -81.598461046815,
                    TimeWindowStart  = 8 * 3600 + 30 * 60,
                    TimeWindowEnd    = 8 * 3600 + 40 * 60,
                    TimeWindowStart2 = 8 * 3600 + 50 * 60,
                    TimeWindowEnd2   = 9 * 3600 + 00 * 60,
                    Time             = 100
                },

                new Address()
                {
                    AddressString    = "3495 Purdue St, Cuyahoga Falls, OH 44221",
                    Latitude         = 41.162971496582,
                    Longitude        = -81.479049682617,
                    TimeWindowStart  = 9 * 3600 + 00 * 60,
                    TimeWindowEnd    = 9 * 3600 + 15 * 60,
                    TimeWindowStart2 = 9 * 3600 + 30 * 60,
                    TimeWindowEnd2   = 9 * 3600 + 45 * 60,
                    Time             = 300
                },

                new Address()
                {
                    AddressString    = "1659 Hibbard Dr, Stow, OH 44224",
                    Latitude         = 41.194505989552,
                    Longitude        = -81.443351581693,
                    TimeWindowStart  = 10 * 3600 + 00 * 60,
                    TimeWindowEnd    = 10 * 3600 + 15 * 60,
                    TimeWindowStart2 = 10 * 3600 + 30 * 60,
                    TimeWindowEnd2   = 10 * 3600 + 45 * 60,
                    Time             = 300
                },

                new Address()
                {
                    AddressString    = "2705 N River Rd, Stow, OH 44224",
                    Latitude         = 41.145240783691,
                    Longitude        = -81.410247802734,
                    TimeWindowStart  = 11 * 3600 + 00 * 60,
                    TimeWindowEnd    = 11 * 3600 + 15 * 60,
                    TimeWindowStart2 = 11 * 3600 + 30 * 60,
                    TimeWindowEnd2   = 11 * 3600 + 45 * 60,
                    Time             = 300
                },

                new Address()
                {
                    AddressString    = "10159 Bissell Dr, Twinsburg, OH 44087",
                    Latitude         = 41.340042114258,
                    Longitude        = -81.421226501465,
                    TimeWindowStart  = 12 * 3600 + 00 * 60,
                    TimeWindowEnd    = 12 * 3600 + 15 * 60,
                    TimeWindowStart2 = 12 * 3600 + 30 * 60,
                    TimeWindowEnd2   = 12 * 3600 + 45 * 60,
                    Time             = 300
                },

                new Address()
                {
                    AddressString    = "367 Cathy Dr, Munroe Falls, OH 44262",
                    Latitude         = 41.148578643799,
                    Longitude        = -81.429229736328,
                    TimeWindowStart  = 13 * 3600 + 00 * 60,
                    TimeWindowEnd    = 13 * 3600 + 15 * 60,
                    TimeWindowStart2 = 13 * 3600 + 30 * 60,
                    TimeWindowEnd2   = 13 * 3600 + 45 * 60,
                    Time             = 300,
                    Cube             = 3
                },

                new Address()
                {
                    AddressString    = "367 Cathy Dr, Munroe Falls, OH 44262",
                    Latitude         = 41.148578643799,
                    Longitude        = -81.429229736328,
                    TimeWindowStart  = 14 * 3600 + 00 * 60,
                    TimeWindowEnd    = 14 * 3600 + 15 * 60,
                    TimeWindowStart2 = 14 * 3600 + 30 * 60,
                    TimeWindowEnd2   = 14 * 3600 + 45 * 60,
                    Time             = 300,
                    Cube             = 2
                },

                new Address()
                {
                    AddressString    = "512 Florida Pl, Barberton, OH 44203",
                    Latitude         = 41.003671512008,
                    Longitude        = -81.598461046815,
                    TimeWindowStart  = 15 * 3600 + 00 * 60,
                    TimeWindowEnd    = 15 * 3600 + 15 * 60,
                    TimeWindowStart2 = 15 * 3600 + 30 * 60,
                    TimeWindowEnd2   = 15 * 3600 + 45 * 60,
                    Time             = 300
                },

                new Address()
                {
                    AddressString    = "559 W Aurora Rd, Northfield, OH 44067",
                    Latitude         = 41.315116882324,
                    Longitude        = -81.558746337891,
                    TimeWindowStart  = 16 * 3600 + 00 * 60,
                    TimeWindowEnd    = 16 * 3600 + 15 * 60,
                    TimeWindowStart2 = 16 * 3600 + 30 * 60,
                    TimeWindowEnd2   = 17 * 3600 + 00 * 60,
                    Time             = 50
                }

                #endregion
            };

            // Set parameters
            var parameters = new RouteParameters()
            {
                AlgorithmType = AlgorithmType.TSP,
                RouteName     = "SD Multiple TW Address Bundling " + DateTime.Now.ToString("yyyy-MM-dd"),

                RouteDate    = R4MeUtils.ConvertToUnixTimestamp(DateTime.UtcNow.Date.AddDays(1)),
                RouteTime    = 5 * 3600 + 30 * 60,
                Optimize     = Optimize.Distance.Description(),
                DistanceUnit = DistanceUnit.MI.Description(),
                DeviceType   = DeviceType.Web.Description(),
                Bundling     = new AddressBundling()
                {
                    Mode             = AddressBundlingMode.Address,
                    MergeMode        = AddressBundlingMergeMode.KeepAsSeparateDestinations,
                    ServiceTimeRules = new ServiceTimeRulesClass()
                    {
                        FirstItemMode       = AddressBundlingFirstItemMode.KeepOriginal,
                        AdditionalItemsMode = AddressBundlingAdditionalItemsMode.KeepOriginal
                    }
                }
            };

            var optimizationParameters = new OptimizationParameters()
            {
                Addresses  = addresses,
                Parameters = parameters
            };

            // Run the query
            var dataObject = route4Me.RunOptimization(optimizationParameters, out string errorString);

            OptimizationsToRemove = new List <string>()
            {
                dataObject.OptimizationProblemId
            };

            if (dataObject == null && dataObject.GetType() != typeof(DataObject))
            {
                Console.WriteLine(
                    "BundledAddresses failed" +
                    Environment.NewLine +
                    "Cannot create the optimization. " +
                    Environment.NewLine +
                    errorString
                    );

                return;
            }

            if ((dataObject?.Routes?.Length ?? 0) < 1)
            {
                Console.WriteLine("The optimization doesn't contain route");
                RemoveTestOptimizations();
                return;
            }

            var routeId = dataObject.Routes[0].RouteID;

            if ((routeId?.Length ?? 0) < 32)
            {
                Console.WriteLine("The route ID is not valid");
                RemoveTestOptimizations();
                return;
            }

            var routeQueryParameters = new RouteParametersQuery()
            {
                RouteId       = routeId,
                BundlingItems = true
            };

            var routeBundled = route4Me.GetRoute(routeQueryParameters, out errorString);

            if ((routeBundled?.BundleItems ?? null) == null)
            {
                Console.WriteLine("Cannot retrieve bundled items in the route response.");
                RemoveTestOptimizations();
                return;
            }

            PrintExampleRouteResult(routeBundled, errorString);

            RemoveTestOptimizations();
        }
Esempio n. 7
0
        /// <summary>
        /// The example refers to the process of creating an optimization
        /// with slow-down parameters.
        /// </summary>
        public void RouteSlowdown()
        {
            var route4Me = new Route4MeManager(ActualApiKey);

            // Prepare the addresses
            var addresses = new Address[]
            {
                #region Addresses

                new Address()
                {
                    AddressString = "754 5th Ave New York, NY 10019",
                    Alias         = "Bergdorf Goodman",
                    IsDepot       = true,
                    Latitude      = 40.7636197,
                    Longitude     = -73.9744388,
                    Time          = 0
                },

                new Address()
                {
                    AddressString = "717 5th Ave New York, NY 10022",
                    //Alias         = "Giorgio Armani",
                    Latitude  = 40.7669692,
                    Longitude = -73.9693864,
                    Time      = 0
                },

                new Address()
                {
                    AddressString = "888 Madison Ave New York, NY 10014",
                    //Alias         = "Ralph Lauren Women's and Home",
                    Latitude  = 40.7715154,
                    Longitude = -73.9669241,
                    Time      = 0
                },

                new Address()
                {
                    AddressString = "1011 Madison Ave New York, NY 10075",
                    Alias         = "Yigal Azrou'l",
                    Latitude      = 40.7772129,
                    Longitude     = -73.9669,
                    Time          = 0
                },

                new Address()
                {
                    AddressString = "440 Columbus Ave New York, NY 10024",
                    Alias         = "Frank Stella Clothier",
                    Latitude      = 40.7808364,
                    Longitude     = -73.9732729,
                    Time          = 0
                },

                new Address()
                {
                    AddressString = "324 Columbus Ave #1 New York, NY 10023",
                    Alias         = "Liana",
                    Latitude      = 40.7803123,
                    Longitude     = -73.9793079,
                    Time          = 0
                },

                new Address()
                {
                    AddressString = "110 W End Ave New York, NY 10023",
                    Alias         = "Toga Bike Shop",
                    Latitude      = 40.7753077,
                    Longitude     = -73.9861529,
                    Time          = 0
                },

                new Address()
                {
                    AddressString = "555 W 57th St New York, NY 10019",
                    Alias         = "BMW of Manhattan",
                    Latitude      = 40.7718005,
                    Longitude     = -73.9897716,
                    Time          = 0
                },

                new Address()
                {
                    AddressString = "57 W 57th St New York, NY 10019",
                    Alias         = "Verizon Wireless",
                    Latitude      = 40.7558695,
                    Longitude     = -73.9862019,
                    Time          = 0
                },

                #endregion
            };

            // Set parameters
            var parameters = new RouteParameters()
            {
                AlgorithmType = AlgorithmType.TSP,
                RouteName     = "Single Driver Round Trip",

                RouteDate            = R4MeUtils.ConvertToUnixTimestamp(DateTime.UtcNow.Date.AddDays(1)),
                RouteTime            = 60 * 60 * 7,
                RouteMaxDuration     = 86400,
                VehicleCapacity      = 1,
                VehicleMaxDistanceMI = 10000,

                Optimize     = Optimize.Time.Description(),
                DistanceUnit = DistanceUnit.MI.Description(),
                DeviceType   = DeviceType.Web.Description(),
                TravelMode   = TravelMode.Driving.Description(),

                Slowdowns = new SlowdownParams(15, 20)
            };

            var optimizationParameters = new OptimizationParameters()
            {
                Addresses  = addresses,
                Parameters = parameters
            };

            // Run the query
            var dataObject = route4Me.RunOptimization(
                optimizationParameters,
                out string errorString);

            OptimizationsToRemove = new List <string>()
            {
                dataObject?.OptimizationProblemId ?? null
            };

            PrintExampleOptimizationResult(dataObject, errorString);

            Console.WriteLine("");

            Console.WriteLine(
                "RouteServiceTimeMultiplier: " +
                (dataObject?.Parameters?.RouteServiceTimeMultiplier ?? null)
                );

            Console.WriteLine(
                "RouteTimeMultiplier: " +
                (dataObject?.Parameters?.RouteTimeMultiplier ?? null)
                );

            RemoveTestOptimizations();
        }
        public bool RunOptimizationSingleDriverRoute10Stops()
        {
            var r4mm = new Route4MeManagerV5(c_ApiKey);

            // Prepare the addresses
            Address[] addresses = new Address[]
            {
                #region Addresses

                new Address()
                {
                    AddressString = "151 Arbor Way Milledgeville GA 31061",
                    //indicate that this is a departure stop
                    //single depot routes can only have one departure depot
                    IsDepot = true,

                    //required coordinates for every departure and stop on the route
                    Latitude  = 33.132675170898,
                    Longitude = -83.244743347168,

                    //the expected time on site, in seconds. this value is incorporated into the optimization engine
                    //it also adjusts the estimated and dynamic eta's for a route
                    Time = 0,


                    //input as many custom fields as needed, custom data is passed through to mobile devices and to the manifest
                    CustomFields = new Dictionary <string, string>()
                    {
                        { "color", "red" }, { "size", "huge" }
                    }
                },

                new Address()
                {
                    AddressString = "230 Arbor Way Milledgeville GA 31061",
                    Latitude      = 33.129695892334,
                    Longitude     = -83.24577331543,
                    Time          = 0
                },

                new Address()
                {
                    AddressString = "148 Bass Rd NE Milledgeville GA 31061",
                    Latitude      = 33.143497,
                    Longitude     = -83.224487,
                    Time          = 0
                },

                new Address()
                {
                    AddressString = "117 Bill Johnson Rd NE Milledgeville GA 31061",
                    Latitude      = 33.141784667969,
                    Longitude     = -83.237518310547,
                    Time          = 0
                },

                new Address()
                {
                    AddressString = "119 Bill Johnson Rd NE Milledgeville GA 31061",
                    Latitude      = 33.141086578369,
                    Longitude     = -83.238258361816,
                    Time          = 0
                },

                new Address()
                {
                    AddressString = "131 Bill Johnson Rd NE Milledgeville GA 31061",
                    Latitude      = 33.142036437988,
                    Longitude     = -83.238845825195,
                    Time          = 0
                },

                new Address()
                {
                    AddressString = "138 Bill Johnson Rd NE Milledgeville GA 31061",
                    Latitude      = 33.14307,
                    Longitude     = -83.239334,
                    Time          = 0
                },

                new Address()
                {
                    AddressString = "139 Bill Johnson Rd NE Milledgeville GA 31061",
                    Latitude      = 33.142734527588,
                    Longitude     = -83.237442016602,
                    Time          = 0
                },

                new Address()
                {
                    AddressString = "145 Bill Johnson Rd NE Milledgeville GA 31061",
                    Latitude      = 33.143871307373,
                    Longitude     = -83.237342834473,
                    Time          = 0
                },

                new Address()
                {
                    AddressString = "221 Blake Cir Milledgeville GA 31061",
                    Latitude      = 33.081462860107,
                    Longitude     = -83.208511352539,
                    Time          = 0
                }

                #endregion
            };

            // Set parameters
            var parameters = new RouteParameters()
            {
                AlgorithmType = AlgorithmType.TSP,
                //StoreRoute = false,
                RouteName = "Single Driver Route 10 Stops Test",

                RouteDate    = R4MeUtils.ConvertToUnixTimestamp(DateTime.UtcNow.Date.AddDays(1)),
                RouteTime    = 60 * 60 * 7,
                Optimize     = Optimize.Distance.Description(),
                DistanceUnit = DistanceUnit.MI.Description(),
                DeviceType   = DeviceType.Web.Description()
            };

            var optimizationParameters = new OptimizationParameters()
            {
                Addresses  = addresses,
                Parameters = parameters
            };

            // Run the query
            //string errorString;

            try
            {
                dataObjectSD10Stops = r4mm.RunOptimization(optimizationParameters, out ResultResponse resultResponse);

                SD10Stops_optimization_problem_id = dataObjectSD10Stops.OptimizationProblemId;
                SD10Stops_route = (dataObjectSD10Stops != null &&
                                   dataObjectSD10Stops.Routes != null &&
                                   dataObjectSD10Stops.Routes.Length > 0)
                                  ? dataObjectSD10Stops.Routes[0]
                                  : null;
                SD10Stops_route_id = SD10Stops_route != null ? SD10Stops_route.RouteID : null;

                return(true);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Single Driver Route 10 Stops generation failed. " + ex.Message);
                return(false);
            }
        }
        public bool RunSingleDriverRoundTrip()
        {
            var route4Me = new Route4MeManagerV5(c_ApiKey);

            // Prepare the addresses
            Address[] addresses = new Address[]
            {
                #region Addresses

                new Address()
                {
                    AddressString = "754 5th Ave New York, NY 10019",
                    Alias         = "Bergdorf Goodman",
                    IsDepot       = true,
                    Latitude      = 40.7636197,
                    Longitude     = -73.9744388,
                    Time          = 0
                },

                new Address()
                {
                    AddressString = "717 5th Ave New York, NY 10022",
                    Alias         = "Giorgio Armani",
                    Latitude      = 40.7669692,
                    Longitude     = -73.9693864,
                    Time          = 0
                },

                new Address()
                {
                    AddressString = "888 Madison Ave New York, NY 10014",
                    Alias         = "Ralph Lauren Women's and Home",
                    Latitude      = 40.7715154,
                    Longitude     = -73.9669241,
                    Time          = 0
                },

                new Address()
                {
                    AddressString = "1011 Madison Ave New York, NY 10075",
                    Alias         = "Yigal Azrou'l",
                    Latitude      = 40.7772129,
                    Longitude     = -73.9669,
                    Time          = 0
                },

                new Address()
                {
                    AddressString = "440 Columbus Ave New York, NY 10024",
                    Alias         = "Frank Stella Clothier",
                    Latitude      = 40.7808364,
                    Longitude     = -73.9732729,
                    Time          = 0
                },

                new Address()
                {
                    AddressString = "324 Columbus Ave #1 New York, NY 10023",
                    Alias         = "Liana",
                    Latitude      = 40.7803123,
                    Longitude     = -73.9793079,
                    Time          = 0
                },

                new Address()
                {
                    AddressString = "110 W End Ave New York, NY 10023",
                    Alias         = "Toga Bike Shop",
                    Latitude      = 40.7753077,
                    Longitude     = -73.9861529,
                    Time          = 0
                },

                new Address()
                {
                    AddressString = "555 W 57th St New York, NY 10019",
                    Alias         = "BMW of Manhattan",
                    Latitude      = 40.7718005,
                    Longitude     = -73.9897716,
                    Time          = 0
                },

                new Address()
                {
                    AddressString = "57 W 57th St New York, NY 10019",
                    Alias         = "Verizon Wireless",
                    Latitude      = 40.7558695,
                    Longitude     = -73.9862019,
                    Time          = 0
                },

                #endregion
            };

            // Set parameters
            var parameters = new RouteParameters()
            {
                AlgorithmType = AlgorithmType.TSP,
                //StoreRoute = false,
                RouteName = "Single Driver Round Trip",

                RouteDate            = R4MeUtils.ConvertToUnixTimestamp(DateTime.UtcNow.Date.AddDays(1)),
                RouteTime            = 60 * 60 * 7,
                RouteMaxDuration     = 86400,
                VehicleCapacity      = 1,
                VehicleMaxDistanceMI = 10000,
                RT = true,

                Optimize     = Optimize.Distance.Description(),
                DistanceUnit = DistanceUnit.MI.Description(),
                DeviceType   = DeviceType.Web.Description(),
                TravelMode   = TravelMode.Driving.Description(),
            };

            var optimizationParameters = new OptimizationParameters()
            {
                Addresses  = addresses,
                Parameters = parameters
            };

            // Run the query
            //string errorString;

            try
            {
                dataObjectSDRT = route4Me.RunOptimization(optimizationParameters, out ResultResponse resultResponse);

                SDRT_optimization_problem_id = dataObjectSDRT.OptimizationProblemId;

                SDRT_route = (dataObjectSDRT != null &&
                              dataObjectSDRT.Routes != null &&
                              dataObjectSDRT.Routes.Length > 0)
                             ? dataObjectSDRT.Routes[0]
                             : null;

                SDRT_route_id = (SDRT_route != null) ? SDRT_route.RouteID : null;

                return(true);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Single Driver Round Trip generation failed. " + ex.Message);
                return(false);
            }
        }
        /// <summary>
        /// The example refers to the process of creating an optimization
        /// with separate depot segment and multi-depot, multi-driver,
        /// time windows options.
        /// </summary>
        public void MultipleSeparateDepostMultipleDriver()
        {
            var route4Me = new Route4MeManager(ActualApiKey);

            #region Depots
            Address[] depots = new Address[]
            {
                new Address()
                {
                    AddressString = "3634 W Market St, Fairlawn, OH 44333",
                    Latitude      = 41.135762259364,
                    Longitude     = -81.629313826561
                },

                new Address()
                {
                    AddressString = "2705 N River Rd, Stow, OH 44224",
                    Latitude      = 41.145240783691,
                    Longitude     = -81.410247802734
                }
            };
            #endregion

            // Prepare the addresses
            Address[] addresses = new Address[]
            {
                #region Addresses

                new Address()
                {
                    AddressString   = "1218 Ruth Ave, Cuyahoga Falls, OH 44221",
                    Latitude        = 41.135762259364,
                    Longitude       = -81.629313826561,
                    Time            = 300,
                    TimeWindowStart = 29465,
                    TimeWindowEnd   = 30529
                },

                new Address()
                {
                    AddressString   = "512 Florida Pl, Barberton, OH 44203",
                    Latitude        = 41.003671512008,
                    Longitude       = -81.598461046815,
                    Time            = 300,
                    TimeWindowStart = 30529,
                    TimeWindowEnd   = 33779
                },

                new Address()
                {
                    AddressString   = "512 Florida Pl, Barberton, OH 44203",
                    Latitude        = 41.003671512008,
                    Longitude       = -81.598461046815,
                    Time            = 100,
                    TimeWindowStart = 33779,
                    TimeWindowEnd   = 33944
                },

                new Address()
                {
                    AddressString   = "3495 Purdue St, Cuyahoga Falls, OH 44221",
                    Latitude        = 41.162971496582,
                    Longitude       = -81.479049682617,
                    Time            = 300,
                    TimeWindowStart = 33944,
                    TimeWindowEnd   = 34801
                },

                new Address()
                {
                    AddressString   = "1659 Hibbard Dr, Stow, OH 44224",
                    Latitude        = 41.194505989552,
                    Longitude       = -81.443351581693,
                    Time            = 300,
                    TimeWindowStart = 34801,
                    TimeWindowEnd   = 36366
                },

                new Address()
                {
                    AddressString   = "10159 Bissell Dr, Twinsburg, OH 44087",
                    Latitude        = 41.340042114258,
                    Longitude       = -81.421226501465,
                    Time            = 300,
                    TimeWindowStart = 39173,
                    TimeWindowEnd   = 41617
                },

                new Address()
                {
                    AddressString   = "367 Cathy Dr, Munroe Falls, OH 44262",
                    Latitude        = 41.148578643799,
                    Longitude       = -81.429229736328,
                    Time            = 300,
                    TimeWindowStart = 41617,
                    TimeWindowEnd   = 43660
                },

                new Address()
                {
                    AddressString   = "367 Cathy Dr, Munroe Falls, OH 44262",
                    Latitude        = 41.148578643799,
                    Longitude       = -81.429229736328,
                    Time            = 300,
                    TimeWindowStart = 43660,
                    TimeWindowEnd   = 46392
                },

                new Address()
                {
                    AddressString   = "512 Florida Pl, Barberton, OH 44203",
                    Latitude        = 41.003671512008,
                    Longitude       = -81.598461046815,
                    Time            = 300,
                    TimeWindowStart = 46392,
                    TimeWindowEnd   = 48389
                },

                new Address()
                {
                    AddressString   = "559 W Aurora Rd, Northfield, OH 44067",
                    Latitude        = 41.315116882324,
                    Longitude       = -81.558746337891,
                    Time            = 50,
                    TimeWindowStart = 48389,
                    TimeWindowEnd   = 48449
                },

                new Address()
                {
                    AddressString   = "3933 Klein Ave, Stow, OH 44224",
                    Latitude        = 41.169467926025,
                    Longitude       = -81.429420471191,
                    Time            = 300,
                    TimeWindowStart = 48449,
                    TimeWindowEnd   = 50152
                },

                new Address()
                {
                    AddressString   = "2148 8th St, Cuyahoga Falls, OH 44221",
                    Latitude        = 41.136692047119,
                    Longitude       = -81.493492126465,
                    Time            = 300,
                    TimeWindowStart = 50152,
                    TimeWindowEnd   = 51982
                },

                new Address()
                {
                    AddressString   = "3731 Osage St, Stow, OH 44224",
                    Latitude        = 41.161357879639,
                    Longitude       = -81.42293548584,
                    Time            = 100,
                    TimeWindowStart = 51982,
                    TimeWindowEnd   = 52180
                },

                new Address()
                {
                    AddressString   = "3731 Osage St, Stow, OH 44224",
                    Latitude        = 41.161357879639,
                    Longitude       = -81.42293548584,
                    Time            = 300,
                    TimeWindowStart = 52180,
                    TimeWindowEnd   = 54379
                }

                #endregion
            };

            // Set parameters
            var parameters = new RouteParameters()
            {
                //specify capacitated vehicle routing with time windows and multiple depots, with multiple drivers
                AlgorithmType = AlgorithmType.CVRP_TW_MD,

                //set an arbitrary route name
                //this value shows up in the website, and all the connected mobile device
                RouteName = "Multiple Separate Depots, Multiple Driver",

                //the route start date in UTC, unix timestamp seconds (Tomorrow)
                RouteDate = R4MeUtils.ConvertToUnixTimestamp(DateTime.UtcNow.Date.AddDays(1)),
                //the time in UTC when a route is starting (7AM)
                RouteTime = 60 * 60 * 7,

                //the maximum duration of a route
                RouteMaxDuration     = 86400,
                VehicleCapacity      = 5,
                VehicleMaxDistanceMI = 10000,

                Optimize     = Optimize.Distance.Description(),
                DistanceUnit = DistanceUnit.MI.Description(),
                DeviceType   = DeviceType.Web.Description(),
                TravelMode   = TravelMode.Driving.Description(),
                Metric       = Metric.Matrix
            };

            var optimizationParameters = new OptimizationParameters()
            {
                Addresses  = addresses,
                Parameters = parameters,
                Depots     = depots
            };

            // Run the query
            var dataObject = route4Me.RunOptimization(
                optimizationParameters,
                out string errorString);

            OptimizationsToRemove = new List <string>()
            {
                dataObject?.OptimizationProblemId ?? null
            };

            PrintExampleOptimizationResult(dataObject, errorString);

            var optimizationDepots = dataObject.Addresses.Where(x => x.IsDepot == true);

            if (optimizationDepots.Count() != depots.Length)
            {
                Console.WriteLine("The depots number is not " + depots.Length);
                RemoveTestOptimizations();
                return;
            }

            List <string> depotAddresses = depots.Select(x => x.AddressString).ToList();

            foreach (var depot in optimizationDepots)
            {
                if (!depotAddresses.Contains(depot.AddressString))
                {
                    Console.WriteLine("The address " + depot.AddressString + " is not depot");
                }
            }

            RemoveTestOptimizations();
        }
        /// <summary>
        /// Update route by sending a modified whole route object.
        /// </summary>
        public void UpdateWholeRoute()
        {
            var route4Me = new Route4MeManager(ActualApiKey);

            RunOptimizationSingleDriverRoute10Stops();
            OptimizationsToRemove = new List <string>()
            {
                SD10Stops_optimization_problem_id
            };

            string routeId = SD10Stops_route_id;

            var initialRoute = R4MeUtils.ObjectDeepClone <DataObjectRoute>(SD10Stops_route);

            #region // Notes, Custom Type Notes, Note File Uploading

            var customNotesResponse = route4Me.getAllCustomNoteTypes(out string errorString5);

            var allCustomNotes = customNotesResponse != null && customNotesResponse.GetType() == typeof(CustomNoteType[])
                ? (CustomNoteType[])customNotesResponse : null;

            string tempFilePath = null;
            using (Stream stream = Assembly
                                   .GetExecutingAssembly()
                                   .GetManifestResourceStream("Route4MeSDKTest.Resources.test.png"))
            {
                var tempFiles = new TempFileCollection();
                {
                    tempFilePath = tempFiles.AddExtension("png");

                    Console.WriteLine(tempFilePath);

                    using (Stream fileStream = File.OpenWrite(tempFilePath))
                    {
                        stream.CopyTo(fileStream);
                    }
                }
            }

            SD10Stops_route.Addresses[1].Notes = new AddressNote[] {
                new AddressNote()
                {
                    NoteId       = -1,
                    RouteId      = SD10Stops_route.RouteID,
                    Latitude     = SD10Stops_route.Addresses[1].Latitude,
                    Longitude    = SD10Stops_route.Addresses[1].Longitude,
                    ActivityType = "dropoff",
                    Contents     = "C# SDK Test Content",
                    CustomTypes  = allCustomNotes.Length > 0
                    ? new AddressCustomNote[]
                    {
                        new AddressCustomNote()
                        {
                            NoteCustomTypeID = allCustomNotes[0].NoteCustomTypeID.ToString(),
                            NoteCustomValue  = allCustomNotes[0].NoteCustomTypeValues[0]
                        }
                    }
                    : null,
                    UploadUrl = tempFilePath
                }
            };

            var updatedRoute0 = route4Me.UpdateRoute(
                SD10Stops_route,
                initialRoute,
                out string errorString0
                );

            if ((updatedRoute0?.Addresses[1]?.Notes.Length ?? 0) != 1)
            {
                Console.WriteLine("UpdateRouteTest failed: cannot create a note");
            }

            if (allCustomNotes.Length > 0)
            {
                Assert.IsTrue(updatedRoute0.Addresses[1].Notes[0].CustomTypes.Length == 1, "UpdateRouteTest failed: cannot create a custom type note");
            }

            Assert.IsTrue(updatedRoute0.Addresses[1].Notes[0].UploadId.Length == 32, "UpdateRouteTest failed: cannot create a custom type note");

            #endregion

            SD10Stops_route.ApprovedForExecution  = true;
            SD10Stops_route.Parameters.RouteName += " Edited";
            SD10Stops_route.Parameters.Metric     = Metric.Manhattan;

            SD10Stops_route.Addresses[1].AddressString += " Edited";
            SD10Stops_route.Addresses[1].Group          = "Example Group";
            SD10Stops_route.Addresses[1].CustomerPo     = "CPO 456789";
            SD10Stops_route.Addresses[1].InvoiceNo      = "INO 789654";
            SD10Stops_route.Addresses[1].ReferenceNo    = "RNO 313264";
            SD10Stops_route.Addresses[1].OrderNo        = "ONO 654878";
            SD10Stops_route.Addresses[1].Notes          = new AddressNote[] {
                new AddressNote()
                {
                    RouteDestinationId = -1,
                    RouteId            = SD10Stops_route.RouteID,
                    Latitude           = SD10Stops_route.Addresses[1].Latitude,
                    Longitude          = SD10Stops_route.Addresses[1].Longitude,
                    ActivityType       = "dropoff",
                    Contents           = "C# SDK Test Content"
                }
            };

            SD10Stops_route.Addresses[2].SequenceNo = 5;
            var addressID = SD10Stops_route.Addresses[2].RouteDestinationId;

            var dataObject = route4Me.UpdateRoute(
                SD10Stops_route,
                initialRoute,
                out string errorString
                );

            Assert.IsTrue(dataObject.Addresses.Where(x => x.RouteDestinationId == addressID)
                          .FirstOrDefault()
                          .SequenceNo == 5, "UpdateWholeRouteTest failed.");

            Assert.IsTrue(SD10Stops_route.ApprovedForExecution, "UpdateRouteTest failed, ApprovedForExecution cannot set to true");
            Assert.IsNotNull(dataObject, "UpdateRouteTest failed. " + errorString);
            Assert.IsTrue(dataObject.Parameters.RouteName.Contains("Edited"), "UpdateRouteTest failed, the route name not changed.");
            Assert.IsTrue(dataObject.Addresses[1].AddressString.Contains("Edited"), "UpdateRouteTest failed, second address name not changed.");

            Assert.IsTrue(dataObject.Addresses[1].Group == "Example Group", "UpdateWholeRouteTest failed.");
            Assert.IsTrue(dataObject.Addresses[1].CustomerPo == "CPO 456789", "UpdateWholeRouteTest failed.");
            Assert.IsTrue(dataObject.Addresses[1].InvoiceNo == "INO 789654", "UpdateWholeRouteTest failed.");
            Assert.IsTrue(dataObject.Addresses[1].ReferenceNo == "RNO 313264", "UpdateWholeRouteTest failed.");
            Assert.IsTrue(dataObject.Addresses[1].OrderNo == "ONO 654878", "UpdateWholeRouteTest failed.");

            initialRoute = R4MeUtils.ObjectDeepClone <DataObjectRoute>(SD10Stops_route);

            SD10Stops_route.ApprovedForExecution     = false;
            SD10Stops_route.Addresses[1].Group       = null;
            SD10Stops_route.Addresses[1].CustomerPo  = null;
            SD10Stops_route.Addresses[1].InvoiceNo   = null;
            SD10Stops_route.Addresses[1].ReferenceNo = null;
            SD10Stops_route.Addresses[1].OrderNo     = null;

            dataObject = route4Me.UpdateRoute(
                SD10Stops_route,
                initialRoute,
                out errorString
                );

            PrintExampleRouteResult(dataObject, errorString);

            RemoveTestOptimizations();
        }
Esempio n. 12
0
        public DataObject SingleDriverRoundTrip()
        {
            // Create the manager with the api key
            Route4MeManager route4Me = new Route4MeManager(c_ApiKey);

            // Prepare the addresses
            Address[] addresses = new Address[]
            {
                #region Addresses

                new Address()
                {
                    AddressString = "754 5th Ave New York, NY 10019",
                    Alias         = "Bergdorf Goodman",
                    IsDepot       = true,
                    Latitude      = 40.7636197,
                    Longitude     = -73.9744388,
                    Time          = 0
                },

                new Address()
                {
                    AddressString = "717 5th Ave New York, NY 10022",
                    Alias         = "Giorgio Armani",
                    Latitude      = 40.7669692,
                    Longitude     = -73.9693864,
                    Time          = 0
                },

                new Address()
                {
                    AddressString = "888 Madison Ave New York, NY 10014",
                    Alias         = "Ralph Lauren Women's and Home",
                    Latitude      = 40.7715154,
                    Longitude     = -73.9669241,
                    Time          = 0
                },

                new Address()
                {
                    AddressString = "1011 Madison Ave New York, NY 10075",
                    Alias         = "Yigal Azrou'l",
                    Latitude      = 40.7772129,
                    Longitude     = -73.9669,
                    Time          = 0
                },

                new Address()
                {
                    AddressString = "440 Columbus Ave New York, NY 10024",
                    Alias         = "Frank Stella Clothier",
                    Latitude      = 40.7808364,
                    Longitude     = -73.9732729,
                    Time          = 0
                },

                new Address()
                {
                    AddressString = "324 Columbus Ave #1 New York, NY 10023",
                    Alias         = "Liana",
                    Latitude      = 40.7803123,
                    Longitude     = -73.9793079,
                    Time          = 0
                },

                new Address()
                {
                    AddressString = "110 W End Ave New York, NY 10023",
                    Alias         = "Toga Bike Shop",
                    Latitude      = 40.7753077,
                    Longitude     = -73.9861529,
                    Time          = 0
                },

                new Address()
                {
                    AddressString = "555 W 57th St New York, NY 10019",
                    Alias         = "BMW of Manhattan",
                    Latitude      = 40.7718005,
                    Longitude     = -73.9897716,
                    Time          = 0
                },

                new Address()
                {
                    AddressString = "57 W 57th St New York, NY 10019",
                    Alias         = "Verizon Wireless",
                    Latitude      = 40.7558695,
                    Longitude     = -73.9862019,
                    Time          = 0
                },

                #endregion
            };

            // Set parameters
            RouteParameters parameters = new RouteParameters()
            {
                AlgorithmType = AlgorithmType.TSP,
                StoreRoute    = false,
                RouteName     = "Single Driver Round Trip",

                RouteDate            = R4MeUtils.ConvertToUnixTimestamp(DateTime.UtcNow.Date.AddDays(1)),
                RouteTime            = 60 * 60 * 7,
                RouteMaxDuration     = 86400,
                VehicleCapacity      = 1,
                VehicleMaxDistanceMI = 10000,

                Optimize     = Optimize.Distance.Description(),
                DistanceUnit = DistanceUnit.KM.Description(),
                DeviceType   = DeviceType.Web.Description(),
                TravelMode   = TravelMode.Driving.Description(),
            };

            OptimizationParameters optimizationParameters = new OptimizationParameters()
            {
                Addresses  = addresses,
                Parameters = parameters
            };

            // Run the query
            string     errorString;
            DataObject dataObject = route4Me.RunOptimization(optimizationParameters, out errorString);

            // Output the result
            PrintExampleOptimizationResult("SingleDriverRoundTrip", dataObject, errorString);

            return(dataObject);
        }
        /* Method for importing an addressbook CSV file (with structure equal to exported by Route4Me web UI CSV file) to an addressbook table on the SQL type server.
         * sFileName --- CSV file name.
         * sTableName --- Server addressbook table name.
         * sIdName --- The name of id column of the server addressbook table (it's differs from address_id, you need it for editing prior updloading to the Route4Me server)
         * isFirstRowHeader --- If true, first column of the CSV file is header.
         * */
        public void Csv2Table(string sFileName, string sTableName, string sIdName, int iFieldsNumber, bool isFirstRowHeader)
        {
            if (!File.Exists(sFileName))
            {
                Console.WriteLine("The file " + sFileName + " doesn't exist..."); return;
            }

            string header = isFirstRowHeader ? "Yes" : "No";

            string pathOnly = System.IO.Path.GetDirectoryName(sFileName);
            string fileName = System.IO.Path.GetFileName(sFileName);

            string csvCom = @"SELECT * FROM [" + fileName + "]";

            DataTable tblDictionary = GetCsv2ApiDictionary(sTableName);

            DataTable tblTempTable = new DataTable();

            using (OleDbConnection csvCon = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + pathOnly + ";Extended Properties=\"Text;HDR=" + header + "\""))
                using (OleDbCommand comCsv = new OleDbCommand(csvCom, csvCon))
                    using (OleDbDataAdapter csvAdapter = new OleDbDataAdapter(comCsv))
                    {
                        tblTempTable.Locale = System.Globalization.CultureInfo.CurrentCulture;
                        csvAdapter.Fill(tblTempTable);
                    }

            foreach (DataRow row in tblTempTable.Rows)
            {
                int id = -1;

                bool blNew = true;

                if (row.Table.Columns.Contains(sIdName))
                {
                    if (int.TryParse(row[sIdName].ToString(), out id))
                    {
                        id = Convert.ToInt32(row[sIdName]);
                    }

                    if (id > 0)
                    {
                        blNew = IsNewAddress(sTableName, sIdName, id);
                    }
                }
                string sList   = "(";
                string sValues = "Values (";

                if (!blNew)
                {
                    sList = "SET ";

                    for (int iCol = 0; iCol < iFieldsNumber; iCol++)
                    {
                        bool isValid = IsValidValue(tblTempTable.Columns[iCol], row[iCol]);
                        if (isValid)
                        {
                            string sCsvFieldName = tblTempTable.Columns[iCol].ColumnName;

                            if (sCsvFieldName == sIdName)
                            {
                                continue;
                            }

                            DataRow[] arRows = tblDictionary.Select("r4m_csv_field_name='" + sCsvFieldName + "'");
                            if (arRows.Length == 1)
                            {
                                string sFieldApiName = arRows[0]["api_field_name"].ToString();
                                string sApiFieldType = arRows[0]["api_field_type"].ToString();
                                string sCsvFieldType = arRows[0]["csv_field_type"].ToString();

                                if (sFieldApiName == "day_scheduled_for_YYMMDD")
                                {
                                    var oSchedule = ExceptFields2QueryValue(sFieldApiName, row[iCol]);
                                    if (oSchedule == null)
                                    {
                                        sList += sFieldApiName + "=null,";
                                    }
                                    else
                                    {
                                        sList += sFieldApiName + "='" + oSchedule + "',";
                                    }
                                }
                                else
                                {
                                    switch (tblTempTable.Columns[iCol].DataType.Name)
                                    {
                                    case "String":
                                        sList += sFieldApiName + "=N'" + row[iCol].ToString() + "',";
                                        break;

                                    case "Int32":
                                        sList += sFieldApiName + "=" + row[iCol].ToString() + ",";;
                                        break;

                                    case "Double":
                                        sList += sFieldApiName + "=" + row[iCol].ToString() + ",";
                                        break;

                                    case "DateTime":
                                        DateTime dt1900 = new DateTime(1900, 1, 1, 0, 0, 0);
                                        if (DateTime.TryParse(row[iCol].ToString(), out dt1900))
                                        {
                                            dt1900 = Convert.ToDateTime(row[iCol]);
                                            if (sApiFieldType != sCsvFieldType && sApiFieldType == "int")
                                            {
                                                long iUnixTime = R4MeUtils.ConvertToUnixTimestamp(dt1900);
                                                sList += sFieldApiName + "=" + iUnixTime + ",";
                                            }
                                            else
                                            {
                                                if (_conStngInstitute.ProviderName == "System.Data.OleDb")
                                                {
                                                    sList += sFieldApiName + "=#" + dt1900.ToString("yyyy-MM-dd HH:mm:ss") + "#,";
                                                }
                                                else
                                                {
                                                    sList += sFieldApiName + "='" + dt1900.ToString("yyyy-MM-dd HH:mm:ss") + "',";
                                                }
                                            }
                                        }
                                        break;
                                    }
                                }
                            }
                            else
                            {
                                continue;
                            }
                        }
                    }
                    sList = sList.TrimEnd(',');

                    if (tblTempTable.Columns.Count > 33)
                    {
                        System.Text.StringBuilder sbCustom = new System.Text.StringBuilder();
                        sbCustom.Append("{");
                        for (int iCol = 33; iCol < tblTempTable.Columns.Count; iCol++)
                        {
                            System.Text.StringBuilder sbCustom1 = new System.Text.StringBuilder();
                            sbCustom1.Append("{");
                            for (int iCol1 = 33; iCol1 < tblTempTable.Columns.Count; iCol1++)
                            {
                                bool isValid = IsValidValue(tblTempTable.Columns[iCol1], row[iCol1]);
                                if (isValid)
                                {
                                    if (tblTempTable.Columns[iCol1].DataType.Name == "String")
                                    {
                                        string sFieldName = tblTempTable.Columns[iCol1].ColumnName;
                                        string sValue     = row[iCol1].ToString();
                                        sbCustom1.Append("\"" + sFieldName + "\": \"" + sValue + "\",");
                                    }
                                }
                            }
                            string sCustom = sbCustom.ToString();
                            sCustom  = sCustom.TrimEnd(',');
                            sCustom += "}";
                            if (sCustom.Length > 3)
                            {
                                sList += "address_custom_data='" + " N'" + sCustom + "'";
                            }
                        }
                    }

                    string sQuery2 = "UPDATE " + sTableName + " " + sList + " WHERE " + sIdName + "=" + id;

                    int iResult2 = ExecuteNon(sQuery2);

                    if (iResult2 > 0)
                    {
                        Console.WriteLine(":) The row with " + sIdName + "d=" + id + " was updated in the table " + sTableName);
                    }
                    else
                    {
                        Console.WriteLine(":( Can not updated the row in the table " + sTableName);
                    }
                }
                else
                {
                    for (int iCol = 0; iCol < iFieldsNumber; iCol++)
                    {
                        bool isValid = IsValidValue(tblTempTable.Columns[iCol], row[iCol]);

                        if (isValid)
                        {
                            string    sCvsFieldName = tblTempTable.Columns[iCol].ColumnName;
                            DataRow[] arRows        = tblDictionary.Select("r4m_csv_field_name='" + sCvsFieldName + "'");
                            if (arRows.Length == 1)
                            {
                                string sFieldApiName = arRows[0]["api_field_name"].ToString();
                                string sApiFieldType = arRows[0]["api_field_type"].ToString();
                                string sCsvFieldType = arRows[0]["csv_field_type"].ToString();

                                //sFields += prop.Name + ",";
                                if (sFieldApiName == "day_scheduled_for_YYMMDD")
                                {
                                    sList += sFieldApiName + ",";
                                    var oSchedule = ExceptFields2QueryValue(sFieldApiName, row[iCol]);
                                    if (oSchedule == null)
                                    {
                                        sValues += "null";
                                    }
                                    else
                                    {
                                        sValues += "'" + oSchedule + "',";
                                    }
                                }
                                else
                                {
                                    switch (tblTempTable.Columns[iCol].DataType.Name)
                                    {
                                    case "String":
                                        sList   += sFieldApiName + ",";
                                        sValues += "N'" + row[iCol].ToString() + "',";
                                        break;

                                    case "Int32":
                                        sList   += sFieldApiName + ",";
                                        sValues += row[iCol].ToString() + ",";
                                        break;

                                    case "Double":
                                        sList   += sFieldApiName + ",";
                                        sValues += row[iCol].ToString() + ",";
                                        break;

                                    case "DateTime":
                                        DateTime dt1900 = new DateTime(1900, 1, 1, 0, 0, 0);
                                        if (DateTime.TryParse(row[iCol].ToString(), out dt1900))
                                        {
                                            dt1900 = Convert.ToDateTime(row[iCol]);
                                            sList += sFieldApiName + ",";
                                            if (sApiFieldType != sCsvFieldType && sApiFieldType == "int")
                                            {
                                                long iUnixTime = R4MeUtils.ConvertToUnixTimestamp(dt1900);
                                                sValues += iUnixTime + ",";
                                            }
                                            else
                                            {
                                                if (_conStngInstitute.ProviderName == "System.Data.OleDb")
                                                {
                                                    sValues += "#" + dt1900.ToString("yyyy-MM-dd HH:mm:ss") + "#,";
                                                }
                                                else
                                                {
                                                    sValues += "'" + dt1900.ToString("yyyy-MM-dd HH:mm:ss") + "',";
                                                }
                                            }
                                        }
                                        break;
                                    }
                                }
                            }
                        }
                    }

                    #region custom fields in case of the addressbook contact, added in csv export as additional columns.
                    if (tblTempTable.Columns.Count > 33)
                    {
                        System.Text.StringBuilder sbCustom = new System.Text.StringBuilder();
                        sbCustom.Append("{");
                        for (int iCol = 33; iCol < tblTempTable.Columns.Count; iCol++)
                        {
                            bool isValid = IsValidValue(tblTempTable.Columns[iCol], row[iCol]);
                            if (isValid)
                            {
                                if (tblTempTable.Columns[iCol].DataType.Name == "String")
                                {
                                    string sFieldName = tblTempTable.Columns[iCol].ColumnName;
                                    string sValue     = row[iCol].ToString();
                                    sbCustom.Append("\"" + sFieldName + "\": \"" + sValue + "\",");
                                }
                            }
                        }
                        string sCustom = sbCustom.ToString();
                        sCustom  = sCustom.TrimEnd(',');
                        sCustom += "}";
                        if (sCustom.Length > 3)
                        {
                            sList   += "address_custom_data,";
                            sValues += " N'" + sCustom + "'";
                        }
                    }
                    #endregion

                    sList   = sList.TrimEnd(','); sList += ")";
                    sValues = sValues.TrimEnd(','); sValues += ")";
                    string sQuery1 = "INSERT INTO " + sTableName + " " + sList + " " + sValues;

                    int iResult = ExecuteNon(sQuery1);

                    if (iResult > 0)
                    {
                        Console.WriteLine(":) New row with " + sIdName + "=" + id + " was added to the table " + sTableName);
                    }
                    else
                    {
                        Console.WriteLine(":( Can not created new row in the table " + sTableName);
                    }
                }
            }
        }
Esempio n. 14
0
        public void ExampleOptimization()
        {
            var Route4Me = new Route4MeManager(ActualApiKey);

            var dateWhenTheRouteStart = R4MeUtils.ConvertToUnixTimestamp(DateTime.UtcNow.Date.AddDays(1));

            var addresses = new List <Address>()
            {
                #region Addresses

                new Address()
                {
                    AddressString = "754 5th Ave New York, NY 10019",
                    Alias         = "Bergdorf Goodman",
                    IsDepot       = true,
                    Latitude      = 40.7636197,
                    Longitude     = -73.9744388,
                    Time          = 0
                },

                new Address()
                {
                    AddressString = "717 5th Ave New York, NY 10022",
                    Alias         = "Giorgio Armani",
                    Latitude      = 40.7669692,
                    Longitude     = -73.9693864,
                    Time          = 0
                },

                new Address()
                {
                    AddressString = "888 Madison Ave New York, NY 10014",
                    Alias         = "Ralph Lauren Women's and Home",
                    Latitude      = 40.7715154,
                    Longitude     = -73.9669241,
                    Time          = 0
                },

                new Address()
                {
                    AddressString = "1011 Madison Ave New York, NY 10075",
                    Alias         = "Yigal Azrou'l",
                    Latitude      = 40.7772129,
                    Longitude     = -73.9669,
                    Time          = 0
                },

                new Address()
                {
                    AddressString = "440 Columbus Ave New York, NY 10024",
                    Alias         = "Frank Stella Clothier",
                    Latitude      = 40.7808364,
                    Longitude     = -73.9732729,
                    Time          = 0
                },

                new Address()
                {
                    AddressString = "324 Columbus Ave #1 New York, NY 10023",
                    Alias         = "Liana",
                    Latitude      = 40.7803123,
                    Longitude     = -73.9793079,
                    Time          = 0
                },

                new Address()
                {
                    AddressString = "110 W End Ave New York, NY 10023",
                    Alias         = "Toga Bike Shop",
                    Latitude      = 40.7753077,
                    Longitude     = -73.9861529,
                    Time          = 0
                },

                new Address()
                {
                    AddressString = "555 W 57th St New York, NY 10019",
                    Alias         = "BMW of Manhattan",
                    Latitude      = 40.7718005,
                    Longitude     = -73.9897716,
                    Time          = 0
                },

                new Address()
                {
                    AddressString = "57 W 57th St New York, NY 10019",
                    Alias         = "Verizon Wireless",
                    Latitude      = 40.7558695,
                    Longitude     = -73.9862019,
                    Time          = 0
                },

                #endregion
            };

            var parameters = new RouteParameters()
            {
                AlgorithmType = AlgorithmType.TSP,

                RouteName = "Single Driver Round Trip Customer Case",

                RouteDate = dateWhenTheRouteStart,

                RouteTime = 60 * 60 * 7,

                Optimize = Route4MeSDK.DataTypes.Optimize.Distance.Description(),

                DistanceUnit = DistanceUnit.MI.Description(),

                DeviceType = DeviceType.Web.Description()
            };

            var optimizationParameters = new OptimizationParameters()
            {
                Addresses = addresses.ToArray(),

                Parameters = parameters
            };

            var dataObject = Route4Me.RunOptimization(
                optimizationParameters,
                out string errorString);

            OptimizationsToRemove = new List <string>()
            {
                dataObject?.OptimizationProblemId ?? null
            };

            Console.WriteLine(
                dataObject != null
                    ? "Optimization Problem ID = " + dataObject.OptimizationProblemId
                    : "ExampleOptimization failed"
                );

            RemoveTestOptimizations();
        }
Esempio n. 15
0
        public void CreateBBCSOptimizationWithDriverSkills()
        {
            // Create the manager with the api key
            var route4Me = new Route4MeManager(ActualApiKey);

            Dictionary <string, string> r4metobbcsid = new Dictionary <string, string>();

            #region Create Skilled Drivers

            int?ownerId = GetOwnerMemberId();

            if (ownerId == null)
            {
                return;
            }

            #region 1st Driver
            // Driver 1
            var newMemberParameters1 = new TeamRequest()
            {
                NewPassword     = testPassword,
                MemberFirstName = "Vaishali",
                MemberLastName  = "Deshpande",
                MemberCompany   = "Test Member 1 Created",
                MemberEmail     = GetTestEmail().Replace("+", "1+"),
                OwnerMemberId   = (int)ownerId,
            };

            newMemberParameters1.SetMemberType(DataTypes.V5.MemberTypes.Driver);

            var route4MeV5 = new Route4MeManagerV5(ActualApiKey);

            // Run the query
            var member1 = route4MeV5.CreateTeamMember(newMemberParameters1,
                                                      out DataTypes.V5.ResultResponse resultResponse);

            if (member1 != null && member1.GetType() == typeof(DataTypes.V5.TeamResponse))
            {
                membersToRemove.Add(member1);
            }

            var queryParams1 = new MemberQueryParameters()
            {
                UserId = member1.MemberId.ToString()
            };

            string[] skills1 = new string[]
            {
                "MLT3PLUMB", "MLT3AUDIT"
            };

            var updatedMember1 = route4MeV5.AddSkillsToDriver(queryParams1,
                                                              skills1,
                                                              out resultResponse);

            #endregion

            #region 2nd Driver

            var newMemberParameters2 = new TeamRequest()
            {
                NewPassword     = testPassword,
                MemberFirstName = "Guru",
                MemberLastName  = "Deshpande",
                MemberCompany   = "Test Member 2 Created",
                MemberEmail     = GetTestEmail().Replace("+", "1+"),
                OwnerMemberId   = (int)ownerId,
            };

            newMemberParameters2.SetMemberType(DataTypes.V5.MemberTypes.Driver);

            route4MeV5 = new Route4MeManagerV5(ActualApiKey);

            // Run the query
            var member2 = route4MeV5.CreateTeamMember(newMemberParameters2,
                                                      out resultResponse);

            if (member2 != null && member2.GetType() == typeof(DataTypes.V5.TeamResponse))
            {
                membersToRemove.Add(member2);
            }

            var queryParams2 = new MemberQueryParameters()
            {
                UserId = member2.MemberId.ToString()
            };

            string[] skills2 = new string[]
            {
                "MLT3ELEC", "MLT3AUDIT"
            };

            var updatedMember2 = route4MeV5.AddSkillsToDriver(queryParams2,
                                                              skills2,
                                                              out resultResponse);

            #endregion

            #endregion

            // Prepare the addresses
            var addresses = new Address[]
            {
                #region Addresses

                new Address()
                {
                    AddressString = "Orion Tower 1, 19/2, Devarbisana halli, KR puram Hobli",
                    //all possible originating locations are depots, should be marked as true
                    //stylistically we recommend all depots should be at the top of the destinations list
                    IsDepot   = true,
                    Latitude  = 12.924868075027042,
                    Longitude = 77.686757839656,
                },

                new Address()
                {
                    AddressString   = "Janhavi Shelters,Koppa Rd,Yelenahalli, Akshayanagar",
                    Latitude        = 12.867198760559722,
                    Longitude       = 77.61945059918025,
                    Time            = 60 * 60,
                    TimeWindowStart = (10 - 5) * 3600,
                    TimeWindowEnd   = (12 - 5) * 3600,
                    Tags            = new string[] { "MLT3PLUMB" },
                },

                new Address()
                {
                    AddressString = "Bannerghatta Main Rd, Classic Orchards Layout, Hulimavu, Bengaluru, Karnataka 560076",
                    Latitude      = 12.874972927579234,
                    Longitude     = 77.59465999732771,

                    Time            = 60 * 60,
                    TimeWindowStart = (12 - 5) * 3600,
                    TimeWindowEnd   = (14 - 5) * 3600,
                    Tags            = new string[] { "MLT3PLUMB" },
                },

                new Address()
                {
                    AddressString = "DLF Newtown,Akshayanagar",
                    Latitude      = 12.877644069349397,
                    Longitude     = 77.61905398407804,

                    Time            = 60 * 60,
                    TimeWindowStart = (14 - 5) * 3600,
                    TimeWindowEnd   = (16 - 5) * 3600,
                    Tags            = new string[] { "MLT3ELEC" },
                },

                new Address()
                {
                    AddressString   = "9th Main, 6th Sector, HSR Layout, Bengaluru, Karnataka 560034",
                    Latitude        = 12.914053742570712,
                    Longitude       = 77.63510075685282,
                    Time            = 60 * 60,
                    TimeWindowStart = (16 - 5) * 3600,
                    TimeWindowEnd   = (18 - 5) * 3600,
                    Tags            = new string[] { "MLT3PLUMB" }
                }

                #endregion
            };

            // Set parameters
            var parameters = new RouteParameters()
            {
                //specify capacitated vehicle routing with time windows and multiple depots, with multiple drivers
                AlgorithmType = AlgorithmType.ADVANCED_CVRP_TW,

                //set an arbitrary route name
                //this value shows up in the website, and all the connected mobile device
                RouteName = "Multiple Depot, Multiple Driver Fixed " + DateTime.Now,

                //the route start date in UTC, unix timestamp seconds (Tomorrow)
                RouteDate = R4MeUtils.ConvertToUnixTimestamp(DateTime.UtcNow.Date.AddDays(1)),
                //the time in UTC when a route is starting (7AM)
                RouteTime = 60 * 60 * (9 - 5),

                //the maximum duration of a route
                VehicleCapacity      = 7,
                VehicleMaxDistanceMI = 10000,

                Optimize     = Optimize.Distance.Description(),
                DistanceUnit = DistanceUnit.MI.Description(),
                DeviceType   = DeviceType.Web.Description(),
                TravelMode   = TravelMode.Driving.Description(),

                AdvancedConstraints = new DataTypes.V5.RouteAdvancedConstraints[]
                {
                    new DataTypes.V5.RouteAdvancedConstraints()
                    {
                        AvailableTimeWindows = new List <int[]>()   // drivers availability or working hours?
                        {
                            new int[] { 60 * 60 * (9 - 5), 60 * 60 * (20 - 5) }
                        },
                        MaximumCapacity    = 30,
                        MaximumCargoVolume = 15,
                        Tags = new string[] { "MLT3PLUMB" },
                        Route4meMembersId = new int[]
                        {
                            (int)updatedMember1.MemberId
                        }
                    },

                    new DataTypes.V5.RouteAdvancedConstraints()
                    {
                        AvailableTimeWindows = new List <int[]>()   // drivers availability or working hours?
                        {
                            new int[] { 60 * 60 * (9 - 5), 60 * 60 * (20 - 5) }
                        },
                        MaximumCapacity    = 30,
                        MaximumCargoVolume = 15,
                        MembersCount       = 10,
                        Tags = new string[] { "MLT3ELEC" },
                        Route4meMembersId = new int[]
                        {
                            (int)updatedMember2.MemberId
                        }
                    }
                }
            };

            var optimizationParameters = new QueryTypes.OptimizationParameters()
            {
                Addresses  = addresses,
                Parameters = parameters
            };

            // Run the query
            DataObject dataObject = route4Me.RunOptimization(
                optimizationParameters,
                out string errorString);

            OptimizationsToRemove = new List <string>()
            {
                dataObject?.OptimizationProblemId ?? null
            };

            // Output the result
            PrintExampleOptimizationResult(dataObject, errorString);

            RemoveTestOptimizations();

            RemoveTestTeamMembers();
        }
        public DataObject SingleDriverRoute10Stops()
        {
            // Create the manager with the api key
            Route4MeManager route4Me = new Route4MeManager(c_ApiKey);

            // Prepare the addresses
            Address[] addresses = new Address[]
            {
                #region Addresses

                new Address()
                {
                    AddressString = "151 Arbor Way Milledgeville GA 31061",
                    //indicate that this is a departure stop
                    //single depot routes can only have one departure depot
                    IsDepot = true,

                    //required coordinates for every departure and stop on the route
                    Latitude  = 33.132675170898,
                    Longitude = -83.244743347168,

                    //the expected time on site, in seconds. this value is incorporated into the optimization engine
                    //it also adjusts the estimated and dynamic eta's for a route
                    Time = 0,


                    //input as many custom fields as needed, custom data is passed through to mobile devices and to the manifest
                    CustomFields = new Dictionary <string, string>()
                    {
                        { "color", "red" }, { "size", "huge" }
                    }
                },

                new Address()
                {
                    AddressString = "230 Arbor Way Milledgeville GA 31061",
                    Latitude      = 33.129695892334,
                    Longitude     = -83.24577331543,
                    Time          = 0
                },

                new Address()
                {
                    AddressString = "148 Bass Rd NE Milledgeville GA 31061",
                    Latitude      = 33.143497,
                    Longitude     = -83.224487,
                    Time          = 0
                },

                new Address()
                {
                    AddressString = "117 Bill Johnson Rd NE Milledgeville GA 31061",
                    Latitude      = 33.141784667969,
                    Longitude     = -83.237518310547,
                    Time          = 0
                },

                new Address()
                {
                    AddressString = "119 Bill Johnson Rd NE Milledgeville GA 31061",
                    Latitude      = 33.141086578369,
                    Longitude     = -83.238258361816,
                    Time          = 0
                },

                new Address()
                {
                    AddressString = "131 Bill Johnson Rd NE Milledgeville GA 31061",
                    Latitude      = 33.142036437988,
                    Longitude     = -83.238845825195,
                    Time          = 0
                },

                new Address()
                {
                    AddressString = "138 Bill Johnson Rd NE Milledgeville GA 31061",
                    Latitude      = 33.14307,
                    Longitude     = -83.239334,
                    Time          = 0
                },

                new Address()
                {
                    AddressString = "139 Bill Johnson Rd NE Milledgeville GA 31061",
                    Latitude      = 33.142734527588,
                    Longitude     = -83.237442016602,
                    Time          = 0
                },

                new Address()
                {
                    AddressString = "145 Bill Johnson Rd NE Milledgeville GA 31061",
                    Latitude      = 33.143871307373,
                    Longitude     = -83.237342834473,
                    Time          = 0
                },

                new Address()
                {
                    AddressString = "221 Blake Cir Milledgeville GA 31061",
                    Latitude      = 33.081462860107,
                    Longitude     = -83.208511352539,
                    Time          = 0
                }

                #endregion
            };

            // Set parameters
            RouteParameters parameters = new RouteParameters()
            {
                AlgorithmType = AlgorithmType.TSP,
                StoreRoute    = false,
                RouteName     = "Single Driver Route 10 Stops",

                RouteDate    = R4MeUtils.ConvertToUnixTimestamp(DateTime.UtcNow.Date.AddDays(1)),
                RouteTime    = 60 * 60 * 7,
                Optimize     = Optimize.Distance.Description(),
                DistanceUnit = DistanceUnit.MI.Description(),
                DeviceType   = DeviceType.Web.Description()
            };

            OptimizationParameters optimizationParameters = new OptimizationParameters()
            {
                Addresses  = addresses,
                Parameters = parameters
            };

            // Run the query
            string     errorString;
            DataObject dataObject = route4Me.RunOptimization(optimizationParameters, out errorString);

            // Output the result
            PrintExampleOptimizationResult("SingleDriverRoute10Stops", dataObject, errorString);

            return(dataObject);
        }
        /// <summary>
        /// The example refers to the process of creating an optimization
        /// with multi-depot, multi-driver options, and fine-tuning.
        /// </summary>
        public void MultipleDepotMultipleDriverFineTuning()
        {
            var route4Me = new Route4MeManager(ActualApiKey);

            // Prepare the addresses
            Address[] addresses = new Address[]
            {
                #region Addresses

                new Address()
                {
                    AddressString   = "3634 W Market St, Fairlawn, OH 44333",
                    IsDepot         = true,
                    Latitude        = 41.135762259364,
                    Longitude       = -81.629313826561,
                    Time            = 300,
                    TimeWindowStart = 28800,
                    TimeWindowEnd   = 29465
                },

                new Address()
                {
                    AddressString   = "1218 Ruth Ave, Cuyahoga Falls, OH 44221",
                    Latitude        = 41.143505096435,
                    Longitude       = -81.46549987793,
                    Time            = 300,
                    TimeWindowStart = 29465,
                    TimeWindowEnd   = 30529
                },

                new Address()
                {
                    AddressString   = "512 Florida Pl, Barberton, OH 44203",
                    IsDepot         = true,
                    Latitude        = 41.003671512008,
                    Longitude       = -81.598461046815,
                    Time            = 300,
                    TimeWindowStart = 33479,
                    TimeWindowEnd   = 33944
                },

                new Address()
                {
                    AddressString   = "3495 Purdue St, Cuyahoga Falls, OH 44221",
                    Latitude        = 41.162971496582,
                    Longitude       = -81.479049682617,
                    Time            = 300,
                    TimeWindowStart = 33944,
                    TimeWindowEnd   = 34801
                },

                new Address()
                {
                    AddressString   = "1659 Hibbard Dr, Stow, OH 44224",
                    Latitude        = 41.194505989552,
                    Longitude       = -81.443351581693,
                    Time            = 300,
                    TimeWindowStart = 34801,
                    TimeWindowEnd   = 36366
                },

                new Address()
                {
                    AddressString   = "2705 N River Rd, Stow, OH 44224",
                    Latitude        = 41.145240783691,
                    Longitude       = -81.410247802734,
                    Time            = 300,
                    TimeWindowStart = 36366,
                    TimeWindowEnd   = 39173
                },

                new Address()
                {
                    AddressString   = "10159 Bissell Dr, Twinsburg, OH 44087",
                    Latitude        = 41.340042114258,
                    Longitude       = -81.421226501465,
                    Time            = 300,
                    TimeWindowStart = 39173,
                    TimeWindowEnd   = 41617
                },

                new Address()
                {
                    AddressString   = "367 Cathy Dr, Munroe Falls, OH 44262",
                    Latitude        = 41.148578643799,
                    Longitude       = -81.429229736328,
                    Time            = 300,
                    TimeWindowStart = 41617,
                    TimeWindowEnd   = 43660
                },

                new Address()
                {
                    AddressString   = "367 Cathy Dr, Munroe Falls, OH 44262",
                    Latitude        = 41.148579,
                    Longitude       = -81.42923,
                    Time            = 300,
                    TimeWindowStart = 43660,
                    TimeWindowEnd   = 46392
                },

                new Address()
                {
                    AddressString   = "512 Florida Pl, Barberton, OH 44203",
                    Latitude        = 41.003671512008,
                    Longitude       = -81.598461046815,
                    Time            = 300,
                    TimeWindowStart = 46392,
                    TimeWindowEnd   = 48089
                },

                new Address()
                {
                    AddressString   = "559 W Aurora Rd, Northfield, OH 44067",
                    Latitude        = 41.315116882324,
                    Longitude       = -81.558746337891,
                    Time            = 300,
                    TimeWindowStart = 48089,
                    TimeWindowEnd   = 48449
                },

                new Address()
                {
                    AddressString   = "3933 Klein Ave, Stow, OH 44224",
                    Latitude        = 41.169467926025,
                    Longitude       = -81.429420471191,
                    Time            = 300,
                    TimeWindowStart = 48449,
                    TimeWindowEnd   = 50152
                },

                new Address()
                {
                    AddressString   = "2148 8th St, Cuyahoga Falls, OH 44221",
                    Latitude        = 41.136692047119,
                    Longitude       = -81.493492126465,
                    Time            = 300,
                    TimeWindowStart = 50152,
                    TimeWindowEnd   = 51682
                },

                new Address()
                {
                    AddressString   = "3731 Osage St, Stow, OH 44224",
                    Latitude        = 41.161357879639,
                    Longitude       = -81.42293548584,
                    Time            = 300,
                    TimeWindowStart = 51682,
                    TimeWindowEnd   = 54379
                },

                new Address()
                {
                    AddressString   = "3862 Klein Ave, Stow, OH 44224",
                    Latitude        = 41.167895123363,
                    Longitude       = -81.429973393679,
                    Time            = 300,
                    TimeWindowStart = 54379,
                    TimeWindowEnd   = 54879
                },

                new Address()
                {
                    AddressString   = "138 Northwood Ln, Tallmadge, OH 44278",
                    Latitude        = 41.085464134812,
                    Longitude       = -81.447411775589,
                    Time            = 300,
                    TimeWindowStart = 54879,
                    TimeWindowEnd   = 56613
                },

                new Address()
                {
                    AddressString   = "3401 Saratoga Blvd, Stow, OH 44224",
                    Latitude        = 41.148849487305,
                    Longitude       = -81.407363891602,
                    Time            = 300,
                    TimeWindowStart = 56613,
                    TimeWindowEnd   = 57052
                },

                new Address()
                {
                    AddressString   = "5169 Brockton Dr, Stow, OH 44224",
                    Latitude        = 41.195003509521,
                    Longitude       = -81.392700195312,
                    Time            = 300,
                    TimeWindowStart = 57052,
                    TimeWindowEnd   = 59004
                },

                new Address()
                {
                    AddressString   = "5169 Brockton Dr, Stow, OH 44224",
                    Latitude        = 41.195003509521,
                    Longitude       = -81.392700195312,
                    Time            = 300,
                    TimeWindowStart = 59004,
                    TimeWindowEnd   = 60027
                },

                new Address()
                {
                    AddressString   = "458 Aintree Dr, Munroe Falls, OH 44262",
                    Latitude        = 41.1266746521,
                    Longitude       = -81.445808410645,
                    Time            = 300,
                    TimeWindowStart = 60027,
                    TimeWindowEnd   = 60375
                },

                new Address()
                {
                    AddressString   = "512 Florida Pl, Barberton, OH 44203",
                    Latitude        = 41.003671512008,
                    Longitude       = -81.598461046815,
                    Time            = 300,
                    TimeWindowStart = 60375,
                    TimeWindowEnd   = 63891
                },

                new Address()
                {
                    AddressString   = "2299 Tyre Dr, Hudson, OH 44236",
                    Latitude        = 41.250511169434,
                    Longitude       = -81.420433044434,
                    Time            = 300,
                    TimeWindowStart = 63891,
                    TimeWindowEnd   = 65277
                },

                new Address()
                {
                    AddressString   = "2148 8th St, Cuyahoga Falls, OH 44221",
                    Latitude        = 41.136692047119,
                    Longitude       = -81.493492126465,
                    Time            = 300,
                    TimeWindowStart = 65277,
                    TimeWindowEnd   = 68545
                }

                #endregion
            };

            // Set parameters
            var parameters = new RouteParameters()
            {
                AlgorithmType = AlgorithmType.CVRP_TW_MD,
                RouteName     = "Multiple Depot, Multiple Driver Fine Tuning, Time Window",

                RouteDate            = R4MeUtils.ConvertToUnixTimestamp(DateTime.UtcNow.Date.AddDays(1)),
                RouteTime            = 60 * 60 * 7,
                RouteMaxDuration     = 86400 * 3,
                VehicleCapacity      = 5,
                VehicleMaxDistanceMI = 10000,

                Optimize     = Optimize.TimeWithTraffic.Description(),
                DistanceUnit = DistanceUnit.MI.Description(),
                DeviceType   = DeviceType.Web.Description(),
                TravelMode   = TravelMode.Driving.Description(),
                Metric       = Metric.Matrix,

                TargetDistance = 100,
                TargetDuration = 1,
                WaitingTime    = 1
            };

            var optimizationParameters = new OptimizationParameters()
            {
                Addresses  = addresses,
                Parameters = parameters
            };

            // Run the query
            var dataObjectFineTuning = route4Me
                                       .RunOptimization(optimizationParameters, out string errorString);

            PrintExampleOptimizationResult(dataObjectFineTuning, errorString);

            OptimizationsToRemove = new List <string>()
            {
                dataObjectFineTuning?.OptimizationProblemId ?? null
            };

            Console.WriteLine("");

            Console.WriteLine("TargetDistance: " + (dataObjectFineTuning?.Parameters?.TargetDistance ?? null));
            Console.WriteLine("TargetDuration: " + (dataObjectFineTuning?.Parameters?.TargetDuration ?? null));
            Console.WriteLine("WaitingTime: " + (dataObjectFineTuning?.Parameters?.WaitingTime ?? null));

            RemoveTestOptimizations();
        }
        public void SingleDriverRoute7Stops()
        {
            // Create the manager with the api key
            var route4Me = new Route4MeManager(ActualApiKey);

            // Prepare the addresses
            Address[] addresses = new Address[]
            {
                #region Addresses

                new Address()
                {
                    AddressString = "128 Woodland Dr, Stafford, VA 22556",
                    IsDepot       = true,
                    Alias         = "HQ",
                    Latitude      = 38.5022586,
                    Longitude     = -77.5402276
                },

                new Address()
                {
                    AddressString   = "2232 Aquia Dr, Stafford, VA 22554",
                    Latitude        = 38.4613311,
                    Longitude       = -77.3733942,
                    IsDepot         = false,
                    Alias           = "1",
                    TimeWindowStart = 32400,
                    TimeWindowEnd   = 82800
                },

                new Address()
                {
                    AddressString   = "94 The Vance Way, Fredericksburg, VA 22405",
                    Latitude        = 38.343827,
                    Longitude       = -77.358127,
                    IsDepot         = false,
                    Alias           = "2",
                    TimeWindowStart = 32400,
                    TimeWindowEnd   = 82800
                },

                new Address()
                {
                    AddressString   = "3 Edgewood Circle, Fredericksburg, VA 22405",
                    Latitude        = 38.3560299,
                    Longitude       = -77.44275,
                    IsDepot         = false,
                    Alias           = "3",
                    TimeWindowStart = 32400,
                    TimeWindowEnd   = 82800
                },

                new Address()
                {
                    AddressString   = "609 Jett St, Fredericksburg, VA 22405",
                    Latitude        = 38.321677,
                    Longitude       = -77.434507,
                    IsDepot         = false,
                    Alias           = "4",
                    TimeWindowStart = 39600,
                    TimeWindowEnd   = 82800
                },

                new Address()
                {
                    AddressString   = "1120 Potomac Ave, Fredericksburg, VA 22405",
                    Latitude        = 38.3115498,
                    Longitude       = -77.4349647,
                    Alias           = "5",
                    TimeWindowStart = 39600,
                    TimeWindowEnd   = 82800
                },

                new Address()
                {
                    AddressString   = "10809 Stacy Run, Fredericksburg, VA 22408",
                    Latitude        = 38.258764,
                    Longitude       = -77.425318,
                    Alias           = "6",
                    TimeWindowStart = 39600,
                    TimeWindowEnd   = 82800
                }
                #endregion
            };

            // Set parameters
            var parameters = new RouteParameters()
            {
                AlgorithmType        = AlgorithmType.TSP,
                RouteName            = "Test for equal sequences Single Driver Route 7 Stops",
                DisableOptimization  = false,
                MemberId             = 403634,
                RouteDate            = R4MeUtils.ConvertToUnixTimestamp(DateTime.UtcNow.Date.AddDays(1)),
                RouteTime            = 60 * 60 * 7,
                RouteMaxDuration     = 24 * 3600,
                TravelMode           = TravelMode.Driving.Description(),
                VehicleCapacity      = 1,
                VehicleMaxDistanceMI = 10000,
                RT           = false,
                Optimize     = Optimize.Distance.Description(),
                DistanceUnit = DistanceUnit.MI.Description(),
                DeviceType   = DeviceType.Web.Description()
            };

            var optimizationParameters = new OptimizationParameters()
            {
                Addresses  = addresses,
                Parameters = parameters
            };

            // Run the query
            DataObject dataObject = route4Me.RunOptimization(
                optimizationParameters,
                out string errorString);

            OptimizationsToRemove = new List <string>()
            {
                dataObject?.OptimizationProblemId ?? null
            };

            // Output the result
            PrintExampleOptimizationResult(dataObject, errorString);

            RemoveTestOptimizations();
        }
        public bool MultipleDepotMultipleDriverWith24StopsTimeWindowTest()
        {
            var route4Me = new Route4MeManagerV5(c_ApiKey);

            // Prepare the addresses
            Address[] addresses = new Address[]
            {
                #region Addresses

                new Address()
                {
                    AddressString   = "3634 W Market St, Fairlawn, OH 44333",
                    IsDepot         = true,
                    Latitude        = 41.135762259364,
                    Longitude       = -81.629313826561,
                    Time            = 300,
                    TimeWindowStart = 28800,
                    TimeWindowEnd   = 29465
                },

                new Address()
                {
                    AddressString   = "1218 Ruth Ave, Cuyahoga Falls, OH 44221",
                    Latitude        = 41.143505096435,
                    Longitude       = -81.46549987793,
                    Time            = 300,
                    TimeWindowStart = 29465,
                    TimeWindowEnd   = 30529
                },

                new Address()
                {
                    AddressString   = "512 Florida Pl, Barberton, OH 44203",
                    Latitude        = 41.003671512008,
                    Longitude       = -81.598461046815,
                    Time            = 300,
                    TimeWindowStart = 30529,
                    TimeWindowEnd   = 33479
                },

                new Address()
                {
                    AddressString   = "512 Florida Pl, Barberton, OH 44203",
                    IsDepot         = true,
                    Latitude        = 41.003671512008,
                    Longitude       = -81.598461046815,
                    Time            = 300,
                    TimeWindowStart = 33479,
                    TimeWindowEnd   = 33944
                },

                new Address()
                {
                    AddressString   = "3495 Purdue St, Cuyahoga Falls, OH 44221",
                    Latitude        = 41.162971496582,
                    Longitude       = -81.479049682617,
                    Time            = 300,
                    TimeWindowStart = 33944,
                    TimeWindowEnd   = 34801
                },

                new Address()
                {
                    AddressString   = "1659 Hibbard Dr, Stow, OH 44224",
                    Latitude        = 41.194505989552,
                    Longitude       = -81.443351581693,
                    Time            = 300,
                    TimeWindowStart = 34801,
                    TimeWindowEnd   = 36366
                },

                new Address()
                {
                    AddressString   = "2705 N River Rd, Stow, OH 44224",
                    Latitude        = 41.145240783691,
                    Longitude       = -81.410247802734,
                    Time            = 300,
                    TimeWindowStart = 36366,
                    TimeWindowEnd   = 39173
                },

                new Address()
                {
                    AddressString   = "10159 Bissell Dr, Twinsburg, OH 44087",
                    Latitude        = 41.340042114258,
                    Longitude       = -81.421226501465,
                    Time            = 300,
                    TimeWindowStart = 39173,
                    TimeWindowEnd   = 41617
                },

                new Address()
                {
                    AddressString   = "367 Cathy Dr, Munroe Falls, OH 44262",
                    Latitude        = 41.148578643799,
                    Longitude       = -81.429229736328,
                    Time            = 300,
                    TimeWindowStart = 41617,
                    TimeWindowEnd   = 43660
                },

                new Address()
                {
                    AddressString   = "367 Cathy Dr, Munroe Falls, OH 44262",
                    Latitude        = 41.148579,
                    Longitude       = -81.42923,
                    Time            = 300,
                    TimeWindowStart = 43660,
                    TimeWindowEnd   = 46392
                },

                new Address()
                {
                    AddressString   = "512 Florida Pl, Barberton, OH 44203",
                    Latitude        = 41.003671512008,
                    Longitude       = -81.598461046815,
                    Time            = 300,
                    TimeWindowStart = 46392,
                    TimeWindowEnd   = 48089
                },

                new Address()
                {
                    AddressString   = "559 W Aurora Rd, Northfield, OH 44067",
                    Latitude        = 41.315116882324,
                    Longitude       = -81.558746337891,
                    Time            = 300,
                    TimeWindowStart = 48089,
                    TimeWindowEnd   = 48449
                },

                new Address()
                {
                    AddressString   = "3933 Klein Ave, Stow, OH 44224",
                    Latitude        = 41.169467926025,
                    Longitude       = -81.429420471191,
                    Time            = 300,
                    TimeWindowStart = 48449,
                    TimeWindowEnd   = 50152
                },

                new Address()
                {
                    AddressString   = "2148 8th St, Cuyahoga Falls, OH 44221",
                    Latitude        = 41.136692047119,
                    Longitude       = -81.493492126465,
                    Time            = 300,
                    TimeWindowStart = 50152,
                    TimeWindowEnd   = 51682
                },

                new Address()
                {
                    AddressString   = "3731 Osage St, Stow, OH 44224",
                    Latitude        = 41.161357879639,
                    Longitude       = -81.42293548584,
                    Time            = 300,
                    TimeWindowStart = 51682,
                    TimeWindowEnd   = 54379
                },

                new Address()
                {
                    AddressString   = "3862 Klein Ave, Stow, OH 44224",
                    Latitude        = 41.167895123363,
                    Longitude       = -81.429973393679,
                    Time            = 300,
                    TimeWindowStart = 54379,
                    TimeWindowEnd   = 54879
                },

                new Address()
                {
                    AddressString   = "138 Northwood Ln, Tallmadge, OH 44278",
                    Latitude        = 41.085464134812,
                    Longitude       = -81.447411775589,
                    Time            = 300,
                    TimeWindowStart = 54879,
                    TimeWindowEnd   = 56613
                },

                new Address()
                {
                    AddressString   = "3401 Saratoga Blvd, Stow, OH 44224",
                    Latitude        = 41.148849487305,
                    Longitude       = -81.407363891602,
                    Time            = 300,
                    TimeWindowStart = 56613,
                    TimeWindowEnd   = 57052
                },

                new Address()
                {
                    AddressString   = "5169 Brockton Dr, Stow, OH 44224",
                    Latitude        = 41.195003509521,
                    Longitude       = -81.392700195312,
                    Time            = 300,
                    TimeWindowStart = 57052,
                    TimeWindowEnd   = 59004
                },

                new Address()
                {
                    AddressString   = "5169 Brockton Dr, Stow, OH 44224",
                    Latitude        = 41.195003509521,
                    Longitude       = -81.392700195312,
                    Time            = 300,
                    TimeWindowStart = 59004,
                    TimeWindowEnd   = 60027
                },

                new Address()
                {
                    AddressString   = "458 Aintree Dr, Munroe Falls, OH 44262",
                    Latitude        = 41.1266746521,
                    Longitude       = -81.445808410645,
                    Time            = 300,
                    TimeWindowStart = 60027,
                    TimeWindowEnd   = 60375
                },

                new Address()
                {
                    AddressString   = "512 Florida Pl, Barberton, OH 44203",
                    Latitude        = 41.003671512008,
                    Longitude       = -81.598461046815,
                    Time            = 300,
                    TimeWindowStart = 60375,
                    TimeWindowEnd   = 63891
                },

                new Address()
                {
                    AddressString   = "2299 Tyre Dr, Hudson, OH 44236",
                    Latitude        = 41.250511169434,
                    Longitude       = -81.420433044434,
                    Time            = 300,
                    TimeWindowStart = 63891,
                    TimeWindowEnd   = 65277
                },

                new Address()
                {
                    AddressString   = "2148 8th St, Cuyahoga Falls, OH 44221",
                    Latitude        = 41.136692047119,
                    Longitude       = -81.493492126465,
                    Time            = 300,
                    TimeWindowStart = 65277,
                    TimeWindowEnd   = 68545
                }

                #endregion
            };

            // Set parameters
            var parameters = new RouteParameters()
            {
                AlgorithmType = AlgorithmType.CVRP_TW_MD,
                RouteName     = "Multiple Depot, Multiple Driver with 24 Stops, Time Window",
                //StoreRoute = false,

                RouteDate            = R4MeUtils.ConvertToUnixTimestamp(DateTime.UtcNow.Date.AddDays(1)),
                RouteTime            = 60 * 60 * 7,
                RouteMaxDuration     = 86400,
                VehicleCapacity      = 5,
                VehicleMaxDistanceMI = 10000,

                Optimize     = Optimize.Distance.Description(),
                DistanceUnit = DistanceUnit.MI.Description(),
                DeviceType   = DeviceType.Web.Description(),
                TravelMode   = TravelMode.Driving.Description(),
                Metric       = Metric.Matrix
            };

            var optimizationParameters = new OptimizationParameters()
            {
                Addresses  = addresses,
                Parameters = parameters
            };

            // Run the query
            try
            {
                dataObjectMDMD24 = route4Me.RunOptimization(optimizationParameters, out ResultResponse resultResponse);

                MDMD24_route_id = (dataObjectMDMD24 != null &&
                                   dataObjectMDMD24.Routes != null &&
                                   dataObjectMDMD24.Routes.Length > 0)
                                  ? dataObjectMDMD24.Routes[0].RouteID
                                  : null;

                MDMD24_optimization_problem_id = dataObjectMDMD24.OptimizationProblemId;

                MDMD24_route = (dataObjectMDMD24 != null &&
                                dataObjectMDMD24.Routes != null &&
                                dataObjectMDMD24.Routes.Length > 0)
                                ? dataObjectMDMD24.Routes[0]
                                : null;

                MDMD24_route_id = (MDMD24_route != null) ? MDMD24_route.RouteID : null;

                return(true);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Generation of the Multiple Depot, Multiple Driver with 24 Stops optimization problem failed. " + ex.Message);
                return(false);
            }
        }
        public string SingleDriverRoundTripGeneric()
        {
            const string uri      = R4MEInfrastructureSettings.MainHost + "/api.v4/optimization_problem.php";
            const string myApiKey = "11111111111111111111111111111111";

            // Create the manager with the api key
            Route4MeManager route4Me = new Route4MeManager(myApiKey);

            // Prepare the addresses
            // Using the defined class, can use user-defined class instead
            Address[] addresses = new Address[]
            {
                #region Addresses

                new Address()
                {
                    AddressString = "754 5th Ave New York, NY 10019",
                    Alias         = "Bergdorf Goodman",
                    IsDepot       = true,
                    Latitude      = 40.7636197,
                    Longitude     = -73.9744388,
                    Time          = 0
                },

                new Address()
                {
                    AddressString = "717 5th Ave New York, NY 10022",
                    Alias         = "Giorgio Armani",
                    Latitude      = 40.7669692,
                    Longitude     = -73.9693864,
                    Time          = 0
                },

                new Address()
                {
                    AddressString = "888 Madison Ave New York, NY 10014",
                    Alias         = "Ralph Lauren Women's and Home",
                    Latitude      = 40.7715154,
                    Longitude     = -73.9669241,
                    Time          = 0
                },

                new Address()
                {
                    AddressString = "1011 Madison Ave New York, NY 10075",
                    Alias         = "Yigal Azrou'l",
                    Latitude      = 40.7772129,
                    Longitude     = -73.9669,
                    Time          = 0
                },

                new Address()
                {
                    AddressString = "440 Columbus Ave New York, NY 10024",
                    Alias         = "Frank Stella Clothier",
                    Latitude      = 40.7808364,
                    Longitude     = -73.9732729,
                    Time          = 0
                },

                new Address()
                {
                    AddressString = "324 Columbus Ave #1 New York, NY 10023",
                    Alias         = "Liana",
                    Latitude      = 40.7803123,
                    Longitude     = -73.9793079,
                    Time          = 0
                },

                new Address()
                {
                    AddressString = "110 W End Ave New York, NY 10023",
                    Alias         = "Toga Bike Shop",
                    Latitude      = 40.7753077,
                    Longitude     = -73.9861529,
                    Time          = 0
                },

                new Address()
                {
                    AddressString = "555 W 57th St New York, NY 10019",
                    Alias         = "BMW of Manhattan",
                    Latitude      = 40.7718005,
                    Longitude     = -73.9897716,
                    Time          = 0
                },

                new Address()
                {
                    AddressString = "57 W 57th St New York, NY 10019",
                    Alias         = "Verizon Wireless",
                    Latitude      = 40.7558695,
                    Longitude     = -73.9862019,
                    Time          = 0
                },

                #endregion
            };

            // Set parameters
            // Using the defined class, can use user-defined class instead
            RouteParameters parameters = new RouteParameters()
            {
                AlgorithmType = AlgorithmType.TSP,
                StoreRoute    = false,
                RouteName     = "Single Driver Round Trip",

                RouteDate            = R4MeUtils.ConvertToUnixTimestamp(DateTime.UtcNow.Date.AddDays(1)),
                RouteTime            = 60 * 60 * 7,
                RouteMaxDuration     = 86400,
                VehicleCapacity      = "1",
                VehicleMaxDistanceMI = "10000",

                Optimize     = Optimize.Distance.Description(),
                DistanceUnit = DistanceUnit.MI.Description(),
                DeviceType   = DeviceType.Web.Description(),
                TravelMode   = TravelMode.Driving.Description(),
            };

            MyAddressAndParametersHolder myParameters = new MyAddressAndParametersHolder()
            {
                addresses  = addresses,
                parameters = parameters
            };

            // Run the query
            string errorString;
            MyDataObjectGeneric dataObject = route4Me.GetJsonObjectFromAPI <MyDataObjectGeneric>(myParameters,
                                                                                                 uri,
                                                                                                 HttpMethodType.Post,
                                                                                                 out errorString);

            Console.WriteLine("");

            if (dataObject != null)
            {
                Console.WriteLine("SingleDriverRoundTripGeneric executed successfully");
                Console.WriteLine("");

                Console.WriteLine("Optimization Problem ID: {0}", dataObject.OptimizationProblemId);
                Console.WriteLine("State: {0}", dataObject.MyState);
                Console.WriteLine("");

                dataObject.Addresses.ForEach(address =>
                {
                    Console.WriteLine("Address: {0}", address.AddressString);
                    Console.WriteLine("Route ID: {0}", address.RouteId);
                });
                return(dataObject.OptimizationProblemId);
            }
            else
            {
                Console.WriteLine("SingleDriverRoundTripGeneric error {0}", errorString);
                return(null);
            }
        }
Esempio n. 21
0
        public DataObject MultipleDepotMultipleDriver()
        {
            // Create the manager with the api key
            Route4MeManager route4Me = new Route4MeManager(c_ApiKey);

            // Prepare the addresses
            Address[] addresses = new Address[]
            {
                #region Addresses

                new Address()
                {
                    AddressString = "3634 W Market St, Fairlawn, OH 44333",
                    //all possible originating locations are depots, should be marked as true
                    //stylistically we recommend all depots should be at the top of the destinations list
                    IsDepot   = true,
                    Latitude  = 41.135762259364,
                    Longitude = -81.629313826561,

                    //the number of seconds at destination
                    Time = 300,

                    //together these two specify the time window of a destination
                    //seconds offset relative to the route start time for the open availability of a destination
                    TimeWindowStart = 28800,

                    //seconds offset relative to the route end time for the open availability of a destination
                    TimeWindowEnd = 29465
                },

                new Address()
                {
                    AddressString   = "1218 Ruth Ave, Cuyahoga Falls, OH 44221",
                    Latitude        = 41.135762259364,
                    Longitude       = -81.629313826561,
                    Time            = 300,
                    TimeWindowStart = 29465,
                    TimeWindowEnd   = 30529
                },

                new Address()
                {
                    AddressString   = "512 Florida Pl, Barberton, OH 44203",
                    Latitude        = 41.003671512008,
                    Longitude       = -81.598461046815,
                    Time            = 300,
                    TimeWindowStart = 30529,
                    TimeWindowEnd   = 33779
                },

                new Address()
                {
                    AddressString   = "512 Florida Pl, Barberton, OH 44203",
                    Latitude        = 41.003671512008,
                    Longitude       = -81.598461046815,
                    Time            = 100,
                    TimeWindowStart = 33779,
                    TimeWindowEnd   = 33944
                },

                new Address()
                {
                    AddressString   = "3495 Purdue St, Cuyahoga Falls, OH 44221",
                    Latitude        = 41.162971496582,
                    Longitude       = -81.479049682617,
                    Time            = 300,
                    TimeWindowStart = 33944,
                    TimeWindowEnd   = 34801
                },

                new Address()
                {
                    AddressString   = "1659 Hibbard Dr, Stow, OH 44224",
                    Latitude        = 41.194505989552,
                    Longitude       = -81.443351581693,
                    Time            = 300,
                    TimeWindowStart = 34801,
                    TimeWindowEnd   = 36366
                },

                new Address()
                {
                    AddressString   = "2705 N River Rd, Stow, OH 44224",
                    Latitude        = 41.145240783691,
                    Longitude       = -81.410247802734,
                    Time            = 300,
                    TimeWindowStart = 36366,
                    TimeWindowEnd   = 39173
                },

                new Address()
                {
                    AddressString   = "10159 Bissell Dr, Twinsburg, OH 44087",
                    Latitude        = 41.340042114258,
                    Longitude       = -81.421226501465,
                    Time            = 300,
                    TimeWindowStart = 39173,
                    TimeWindowEnd   = 41617
                },

                new Address()
                {
                    AddressString   = "367 Cathy Dr, Munroe Falls, OH 44262",
                    Latitude        = 41.148578643799,
                    Longitude       = -81.429229736328,
                    Time            = 300,
                    TimeWindowStart = 41617,
                    TimeWindowEnd   = 43660
                },

                new Address()
                {
                    AddressString   = "367 Cathy Dr, Munroe Falls, OH 44262",
                    Latitude        = 41.148578643799,
                    Longitude       = -81.429229736328,
                    Time            = 300,
                    TimeWindowStart = 43660,
                    TimeWindowEnd   = 46392
                },

                new Address()
                {
                    AddressString   = "512 Florida Pl, Barberton, OH 44203",
                    Latitude        = 41.003671512008,
                    Longitude       = -81.598461046815,
                    Time            = 300,
                    TimeWindowStart = 46392,
                    TimeWindowEnd   = 48389
                },

                new Address()
                {
                    AddressString   = "559 W Aurora Rd, Northfield, OH 44067",
                    Latitude        = 41.315116882324,
                    Longitude       = -81.558746337891,
                    Time            = 50,
                    TimeWindowStart = 48389,
                    TimeWindowEnd   = 48449
                },

                new Address()
                {
                    AddressString   = "3933 Klein Ave, Stow, OH 44224",
                    Latitude        = 41.169467926025,
                    Longitude       = -81.429420471191,
                    Time            = 300,
                    TimeWindowStart = 48449,
                    TimeWindowEnd   = 50152
                },

                new Address()
                {
                    AddressString   = "2148 8th St, Cuyahoga Falls, OH 44221",
                    Latitude        = 41.136692047119,
                    Longitude       = -81.493492126465,
                    Time            = 300,
                    TimeWindowStart = 50152,
                    TimeWindowEnd   = 51982
                },

                new Address()
                {
                    AddressString   = "3731 Osage St, Stow, OH 44224",
                    Latitude        = 41.161357879639,
                    Longitude       = -81.42293548584,
                    Time            = 100,
                    TimeWindowStart = 51982,
                    TimeWindowEnd   = 52180
                },

                new Address()
                {
                    AddressString   = "3731 Osage St, Stow, OH 44224",
                    Latitude        = 41.161357879639,
                    Longitude       = -81.42293548584,
                    Time            = 300,
                    TimeWindowStart = 52180,
                    TimeWindowEnd   = 54379
                }

                #endregion
            };

            // Set parameters
            RouteParameters parameters = new RouteParameters()
            {
                //specify capacitated vehicle routing with time windows and multiple depots, with multiple drivers
                AlgorithmType = AlgorithmType.CVRP_TW_MD,

                //set an arbitrary route name
                //this value shows up in the website, and all the connected mobile device
                RouteName = "Multiple Depot, Multiple Driver",

                //the route start date in UTC, unix timestamp seconds (Tomorrow)
                RouteDate = R4MeUtils.ConvertToUnixTimestamp(DateTime.UtcNow.Date.AddDays(1)),
                //the time in UTC when a route is starting (7AM)
                RouteTime = 60 * 60 * 7,

                //the maximum duration of a route
                RouteMaxDuration     = 86400,
                VehicleCapacity      = "1",
                VehicleMaxDistanceMI = "10000",

                Optimize     = Optimize.Distance.Description(),
                DistanceUnit = DistanceUnit.MI.Description(),
                DeviceType   = DeviceType.Web.Description(),
                TravelMode   = TravelMode.Driving.Description(),
                Metric       = Metric.Geodesic
            };

            OptimizationParameters optimizationParameters = new OptimizationParameters()
            {
                Addresses  = addresses,
                Parameters = parameters
            };

            // Run the query
            string     errorString;
            DataObject dataObject = route4Me.RunOptimization(optimizationParameters, out errorString);

            // Output the result
            PrintExampleOptimizationResult("MultipleDepotMultipleDriver", dataObject, errorString);

            return(dataObject);
        }
        /// <summary>
        /// Add Orders to an Optimization Problem object
        /// </summary>
        public void AddOrdersToOptimization()
        {
            // Create the manager with the api key
            var route4Me = new Route4MeManager(ActualApiKey);

            RunOptimizationSingleDriverRoute10Stops();

            OptimizationsToRemove = new List <string>()
            {
                SD10Stops_optimization_problem_id
            };

            var rQueryParams = new OptimizationParameters()
            {
                OptimizationProblemID = SD10Stops_optimization_problem_id,
                Redirect = false
            };

            var lsTimeWindowStart = new List <int>();

            var dtCurDate = DateTime.Now + (new TimeSpan(1, 0, 0, 0));

            dtCurDate = new DateTime(dtCurDate.Year, dtCurDate.Month, dtCurDate.Day, 8, 0, 0);

            var tsp1000sec = new TimeSpan(0, 0, 1000);
            var tsp7days   = new TimeSpan(7, 0, 0, 0);

            lsTimeWindowStart.Add((int)R4MeUtils.ConvertToUnixTimestamp(dtCurDate));
            dtCurDate += tsp1000sec;
            lsTimeWindowStart.Add((int)R4MeUtils.ConvertToUnixTimestamp(dtCurDate));
            dtCurDate += tsp1000sec;
            lsTimeWindowStart.Add((int)R4MeUtils.ConvertToUnixTimestamp(dtCurDate));

            #region Addresses
            Address[] addresses = new Address[] {
                new Address {
                    AddressString     = "273 Canal St, New York, NY 10013, USA",
                    Latitude          = 40.7191558,
                    Longitude         = -74.0011966,
                    Alias             = "",
                    CurbsideLatitude  = 40.7191558,
                    CurbsideLongitude = -74.0011966,
                    IsDepot           = true
                },
                new Address {
                    AddressString     = "106 Liberty St, New York, NY 10006, USA",
                    Alias             = "BK Restaurant #: 2446",
                    Latitude          = 40.709637,
                    Longitude         = -74.011912,
                    CurbsideLatitude  = 40.709637,
                    CurbsideLongitude = -74.011912,
                    Email             = "",
                    Phone             = "(917) 338-1887",
                    FirstName         = "",
                    LastName          = "",
                    CustomFields      = new Dictionary <string, string> {
                        { "icon", null }
                    },
                    Time            = 0,
                    TimeWindowStart = lsTimeWindowStart[0],
                    TimeWindowEnd   = lsTimeWindowStart[0] + 300,
                    OrderId         = 7205705
                },
                new Address {
                    AddressString     = "325 Broadway, New York, NY 10007, USA",
                    Alias             = "BK Restaurant #: 20333",
                    Latitude          = 40.71615,
                    Longitude         = -74.00505,
                    CurbsideLatitude  = 40.71615,
                    CurbsideLongitude = -74.00505,
                    Email             = "",
                    Phone             = "(212) 227-7535",
                    FirstName         = "",
                    LastName          = "",
                    CustomFields      = new Dictionary <string, string> {
                        { "icon", null }
                    },
                    Time            = 0,
                    TimeWindowStart = lsTimeWindowStart[1],
                    TimeWindowEnd   = lsTimeWindowStart[1] + 300,
                    OrderId         = 7205704
                },
                new Address {
                    AddressString     = "106 Fulton St, Farmingdale, NY 11735, USA",
                    Alias             = "BK Restaurant #: 17871",
                    Latitude          = 40.73073,
                    Longitude         = -73.459283,
                    CurbsideLatitude  = 40.73073,
                    CurbsideLongitude = -73.459283,
                    Email             = "",
                    Phone             = "(212) 566-5132",
                    FirstName         = "",
                    LastName          = "",
                    CustomFields      = new Dictionary <string, string> {
                        { "icon", null }
                    },
                    Time            = 0,
                    TimeWindowStart = lsTimeWindowStart[2],
                    TimeWindowEnd   = lsTimeWindowStart[2] + 300,
                    OrderId         = 7205703
                }
            };
            #endregion

            var rParams = new RouteParameters()
            {
                RouteName           = "Wednesday 15th of June 2016 07:01 PM (+03:00)",
                RouteDate           = R4MeUtils.ConvertToUnixTimestamp(DateTime.Now + tsp7days),
                RouteTime           = 14400,
                Optimize            = "Time",
                AlgorithmType       = AlgorithmType.TSP,
                RT                  = false,
                LockLast            = false,
                VehicleId           = "",
                DisableOptimization = false
            };

            var dataObject = route4Me.AddOrdersToOptimization(
                rQueryParams,
                addresses,
                rParams, out string errorString);

            PrintExampleOptimizationResult(dataObject, errorString);

            RemoveTestOptimizations();
        }
Esempio n. 23
0
        public DataObject SingleDriverMultipleTimeWindows()
        {
            // Create the manager with the api key
            Route4MeManager route4Me = new Route4MeManager(c_ApiKey);

            // Prepare the addresses
            Address[] addresses = new Address[]
            {
                #region Addresses

                new Address()
                {
                    AddressString = "3634 W Market St, Fairlawn, OH 44333",
                    //all possible originating locations are depots, should be marked as true
                    //stylistically we recommend all depots should be at the top of the destinations list
                    IsDepot   = true,
                    Latitude  = 41.135762259364,
                    Longitude = -81.629313826561,

                    TimeWindowStart  = null,
                    TimeWindowEnd    = null,
                    TimeWindowStart2 = null,
                    TimeWindowEnd2   = null,
                    Time             = null
                },

                new Address()
                {
                    AddressString = "1218 Ruth Ave, Cuyahoga Falls, OH 44221",
                    Latitude      = 41.135762259364,
                    Longitude     = -81.629313826561,

                    //together these two specify the time window of a destination
                    //seconds offset relative to the route start time for the open availability of a destination
                    TimeWindowStart = 6 * 3600 + 00 * 60,
                    //seconds offset relative to the route end time for the open availability of a destination
                    TimeWindowEnd = 6 * 3600 + 30 * 60,

                    // Second 'TimeWindowStart'
                    TimeWindowStart2 = 7 * 3600 + 00 * 60,
                    // Second 'TimeWindowEnd'
                    TimeWindowEnd2 = 7 * 3600 + 20 * 60,

                    //the number of seconds at destination
                    Time = 300
                },

                new Address()
                {
                    AddressString    = "512 Florida Pl, Barberton, OH 44203",
                    Latitude         = 41.003671512008,
                    Longitude        = -81.598461046815,
                    TimeWindowStart  = 7 * 3600 + 30 * 60,
                    TimeWindowEnd    = 7 * 3600 + 40 * 60,
                    TimeWindowStart2 = 8 * 3600 + 00 * 60,
                    TimeWindowEnd2   = 8 * 3600 + 10 * 60,
                    Time             = 300
                },

                new Address()
                {
                    AddressString    = "512 Florida Pl, Barberton, OH 44203",
                    Latitude         = 41.003671512008,
                    Longitude        = -81.598461046815,
                    TimeWindowStart  = 8 * 3600 + 30 * 60,
                    TimeWindowEnd    = 8 * 3600 + 40 * 60,
                    TimeWindowStart2 = 8 * 3600 + 50 * 60,
                    TimeWindowEnd2   = 9 * 3600 + 00 * 60,
                    Time             = 100
                },

                new Address()
                {
                    AddressString    = "3495 Purdue St, Cuyahoga Falls, OH 44221",
                    Latitude         = 41.162971496582,
                    Longitude        = -81.479049682617,
                    TimeWindowStart  = 9 * 3600 + 00 * 60,
                    TimeWindowEnd    = 9 * 3600 + 15 * 60,
                    TimeWindowStart2 = 9 * 3600 + 30 * 60,
                    TimeWindowEnd2   = 9 * 3600 + 45 * 60,
                    Time             = 300
                },

                new Address()
                {
                    AddressString    = "1659 Hibbard Dr, Stow, OH 44224",
                    Latitude         = 41.194505989552,
                    Longitude        = -81.443351581693,
                    TimeWindowStart  = 10 * 3600 + 00 * 60,
                    TimeWindowEnd    = 10 * 3600 + 15 * 60,
                    TimeWindowStart2 = 10 * 3600 + 30 * 60,
                    TimeWindowEnd2   = 10 * 3600 + 45 * 60,
                    Time             = 300
                },

                new Address()
                {
                    AddressString    = "2705 N River Rd, Stow, OH 44224",
                    Latitude         = 41.145240783691,
                    Longitude        = -81.410247802734,
                    TimeWindowStart  = 11 * 3600 + 00 * 60,
                    TimeWindowEnd    = 11 * 3600 + 15 * 60,
                    TimeWindowStart2 = 11 * 3600 + 30 * 60,
                    TimeWindowEnd2   = 11 * 3600 + 45 * 60,
                    Time             = 300
                },

                new Address()
                {
                    AddressString    = "10159 Bissell Dr, Twinsburg, OH 44087",
                    Latitude         = 41.340042114258,
                    Longitude        = -81.421226501465,
                    TimeWindowStart  = 12 * 3600 + 00 * 60,
                    TimeWindowEnd    = 12 * 3600 + 15 * 60,
                    TimeWindowStart2 = 12 * 3600 + 30 * 60,
                    TimeWindowEnd2   = 12 * 3600 + 45 * 60,
                    Time             = 300
                },

                new Address()
                {
                    AddressString    = "367 Cathy Dr, Munroe Falls, OH 44262",
                    Latitude         = 41.148578643799,
                    Longitude        = -81.429229736328,
                    TimeWindowStart  = 13 * 3600 + 00 * 60,
                    TimeWindowEnd    = 13 * 3600 + 15 * 60,
                    TimeWindowStart2 = 13 * 3600 + 30 * 60,
                    TimeWindowEnd2   = 13 * 3600 + 45 * 60,
                    Time             = 300
                },

                new Address()
                {
                    AddressString    = "367 Cathy Dr, Munroe Falls, OH 44262",
                    Latitude         = 41.148578643799,
                    Longitude        = -81.429229736328,
                    TimeWindowStart  = 14 * 3600 + 00 * 60,
                    TimeWindowEnd    = 14 * 3600 + 15 * 60,
                    TimeWindowStart2 = 14 * 3600 + 30 * 60,
                    TimeWindowEnd2   = 14 * 3600 + 45 * 60,
                    Time             = 300
                },

                new Address()
                {
                    AddressString    = "512 Florida Pl, Barberton, OH 44203",
                    Latitude         = 41.003671512008,
                    Longitude        = -81.598461046815,
                    TimeWindowStart  = 15 * 3600 + 00 * 60,
                    TimeWindowEnd    = 15 * 3600 + 15 * 60,
                    TimeWindowStart2 = 15 * 3600 + 30 * 60,
                    TimeWindowEnd2   = 15 * 3600 + 45 * 60,
                    Time             = 300
                },

                new Address()
                {
                    AddressString    = "559 W Aurora Rd, Northfield, OH 44067",
                    Latitude         = 41.315116882324,
                    Longitude        = -81.558746337891,
                    TimeWindowStart  = 16 * 3600 + 00 * 60,
                    TimeWindowEnd    = 16 * 3600 + 15 * 60,
                    TimeWindowStart2 = 16 * 3600 + 30 * 60,
                    TimeWindowEnd2   = 17 * 3600 + 00 * 60,
                    Time             = 50
                }

                #endregion
            };

            // Set parameters
            RouteParameters parameters = new RouteParameters()
            {
                AlgorithmType = AlgorithmType.TSP,
                StoreRoute    = false,
                RouteName     = "Single Driver Multiple TimeWindows 12 Stops",

                RouteDate    = R4MeUtils.ConvertToUnixTimestamp(DateTime.UtcNow.Date.AddDays(1)),
                RouteTime    = 5 * 3600 + 30 * 60,
                Optimize     = Optimize.Distance.Description(),
                DistanceUnit = DistanceUnit.MI.Description(),
                DeviceType   = DeviceType.Web.Description()
            };

            OptimizationParameters optimizationParameters = new OptimizationParameters()
            {
                Addresses  = addresses,
                Parameters = parameters
            };

            // Run the query
            string     errorString;
            DataObject dataObject = route4Me.RunOptimization(optimizationParameters, out errorString);

            // Output the result
            PrintExampleOptimizationResult("SingleDriverMultipleTimeWindows", dataObject, errorString);

            return(dataObject);
        }
Esempio n. 24
0
        /// <summary>
        /// The Example refers to the process of creating an optimization
        /// with advanced constraints (including driver skills).
        /// </summary>
        public void CreateOptimizationWithDriverSkills()
        {
            // Create the manager with the api key
            var route4Me = new Route4MeManagerV5(ActualApiKey);

            #region Create Skilled Drivers

            int?ownerId = GetOwnerMemberId();

            if (ownerId == null)
            {
                return;
            }

            #region 1st Driver

            var newMemberParameters1 = new TeamRequest()
            {
                NewPassword     = testPassword,
                MemberFirstName = "John1",
                MemberLastName  = "Doe1",
                MemberCompany   = "Test Member Created",
                MemberEmail     = GetTestEmail().Replace("+", "1+"),
                OwnerMemberId   = (int)ownerId
            };

            newMemberParameters1.SetMemberType(DataTypes.V5.MemberTypes.Driver);

            var route4MeV5 = new Route4MeManagerV5(ActualApiKey);

            // Run the query
            var member1 = route4MeV5.CreateTeamMember(newMemberParameters1,
                                                      out DataTypes.V5.ResultResponse resultResponse);

            if (member1 != null && member1.GetType() == typeof(DataTypes.V5.TeamResponse))
            {
                membersToRemove.Add(member1);
            }

            var queryParams1 = new MemberQueryParameters()
            {
                UserId = member1.MemberId.ToString()
            };

            string[] skills1 = new string[]
            {
                "Class A CDL", "Forklift"
            };

            var updatedMember1 = route4MeV5.AddSkillsToDriver(queryParams1,
                                                              skills1,
                                                              out resultResponse);

            #endregion

            #region 2nd Driver

            var newMemberParameters2 = new TeamRequest()
            {
                NewPassword     = testPassword,
                MemberFirstName = "John2",
                MemberLastName  = "Doe2",
                MemberCompany   = "Test Member Created",
                MemberEmail     = GetTestEmail().Replace("+", "2+"),
                OwnerMemberId   = (int)ownerId
            };

            newMemberParameters2.SetMemberType(DataTypes.V5.MemberTypes.Driver);

            // Run the query
            var member2 = route4MeV5.CreateTeamMember(newMemberParameters2,
                                                      out resultResponse);

            if (member2 != null && member2.GetType() == typeof(DataTypes.V5.TeamResponse))
            {
                membersToRemove.Add(member2);
            }

            var queryParams2 = new MemberQueryParameters()
            {
                UserId = member2.MemberId.ToString()
            };

            string[] skills2 = new string[]
            {
                "Forklift", "Skid Steer Loader"
            };

            var updatedMember2 = route4MeV5.AddSkillsToDriver(queryParams2,
                                                              skills2,
                                                              out resultResponse);

            #endregion

            #endregion

            // Prepare the addresses
            var addresses = new Address[]
            {
                #region Addresses

                new Address()
                {
                    AddressString = "3634 W Market St, Fairlawn, OH 44333",
                    //all possible originating locations are depots, should be marked as true
                    //stylistically we recommend all depots should be at the top of the destinations list
                    IsDepot   = true,
                    Latitude  = 41.135762259364,
                    Longitude = -81.629313826561,

                    //the number of seconds at destination
                    Time = 300,

                    //together these two specify the time window of a destination
                    //seconds offset relative to the route start time for the open availability of a destination
                    TimeWindowStart = 28800,

                    //seconds offset relative to the route end time for the open availability of a destination
                    TimeWindowEnd = 29465
                },

                new Address()
                {
                    AddressString   = "1218 Ruth Ave, Cuyahoga Falls, OH 44221",
                    Latitude        = 41.135762259364,
                    Longitude       = -81.629313826561,
                    Time            = 300,
                    TimeWindowStart = 29465,
                    TimeWindowEnd   = 30529
                },

                new Address()
                {
                    AddressString   = "512 Florida Pl, Barberton, OH 44203",
                    Latitude        = 41.003671512008,
                    Longitude       = -81.598461046815,
                    Time            = 300,
                    TimeWindowStart = 30529,
                    TimeWindowEnd   = 33779,
                    Tags            = new string[] { "Class A CDL", "Forklift" }
                },

                new Address()
                {
                    AddressString   = "512 Florida Pl, Barberton, OH 44203",
                    IsDepot         = true,
                    Latitude        = 41.003671512008,
                    Longitude       = -81.598461046815,
                    Time            = 100,
                    TimeWindowStart = 33779,
                    TimeWindowEnd   = 33944
                },

                new Address()
                {
                    AddressString   = "3495 Purdue St, Cuyahoga Falls, OH 44221",
                    Latitude        = 41.162971496582,
                    Longitude       = -81.479049682617,
                    Time            = 300,
                    TimeWindowStart = 33944,
                    TimeWindowEnd   = 34801,
                    Tags            = new string[] { "Forklift", "Skid Steer Loader" }
                },

                new Address()
                {
                    AddressString   = "1659 Hibbard Dr, Stow, OH 44224",
                    Latitude        = 41.194505989552,
                    Longitude       = -81.443351581693,
                    Time            = 300,
                    TimeWindowStart = 34801,
                    TimeWindowEnd   = 36366
                },

                new Address()
                {
                    AddressString   = "2705 N River Rd, Stow, OH 44224",
                    Latitude        = 41.145240783691,
                    Longitude       = -81.410247802734,
                    Time            = 300,
                    TimeWindowStart = 36366,
                    TimeWindowEnd   = 39173
                },

                new Address()
                {
                    AddressString   = "10159 Bissell Dr, Twinsburg, OH 44087",
                    Latitude        = 41.340042114258,
                    Longitude       = -81.421226501465,
                    Time            = 300,
                    TimeWindowStart = 39173,
                    TimeWindowEnd   = 41617
                },

                new Address()
                {
                    AddressString   = "367 Cathy Dr, Munroe Falls, OH 44262",
                    Latitude        = 41.148578643799,
                    Longitude       = -81.429229736328,
                    Time            = 300,
                    TimeWindowStart = 41617,
                    TimeWindowEnd   = 43660
                },

                new Address()
                {
                    AddressString   = "367 Cathy Dr, Munroe Falls, OH 44262",
                    Latitude        = 41.148578643799,
                    Longitude       = -81.429229736328,
                    Time            = 300,
                    TimeWindowStart = 43660,
                    TimeWindowEnd   = 46392
                },

                new Address()
                {
                    AddressString   = "512 Florida Pl, Barberton, OH 44203",
                    Latitude        = 41.003671512008,
                    Longitude       = -81.598461046815,
                    Time            = 300,
                    TimeWindowStart = 46392,
                    TimeWindowEnd   = 48389
                },

                new Address()
                {
                    AddressString   = "559 W Aurora Rd, Northfield, OH 44067",
                    Latitude        = 41.315116882324,
                    Longitude       = -81.558746337891,
                    Time            = 50,
                    TimeWindowStart = 48389,
                    TimeWindowEnd   = 48449
                },

                new Address()
                {
                    AddressString   = "3933 Klein Ave, Stow, OH 44224",
                    Latitude        = 41.169467926025,
                    Longitude       = -81.429420471191,
                    Time            = 300,
                    TimeWindowStart = 48449,
                    TimeWindowEnd   = 50152
                },

                new Address()
                {
                    AddressString   = "2148 8th St, Cuyahoga Falls, OH 44221",
                    Latitude        = 41.136692047119,
                    Longitude       = -81.493492126465,
                    Time            = 300,
                    TimeWindowStart = 50152,
                    TimeWindowEnd   = 51982
                },

                new Address()
                {
                    AddressString   = "3731 Osage St, Stow, OH 44224",
                    Latitude        = 41.161357879639,
                    Longitude       = -81.42293548584,
                    Time            = 100,
                    TimeWindowStart = 51982,
                    TimeWindowEnd   = 52180
                },

                new Address()
                {
                    AddressString   = "3731 Osage St, Stow, OH 44224",
                    Latitude        = 41.161357879639,
                    Longitude       = -81.42293548584,
                    Time            = 300,
                    TimeWindowStart = 52180,
                    TimeWindowEnd   = 54379
                }

                #endregion
            };

            // Set parameters
            var parameters = new RouteParameters()
            {
                //specify capacitated vehicle routing with time windows and multiple depots, with multiple drivers
                AlgorithmType = AlgorithmType.ADVANCED_CVRP_TW,

                //set an arbitrary route name
                //this value shows up in the website, and all the connected mobile device
                RouteName = "Multiple Depot, Multiple Driver",

                //the route start date in UTC, unix timestamp seconds (Tomorrow)
                RouteDate = R4MeUtils.ConvertToUnixTimestamp(DateTime.UtcNow.Date.AddDays(1)),
                //the time in UTC when a route is starting (7AM)
                RouteTime = 60 * 60 * 7,

                //the maximum duration of a route
                RouteMaxDuration     = 86400,
                VehicleCapacity      = 7,
                VehicleMaxDistanceMI = 10000,

                Optimize     = Optimize.Distance.Description(),
                DistanceUnit = DistanceUnit.MI.Description(),
                DeviceType   = DeviceType.Web.Description(),
                TravelMode   = TravelMode.Driving.Description(),
                Metric       = Metric.Geodesic,

                AdvancedConstraints = new DataTypes.V5.RouteAdvancedConstraints[]
                {
                    new DataTypes.V5.RouteAdvancedConstraints()
                    {
                        AvailableTimeWindows = new List <int[]>()
                        {
                            new int[] { 25200, 39600 },
                            new int[] { 57600, 61200 }
                        },
                        MaximumCapacity    = 30,
                        MaximumCargoVolume = 15,
                        MembersCount       = 10,
                        Tags = new string[] { "Forklift", "Skid Steer Loader" },
                        Route4meMembersId = new int[]
                        {
                            (int)updatedMember1.MemberId,
                            (int)updatedMember2.MemberId
                        }
                    }
                }
            };

            var optimizationParameters = new OptimizationParameters()
            {
                Addresses  = addresses,
                Parameters = parameters
            };

            // Run the query
            DataObject dataObject = route4Me.RunOptimization(
                optimizationParameters,
                out ResultResponse resultResponse1);

            OptimizationsToRemove = new List <string>()
            {
                dataObject?.OptimizationProblemId ?? null
            };

            // Output the result
            PrintExampleOptimizationResult(
                dataObject,
                resultResponse1.Messages.Count > 0 ? String.Join(Environment.NewLine, resultResponse1.Messages) : ""
                );

            RemoveTestOptimizations();

            RemoveTestTeamMembers();
        }