I want to write code of Media selection problem in Python Gurobi which gives error. can anyone guide me about that code. code is given below
from gurobipy import *
# Warehouse demand in thousands of gallons
demand = [[1, 0, 1],
[0, 1, 1],
[1, 1, 0]]
# Plant capacity in thousands of gallons
capacity = [1, 1, 1]
# Transportation costs per thousand of gallons
Cost = [10000,20000,30000]
# Range of plants and warehouses
resource = range(len(capacity))
target_group = range(len(demand))
# Model
m = Model("media_selection")
# Transportation decision variables: how much to transport from a plant p to a warehouse w
media_selection = []
for r in resource:
media_selection.append([])
for t in target_group:
media_selection[r].append(m.addVar(vtype=GRB.BINARY, name="Trans_%d,%d" % (r, t)))
# The objective is to minimize the total fixed and variable costs
m.modelSense = GRB.MINIMIZE
# Update model to integrate new variables
m.update()
# Set optimization objective - minimize sum of fixed costs
m.setObjective(quicksum(media_selection[r][t]*Cost[r][t] for r in resource for t in target_group))
# Production/Supply constraints
for r in resource:
m.addConstr(quicksum(media_selection[r][t] for t in target_group) <= 1, "Capacity_%d" % r)
# Demand constraints
for t in target_group:
m.addConstr(quicksum(media_selection[r][t]*target_group for r in resource for t in target_group) >= 1, "Demand_%d" % t)
# Solve
m.optimize()
# Print solution
print('\nTOTAL COSTS: %g' % m.objVal)
print('SOLUTION:')