Hello there, the vroom optimization does not work in this sense for my case, Here is how Im passing it in my code
# init variables
depot = 36.791548, -1.840116
coords = [[36.686, -1.127],
[36.6395, -1.0717],
[36.6439, -1.0553],
[36.6461, -1.0351],
[36.6418, -1.0376],
[36.6353, -1.0548]]
amt =[100,50,200,30,50,200]
open_from = [datetime(2019, 3, 22, 8, 0 , 0), datetime(2019, 3, 22, 8, 30 , 0),
datetime(2019, 3, 22, 9, 30 , 0), datetime(2019, 3, 22, 10, 30 , 0),
datetime(2019, 3, 22, 11, 30 , 0), datetime(2019, 3, 22, 1, 30 , 0)]
closes_at = [datetime(2019, 3, 22, 18, 30 , 0), datetime(2019, 3, 22, 19, 30 , 0),
datetime(2019, 3, 22, 20, 30 , 0), datetime(2019, 3, 22, 21, 30 , 0),
datetime(2019, 3, 22, 22, 30 , 0), datetime(2019, 3, 22, 23, 30 , 0)]
import openrouteservice as ors
# Define the vehicles
# https://openrouteservice-py.readthedocs.io/en/latest/openrouteservice.html#openrouteservice.optimization.Vehicle
vehicles = []
for idx in range(1):
vehicles.append(
ors.optimization.Vehicle(
id=idx,
start= depot,
end = depot,
# end=list(reversed(depot)),
capacity=[2000],
# time_window=[1553241600, 1553284800] # Fri 8:00-20:00, expressed in POSIX timestamp
)
)
deliveries =[]
for ix, d in enumerate(coords):
deliveries.append(
ors.optimization.Job(
id=ix,
location= d,
service=1200, # Assume 20 minutes at each site
amount=[amt[ix]],
# time_windows=[[
# int(open_from[ix].timestamp()), # VROOM expects UNIX timestamp
# int(closes_at[ix].timestamp())
# ]]
)
)
# now call the vroom optimizer
url_vroom = 'http://localhost:3000'
clientVrp = ors.Client(base_url=url_vroom, key='')
solution = clientVrp.optimization(
vehicles = vehicles,
jobs = deliveries,
geometry = True,
)
I then receive an error:
---------------------------------------------------------------------------
JSONDecodeError Traceback (most recent call last)
File ~\anaconda3\lib\site-packages\requests\models.py:971, in Response.json(self, **kwargs)
970 try:
--> 971 return complexjson.loads(self.text, **kwargs)
972 except JSONDecodeError as e:
973 # Catch JSON-related errors and raise as requests.JSONDecodeError
974 # This aliases json.JSONDecodeError and simplejson.JSONDecodeError
File ~\anaconda3\lib\json\__init__.py:346, in loads(s, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
343 if (cls is None and object_hook is None and
344 parse_int is None and parse_float is None and
345 parse_constant is None and object_pairs_hook is None and not kw):
--> 346 return _default_decoder.decode(s)
347 if cls is None:
File ~\anaconda3\lib\json\decoder.py:337, in JSONDecoder.decode(self, s, _w)
333 """Return the Python representation of ``s`` (a ``str`` instance
334 containing a JSON document).
335
336 """
--> 337 obj, end = self.raw_decode(s, idx=_w(s, 0).end())
338 end = _w(s, end).end()
File ~\anaconda3\lib\json\decoder.py:355, in JSONDecoder.raw_decode(self, s, idx)
354 except StopIteration as err:
--> 355 raise JSONDecodeError("Expecting value", s, err.value) from None
356 return obj, end
JSONDecodeError: Expecting value: line 1 column 1 (char 0)
During handling of the above exception, another exception occurred:
JSONDecodeError Traceback (most recent call last)
File ~\anaconda3\lib\site-packages\openrouteservice\client.py:229, in Client._get_body(response)
228 try:
--> 229 body = response.json()
230 except json.JSONDecodeError:
File ~\anaconda3\lib\site-packages\requests\models.py:975, in Response.json(self, **kwargs)
972 except JSONDecodeError as e:
973 # Catch JSON-related errors and raise as requests.JSONDecodeError
974 # This aliases json.JSONDecodeError and simplejson.JSONDecodeError
--> 975 raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
JSONDecodeError: Expecting value: line 1 column 1 (char 0)
During handling of the above exception, another exception occurred:
HTTPError Traceback (most recent call last)
Input In [45], in <cell line: 4>()
1 url_vroom = 'http://localhost:3000'
2 clientVrp = ors.Client(base_url=url_vroom, key='')
----> 4 solution = clientVrp.optimization(
5 vehicles = vehicles,
6 jobs = deliveries,
7 geometry = True, #VROOM RESTITUISCE LA GEOMETRIA DEL PERCORSO OLTRE ALLA SOLUZIONE
8 )
File ~\anaconda3\lib\site-packages\openrouteservice\client.py:299, in _make_api_method.<locals>.wrapper(*args, **kwargs)
296 @functools.wraps(func)
297 def wrapper(*args, **kwargs):
298 args[0]._extra_params = kwargs.pop("extra_params", None)
--> 299 result = func(*args, **kwargs)
300 try:
301 del args[0]._extra_params
File ~\anaconda3\lib\site-packages\openrouteservice\optimization.py:97, in optimization(client, jobs, vehicles, shipments, matrix, geometry, dry_run)
94 if matrix:
95 params['matrix'] = matrix
---> 97 return client.request("/optimization", {}, post_json=params, dry_run=dry_run)
File ~\anaconda3\lib\site-packages\openrouteservice\client.py:204, in Client.request(self, url, get_params, first_request_time, retry_counter, requests_kwargs, post_json, dry_run)
200 return self.request(url, get_params, first_request_time,
201 retry_counter + 1, requests_kwargs, post_json)
203 try:
--> 204 result = self._get_body(response)
206 return result
207 except exceptions._RetriableRequest as e:
File ~\anaconda3\lib\site-packages\openrouteservice\client.py:231, in Client._get_body(response)
229 body = response.json()
230 except json.JSONDecodeError:
--> 231 raise exceptions.HTTPError(response.status_code)
233 # error = body.get('error')
234 status_code = response.status_code
HTTPError: HTTP Error: 404
whereas if I use the API key this is not the case,