具有多行方程式的主标签和子标签?

具有多行方程式的主标签和子标签?

是否可以使用主标签来标记优化问题,并使用子标签来标记每一行?

例如,我想将优化问题标记为(AP),但我还想在单一方程环境中标记目标和每个约束。

这就是我能做的。

\documentclass{article}

\usepackage{amsmath}

\begin{document}

The assignment problem is the problem of assigning
agents $i = 1, 2, \ldots, N$
to tasks $j = 1, 2, \ldots N$
in order to minimize the total cost of the assignments.
Any agent could be assigned to any task,
incurring a cost that depends on the agent-task assignment.
The objective is to minimize the total cost of assignment.

\paragraph{Input data:}
\begin{itemize}
\item $N = $ number of agents $ = $ number of tasks
\item $c_{ij} = $ cost of assigning task $j$ to agent $i$
\end{itemize}

\paragraph{Decision variables:}
\begin{itemize}
\item $x_{ij} = 1$ if agent $i$ is assigned to task $j$,
$x_{ij} = 0$ otherwise
\end{itemize}

\paragraph{Optimization problem formulation:}
\begin{alignat}{3}
   & \min\
  && \sum_{i=1}^N \sum_{j=1}^N c_{ij}x_{ij}
  & \quad &
  \label{objective}  
\\
   & \text{s.t.}
  && \sum_{i=1}^N x_{ij} = 1
  && \forall j \in \{1,2,\ldots,N\}
  \label{each task must be assigned to an agent}
\\
   & 
  && \sum_{j=1}^N x_{ij} = 1
  && \forall i = \{1,2,\ldots,N\}
  \label{each agent must be assigned to a task}
\\
   &
  && 0 \leq x_{ij} \geq 1
  && \forall i \in \{1,2,\ldots,N\}, j \in \{1,2,\ldots,N\}
  \label{binary variable constraint}
\end{alignat}

The objective \eqref{objective} is to minimize the total cost of assignment.
The constraint \eqref{each task must be assigned to an agent}
states that each task must be assigned to an agent.
The constraint \eqref{each agent must be assigned to a task}
states that each agent must be assigned to a task.
The constraint \eqref{binary variable constraint}
imposes binary lower and upper bounds on the assignment variables $x_{ij}$.


The assignment problem can be formulated as the following optimization problem
\begin{equation}
\tag{AP}
\label{assignment problem}
\begin{alignedat}{3}
   & \min\
  && \sum_{i=1}^N \sum_{j=1}^N c_{ij}x_{ij}
  & \quad &
\\
   & \text{s.t.}
  && \sum_{i=1}^N x_{ij} = 1
  && \forall j \in \{1,2,\ldots,N\}
\\
   & 
  && \sum_{j=1}^N x_{ij} = 1
  && \forall i = \{1,2,\ldots,N\}
\\
   &
  && 0 \leq x_{ij} \leq 1
  && \forall i \in \{1,2,\ldots,N\}, j \in \{1,2,\ldots,N\}
\end{alignedat}
\end{equation}

Are you looking for the formulation of the assignment problem?
It is in equation \eqref{assignment problem} above.

\end{document}

在此处输入图片描述

我希望输出类似于以下内容:

        min  sum sum c_ij x_ij               (1)
(AP)    s.t. sum_i x_ij = 1                  (2)
             sum_j x_ij = 1                  (3)
             0 <= x_ij <= 1                  (4)

其中 (AP) 垂直对齐于中心,基本上是输出图像中两个方程的组合。

如果有更好的方法来实现主标签和子标签,我也想了解一下。

答案1

我假设您想用 (I) (II) 等替换 (AP)。您也可以轻松使用 (AP.1) 或 (A) 等。\rule 只是为了检查对齐。

这种方法的缺点是方程式不太居中。优点是您可以包含文本或很长的方程式而不会重叠。您甚至可以考虑使用 \llap 将作业编号移到左边距。

\documentclass{article}
\usepackage{amsmath}

\newcounter{AScount}
\renewcommand{\theAScount}{\Roman{AScount}}
\newlength{\ASlen}

