コード例 #1
0
ファイル: ApiTests.cs プロジェクト: nfleet/.net-sdk
        public void T30RequestingVehicleTypesFromProblem()
        {
            var api = TestHelper.Authenticate();
            var user = TestHelper.GetOrCreateUser( api );
            var problem = TestHelper.CreateProblem( api, user, "VehicleTypeTest" );

            var vehicleTypes = new List<string> {"Rekka", "Auto", "Mopo"};
            var vehicleSet = new VehicleSetImportRequest
            {
                Items = new List<VehicleUpdateRequest>()
            };

            for ( int i = 0; i < 3; i++ )
            {
                var vehicle = TestHelper.GenerateVehicleUpdateRequestWithName( "Vehicle" + i );
                vehicle.VehicleType = vehicleTypes[i];
                vehicleSet.Items.Add( vehicle );
            }

            var response = api.Navigate<ResponseData>(problem.GetLink("import-vehicles"), vehicleSet);
            
            var types = api.Navigate<VehicleTypeData>(problem.GetLink("get-types"));

            Assert.AreEqual(types.VehicleTypes.Count, vehicleTypes.Count);
        }
コード例 #2
0
ファイル: ApiTests.cs プロジェクト: nfleet/.net-sdk
        public void T27ApplyImportedVehiclesAndTasks()
        {
            var api = TestHelper.Authenticate();
            var user = TestHelper.GetOrCreateUser(api);
            var problem = TestHelper.CreateProblem(api, user, "applied-import-problem");

            var vehicleSet = new VehicleSetImportRequest
            {
                Items = new List<VehicleUpdateRequest>()
            };

            for (int i = 0; i < 5; i++)
            {
                var vehicle = TestHelper.GenerateVehicleUpdateRequestWithName("Vehicle" + i);
                vehicleSet.Items.Add(vehicle);
            }


            var taskSet = new TaskSetImportRequest
            {
                Items = new List<TaskUpdateRequest>()
            };

            for (int i = 0; i < 5; i++)
            {
                var task = TestHelper.GenerateTaskUpdateRequestWithName("Task" + i);
                taskSet.Items.Add(task);
            }

            var depotSet = new ImportDepotSetRequest { Items = new List<UpdateDepotRequest>() };

            var request = new ImportRequest
            {
                Tasks = taskSet,
                Vehicles = vehicleSet,
                Depots = depotSet
            };

            var result = api.Navigate<ResponseData>(problem.GetLink("import-data"), request);

            var import = api.Navigate<ImportData>(result.Location);

            Assert.AreEqual("Success", import.State);
            Assert.AreEqual(0, import.ErrorCount);
            Assert.AreEqual(5, import.Vehicles.Count);
            Assert.AreEqual(5, import.Tasks.Count);

            Assert.IsTrue(import.Meta.Find(link => link.Rel.Equals("self")).Enabled);
            Assert.IsTrue(import.Meta.Find(link => link.Rel.Equals("apply-import")).Enabled);
            //##BEGIN EXAMPLE applyimport##
            var appyResult = api.Navigate<ResponseData>(import.GetLink("apply-import"));
            problem = api.Navigate<RoutingProblemData>(problem.GetLink("self"));

            // now we wait for NFleet to do geocoding i.e. data state turns from 'Pending' into 'Ready'
            while (problem.DataState == "Pending")
            {
                Thread.Sleep(1000);
                problem = api.Navigate<RoutingProblemData>( problem.GetLink( "self" ) );
            }
            //##END EXAMPLE##
            var vehicles = api.Navigate<VehicleDataSet>(problem.GetLink("list-vehicles"));
            var tasks = api.Navigate<VehicleDataSet>(problem.GetLink("list-tasks"));
            Assert.AreEqual(5, vehicles.Items.Count);
            Assert.AreEqual(5, tasks.Items.Count);
        }
コード例 #3
0
ファイル: ApiTests.cs プロジェクト: nfleet/.net-sdk
        public void T22VehicleMassImport()
        {
            var api = TestHelper.Authenticate();
            var user = TestHelper.GetOrCreateUser(api);
            var problem = TestHelper.CreateProblemWithDemoData(api, user);
            //vehiclemassimport

            var vehicleCapacities = new List<CapacityData> {new CapacityData() {Name = "Weight", Amount = 100000}};

            var vehicleTimeWindow = new List<TimeWindowData>
            {
                new TimeWindowData
                {
                    Start = new DateTime(2013, 5, 14, 7, 0, 0),
                    End = new DateTime(2013, 5, 14, 16, 0, 0)
                }
            };

            var vehiclePickup = new LocationData()
            {
                Coordinate = new CoordinateData {Latitude = 62.244588, Longitude = 25.742683, System = "WGS84"}
            };
            var vehicleDelivery = new LocationData()
            {
                Coordinate = new CoordinateData {Latitude = 62.244588, Longitude = 25.742683, System = "WGS84"}
            };

            //##BEGIN EXAMPLE importvehicleset##
            var importRequest = new VehicleSetImportRequest
            {
                Items = new List<VehicleUpdateRequest>()
            };

            for (int i = 0; i < 10; i++)
            {
                var veh = new VehicleUpdateRequest()
                {
                    Name = "Vehicle name "+i,
                    Capacities = vehicleCapacities,
                    StartLocation = vehiclePickup,
                    EndLocation = vehicleDelivery,
                    TimeWindows = vehicleTimeWindow,
                    RelocationType = "None"
                };
                importRequest.Items.Add(veh);
            }

            var result = api.Navigate<ResponseData>(problem.GetLink("import-vehicles"), importRequest);
            var vehicles = api.Navigate<VehicleDataSet>( problem.GetLink( "list-vehicles" ) );
            //##END EXAMPLE##
        }
