6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

LaTeXで数理計画(数理最適化)問題を記述する環境

Last updated at Posted at 2017-06-28

概要

LaTeXで、数理計画(数理最適化)問題を、

aae.png

のように記述するための、mpproblem環境(\begin{mpproblem} ... \end{mpproblem})というものを作りました。

特徴

  • 問題名(上記の例では(P))と、縦棒を出力
  • 問題の中身は、amsmathパッケージのalignatを使用可能
    • 複数の式の記述が可能
    • 数式番号の個別付与、相互参照が可能
  • nameref(hyperref)パッケージを使えば、問題名(P)は相互参照可能

サンプルコード

MPProblem_excerpt.tex
\documentclass[12pt, a4paper, papersize, dvipdfmx]{jsarticle}

% ---- Preamble -------------------------------------------------------------- %
% -------- Packages ------------------------------------------------------ %
% AMS
\usepackage{amsmath}

% Ref
\usepackage{nameref}

% -------- Environments -------------------------------------------------- %
% New Environments
\newcounter{mpproblem}[section]
\renewcommand{\thempproblem}{\thesection.\arabic{mpproblem}}
\makeatletter
\newenvironment{mpproblem}[1]%
{%
    \protected@edef\@currentlabelname{#1}%
    \par\vspace{\baselineskip}\noindent%
    \ifx#1\empty %
    \else \refstepcounter{mpproblem}$($#1$)$ %
    \fi%
    \hfill%
    $\left|%
    \hfill%
    \hspace{0.00\textwidth}%
    \@fleqntrue\@mathmargin\parindent%
    \begin{minipage}{0.86\textwidth}%
    \vspace{-1.0\baselineskip}%
}%
{%
    \end{minipage}%
    \@fleqnfalse%
    \right.$%
    \par\vspace{\baselineskip}\noindent%
    \ignorespacesafterend%
}%
\makeatother
\newcommand{\mpprobref}[1]{$($\nameref{#1}$)$}

\newenvironment{mpproblem*}%
{%
    \begin{mpproblem}{}%
}%
{%
    \end{mpproblem}%
    \ignorespacesafterend%
}



% ---- Text ------------------------------------------------------------------ %
\begin{document}

問題名あり。
%
\begin{mpproblem}{$P$}
\label{mpprob:P}
\begin{alignat}{2}
 &\text{minimize}   & \quad  c^\top x  &        \label{eqn:P_Obj}     \\
 &\text{subject to} & \quad  Ax        &\geq b  \label{eqn:P_Con-Eq}  \\
 &                  & \quad  x         &\geq 0. \label{eqn:P_Con-Non} 
\end{alignat}
\end{mpproblem}

問題名なし。
%
\begin{mpproblem*}
\begin{alignat}{2}
 &\text{minimize}   & \quad f(x)  &        \label{eqn:FG_Obj}    \\
 &\text{subject to} & \quad g(x)  &\leq 0. \label{eqn:FG_Con-Eq} 
\end{alignat}
\end{mpproblem*}

nameref(hyperref)パッケージを使えば、
問題名\mpprobref{mpprob:P}は相互参照可能。

\end{document}

もうちょっと詳しいサンプルコードをGitHubで公開しました。
https://github.com/samuelladoco/LaTeXEnvMPProblem

6
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?