im running this code and not getting an output cell at all [closed]

asked 2023-05-05 09:51:16 +0200

updated 2023-05-05 20:40:36 +0200

Max Alekseyev gravatar image

.

import gurobipy as gp

def batch_scheduling(m, L0, L1, j, rj, pj, qj):

    # Define the values of the variables
    m = 2
    L0 = 30
    L1 = 45
    j = range(10)
    rj = [12, 7, 4, 9, 2, 14, 3, 0, 9, 18]
    pj = [9, 14, 5, 11, 12, 6, 7, 4, 9, 8]
    qj = [16, 25, 19, 11, 13, 10, 18, 22, 12, 15]

    # Create the model
    m = gp.Model("batch_scheduling")

    # Decision variables
    x = m.addVars([(j, b, m) for j in range(10) for b in range(2) for m in range(2)], vtype="binary")
    y = m.addVars([(j, b) for j in range(10) for b in range(2)], vtype="binary")
    t = m.addVars([b for b in range(2)], vtype="continuous")

    # Objective function
    m.setObjective(m.minimize(t[0] + t[1]))

    # Constraints
    # Each job must be assigned to exactly one batch
    for j in range(10):
        m.addConstr(gp.sum(x[j, b, m] for b in range(2) for m in range(2)) == 1)

    # Each job must be processed in exactly one batch
    for j in range(10):
        m.addConstr(gp.sum(y[j, b] for b in range(2)) == 1)

    # The processing time of each batch must be less than or equal to its capacity
    for b in range(2):
        m.addConstr(t[b] <= gp.sum(p[j] * x[j, b, m] for j in range(10) for m in range(2)))

    # The start time of each job must be greater than or equal to its release time
    for j in range(10):
        m.addConstr(t[0] + gp.sum(p[j] * x[j, 0, m] for m in range(2)) >= r[j])

    # The size of each batch must be less than or equal to the capacity of the machine it is assigned to
    for j in range(10):
        for m in range(2):
            m.addConstr(q[j] * x[j, b, m] <= L[m])

    # The variables must be binary
    for j in range(10):
        for b in range(2):
            for m in range(2):
                m.addConstr(x[j, b, m] <= 1)
                m.addConstr(y[j, b] <= 1)

    # Solve the model
    m.optimize()

    # Print the solution
    if m.status == gp.OPTIMAL:
        print("The optimal objective value is", m.objVal)
        print("The optimal schedule is")
        for j in range(10):
            for b in range(2):
                if x[j, b, 0].x == 1:
                    print("Job", j, "is assigned to batch", b, "on machine", 0)
                if x[j, b, 1].x == 1:
                    print("Job", j, "is assigned to batch", b, "on machine", 1)
    else:
        print("The model is infeasible")
edit retag flag offensive reopen merge delete

Closed for the following reason question is off-topic or not relevant by Max Alekseyev
close date 2023-05-07 17:41:52.804606

Comments

How do you run it? What are parameters?

Max Alekseyev gravatar imageMax Alekseyev ( 2023-05-05 20:44:34 +0200 )edit

Can you run the simple example given at https://pypi.org/project/gurobipy/?

tolga gravatar imagetolga ( 2023-05-05 22:37:31 +0200 )edit

What's the point in using gurobipy? Sage natively supports gurobi solver: https://doc.sagemath.org/html/en/refe... Your code looks more like Python than Sage code as it does not rely on Sage functionality.

Max Alekseyev gravatar imageMax Alekseyev ( 2023-05-06 00:18:06 +0200 )edit