1 comment

It looks like this was answered in Optimizationproblem with Exception Unable to convert argument to an expression – Gurobi Support Portal: there is a parenthesis error causing this problem.

If you wind up with a similar issue, I recommend making sure each quicksum's final end parenthesis is in the right spot.

To troubleshoot, it may help to create each term one at a time.  Once you know that each is written correctly, you can combine them.

For example, you can start with the first term in your objective.  Try setting an objective with only this term.  Then make sure your code executes properly in model.setObjective().  Then you can do the same for term 2. Here is how it should look:

# Test for term 1model.setObjective( quicksum(Prob[s] *quicksum(c[k,j,p]*x[k,j,p,t,s] for k in K for j in J for p in P for t in range(1,len(T)+1)) for s in range(0,len(S)))                    , GRB.MINIMIZE)# Test for term 2model.setObjective( quicksum(Prob[s]* quicksum(f*y[j] for j in J )for s in range(0,len(S)))                    , GRB.MINIMIZE)

If those two terms run without error, then you have their parenthesis correct.  Now, you can combine them as follows:

# Test with term 1 + term 2model.setObjective( quicksum(Prob[s] *quicksum(c[k,j,p]*x[k,j,p,t,s] for k in K for j in J for p in P for t in range(1,len(T)+1)) for s in range(0,len(S)))                    + quicksum(Prob[s]* quicksum(f*y[j] for j in J )for s in range(0,len(S)))                    , GRB.MINIMIZE)

Next, you can do this for the remainder of your objective.