11
3

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 1 year has passed since last update.

LaTeXで最適化問題を記述するためのパッケージ"Optidef"

Last updated at Posted at 2022-12-12

はじめに

LaTeXで最適化問題を記述する時に,Optidefというパッケージが便利です.

できることは

  • 簡単に最適化問題を書ける
  • 問題番号(数字)と式番号(アルファベット)を付けれる
  • min max問題も簡単に書ける(styファイルのダウンロードが必要)

などです.

image.png

\begin{mini!}
    {w,x}          % 決定変数
    {f(w)+ R(w+6x) \label{eq:prb-obj}} % 目的関数
    {\label{prb}}  % 問題のラベル
    {J(w^*, x^*)=} % minの左側
    \addConstraint{g(w)}{=0  \label{eq:constr1}} % 1つ目の制約
    \addConstraint{n(w)}{= 6 \label{eq:constr2}} % 2つ目の制約
    \addConstraint{L(w)}{=Kw \label{eq:constr3}} % 3つ目の制約
    \addConstraint{h(x)}{=0. \label{eq:constr4}} % 4つ目の制約
\end{mini!}

使うには

プリアンブルに

\usepackage{optidef}

と記述すると,使うことができます.Overleafでも使用できることは確認済みです.

他の記述方法

  • 最適化問題一つに対して,一つの参照(式番号)にするには

    -> mini!miniに書き換える

  • 参照(式番号)を無くすには

    -> mini!mini*に書き換える.

  • minimize を min,subject to を s.t. にするには

    -> \begin{mini!}の後に|s|を付け足す.

  • minimize を argmin にするには

    -> mini!argmini!に書き換える.

  • ページをまたいで記述するには

    -> \begin{mini!}の後に<b>を付け足す
    (mini環境での問題へのラベル付けは\labelOP{}を使用)

  • 最適化問題中のカンマを全て無くすには

    -> \usepackage[nocomma]{optidef}

他にも,制約の揃え方についてのオプションなどを指定できます.

より新しい機能

Githubからoptidef.styをダウンロードして,プロジェクト内に置くと最新の機能を使うことができます.

例えば,customopti環境を使えば,min や argmin の部分を,"inf" や "min max" に置き換えることができます.

inf

image.png

\begin{customopti!}|s|
    {inf}          % minimize の代わり
    {w,x}          % 決定変数
    {f(w)+ R(w+6x) \label{eq:prb-obj}} % 目的関数
    {\label{prb}}  % 問題のラベル
    {J(w^*, x^*)=} % minの左側
    \addConstraint{g(w)}{=0  \label{eq:constr1}} % 1つ目の制約
    \addConstraint{n(w)}{= 6 \label{eq:constr2}} % 2つ目の制約
    \addConstraint{L(w)}{=Kw \label{eq:constr3}} % 3つ目の制約
    \addConstraint{h(x)}{=0. \label{eq:constr4}} % 4つ目の制約
\end{customopti!}

min max

min max の場合は,決定変数の部分は空欄にして,「minimize の代わり」の部分に自分で記入します.

image.png

\begin{customopti!}
    {\underset{\displaystyle \mathit{w}}{max}\quad\underset{\displaystyle \mathit{x}}{min}} % minimize の代わり
    {}             % 決定変数
    {f(w)+ R(w+6x) \label{eq:prb-obj}} % 目的関数
    {\label{prb}}  % 問題のラベル
    {J(w^*, x^*)=} % minの左側
    \addConstraint{g(w)}{=0  \label{eq:constr1}} % 1つ目の制約
    \addConstraint{n(w)}{= 6 \label{eq:constr2}} % 2つ目の制約
    \addConstraint{L(w)}{=Kw \label{eq:constr3}} % 3つ目の制約
    \addConstraint{h(x)}{=0. \label{eq:constr4}} % 4つ目の制約
\end{customopti!}

参考

optidef – Environments for writing optimization problems
Package documentation
Issues: Personalized environments

11
3
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
11
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?