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.



Precedence constraints in assignment problem
Here are linear constraints for the bottom:
$$\sum\_{p\in P^{bot}}px\_{pv} \le \sum\_{p\in P^{bot}}(p-1)x\_{pu} +|P^{bot}|\sum\_{p\in P^{top}}x\_{pu}\quad \forall (v, u)\in A$$
Equivalently,
$$\sum\_{p\in P^{bot}}px\_{pv} \le \sum\_{p\in P^{bot}}(p-1-|P^{bot}|)x\_{pu}+|P^{bot}|\quad \forall (v, u)\in A$$
The constraints for the top are similar.


