I wanted to solve vehicle routing problem instance as a usage example I used cvrptw.py. Then I have created weekly model which has time_horizon=5x24x3600(the total number of seconds in a week). After that when I setting time constraints :
time_dimension.CumulVar(int(customer.index)).SetRange(
customer.tw_open,
customer.tw_close)
I am getting exception like this :
ortools-2.3393-py2.7-linux-x86_64.egg/ortools/constraint_solver/pywrapcp.py", line 1300, in SetRange
return _pywrapcp.IntExpr_SetRange(self, l, u)
Exception: CP Solver fail
In that case tw_open=28800 and tw_close=68400. I expected to get more informative exception message to be able to understand what I am doing wrong.
What's the value of time_dimension.CumulVar(int(customer.index)).GetMin()
and GetMax() just before the call to SetRange ?
On Wed, Mar 16, 2016 at 11:35 AM, Tigran Hakobyan [email protected]
wrote:
I wanted to solve vehicle routing problem instance as a usage example I
used cvrptw.py. Then I have created weekly model which has time_horizon=5
_24_3600(the total number of seconds in a week). After that when I
setting time constraints :
time_dimension.CumulVar(int(customer.index)).SetRange(
customer.tw_open,
customer.tw_close)I am getting exception like this :
ortools-2.3393-py2.7-linux-x86_64.egg/ortools/constraint_solver/pywrapcp.py",
line 1300, in SetRange
return _pywrapcp.IntExpr_SetRange(self, l, u)
Exception: CP Solver failIn that case tw_open=28800 and tw_close=68400. I expected to get more
informative exception message to be able to understand what I am doing
wrong.—
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub
https://github.com/google/or-tools/issues/162
Here is what I got :
print ('Min=', time_dimension.CumulVar(int(stop.index)).GetMin())
File "/lib/python2.7/site-packages/ortools-2.3393-py2.7-linux-x86_64.egg/ortools/constraint_solver/pywrapcp.py", line 1436, in <lambda>
__getattr__ = lambda self, name: _swig_getattr(self, IntVar, name)
File "/lib/python2.7/site-packages/ortools-2.3393-py2.7-linux-x86_64.egg/ortools/constraint_solver/pywrapcp.py", line 74, in _swig_getattr
return _swig_getattr_nondynamic(self, class_type, name, 0)
File "/lib/python2.7/site-packages/ortools-2.3393-py2.7-linux-x86_64.egg/ortools/constraint_solver/pywrapcp.py", line 69, in _swig_getattr_nondynamic
return object.__getattr__(self, name)
AttributeError: type object 'object' has no attribute '__getattr__'
Sorry for incovenience, it seems something wrong on my side, cause I changed cvrptw.py to use the same time frames and it worked smoothly.
@tigrandp What was your mistake? I'm having the same issue right now and I'm doing something similar to your week-period horizon
@Alanbato please paste error here or code I will try to help I do not remember.
@tigrandp Hello, thank you for your fast reply
Here's the error I'm getting when trying to solve my problem:
<ipython-input-25-7418aa8aeead> in <module>()
190
191 if __name__ == '__main__':
--> 192 main()
<ipython-input-25-7418aa8aeead> in main()
87 time_dimension.CumulVar(int(cust.index)).SetRange(
88 int(cust.tw_open.total_seconds()),
---> 89 int(cust.tw_close.total_seconds()))
90
91 """
~/lib/python2.7/site-packages/ortools-4.2.3790-py2.7-linux-x86_64.egg/ortools/constraint_solver/pywrapcp.pyc in SetRange(self, l, u)
1337
1338 def SetRange(self, l, u):
-> 1339 return _pywrapcp.IntExpr_SetRange(self, l, u)
1340
1341 def SetValue(self, v):
Exception: CP Solver fail
try to check :
time_dimension.CumulVar(int(cust.index)).Max() >= time_dimension.CumulVar(int(cust.index)).Min()
and then
cust.index < routing.nodes()
Both of them are True :sweat:
And I have the same mistake.
I need to solve the problem with total time constraint. I know, that this is solving by time_horizon in AddDimension.
But my nodes have over day time windows, for example it open at 23:00 and close at 01:00 next day.
So I convert it to 82800 and 90000.
But total time constraint is only 12 hours, 43200.
So I want open depot from 0 to 259200 (not to 43200, thats how AddDimension works) and add 1 day to all customers, so that this customer will be 169200 and 176400.
In this case i understand, that dimension of time_horizon have to be equal as max dimension of time windows.
For example, if my max time windows dimension (on customers, not on depot) will be = 176400 (6 characters) time_horizon 43200 (5 characters) will raise an error
Traceback (most recent call last):
File "D:/Work/VRPTW/VRPTW3/cvrptw.py", line 342, in
main()
File "D:/Work/VRPTW/VRPTW3/cvrptw.py", line 235, in main
time_dimension.CumulVar(locations).SetRange(start, end)
File "C:\Users\MDesh.virtualenvs\VRPTW3-rmdLUytm\lib\site-packages\ortools\constraint_solver\pywrapcp.py", line 1339, in SetRange
return _pywrapcp.IntExpr_SetRange(self, l, u)
Exception: CP Solver fail
But if time_horizon will be , for example, 143200 (6 characters) - everything will be ok.
So that there are two ways - to open the depot for my task (i dont know, how i can do it, i ll ask about it in the new issue, #533) and, probably, repair this error.
Will be grateful for any help.
Thanks.
Hi Guys, I have the same problem and issues when I implemented my model.
Please check If you set fix_start_cumul_to_zero == false, whether the problem will be solved.
We need to set this value to FALSE, if we do not want to cumulate from zero, which is the lower bound.
Are you calling set range outside search?
This is not supported.
You should add a constraint instead of calling a modifier.
Laurent Perron | Operations Research | [email protected] | (33) 1 42 68 53
00
Le mar. 15 mai 2018 à 17:00, Yajun Ding notifications@github.com a écrit :
Hi Guys, I have the same problem and issues when I implemented my model.
Please check If you set fix_start_cumul_to_zero == false, whether the
problem will be solved.
We need to set this value to FALSE, if we do not want to cumulate from
zero, which is the lower bound.—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/google/or-tools/issues/162#issuecomment-389199138,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AKj17XtkVljeM-tKdCHIGKlsQoS3vzanks5tyu2CgaJpZM4Hx20P
.
Hi Guys i am also facing the similar issue.
i am running the below code but getting some issue. Please help me finding out the issue.
Code:
time_dimension.CumulVar(index).SetRange(location_time_window[0], location_time_window[1])
Error:
TypeError Traceback (most recent call last)
<ipython-input-1-fb312911ee19> in <module>
158
159 if __name__ == '__main__':
--> 160 main()
<ipython-input-1-fb312911ee19> in main()
147 # Add Time Window constraint
148 time_callback = create_time_callback(data)
--> 149 add_time_window_constraints(routing, data, time_callback)
150 # Setting first solution heuristic (cheapest addition).
151 search_parameters = pywrapcp.RoutingModel.DefaultSearchParameters()
<ipython-input-1-fb312911ee19> in add_time_window_constraints(routing, data, time_callback)
88 print(location_time_window[1].item())
89 #print("=============================================")
---> 90 time_dimension.CumulVar(index).SetRange(location_time_window[0], location_time_window[1])
91
92 print(type(location_time_window[0]))
~\AppData\Roaming\Python\Python37\site-packages\ortools\constraint_solver\pywrapcp.py in SetRange(self, l, u)
1340
1341 def SetRange(self, l: 'int64', u: 'int64') -> "void":
-> 1342 return _pywrapcp.IntExpr_SetRange(self, l, u)
1343
1344 def SetValue(self, v: 'int64') -> "void":
TypeError: in method 'IntExpr_SetRange', argument 2 of type 'int64'
As @lperron said, you might want to try adding constraints instead of setting the range, like this:
solver.Add(time_dimension.CumulVar(index) >= location_time_window[0])
solver.Add(time_dimension.CumulVar(index) <= location_time_window[1])
or, if you don't want to use constraints for some reason, try setting the min and max values independently.
time_dimension.CumulVar(index).SetMin(location_time_window[0])
time_dimension.CumulVar(index).SetMax(location_time_window[1])
Sometimes I fix errors that mention argument 2 of type 'int64' by doing an explicit cast to int, but I don't know why this works.
Hope it helps.
I ran into this issue recently, turns out I had fix_start_cumul_to_zero set to true, and you get this error if you try to SetMin() to a positive value with fix_start_cumul_to_zero = True.
@vkarpov15 did you try to setMin() on a vehicle start node or a "location to visit" node ?
let's say vehicle starts 9.00 AM (3600x9 = 32400)
if you're setting dimension with fix_start_cumul_to_zero=False
your capacity argument while setting dimension should be greater than 32400
routing.AddDimension(... , capacity>32400)
let's say vehicle starts 9.00 AM (3600x9 = 32400)
if you're setting dimension withfix_start_cumul_to_zero=Falseyour capacity argument while setting dimension should be greater than 32400
routing.AddDimension(... , capacity>32400)
I had the same problem and found out that I'm missing my waiting total vehicle max time by a digit :)))
Most helpful comment
Are you calling set range outside search?
This is not supported.
You should add a constraint instead of calling a modifier.
Laurent Perron | Operations Research | [email protected] | (33) 1 42 68 53
00
Le mar. 15 mai 2018 à 17:00, Yajun Ding notifications@github.com a écrit :