Reputation: 43
The goal of my study is to optimize garbage collection routes. To achieve this, I utilized OpenStreetMaps to obtain a list of coordinates and, using OSRM, calculated the distance of the current route. With the same list of coordinates, I created a JSON file and used it with VROOM to obtain the distance of the optimized route. However, now I need to make an HTTP request to VROOM to obtain the list of coordinates of the optimized route.
That's my code:
# Generate VROOM file:
def generateVROOMFile(data):
# Lists for vehicles and jobs
vehicles = [] # (Initially, I will only implement one vehicle, for now, this list is useless)
jobs = []
start_coord = [data.longitude[0], data.latitude[0]] # Garage position
end_coord = [data.longitude.iloc[-1], data.latitude.iloc[-1]] # Landfill position
# Add a single vehicle
vehicle = {
"id": 1,
"start": start_coord,
"end": end_coord,
"steps": [
{"type": "start"}
]
}
# Adding steps
for j in range(len(data.latitude) - 1):
vehicle["steps"].append({"type": "job", "id": j+1})
vehicle["steps"].append({"type": "end"})
# Add the vehicle to the list of vehicles
vehicles.append(vehicle)
# Adding "jobs" for each coordinate
for i in range(len(data.latitude) - 1):
coord = [data.longitude[i], data.latitude[i]]
job = {
"id": i+1,
"description": data.logradouro[i],
"location": coord
}
jobs.append(job)
# Create the VROOM object
vroom_data = {
"vehicles": vehicles,
"jobs": jobs
}
# # Save the data to a file
with open(f'VROOM_{data.name}.json', 'w') as f:
json.dump(vroom_data, f, indent=2)
return vroom_data
# Get optimized coordinates from VROOM
def getOptimizedCoords(vroom_data):
# Local address of the VROOM server
vroom_url = 'http://localhost:3000'
# Send a POST request to the local VROOM API
response = requests.post(vroom_url, json=vroom_data)
# Check if the request was successful (status 200)
if response.status_code == 200:
return response.json()
else:
print("Error querying VROOM API:", response.status_code)
return None
The message error is: 500. I'm in doubt because in the documentation the port would be 3000, but when I run VROOM in the terminal with "npm run serve" it opens on port 9966. However, when I update the port to 9966, the error code becomes: 404.
Upvotes: 1
Views: 241