3

I use the Align environment to write an ILP model, numbering goes wrong: instead of having each number following his constraint I have all the constraints and then all the numbers at the end. If i use the same code in another document it works properly. What could be the problem?

\begin{align}
\mbox{min.} \quad & \sum_{p \in P} \sum_{(t_{1},v_{1},t_{2},v_{2}) \in WT} c_{v_{1},v_{2}}x^p_{t_{1},v_{1},t_{2},v_{2}}  \notag \\
\mbox{s.t.} \quad 
        & \sum_{(t_{2},v_{2},t_{1},v_{1}) \in BS(t_{1},v_{1})} x^p_{t_{2},v_{2},t_{1},v_{1}}  - \sum_{(t_{1},v_{1},t_{2},v_{2}) \in FS(t_{1},v_{1})} x^p_{t_{1},v_{1},t_{2},v_{2}}\; = \; 0\qquad \forall p \in P,(v_{1},t_{1}) \in VT \\
        &  - \sum_{(p,o,t_{2},v_{2}) \in FS(p,o)} x^p_{p,o,t_{2},v_{2}}\; = \; - d_p \qquad  \forall p \in  P\\
        & \sum_{(t_{1},v_{1},p,w) \in BS(p,w)} x^p_{t_{1},v_{1},p,w}  \; = \; + d_p \qquad  \forall p \in  P\\
        & \sum_{p \in P} \sum_{(t_{2},v_{2},t_{1},v_{1}) \in BS(t_{1},v_{1})} x^p_{t_{2},v_{2},t_{1},v_{1}}  \; \leq \; Q \qquad\qquad\qquad\qquad\qquad\qquad\qquad\forall (v_{1},t_{1}) \in VT \\     
        & x^p_{t_{1},v_{1},t_{2},v_{2}} \in Z \qquad \qquad \qquad  \qquad \qquad \quad \forall p \in P, \forall (t_{1},v_{1},t_{2},v_{2}) \in WT     
 \end{align}\\
 \\
3
  • 2
    Welcome to TSE. Please post a Minimal Working Example, instead of a code snippet. Feb 5 at 15:40
  • 2
    Claims such as "if i use the same code in another document it works properly" are not actionable, since you haven't provided any information about those mysterious "other documents". For that matter, you haven't provided a lot of information about the current document either. Do feel free to share some information about the document class you employ, which packages you load, how wide the text block is, what the main font size is, etc.
    – Mico
    Feb 5 at 16:52
  • 1
    Off topic: a display environment shouldn't be followed by \\ . Feb 6 at 3:36

1 Answer 1

4

I suggest you embed an alignat{2} environment in a gather* environment. Both environments are provided by the amsmath package, which is loaded automatically by the mathtools package. I'd further use the \smashoperator macro (provided by the mathtools package) to typeset the material below some of the \sum directives more compactly.

enter image description here

\documentclass{article} % or some other suitable document class   
\usepackage[letterpaper,margin=1in]{geometry} % set page parameters as needed   
\usepackage{mathtools} % for '\smashoperator' macro
\newcommand\vn[1]{\mathit{#1}}

\begin{document}
\begin{gather*}
  \min \sum_{p \in P\mathstrut} \  
  \smashoperator[r]{\sum_{(t_{1},v_{1},t_{2},v_{2}) \in \vn{\vn{WT}}} }
  c_{v_{1},v_{2}}x^p_{t_{1},v_{1},t_{2},v_{2}} \\
\shortintertext{such that}
\begin{alignat}{2} 
  \smashoperator{\sum_{(t_{2},v_{2},t_{1},v_{1}) \in \vn{BS}(t_{1},v_{1})}} 
  x^p_{t_{2},v_{2},t_{1},v_{1}}  
  \quad-\quad 
  \smashoperator{\sum_{(t_{1},v_{1},t_{2},v_{2}) \in \vn{FS}(t_{1},v_{1})}} 
  x^p_{t_{1},v_{1},t_{2},v_{2}}
  &= 0
  &\qquad&\forall p \in P,\ \forall(v_{1},t_{1}) \in \vn{VT} \\
  -\smashoperator{\sum_{(p,o,t_{2},v_{2}) \in \vn{FS}(p,o)}} 
  x^p_{p,o,t_{2},v_{2}} 
  &= -d_p 
  &&\forall p \in P \\
  \smashoperator{\sum_{(t_{1},v_{1},p,w) \in \vn{BS}(p,w)}} 
  x^p_{t_{1},v_{1},p,w} 
  &= + d_p 
  &&\forall p \in  P\\
  \sum_{p \in P\mathstrut} \ 
  \smashoperator[r]{\sum_{(t_{2},v_{2},t_{1},v_{1}) \in \vn{BS}(t_{1},v_{1})}} 
  x^p_{t_{2},v_{2},t_{1},v_{1}}  
  &\leq Q 
  &&\forall (v_{1},t_{1}) \in \vn{VT} \\     
  x^p_{t_{1},v_{1},t_{2},v_{2}} &\in Z 
  && \forall p \in P,\ 
  \forall (t_{1},v_{1},t_{2},v_{2}) \in \vn{WT}     
\end{alignat}
\end{gather*}
\end{document}

Addendum: A large part of what makes these equations tedious to write down -- as well as not at all easy to absorb as a reader -- is the presence of the 4-tuples in sum-subscript positions. If it's ok to create abbreviations for these tuples -- say, \tau_1 thru \tau_4 -- and to use double-sum notation, one could rewrite the equations as follows:

enter image description here

\documentclass{article}       
\usepackage{mathtools} % for '\smashoperator' macro
\newcommand\vn[1]{\mathit{#1}}
\newcommand\doublesum{\mathop{\sum\sum}}

\begin{document}

\begin{gather*}
  \min \smashoperator{\doublesum_{p \in P,\;\tau_1\in\vn{WT}}}
  c^{}_{v_{1},v_{2}}x^p_{\tau_1} \\
\intertext{such that}
\begin{alignat}{2} 
  \smashoperator{\sum_{\tau_1\in\vn{FS}(\tau)}} 
  x^p_{\tau_1}
  &= 
  \smashoperator[r]{\sum_{\tau_2\in\vn{BS}(\tau)}} 
  x^p_{\tau_2}
  &\quad&
  \forall p \in P,\ \forall\tau\in\vn{VT} \\
  -\smashoperator{\sum_{\tau_3\in\vn{FS}(p,o)}} 
  x^p_{\tau_3} 
  &= -d_p 
  &&\forall p \in P \\
  \smashoperator{\sum_{\tau_4\in\vn{BS}(p,w)}} 
  x^p_{\tau_4} 
  &= +d_p 
  &&\forall p \in P \\
  \smashoperator{\doublesum_{p \in P,\;\tau_2\in\vn{BS}(\tau)}} 
  x^p_{\tau_2}  
  &\leq Q 
  &&\forall \tau\in\vn{VT} \\     
  x^p_{\tau_1} &\in Z 
  && \forall p \in P,\ \forall \tau_1\in\vn{WT}     
\end{alignat}
\end{gather*}
where   $\tau\equiv(t_{1},v_{1})$, 
      $\tau_1\equiv(t_{1},v_{1},t_{2},v_{2})$, 
      $\tau_2\equiv(t_{2},v_{2},t_{1},v_{1})$, 
      $\tau_3\equiv(p,o,t_{2},v_{2})$, and
      $\tau_4\equiv(t_{1},v_{1},p,w)$.
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .