Skip to content

Commit d3e2657

Browse files
committed
MIO optimizer
1 parent f95c6b3 commit d3e2657

7 files changed

Lines changed: 39 additions & 16 deletions

File tree

‎Samples/REST Services/MIO/mio.html‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@
146146
// Show loading icon
147147
showLoadingIcon(true);
148148

149+
// Clear the route data source
150+
routeDataSource.clear();
151+
149152
// We need all coordinates together depots + stops
150153
const allCoordinates = [...depots, ...stops];
151154

@@ -248,10 +251,9 @@
248251
}
249252
};
250253

251-
console.log(optimizerBody);
252-
253254
// URL for making calls to the NVIDIA optimizer service.
254-
var optimizerUrl = 'https://api.nvcf.nvidia.com/v2/nvcf/exec/functions/4bb2668d-c877-4b89-aabf-1630ed9b32c3/versions/471b94dc-931e-4aa1-99f4-935f5f352737';
255+
//var optimizerUrl = 'https://api.nvcf.nvidia.com/v2/nvcf/exec/functions/4bb2668d-c877-4b89-aabf-1630ed9b32c3/versions/471b94dc-931e-4aa1-99f4-935f5f352737';
256+
var optimizerUrl = 'https://samples.azuremaps.com/api/optimizer'; // this is just demo data, use the real NVIDIA optimizer service
255257

256258
// Bearer token for the NVIDIA optimizer service.
257259
var tokenResponse = await fetch('https://samples.azuremaps.com/api/GetMIOKey');
@@ -276,8 +278,6 @@
276278
// Get the data from the response.
277279
var data = await optimizerResponse.json();
278280

279-
console.log(data);
280-
281281
// Wait until the optimization is complete
282282
while (data.percentComplete < 100) {
283283

‎Services/SampleFunctions/GetAzureMapsToken.cs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ public class GetAzureMapsToken()
1313
"https://demo.azuremaps.com/",
1414
"https://www.microsoft.com/",
1515
"https://microsoft.com/",
16-
"https://msmaps.azurewebsites.net/", // For local testing
17-
"http://localhost:58745/" // For local testing
16+
"https://msmaps.azurewebsites.net/" // For local testing
1817
];
1918

2019
/// <summary>

‎Services/SampleFunctions/GetBingMapsKey.cs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ namespace SampleFunctions;
77
public class GetBingMapsKey()
88
{
99
private static readonly string[] AllowedDomains = [
10-
"https://samples.bingmapsportal.com/",
11-
"https://www.microsoft.com/"
10+
"https://samples.bingmapsportal.com/"
1211
];
1312

1413
[Function("GetBingMapsKey")]

‎Services/SampleFunctions/GetDataFromUrl.cs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ namespace SampleFunctions;
77
public class GetDataFromUrl()
88
{
99
private static readonly string[] AllowedDomains = [
10-
"https://samples.azuremaps.com/",
11-
"https://www.microsoft.com/"
10+
"https://samples.azuremaps.com/"
1211
];
1312

1413
private static readonly HttpClient _HttpClient = new();

‎Services/SampleFunctions/GetGeolocation.cs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ namespace SampleFunctions;
1111
public static class GeolocationService
1212
{
1313
private static readonly string[] AllowedDomains = [
14-
"https://samples.azuremaps.com/",
15-
"https://www.microsoft.com/"
14+
"https://samples.azuremaps.com/"
1615
];
1716

1817
private static readonly HttpClient HttpClient = new();

‎Services/SampleFunctions/GetMIOKey.cs‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ namespace SampleFunctions;
77
public class GetMIOKey
88
{
99
private static readonly string[] AllowedDomains = [
10-
"https://samples.azuremaps.com/",
11-
"https://www.microsoft.com/",
12-
"http://localhost:58745/" // For local testing
10+
"https://samples.azuremaps.com/"
1311
];
1412

1513
[Function("GetMIOKey")]
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using Microsoft.AspNetCore.Http;
2+
using Microsoft.AspNetCore.Mvc;
3+
using Microsoft.Azure.Functions.Worker;
4+
5+
namespace SampleFunctions;
6+
7+
public class Optimizer
8+
{
9+
private static readonly string[] AllowedDomains = [
10+
"https://samples.azuremaps.com/"
11+
];
12+
13+
[Function("Optimizer")]
14+
public static IActionResult Run([HttpTrigger(AuthorizationLevel.Anonymous, "post")] HttpRequest req)
15+
{
16+
// Check if the referer header is present and if the domain is allowed
17+
if (req.Headers.TryGetValue("Referer", out var referer) && AllowedDomains.Any(domain => referer.ToString().StartsWith(domain)))
18+
{
19+
// This is a sample/demo data response from the solver
20+
// You can replace this with your own data
21+
// The data should be in the same format as the response from the solver
22+
// More details: https://docs.nvidia.com/cuopt/user-guide/supported-features.html
23+
return new OkObjectResult("{\"reqId\":\"b3f34ef7-e037-402d-837e-2e97c48ebf74\",\"status\":\"fulfilled\",\"percentComplete\":100,\"response\":{\"response\":{\"solver_response\":{\"status\":0,\"num_vehicles\":4,\"solution_cost\":41830,\"vehicle_data\":{\"Car A\":{\"task_id\":[\"Depot\",\"Break\",\"0\",\"5\",\"Depot\"],\"arrival_stamp\":[28800,43200,43596,44172,44965],\"route\":[0,0,2,7,0],\"type\":[\"Depot\",\"Break\",\"Delivery\",\"Delivery\",\"Depot\"]},\"Car B\":{\"task_id\":[\"Depot\",\"Break\",\"6\",\"7\",\"Depot\"],\"arrival_stamp\":[28800,43200,43838,43987,44527],\"route\":[0,0,8,9,0],\"type\":[\"Depot\",\"Break\",\"Delivery\",\"Delivery\",\"Depot\"]},\"Car C\":{\"task_id\":[\"Depot\",\"3\",\"Break\",\"1\",\"Depot\"],\"arrival_stamp\":[28800,28954,43200,43540,43857],\"route\":[1,5,5,3,1],\"type\":[\"Depot\",\"Delivery\",\"Break\",\"Delivery\",\"Depot\"]},\"Car D\":{\"task_id\":[\"Depot\",\"Break\",\"4\",\"2\",\"Depot\"],\"arrival_stamp\":[28800,43200,43200,43480,43863],\"route\":[1,6,6,4,1],\"type\":[\"Depot\",\"Break\",\"Delivery\",\"Delivery\",\"Depot\"]}},\"dropped_tasks\":{\"task_id\":[],\"task_index\":[]},\"msg\":\"\"},\"perf_times\":null},\"warnings\":[],\"notes\":[]}}");
24+
}
25+
26+
// Retrun access denied if the referer domain is not allowed
27+
return new StatusCodeResult(StatusCodes.Status403Forbidden);
28+
}
29+
}

0 commit comments

Comments
 (0)