コード例 #4
0
ファイル: ApiTests.cs プロジェクト: nfleet/.net-sdk
        public void T26ImportVehiclesAndTasksFails()
        {
            var api = TestHelper.Authenticate();
            var user = TestHelper.GetOrCreateUser(api);
            var problem = TestHelper.CreateProblem(api, user, "failing-import-problem2");

            var vehicleSet = new VehicleSetImportRequest
            {
                Items = new List<VehicleUpdateRequest>()
            };

            for (int i = 0; i < 4; i++)
            {
                var vehicle = TestHelper.GenerateVehicleUpdateRequestWithName("Vehicle" + i);
                vehicleSet.Items.Add(vehicle);
            }
            vehicleSet.Items.Add(TestHelper.GenerateVehicleUpdateRequestWithName(""));

            var taskSet = new TaskSetImportRequest
            {
                Items = new List<TaskUpdateRequest>()
            };

            for (int i = 0; i < 4; i++)
            {
                var task = TestHelper.GenerateTaskUpdateRequestWithName("Task" + i);
                taskSet.Items.Add(task);
            }
            taskSet.Items.Add(TestHelper.GenerateTaskUpdateRequestWithName(""));

            var depotSet = new ImportDepotSetRequest { Items = new List<UpdateDepotRequest>() };

            var request = new ImportRequest
            {
                Tasks = taskSet,
                Vehicles = vehicleSet,
                Depots = depotSet
            };
            var result = api.Navigate<ResponseData>(problem.GetLink("import-data"), request);


            var import = api.Navigate<ImportData>(result.Location);

            Assert.AreEqual("Fail", import.State);
            Assert.AreEqual(2, import.ErrorCount);
            Assert.AreEqual(5, import.Vehicles.Count);
            Assert.AreEqual(5, import.Tasks.Count);

            Assert.IsTrue(import.Meta.Find(link => link.Rel.Equals("self")).Enabled);
            Assert.IsFalse(import.Meta.Find(link => link.Rel.Equals("apply-import")).Enabled);
        }
コード例 #5
0
ファイル: ApiTests.cs プロジェクト: nfleet/.net-sdk
        public void T20VehicleImportSpeedTest()
        {
            var api = TestHelper.Authenticate();
            var user = TestHelper.GetOrCreateUser(api);
            var problem = TestHelper.CreateProblemWithDemoData(api, user);

            var vehicleCapacities = new List<CapacityData> {new CapacityData() {Name = "Weight", Amount = 100000}};

            var vehicleTimeWindow = new List<TimeWindowData>
            {
                new TimeWindowData
                {
                    Start = new DateTime(2013, 5, 14, 7, 0, 0),
                    End = new DateTime(2013, 5, 14, 16, 0, 0)
                }
            };

            var vehiclePickup = new LocationData()
            {
                Coordinate = new CoordinateData {Latitude = 62.244588, Longitude = 25.742683, System = "WGS84"}
            };
            var vehicleDelivery = new LocationData()
            {
                Coordinate = new CoordinateData {Latitude = 62.244588, Longitude = 25.742683, System = "WGS84"}
            };
            var importRequest = new VehicleSetImportRequest
            {
                Items = new List<VehicleUpdateRequest>()
            };

            for (int i = 0; i < 10; i++)
            {
                var veh = new VehicleUpdateRequest()
                {
                    Name = "Vehicle" + i + 1,
                    Capacities = vehicleCapacities,
                    StartLocation = vehiclePickup,
                    EndLocation = vehicleDelivery,
                    TimeWindows = vehicleTimeWindow,
                    RelocationType = "None"
                };
                importRequest.Items.Add(veh);
            }

            Stopwatch timer = new Stopwatch();
            timer.Start();
            var result = api.Navigate<ResponseData>(problem.GetLink("import-vehicles"), importRequest);
            timer.Stop();
            Console.WriteLine("Time elapsed with set import: {0}", timer.Elapsed);



            var vehicleList = new List<VehicleUpdateRequest>();
            for (int i = 0; i < 10; i++)
            {
                var vehicleReq = new VehicleUpdateRequest()
                {
                    Name = "Car" + i + 1,
                    Capacities = vehicleCapacities,
                    StartLocation = vehiclePickup,
                    EndLocation = vehicleDelivery,
                    TimeWindows = vehicleTimeWindow,
                    RelocationType = "None"
                };
                vehicleList.Add(vehicleReq);
            }

            timer = new Stopwatch();
            timer.Start();
            foreach (var request in vehicleList)
            {
                api.Navigate<ResponseData>(problem.GetLink("create-vehicle"), request);
            }
            timer.Stop();
            Console.WriteLine("Time elapsed with 100 create operations: {0}", timer.Elapsed);
        }