Hello,
For information, the attached python model attempts to load a `capacity.csv` that is missing from the attachements, to be able to replicate the issue.
Also, line numbers in `Model.py` do not match exactly the ones in the log that is reported in the message. The attached files may not correspond to the latest version.
The exception reported in the logs is raised because the `model.variables.add(...)` method expects lists as parameters, but primitive types are provided instead.
Also, have you considered using the docplex libraries instead of the Cplex python API for developping your model ?
docplex provides a richer and more user-friendly API.
Best regards,
Hugues
------------------------------
Hugues Juille
------------------------------
Original Message:
Sent: Thu January 12, 2023 02:23 PM
From: Manuel Lopez-Mejia
Subject: Trouble passing in a float object (PyCPLEX)
Hello! I'm trying to develop a facility location model where I have to optimize the assignment of agents to a specific site by minimizing the distance between the agents and site locations. I attached my script and the data set. When I try running my model I receive the following traceback message. Any help is appreciated, thanks!
Traceback (most recent call last):
File "/Users/manny/Documents/Operations Research/Model.py", line 31, in <module>
x = [[model.variables.add(obj=distance[i][j], lb=0, ub=1, types='B') for j in range(m)] for i in range(n)]
File "/Users/manny/Documents/Operations Research/Model.py", line 31, in <listcomp>
x = [[model.variables.add(obj=distance[i][j], lb=0, ub=1, types='B') for j in range(m)] for i in range(n)]
File "/Users/manny/Documents/Operations Research/Model.py", line 31, in <listcomp>
x = [[model.variables.add(obj=distance[i][j], lb=0, ub=1, types='B') for j in range(m)] for i in range(n)]
File "/opt/anaconda3/lib/python3.9/site-packages/cplex/_internal/_subinterfaces.py", line 458, in add
return self._add_iter(self.get_num, self._add,
File "/opt/anaconda3/lib/python3.9/site-packages/cplex/_internal/_baseinterface.py", line 41, in _add_iter
addfun(*args, **kwargs)
File "/opt/anaconda3/lib/python3.9/site-packages/cplex/_internal/_subinterfaces.py", line 373, in _add
num_new_cols = max_arg_length(arg_list)
File "/opt/anaconda3/lib/python3.9/site-packages/cplex/_internal/_aux_functions.py", line 77, in max_arg_length
return max([len(x) for x in arg_list])
File "/opt/anaconda3/lib/python3.9/site-packages/cplex/_internal/_aux_functions.py", line 77, in <listcomp>
return max([len(x) for x in arg_list])
TypeError: object of type 'float' has no len()
------------------------------
Manuel Lopez-Mejia
EPM Data Engineer
IBM
NC
------------------------------
#DecisionOptimization