简体   繁体   中英

Gurobi/Python: set as an element of a list

I have an optimization problem, which im trying to solve with the help of gurobi/python.

Some of the constraints have to be summed up over different sets depending on other indicies, eg:

for i in range(nJobs):
        for j in range(n[i]):
            model.addConstr(quicksum(y[i][j][k][l] for k in range(nJobs) for l in range(nJobs)))

In the constraint above sets M[i][j] and W[i][j] depend on the indices i and j.

Those sets are imported from Excel:

M = [[0]* n[i] for i in range(nJobs)]
    iter_i = 0
    for i in range(nJobs):
        if i != 0:
            iter_i = iter_i+n[i-1]
        for j in range(n[i]):
            M[i][j] = DataSheet.cell(5 + j + iter_i, 5).value

The Excel table with the values for M[i][j] looks like this:

在此处输入图像描述

So some cells might include multiple numbers separated by the comma.

Obviously the constraints can not be summed up over some of the entries of M[i][j] since those are considered as strings. Is there any way to convert the entries in M[i][j], so those can be used for the summation in the constraints?

You should perform some data cleaning before building the model. The values from the Excel table can be converted from str to int or float using int(value) or float(value) . A single cell in the table should not contain multiple values - this is bad practice and can easily be misinterpreted.

It is very hard to understand your question. Please try to follow the Stackoverflow guidelines for how to ask good questions .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM