I am new in coding and need your help. I get the following error:
line 159, in _get_solution
xs = np.array(ms.get_values(self.int_var)).reshape(self.path_n, self.orderbook_n)
AttributeError: 'NoneType' object has no attribute 'get_values'
after reaching this part of the code:
line 159, in _get_solution
xs = np.array(ms.get_values(self.int_var)).reshape(self.path_n, self.orderbook_n)
When I use: print(dir(ms))
to check what could causing this it gives me the following:
['__bool__', '__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__']
How could I proceed to get the code running?
The complete code for this part is:
def _get_solution(self):
'''function to solve the optimization model, save result and print outputs'''
self.print_content = ''
self.trade_solution = OrderedDict()
ms = self.solve()
xs = np.array(ms.get_values(self.int_var)).reshape(self.path_n, self.orderbook_n)
zs = xs * self.precision_matrix
nonzeroZ = list(zip(*np.nonzero(zs)))
nonzeroZ = sorted(nonzeroZ, key=lambda x: x[0])
The error is telling you that the variable ms
has evaluated to None
, which is why it has no get_values()
method.
Assuming that line 159 from the error message is the corresponding line in _get_solution()
, this means that in the line above
ms = self.solve()
the call to self.solve()
returned None
.
You need to inspect self.solve()
to understand why it did that.
Since you are new to Python, keep in mind that, when a function or method has no return statement, or never reaches a valid return statement, it will return None
by default.