Ask Your Question

Revision history [back]

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

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")

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

import gurobipy as gp

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

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")

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

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")

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

.

import gurobipy as gp

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")