Skip to main content

Code not working and do not know how to proceed. Any one know what I am doing wrong?



1 comment

  • Jaromił Najman
    Gurobi Staff Gurobi Staff

    I will discuss one type of constraints, because the others can be fixed in the same way.

    You are trying to model the constraints

    \[b_j(t) \leq b_j(t-1) - th_{i+1}(t) + v_i(t)\]

    Your times \(t\) are in \(\{1,\dots,10\}\). First thing that comes up is that you have to start at \(t\geq 2\), because there is no \(b_j(0)\).
    Your machines are given as \(m \in \{\text{machine }1, \dots, \text{machine }5\}\). Thus, you have to go to at most machine \(4\), because there is no \(th_{\text{machine }6}\)(t).
    You can model the above constraints as

    machines = ['Machine 1', 'Machine 2', 'Machine 3', 'Machine 4', 'Machine 5']
    time = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
    buffers = ['b1', 'b2', 'b3', 'b4', 'b5']
    speeds = df[df.columns[:-1]].stack().to_dict()
    k_max = 40

    model = gp.Model()
    thi = model.addVars(machines, time, name = 'Throughputs')  # The throughputs of the machines
    bj = model.addVars(buffers, time, ub = k_max, name = "Buffers")  # Actual amount of units in buffer i
    amount_bj_1 = model.addConstrs((bj[b, t] <= bj[b, t-1]
                              - thi[machines[m+1],t] + speeds[t, machines[m]]
                              for t in time if t>=2 for m in range(len(machines)-1) for b in buffers))
    model.write("myLP.lp") # write LP file to analyze whether the model looks correct so far

    A few remarks:

    • It is best to add constraints one by one and check whether the constraints you generated are correct.
      This makes debugging easier
    • Avoid using indices or names with whitespaces. In your particular case, consider using 'Machine_X' instead of 'Machine X'
    • It might be easier to use integer indices \(1,2,3,...\) for machines instead of strings Machine_1, Machine_2, ...

    Best regards, 


Please sign in to leave a comment.