\newenvironment{assignment}[1]% #1=label
{\refstepcounter{AScount}\label{#1}%
\ifvmode\noindent\else\newline\fi%
\makebox[\labelwidth][l]{(\theAScount)}%
\setlength{\ASlen}{\linewidth}%
\addtolength{\ASlen}{-\labelwidth}%
\minipage[c]{\ASlen}}%
{\endminipage}

\begin{document}
\noindent\rule{\textwidth}{1pt}

\begin{assignment}{assignment problem}
\begin{equation}
x=a
\end{equation}
\begin{equation}
y=b
\end{equation}
\end{assignment}

Assignment problem \eqref{assignment problem}.
\end{document}

任务

答案2

这个问题可能之前有人问过。希望你能灵活应对环境alignat。我改用了align。抱歉,习惯使然。如果这对你不起作用,请发表评论。

\documentclass{article}
\usepackage{amsmath}

\makeatletter
\newenvironment{mysubeqns}[1]
 {%
  \addtocounter{equation}{-1}%
  \begin{subequations}
  \renewcommand{\theparentequation}{#1}%
  \def\@currentlabel{#1}%
 }
 {%
  \end{subequations}
 }
\makeatother

\begin{document}

The assignment problem is the problem of assigning
agents $i = 1, 2, \ldots, N$
to tasks $j = 1, 2, \ldots N$
in order to minimize the total cost of the assignments.
Any agent could be assigned to any task,
incurring a cost that depends on the agent-task assignment.
The objective is to minimize the total cost of assignment.

\paragraph{Input data:}
\begin{itemize}
\item $N = $ number of agents $ = $ number of tasks
\item $c_{ij} = $ cost of assigning task $j$ to agent $i$
\end{itemize}

\paragraph{Decision variables:}
\begin{itemize}
\item $x_{ij} = 1$ if agent $i$ is assigned to task $j$,
$x_{ij} = 0$ otherwise
\end{itemize}

\paragraph{Optimization problem formulation:}
\begin{alignat}{3}
   & \min\
  && \sum_{i=1}^N \sum_{j=1}^N c_{ij}x_{ij}
  & \quad &
  \label{objective}  
\\
   & \text{s.t.}
  && \sum_{i=1}^N x_{ij} = 1
  && \forall j \in \{1,2,\ldots,N\}
  \label{each task must be assigned to an agent}
\\
   & 
  && \sum_{j=1}^N x_{ij} = 1
  && \forall i = \{1,2,\ldots,N\}
  \label{each agent must be assigned to a task}
\\
   &
  && 0 \leq x_{ij} \geq 1
  && \forall i \in \{1,2,\ldots,N\}, j \in \{1,2,\ldots,N\}
  \label{binary variable constraint}
\end{alignat}

The objective \eqref{objective} is to minimize the total cost of assignment.
The constraint \eqref{each task must be assigned to an agent}
states that each task must be assigned to an agent.
The constraint \eqref{each agent must be assigned to a task}
states that each agent must be assigned to a task.
The constraint \eqref{binary variable constraint}
imposes binary lower and upper bounds on the assignment variables $x_{ij}$.


The assignment problem can be formulated as the following optimization problem

\begin{mysubeqns}{AP}
\label{eq:assignment problem}
  \begin{align}
  \min\     &\sum_{i=1}^N \sum_{j=1}^N c_{ij}x_{ij}     &&                  & \label{eq:assignment problem1} \\
  \text{s.t.}   &\sum_{i=1}^N x_{ij} = 1            && \forall j \in \{1,2,\ldots,N\}   & \label{eq:assignment problem2} \\
        &\sum_{j=1}^N x_{ij} = 1            && \forall i = \{1,2,\ldots,N\} &\label{eq:assignment problem3} \\
        &0 \leq x_{ij} \leq 1                   && \forall i \in \{1,2,\ldots,N\}, j \in \{1,2,\ldots,N\}   &\label{eq:assignment problem4}
  \end{align}
\end{mysubeqns}
Another equation
\begin{equation}
2=2
\end{equation}

Are you looking for the formulation of the assignment problem?
It is in equation \eqref{eq:assignment problem} above.

\end{document}

相关内容