2

I am currently working on a a documentation for some benchmark libraries for MIP solvers. This includes a description for every problem type. e.g. for binpacking I have

\section{Bin Packing Problem}\label{bpp}

\subsection{Formulation}
We are given $n$ items in an item set $I$ with weights $w_i$, with $i \in I$. 
The items shall be packed into bins (also $n$ many, but we use $B$ as the set 
of bins for the sake of readability) with capacity $C$ such that the number of 
bins used is minimal. We use two types of variables:
\begin{itemize}
  \item $x_{ij} \in \{0, 1\}$ should be $1$ iff item $i$ is packed into bin $j$.
  \item $y_j \in \{0, 1\}$ should be $1$ iff bin $j$ is used.
\end{itemize}
\begin{align}
  \text{minimize }      & \sum_{j \in B} y_j                                            \label{bpp:obj}\\
  \text{subject to }    & \sum_{j \in B} x_{ij} = 1             & i \in I               \label{bpp:setpp}\\
                        & \sum_{i \in I} w_i x_{ij} \leq C y_j  & j \in B               \label{bpp:capacity}\\
                        & x_{ij} \in \{0, 1\}                   & i \in I, j \in B\\
                        & y_j \in \{0, 1\}                      & j \in B
\end{align}

As you can see the objective function and each constraint gets a label. Now, instead assume this binpacking section would be section 1. The labels are consequently named (1.1), (1.2), (1.3). But I would like them to have a name like (BPP.1), (BPP.2), (BPP.3), i.e. some common abbreviation of the underlying problem. The section itself however, should still have a number for the table of contents and other references.

Any suggestions how that might work?

4

You can define the style setting \theequation:

\renewcommand{\theequation}{BPP.\arabic{equation}}

This would result in labels called (BPP.1), (BPP.2), etc.

To use this in a document I would suggest a macro that sets the the style as following:

\newcounter{oldeq}
\newcommand{\setpreeqno}[1]{% set text before equation number
  \ifx\preeqno\empty% if no preeqno was given before
    \def\preeqno{#1}% set to argument
    \ifx\preeqno\empty\else% if an argument was given
      \renewcommand{\theequation}{#1.\arabic{equation}}% set to "arg.#"
      \setcounter{oldeq}{\value{equation}}% save equation counter
      \setcounter{equation}{0}% reset locally to start with "arg.1"
    \fi%
  \else%
    \def\preeqno{#1}% set to argument
    \ifx\preeqno\empty% if no argument was given
      \renewcommand{\theequation}{\arabic{equation}}% reset to default arabic number
      \setcounter{equation}{\value{oldeq}}% continue counting
    \else%
      \renewcommand{\theequation}{#1.\arabic{equation}}% set to "arg.#"
      \setcounter{equation}{0}% reset locally to start with "arg.1"
    \fi%
  \fi%
  \ignorespaces%
}

Or in a full MWE:

\documentclass{article}
\usepackage{amsmath}


\newcounter{oldeq}
\newcommand{\setpreeqno}[1]{% set text before equation number
  \ifx\preeqno\empty% if no preeqno was given before
    \def\preeqno{#1}% set to argument
    \ifx\preeqno\empty\else% if an argument was given
      \renewcommand{\theequation}{#1.\arabic{equation}}% set to "arg.#"
      \setcounter{oldeq}{\value{equation}}% save equation counter
      \setcounter{equation}{0}% reset locally to start with "arg.1"
    \fi%
  \else%
    \def\preeqno{#1}% set to argument
    \ifx\preeqno\empty% if no argument was given
      \renewcommand{\theequation}{\arabic{equation}}% reset to default arabic number
      \setcounter{equation}{\value{oldeq}}% continue counting
    \else%
      \renewcommand{\theequation}{#1.\arabic{equation}}% set to "arg.#"
      \setcounter{equation}{0}% reset locally to start with "arg.1"
    \fi%
  \fi%
  \ignorespaces%
}


\begin{document}
\thispagestyle{empty}
\section{Bin Packing Problem}\label{bpp}\setpreeqno{BPP}

\subsection{Formulation}
We are given $n$ items in an item set $I$ with weights $w_i$, with $i \in I$. 
The items shall be packed into bins (also $n$ many, but we use $B$ as the set 
of bins for the sake of readability) with capacity $C$ such that the number of 
bins used is minimal. We use two types of variables:
\begin{itemize}
  \item $x_{ij} \in \{0, 1\}$ should be $1$ iff item $i$ is packed into bin $j$.
  \item $y_j \in \{0, 1\}$ should be $1$ iff bin $j$ is used.
\end{itemize}
\begin{align}
  \text{minimize }      & \sum_{j \in B} y_j                                            \label{bpp:obj}\\
  \text{subject to }    & \sum_{j \in B} x_{ij} = 1             & i \in I               \label{bpp:setpp}\\
                        & \sum_{i \in I} w_i x_{ij} \leq C y_j  & j \in B               \label{bpp:capacity}\\
                        & x_{ij} \in \{0, 1\}                   & i \in I, j \in B\\
                        & y_j \in \{0, 1\}                      & j \in B
\end{align}

This reference looks like \eqref{bpp:obj}.
\end{document}

enter image description here

edit I improved the code by taking care of the global counter (inspired by @egreg's answer)

2

A variation upon subequations using the same infrastructure.

\documentclass{article}
\usepackage{amsmath}

\newenvironment{labeledequations}[1]{%
  \setcounter{parentequation}{\value{equation}}%
  \setcounter{equation}{0}%
  \def\theequation{#1.\arabic{equation}}%
  \ignorespaces
}{%
  \setcounter{equation}{\value{parentequation}}%
  \ignorespacesafterend
}


\begin{document}

\section{Bin Packing Problem}\label{bpp}

\subsection{Formulation}
We are given $n$ items in an item set $I$ with weights $w_i$, with $i \in I$. 
The items shall be packed into bins (also $n$ many, but we use $B$ as the set 
of bins for the sake of readability) with capacity $C$ such that the number of 
bins used is minimal. We use two types of variables:
\begin{itemize}
  \item $x_{ij} \in \{0, 1\}$ should be $1$ iff item $i$ is packed into bin $j$.
  \item $y_j \in \{0, 1\}$ should be $1$ iff bin $j$ is used.
\end{itemize}
\begin{labeledequations}{BPP}
\begin{align}
\text{minimize }   & \sum_{j \in B} y_j 
  \label{bpp:obj} \\
\text{subject to } & \sum_{j \in B} x_{ij} = 1             && i \in I
  \label{bpp:setpp} \\
                   & \sum_{i \in I} w_i x_{ij} \leq C y_j  && j \in B
  \label{bpp:capacity} \\
                   & x_{ij} \in \{0, 1\}                   && i \in I, j \in B
  \\
                   & y_j \in \{0, 1\}                      && j \in B
\end{align}
\end{labeledequations}

The references to \eqref{bpp:obj} and \eqref{bpp:capacity} are correct.

\end{document}

enter image description here

  • Resetting the counter number, good idea... – nox Jul 16 '18 at 8:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.