My question is how to model a resource constraint with MIP model
(how should I modify it?)

A factory is making blocks. If there is space left at that time, block can be assembled.
(If factory have space, factory can do multiple tasks at the same time.) 

I'm asking this question because I don't know how to formulate it even though I've been thinking about it after getting feedback comment from [prubin][1] to my previous question: https://or.stackexchange.com/questions/4276/space-constraint-in-scheduling-problem/4279?noredirect=1#comment6982_4279.

Here are my notations:

**Index**


- $i,j$ is the block number

- $f$ is factory number


- $t$ is time

**Parameters**

- $y_{i,f}=\begin{cases}1\quad\text{if}\,i\,\text{process at factory}\,f\\0\quad\text{otherwise}\end{cases}$

- $sp_i$ is required area for each block

- $c_f$ is available space of factory f

- $P_i$ is procees time of each block

- $M$ is a big number



**Variables**

- $S_i$, $C_i$ the start time, completion time of block $i$ respectively

- $y_{i,j,f}=\begin{cases}1\quad\text{if}\,i\,\text{process before}\,j\,\text{at factory}\,f\\0\quad\text{otherwise}\end{cases}$

- $s_{i,f,t}=\begin{cases}1\quad\text{if}\,i\,\text{start at factory }\,f\text{ at time t }\quad\\0\quad\text{otherwise}\end{cases}$


- $s2_{i,f,t}=\begin{cases}1\quad\text{if}\,i\,\text{process at factory }\,f\text{ at time t }\quad\\0\quad\text{otherwise}\end{cases}$


**Constraints**




$$ \sum_{t=1}  sp_{i,f,t} =1\quad\forall f \quad (1)$$


$$ \sum_{t}t \cdot s_{i,f,t} = S_i \quad \forall  i,f \quad (2)$$

$$ S_i+p_i = C_{i}\quad\quad \forall i \quad (3)$$

$$ S_i-M(1-y_{i,j,f}) \le S_{j} \quad\quad \forall i,j,f \quad (4)$$

// I think this part is problem because t is depends on variable $S_i$,$C_i$

//I'm not sure why Problems running when running with gurobi.
$$ \sum_{t=S_i}^{C_i}  s2_{i,f,t} = p_{i}\quad\forall f\quad (5)$$


$$ \sum_{i} sp_i \cdot s2_{i,f,t} \le c_{f}\quad\forall f,t\quad (6)$$

**thanks for your reading**


  [1]: https://or.stackexchange.com/users/67/prubin