1

I am new to Gurobi Python interface. It would be great somebody guides me to this problem.

I want to create a Binary Decision variable using the Python interface.

The binary variable denoted by $X_{k, u, i, j}$ - indicates whether the task j of appliance i of user u at time slot k processed or not. 1 = processed , 0 = not processed.

I have tried like this,but not able to get the desired output.

 x = m.addVars(time_slots, users, appliances, task_appliances, vtype = GRB.BINARY, name = 'x')

Output

x[k1,u1,washingmachine, washingmachine], x[k1,u1,washingmachine, dryer]

Where 

time_slots = ['k1', 'k2','k3', 'k4', 'k5', 'k6', 'k7', 'k8', 'k9', 'k10']
users = ['u1', 'u2', 'u3', 'u4', 'u5']
appliances = ['washingmachine', 'dryer', 'dishwasher', 'refrigerator', 'gashob1', 'gashob2'] 



 task_appliances = {'washingmachine':['movement', 'heating','washing', 'cooling', '1strinse', '2ndrinse', '3rdrinse'], 'dryer': ['drying1', 'drying2', 'drying3', 'drying4', 'drying5', 'drying6', 'drying7', 'drying8'], 'dishwasher': ['movement', 'heating', 'wash', '1strinse', 'drain', 'heating','2ndrinse', 'drain_and_dry'], 'refrigerator': ['cooling1', 'cooling2', 'cooling3', 'cooling4','cooling5', 'cooling6', 'cooling7','cooling8', 'cooling9', 'cooling10'],'gashob1':['heating'], 'gashob2':['heating']}

How can i create a binary variable represents the x[k1,u1,washingmachine, movement], x[k1,u1,washingmachine, heating],.. like this for all washing machine tasks and x[k1,u1,dryer, drying1], x[k1,u1,dryer, drying2],.. like this for all dryer tasks and so on for all the appliances.

2
  • That looks correct - why do you say you do not "get the desired output" ? Commented Sep 28, 2018 at 19:03
  • No actually i am getting output like this, x[k1,u1,washingmachine, washingmachine], ` x[k1,u1,washingmachine, dryer]` Commented Sep 28, 2018 at 21:27

1 Answer 1

1

First of all note that in task_appliances the task heating is twice for the dishwasher, after fixing this you could use a list comprehension to get a list of tuples and then use m.addVars():

from gurobipy import *

# Your lists here

m = Model()
vars_tup = [(t, u, app, task) for t in time_slots for u in users for app in appliances for task in task_appliances[app]]
x = m.addVars(vars_tup, vtype=GRB.BINARY, name="x")
# Your constraints and objective function..
Sign up to request clarification or add additional context in comments.

2 Comments

Actually dishwasher includes two heating task that's why i included heating twice.
Then I recommend to rename them to heating1 and heating2 like you did for the other tasks. Otherwise m.addVars will yield a KeyError due to duplicate keys.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.