I am struggling to model my problem correctly since multiple days.
Maybe someone can give me a hint. I have two levels, both with a fixed number of slots (i.e. 200 each). The items I want to put on the slots are ordered and earlier items have to be positioned on earlier slots.
Imagine a fixed queue of vehicles driving on one of two levels of a train. For every vehicle one can decide whether to drive on the lower or the upper level. Once a vehicle is put in position the following vehicle can either stand behind its predecessor or drive on the opposite level.
Certain slots can remain empty due to capacity constraints. I.e. the first 5 slots on the upper level have a weight constraint of 8 tons, so if all the vehicles weigh 2 tons, one of the 5 slots has to remain empty.
The general model I have developed is working but I can not figure out how to model these precedence constraints.
My current idea is the following:
$p \in P^{top}$ are the slots on the top level and $p \in P^{bot}$ the slots on the bottom level $v \in V$ are the vehicles. For every vehicle $v$ we build a set of pairs that models the precedence requirements for every vehicle according to the order v < u: $(v, u) \in A$.
Led $x_{pv}$ be a binary decision variable that is 1 if $v$ is on $p$ and 0 otherwise.
Precedence rules on the bottom level: $ \sum\limits_{p\in P^{bot}}px_{pv} \sum\limits_{p\in P^{bot}}x_{pu} \leq \sum\limits_{p\in P^{bot}}px_{pu} \forall (v, u)\in A$
Precedence rules on the top level: $ \sum\limits_{p\in P^{top}}px_{pv} \sum\limits_{p\in P^{top}}x_{pu} \leq \sum\limits_{p\in P^{top}}px_{pu} \forall (v, u)\in A$
Order of the vehicles: $\sum\limits_{p\in P}x_{p(v+1)} \leq \sum\limits_{p\in P}x_{pv} \forall v\in V$ \ {last element}
By themselves these three constraints seem to be working. Together they do not do what is intended . I know I am missing a (some) key elements here.
You can try with constraints
$\sum_{p1 \in P^{bot}}p1x_{p1,v} \le \sum_{p2 \in P^{bot} }p2x_{p2,v+1} + \sum_{p \in P^{top}} Mx_{p,v+1}$
where $M=200$
Similar set as above for $P^{top}$ and a general cover for across levels $\sum_{p \in P }x_{p,v+1} \le \sum_{p \in P}x_{p,v} \quad \forall v$
$ \sum_{p \in P}x_{p,v} = 1 \quad \forall v$
where $P= P^{bot} \cup P^{top}$