internal static TaskData GetTask( Api api, RoutingProblemData problem ) { var tasks = api.Navigate<TaskDataSet>( problem.GetLink( "list-tasks" ) ); var newTask = new TaskUpdateRequest { Name = "test name", RelocationType = "None", ActivityState = "Active" }; var capacity = new CapacityData { Name = "Weight", Amount = 20 }; var pickup = new TaskEventUpdateRequest { Type = "Pickup", Location = new LocationData { Coordinate = new CoordinateData { Latitude = 62.244958, Longitude = 25.747143, System = "Euclidian" } }, TimeWindows = { new TimeWindowData { Start = new DateTime( 2013, 5, 14, 8, 0, 0 ), End = new DateTime( 2013, 5, 14, 12, 0, 0 ) } } }; pickup.Capacities.Add( capacity ); newTask.TaskEvents.Add( pickup ); var delivery = new TaskEventUpdateRequest { Type = "Delivery", Location = new LocationData { Coordinate = new CoordinateData { Latitude = 62.244589, Longitude = 25.74892, System = "Euclidian" } }, TimeWindows = { new TimeWindowData { Start = new DateTime( 2013, 5, 14, 8, 0, 0 ), End = new DateTime( 2013, 5, 14, 12, 0, 0 ) } } }; delivery.Capacities.Add( capacity ); newTask.TaskEvents.Add( delivery ); var taskCreationResult = api.Navigate<ResponseData>( problem.GetLink( "create-task" ), newTask ); var task = api.Navigate<TaskData>( taskCreationResult.Location ); return task; }
public void T24TaskMassImport() { var api = TestHelper.Authenticate(); var user = TestHelper.GetOrCreateUser(api); var problem = TestHelper.CreateProblemWithDemoData(api, user); var capacity = new CapacityData {Name = "Weight", Amount = 20}; var timeWindows = 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 importtaskset## var importRequest = new TaskSetImportRequest { Items = new List<TaskUpdateRequest>() }; for (int i = 0; i < 10; i++) { var task = new TaskUpdateRequest {Name = "test name"}; task.RelocationType = "None"; task.ActivityState = "Active"; var pickup = new TaskEventUpdateRequest { Type = "Pickup", Location = new LocationData { Coordinate = new CoordinateData { Latitude = 62.244958, Longitude = 25.747143, System = "Euclidian" } }, TimeWindows = { new TimeWindowData { Start = new DateTime( 2013, 5, 14, 8, 0, 0 ), End = new DateTime( 2013, 5, 14, 12, 0, 0 ) } } }; pickup.Capacities.Add(capacity); task.TaskEvents.Add(pickup); var delivery = new TaskEventUpdateRequest { Type = "Delivery", Location = new LocationData { Coordinate = new CoordinateData { Latitude = 62.244589, Longitude = 25.74892, System = "Euclidian" } }, TimeWindows = { new TimeWindowData { Start = new DateTime( 2013, 5, 14, 8, 0, 0 ), End = new DateTime( 2013, 5, 14, 12, 0, 0 ) } } }; delivery.Capacities.Add(capacity); task.TaskEvents.Add(delivery); importRequest.Items.Add(task); } var result = api.Navigate<ResponseData>(problem.GetLink("import-tasks"), importRequest); //##END EXAMPLE## }
public static TaskUpdateRequest GenerateTaskUpdateRequestWithName(string name) { var task = new TaskUpdateRequest { Name = name, RelocationType = "None", ActivityState = "Active" }; var capacity = new CapacityData { Name = "Weight", Amount = 20 }; var pickup = new TaskEventUpdateRequest { Type = "Pickup", Location = new LocationData { Coordinate = new CoordinateData { Latitude = 62.282617, Longitude = 25.797272, System = "Euclidian" }, }, TimeWindows = { new TimeWindowData { Start = new DateTime(2013, 5, 14, 8, 0, 0), End = new DateTime(2013, 5, 14, 12, 0, 0) } } }; pickup.Capacities.Add(capacity); task.TaskEvents.Add(pickup); var delivery = new TaskEventUpdateRequest { Type = "Delivery", Location = new LocationData { Address = new AddressData { City = "Jyväskylä", Country = "Finland", Street = "Poratie 2", PostalCode = "40320" } }, TimeWindows = { new TimeWindowData { Start = new DateTime(2013, 5, 14, 8, 0, 0), End = new DateTime(2013, 5, 14, 12, 0, 0) } } }; delivery.Capacities.Add(capacity); task.TaskEvents.Add(delivery); return task; }
public void T05UpdatingTaskTest() { var api = TestHelper.Authenticate(); var user = TestHelper.GetOrCreateUser(api); var problem = TestHelper.CreateProblemWithDemoData(api, user); var task = TestHelper.GetTask(api, problem); var oldTaskEvents = new List<TaskEventUpdateRequest>(); foreach (var te in task.TaskEvents) { var teReq = new TaskEventUpdateRequest { Capacities = te.Capacities, Location = te.Location, ServiceTime = te.ServiceTime, TimeWindows = te.TimeWindows, Type = te.Type, }; oldTaskEvents.Add(teReq); } //##BEGIN EXAMPLE updatingtask## var newTaskRequest = new TaskUpdateRequest { Info = task.Info, Name = "Other name", TaskEvents = oldTaskEvents, RelocationType = task.RelocationType, ActivityState = task.ActivityState }; var newTaskLocation = api.Navigate<ResponseData>(task.GetLink("update"), newTaskRequest); //##END EXAMPLE## var newTask = api.Navigate<TaskData>(newTaskLocation.Location); Assert.AreEqual(newTaskRequest.Name, newTask.Name); }
public void T39CreatingTaskWithAddressTest() { var api = TestHelper.Authenticate(); var user = TestHelper.GetOrCreateUser( api ); var problem = TestHelper.CreateProblemWithDemoData( api, user ); var tasks = api.Navigate<TaskDataSet>( problem.GetLink( "list-tasks" ) ); //##BEGIN EXAMPLE creatingtaskwithaddress## var newTask = new TaskUpdateRequest { Name = "test name", RelocationType = "None", ActivityState = "Active" }; var capacity = new CapacityData { Name = "Weight", Amount = 20 }; var pickup = new TaskEventUpdateRequest { Type = "Pickup", Location = new LocationData { Address = new AddressData { Country = "Finland", Street = "Tuohitie", ApartmentNumber = 42, PostalCode = "40320", } }, TimeWindows = { new TimeWindowData { Start = new DateTime( 2013, 5, 14, 8, 0, 0 ), End = new DateTime( 2013, 5, 14, 12, 0, 0 ) } } }; pickup.Capacities.Add( capacity ); newTask.TaskEvents.Add( pickup ); var delivery = new TaskEventUpdateRequest { Type = "Delivery", Location = new LocationData { Address = new AddressData { Country = "Finland", Street = "Pajatie", ApartmentNumber = 8, ApartmentLetter = "F", PostalCode = "40630" } }, TimeWindows = { new TimeWindowData { Start = new DateTime( 2013, 5, 14, 8, 0, 0 ), End = new DateTime( 2013, 5, 14, 12, 0, 0 ) } } }; delivery.Capacities.Add( capacity ); newTask.TaskEvents.Add( delivery ); var taskCreationResult = api.Navigate<ResponseData>( problem.GetLink( "create-task" ), newTask ); //##END EXAMPLE## problem = api.Navigate<RoutingProblemData>(problem.GetLink("self")); while (problem.DataState.Equals("Pending")) { Thread.Sleep(1000); problem = api.Navigate<RoutingProblemData>(problem.GetLink("self")); } var task = api.Navigate<TaskData>(taskCreationResult.Location); Console.WriteLine( task.TaskEvents[0].Location.Address.Resolution ); Assert.NotNull(task.TaskEvents[0].Location.Address.Resolution); }
public void T04CreatingTaskTest() { var api = TestHelper.Authenticate(); var user = TestHelper.GetOrCreateUser(api); var problem = TestHelper.CreateProblemWithDemoData(api, user); var tasks = api.Navigate<TaskDataSet>(problem.GetLink("list-tasks")); //##BEGIN EXAMPLE creatingtask## var newTask = new TaskUpdateRequest { Name = "test name", RelocationType = "None", ActivityState = "Active" }; var capacity = new CapacityData {Name = "Weight", Amount = 20}; var pickup = new TaskEventUpdateRequest { Type = "Pickup", Location = new LocationData { Coordinate = new CoordinateData { Latitude = 62.244958, Longitude = 25.747143, System = "Euclidian" } }, TimeWindows = { new TimeWindowData { Start = new DateTime( 2013, 5, 14, 8, 0, 0 ), End = new DateTime( 2013, 5, 14, 12, 0, 0 ) } } }; pickup.Capacities.Add(capacity); newTask.TaskEvents.Add(pickup); var delivery = new TaskEventUpdateRequest { Type = "Delivery", Location = new LocationData { Coordinate = new CoordinateData { Latitude = 62.244589, Longitude = 25.74892, System = "Euclidian" } }, TimeWindows = { new TimeWindowData { Start = new DateTime( 2013, 5, 14, 8, 0, 0 ), End = new DateTime( 2013, 5, 14, 12, 0, 0 ) } } }; delivery.Capacities.Add(capacity); newTask.TaskEvents.Add(delivery); var taskCreationResult = api.Navigate<ResponseData>(problem.GetLink("create-task"), newTask); //##END EXAMPLE## var mockTaskCreationResult = TestUtils.GetMockResponse<ResponseData>(responses["creatingtaskresp"].json); TestUtils.ResponsesAreEqual(mockTaskCreationResult, taskCreationResult); ResponseWriter.Write(JsonConvert.SerializeObject(taskCreationResult, Formatting.Indented), "creatingtaskresp", responsePath + "/creatingtaskresp.dat"); }
private static void CreateDemoData( RoutingProblemData problem, Api api ) { // To build a test case we first need to create a vehicle. // We start by defining vehicle capacity. var vehicleCapacities = new List<CapacityData> {new CapacityData {Name = "Weight", Amount = 100000}}; // ...the time window(s) 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 ) }}; // ... the locations for pickup and delivery 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" }}; // And then we wrap these into a single vehicle update request. var vehicleUpdateRequest = new VehicleUpdateRequest { Name = "Vehicle1", Capacities = vehicleCapacities, StartLocation = vehiclePickup, EndLocation = vehicleDelivery, TimeWindows = vehicleTimeWindow, RelocationType = "None" }; api.Navigate<ResponseData>( problem.GetLink( "create-vehicle" ), vehicleUpdateRequest ); // This should have created a vehicle. // Next, we will create a pickup and delivery task. // The task will consist of two task events that are the pickup and delivery. // Define the capacity, location and time window for the pickup. var capacity = new CapacityData { Name = "Weight", Amount = 1 }; var task1PickupLocation = new LocationData { Coordinate = new CoordinateData { Latitude = 62.247906, Longitude = 25.867395, System = "WGS84" } }; var task1PickupTimeWindows = new List<TimeWindowData> { new TimeWindowData { Start = new DateTime(2013, 5, 14, 7, 0, 0), End = new DateTime(2013, 5, 14, 16, 0, 0) } }; //... and wrap it in a task event update request. var pickup = new TaskEventUpdateRequest { Type = "Pickup", Location = task1PickupLocation, TimeWindows = task1PickupTimeWindows, Capacities = new List<CapacityData> {capacity} }; // Then we do the same for the delivery. var task1DeliveryLocation = new LocationData { Coordinate = new CoordinateData { Latitude = 61.386909, Longitude = 24.654106, System = "WGS84" } }; var task1DeliveryTimeWindows = new List<TimeWindowData> { new TimeWindowData { Start = new DateTime(2013, 5, 14, 7, 0, 0), End = new DateTime(2013, 5, 14, 16, 0, 0) } }; var delivery = new TaskEventUpdateRequest { Type = "Delivery", Location = task1DeliveryLocation, TimeWindows = task1DeliveryTimeWindows, Capacities = new List<CapacityData> { capacity } }; // And finally we contain the pickup and delivery in a task update request and send it. var newTask = new TaskUpdateRequest {Name = "Task1", RelocationType = "None"}; newTask.TaskEvents.Add( pickup ); newTask.TaskEvents.Add( delivery ); api.Navigate<ResponseData>( problem.GetLink( "create-task" ), newTask ); // And this is how we can create optimization cases. }
public static void CreateDemoData(RoutingProblemData problem, Api api) { api.Navigate<ResponseData>(problem.GetLink("create-vehicle"), new VehicleUpdateRequest { Name = "TestVehicle-" + GenerateRandomString(8), Capacities = new List<CapacityData> { new CapacityData { Name = "Weight", Amount = 5000 } }, StartLocation = new LocationData { Coordinate = new CoordinateData { Latitude = 62.244958, Longitude = 25.747143, System = "Euclidian" } }, EndLocation = new LocationData { Coordinate = new CoordinateData { Latitude = 62.244958, Longitude = 25.747143, System = "Euclidian" } }, TimeWindows = { new TimeWindowData { Start = new DateTime(2013, 5, 14, 8, 0, 0), End = new DateTime(2013, 5, 14, 12, 0, 0) } }, RelocationType = "None", }); var newTask = new TaskUpdateRequest { Name = "task", RelocationType = "None", ActivityState = "Active" }; var capacity = new CapacityData { Name = "Weight", Amount = 20 }; var pickup = new TaskEventUpdateRequest { Type = "Pickup", Location = new LocationData { Coordinate = new CoordinateData { Latitude = 62.282617, Longitude = 25.797272, System = "Euclidian" } }, TimeWindows = { new TimeWindowData { Start = new DateTime(2013, 5, 14, 8, 0, 0), End = new DateTime(2013, 5, 14, 12, 0, 0) } } }; pickup.Capacities.Add(capacity); newTask.TaskEvents.Add(pickup); var delivery = new TaskEventUpdateRequest { Type = "Delivery", Location = new LocationData { Coordinate = new CoordinateData { Latitude = 62.373658, Longitude = 25.885506, System = "Euclidian" } }, TimeWindows = { new TimeWindowData { Start = new DateTime(2013, 5, 14, 8, 0, 0), End = new DateTime(2013, 5, 14, 12, 0, 0) } } }; delivery.Capacities.Add(capacity); newTask.TaskEvents.Add(delivery); api.Navigate<ResponseData>(problem.GetLink("create-task"), newTask); }