Python Pulp using with Matrices

后端 未结 2 1206
孤独总比滥情好
孤独总比滥情好 2021-02-07 07:39

I am still very new to Python, after years and years of Matlab. I am trying to use Pulp to set up an integer linear program.

Given an array of numbers:

{         


        
相关标签:
2条回答
  • 2021-02-07 07:56

    You can set the lowBound and upBound on variables after the initialization. You can create an array of variables with

    LB[i] <= x[i] <= UB[i]
    

    with the following code.

    x = pulp.LpVariable.dicts("x", RANGE,  cat="Integer")
    for i in x.viewkeys():
         x[i].lowBound = LB_ind[i]
         x[i].upBound = UB_ind[i]
    

    The second parameter to LpVariable.dict is the index set of the decision variables, not their lower bounds.

    0 讨论(0)
  • 2021-02-07 08:04

    For the first question, you can do it like this in some other problem.

    students = range(96)
    group = range(24)
    
    var = lp.LpVariable.dicts("if_i_in_group_j", ((i, j) for i in students for j in group),cat='binary')
    
    0 讨论(0)
提交回复
热议问题