# How to create constraints for Mixed integer linear problem?

i am a beginner to Discrete optimization domain. I am working on the real world problem, i.e., Scheduling of hybrid appliances. I have hybrid appliances which can use gas and electricity or electricity and hot water or hot water and gas for their operation. Each appliance has some set of tasks, each task use above mentioned energy carriers based on the requirement.

The question is, i want to create a constraint such that if the task of the appliance starts with electricity and hot water, it should end with using electricity and hot water. It should not alter the energy carrier to gas during the operation.

I have created some of the decision variables like this:

$x_{t,i,j}$ indicates whether task j of appliance i at time slot k processed by electricity or not; 1 = task processed; 0 = not processed

$y_{t,i,j}$ indicates whether task j of appliance i at time slot k processed by natural gas or not; 1 = task processed; 0 = not processed

$z_{t,i,j}$ indicates whether task j of appliance i at time slot k processed by hot water or not; 1 = task processed; 0 = not processed

I tried with the following constraint it seems something missing.

$\sum_{k=t}^{t+H_{i,j}}$ $(x_{t,i,j}+y_{t,i,j}+z_{t,i,j})$ $\geq$ $H_{i,j} (x_{t,i,j}+y_{t,i,j}+z_{t,i,j})$

Where i is index of appliance.

t is current time slot.

j is index of task.

$H_{i,j}$ is run time of tasks.

You have the constraint:

$\sum_{k=t}^{t+H_{i,j}}$ $(x_{t,i,j}+y_{t,i,j}+z_{t,i,j})$ $\geq$ $H_{i,j} (x_{t,i,j}+y_{t,i,j}+z_{t,i,j})$

I presume your iteration variable is $t$. In that case this says that the amount of energy used in the task is at least the expected amount of energy based on its first slot multiplied by task length. This doesn't guarantee using correct type of energy etc.

Assuming you use all required types of energy in the first slot of the task and that you need to use exactly two of them, you should have the following:

1. Exactly two types of energy used in first slot:

$$x_{t, i, j} + y_{t, i, j} + z_{t, i ,j} = 2$$

1. If you use some energy in first slot, you need to use it until the end of the task, so in each step variable indicating use of some energy type has the same value as in the first step of the task:

$$\forall_{t'=t}^{t + H_{i,j}} x_{t', i, j} = x_{t, i, j}$$

Same goes for $y$ and $z$ variables.

• so you mean in addition to my constraint, do i need to add the constraints you mentioned in answer?. – PraveenRB Aug 24 '18 at 14:05
• then it will be lot more combinations of constraints, right? – PraveenRB Aug 24 '18 at 14:22
• 1. Not in addition, instead. 2. How much is “lot more” and why? – user1543037 Aug 24 '18 at 15:35
• Thanks, i got the point. It is so nice without increasing the variables. – PraveenRB Aug 24 '18 at 16:08

I suggest you use the variable to represent when the task was started. For instance, $x^*_{t,i,j}$ indicates that task $j$ of appliance $i$ is started at time $t$, and the task is using electricity. For example if the task is running at times $t,t+1,\dots,t+9$, you'll have $x^*_{t,i,j}=1$ but $x^*_{t+1,i,j}=\dots=x^*_{t+9,i,j}=0$.

• Then how come it shows, the task will end by using the electricity. Because you are saying $x^*_{t+1,i,j}=\dots=x^*_{t+9,i,j}$=0 – PraveenRB Aug 25 '18 at 20:18
• @PraveenRB, you know the length of the task, so once once you know that $x^*_{t,i,j}=1$, you know that the task ran during time slots $t,t+1,\dots,t+9$ and used electricity (for a task that takes 10 time steps). That's what the variable $x^*_{t,i,j}$ means. It's different from the scheme you describe in your question. – D.W. Aug 26 '18 at 0:29