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:


Exactly two types of energy used in first slot:


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


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.