void OnGUI() { GUI.Box(new Rect(10, 10, 300, 150), "Menu"); if (GUI.Button(new Rect(30, 30, 200, 30), "Compute convex covers")) { foreach (Collider go in this.userInputCustomersList) { Destroy(go); // destroy old customers } userInputCustomersList = new LinkedList <Collider>(); infoText.text = "Calculating Convex Covers"; isAutomaticConvexCover = true; } if (GUI.Button(new Rect(30, 70, 200, 30), "Set covers manually")) { foreach (Collider go in this.userInputCustomersList) { Destroy(go); // destroy old customers } userInputCustomersList = new LinkedList <Collider>(); infoText.text = "Set guarding positions by middle mouse click"; isPositioning = true; } if (GUI.Button(new Rect(30, 110, 200, 30), "Start patrolling")) { isPositioning = false; /*get customers*/ this.customers = new Vector3[userInputCustomersList.Count]; int i = 0; foreach (Collider go in this.userInputCustomersList) { this.customers[i] = go.transform.position; i++; } /* computer VRP */ infoText.text = "Compute VRP.."; VRP VRPsolver = new VRP(drones, this.customers); VRPsolver.computeRoutes(); VRPsolution sol = VRPsolver.getSolution(); sol.comunicateRoutesToDrones(); infoText.text = "Routes communicated to drones."; } }
public dynamic Long_Route_VRP(VRP vrp) { string endpointPath = ""; endpointPath = vrp.getLongRouting(); dynamic json_string = ""; // Define your target string url = this.url + "/v" + this.version + endpointPath; try { var json = JsonConvert.SerializeObject(vrp); VRPObject root = new VRPObject(); WebRequest myReq = WebRequest.Create(url); myReq.Method = "POST"; myReq.ContentType = "application/json; charset=UTF-8"; myReq.Headers.Add("Authorization:Bearer " + this.token); using (var streamWriter = new StreamWriter(myReq.GetRequestStream())) { streamWriter.Write(json); streamWriter.Flush(); streamWriter.Close(); } var result = ""; using (HttpWebResponse response = myReq.GetResponse() as HttpWebResponse) { int statusCode = (int)response.StatusCode; StreamReader reader = new StreamReader(response.GetResponseStream()); result = reader.ReadToEnd(); } try { json_string = JsonConvert.DeserializeObject(result); string job_id = json_string["job_id"].ToString(); var respone = this.jobPoll(job_id); List <Solution> slt = new List <Solution>(); dynamic responejson = JsonConvert.DeserializeObject(respone.ToString()); dynamic output = JsonConvert.DeserializeObject(respone["output"].ToString()); dynamic dynJson = JsonConvert.DeserializeObject(respone["output"]["solution"].ToString()); //dynamic solution = JsonConvert.DeserializeObject(dynJson.solution.ToString()); foreach (var vehicle_item in dynJson) { List <Route> d = JsonConvert.DeserializeObject <List <Route> >(vehicle_item.Value.ToString()); Solution m = new Solution(); m.vehicle = vehicle_item.Name; m.route = d; slt.Add(m); } root.status = output.status; root.total_travel_time = output.total_travel_time; root.total_break_time = output.total_break_time; root.total_idle_time = output.total_idle_time; root.num_unserved = output.num_unserved; root.unserved = output.unserved; root.solution = slt; LongResultVRP l = new LongResultVRP(); l.Id = responejson._id; l.Status = responejson.status; l.InputId = responejson.id; l.RequestId = responejson.requestId; l.CreatedAt = responejson.createdAt; l.FinishedAt = responejson.finished_at; l.Output = root; l.FetchedCount = responejson.fetchedCount; return(l); } catch { Console.WriteLine("job Id fail"); return(null); } } catch (WebException ex) { var resp = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd(); dynamic obj = JsonConvert.DeserializeObject(resp); //Console.WriteLine(obj); //throw new Exception(ex.Message); return(obj); } }
public void TestMethod1() { string accessToken = System.Configuration.ConfigurationManager.AppSettings["accessToken"]; string email = System.Configuration.ConfigurationManager.AppSettings["email"]; string password = System.Configuration.ConfigurationManager.AppSettings["password"]; #region VRP VRP vrp = new VRP(); /*Add Visits */ var visit = new Visits() { Location = new Location { Name = "6800 Cambie", Lat = 49.227107, Lng = -123.1163085, }, Start = "8:00", End = "16:00", Duration = 10, }; vrp.addVisit("order_1", visit); var visit2 = new Visits() { Location = new Location { Name = "6800 Cambie", Lat = 49.227107, Lng = -123.1163085, }, Start = "9:00", End = "16:00", Duration = 10, }; vrp.addVisit("order_2", visit2); /*Add Vehicle */ var vehicle = new Vehicle() { StartLocation = new Location { Id = "depot", Lat = 49.2553636, Lng = -123.0873365, }, EndLocation = new Location { Id = "depot", Lat = 49.2553636, Lng = -123.0873365, }, }; vrp.addVehicle("vehicle_1", vehicle); /*Add Option */ vrp.addOption("traffic", "slow"); vrp.addOption("shortest_distance", true); #endregion /* ================== */ #region PDP PDP pdp = new PDP(); var pdp_order1 = new VisitsPDP() { Load = 1, Pickup = new Pickup { Location = new LocationPDP { Name = "3780 Arbutus", Lat = 49.2474624, Lng = -123.1532338, }, Start = "9:00", End = "12:00", Duration = 10, }, Dropoff = new Dropoff { Location = new LocationPDP { Name = "6800 Cambie", Lat = 49.227107, Lng = -123.1163085, }, Start = "9:00", End = "12:00", Duration = 10, }, }; pdp.addVisitPDP("pdp_order1", pdp_order1); var pdp_order2 = new VisitsPDP() { Load = 1, Pickup = new Pickup { Location = new LocationPDP { Name = "3780 Arbutus", Lat = 49.2474624, Lng = -123.1532338, }, Start = "9:00", End = "12:00", Duration = 10, }, Dropoff = new Dropoff { Location = new LocationPDP { Name = "800 Robson", Lat = 49.2819229, Lng = -123.1211844, }, Start = "9:00", End = "12:00", Duration = 10, }, }; pdp.addVisitPDP("pdp_order2", pdp_order2); /*Add Vehicle PDP */ var pdp_vehicle_1 = new VehiclePDP() { StartLocation = new LocationPDP { Id = "depot", Name = "800 Kingsway", Lat = 49.2553636, Lng = -123.0873365, }, EndLocation = new LocationPDP { Id = "depot", Name = "800 Kingsway", Lat = 49.2553636, Lng = -123.0873365, }, ShiftStart = "8:00", ShiftEnd = "12:00", Capacity = 2 }; pdp.addVehiclePDP("pdp_vehicle_1", pdp_vehicle_1); var pdp_vehicle_2 = new VehiclePDP() { StartLocation = new LocationPDP { Id = "depot 2", Name = "800 Robson", Lat = 49.2553636, Lng = -123.1211844, }, EndLocation = new LocationPDP { Id = "depot", Name = "800 Kingsway", Lat = 49.2553636, Lng = -123.0873365, }, ShiftStart = "8:00", ShiftEnd = "12:00", Capacity = 1 }; pdp.addVehiclePDP("pdp_vehicle_2", pdp_vehicle_2); #endregion Client client = new Client(); //var login = client.Login(email, password); //if(login["_id"] == null) //{ // Console.WriteLine(JValue.Parse(JsonConvert.SerializeObject(login)).ToString(Formatting.Indented)); // return; //} var pdp_output_long = client.Long_Route_PDP(pdp); var vrp_output_long = client.Long_Route_VRP(vrp); Console.WriteLine(JValue.Parse(JsonConvert.SerializeObject(pdp_output_long)).ToString(Formatting.Indented)); }
/// <summary> /// solve a VRP problem Adds an item to the system /// </summary> /// <exception cref="SolviceRoutingClient.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="body">VRP problem solve request (optional)</param> /// <returns>Task of ApiResponse (Job)</returns> public async System.Threading.Tasks.Task <ApiResponse <Job> > SolveVRPAsyncWithHttpInfo(VRP body = null) { var localVarPath = "/solve#VRP"; var localVarPathParams = new Dictionary <String, String>(); var localVarQueryParams = new List <KeyValuePair <String, String> >(); var localVarHeaderParams = new Dictionary <String, String>(this.Configuration.DefaultHeader); var localVarFormParams = new Dictionary <String, String>(); var localVarFileParams = new Dictionary <String, FileParameter>(); Object localVarPostBody = null; // to determine the Content-Type header String[] localVarHttpContentTypes = new String[] { "application/json" }; String localVarHttpContentType = this.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes); // to determine the Accept header String[] localVarHttpHeaderAccepts = new String[] { "application/json" }; String localVarHttpHeaderAccept = this.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts); if (localVarHttpHeaderAccept != null) { localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept); } if (body != null && body.GetType() != typeof(byte[])) { localVarPostBody = this.Configuration.ApiClient.Serialize(body); // http body (model) parameter } else { localVarPostBody = body; // byte array } // authentication (basicAuth) required // http basic authentication required if (!String.IsNullOrEmpty(this.Configuration.Username) || !String.IsNullOrEmpty(this.Configuration.Password)) { localVarHeaderParams["Authorization"] = "Basic " + ApiClient.Base64Encode(this.Configuration.Username + ":" + this.Configuration.Password); } // make the HTTP request IRestResponse localVarResponse = (IRestResponse)await this.Configuration.ApiClient.CallApiAsync(localVarPath, Method.POST, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams, localVarPathParams, localVarHttpContentType); int localVarStatusCode = (int)localVarResponse.StatusCode; if (ExceptionFactory != null) { Exception exception = ExceptionFactory("SolveVRP", localVarResponse); if (exception != null) { throw exception; } } return(new ApiResponse <Job>(localVarStatusCode, localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()), (Job)this.Configuration.ApiClient.Deserialize(localVarResponse, typeof(Job)))); }
/// <summary> /// solve a VRP problem Adds an item to the system /// </summary> /// <exception cref="SolviceRoutingClient.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="body">VRP problem solve request (optional)</param> /// <returns>Task of Job</returns> public async System.Threading.Tasks.Task <Job> SolveVRPAsync(VRP body = null) { ApiResponse <Job> localVarResponse = await SolveVRPAsyncWithHttpInfo(body); return(localVarResponse.Data); }
/// <summary> /// solve a VRP problem Adds an item to the system /// </summary> /// <exception cref="SolviceRoutingClient.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="body">VRP problem solve request (optional)</param> /// <returns>Job</returns> public Job SolveVRP(VRP body = null) { ApiResponse <Job> localVarResponse = SolveVRPWithHttpInfo(body); return(localVarResponse.Data); }