nAG数値計算ライブラリ
> 最適化アルゴリズムExample集
> 二次錐計画問題の内点法による解法
二次錐計画問題-SOCP(内点法)
このExampleは、二次錐計画問題(SOCP)を内点法で解いています。内点法に基づく二次錐計画法の使用方法を示すことを目的としています。
目的関数:
タスク | 式 |
---|---|
minimize | \(10x_1 + 20x_2 + x_3\) |
決定変数:
変数 | 範囲 |
---|---|
\(x_1\) | \(-2 \leq x_1 \leq 2\) |
\(x_2\) | \(-2 \leq x_2 \leq 2\) |
\(x_3\) | \(-\infty < x_3 < \infty\) |
制約条件:
制約 | 式 |
---|---|
線形制約1 | \(-0.1x_1 - 0.1x_2 + x_3 \leq 1.5\) |
線形制約2 | \(1 \leq -0.06x_1 + x_2 + x_3\) |
二次錐制約 | \(x_3 \geq \sqrt{x_1^2 + x_2^2}\) |
Exampleの実行コマンド:
python -m naginterfaces.library.examples.opt.handle_solve_socp_ipm_ex
ソースコード表示コマンド:
python -c "import inspect; from naginterfaces.library.examples.opt import handle_solve_socp_ipm_ex; print(''.join(inspect.getsourcelines(handle_solve_socp_ipm_ex)[0]))"
出力結果例:
naginterfaces.library.opt.handle_solve_socp_ipm Python Example Results.
Solve a small SOCP problem.
E04PT, Interior point method for SOCP problems
Status: converged, an optimal solution found
Final primal objective value -1.951817E+01
Final dual objective value -1.951817E+01
マニュアル:
ソース:
#!/usr/bin/env python3
"``naginterfaces.library.opt.handle_solve_socp_ipm`` Python Example."
# nAG Copyright 2019-2020.
# pylint: disable=invalid-name
from naginterfaces.base import utils
from naginterfaces.library import opt
def main():
"""
Example for :func:`naginterfaces.library.opt.handle_solve_socp_ipm`.
Second order cone programming based on an interior point method.
>>> main()
naginterfaces.library.opt.handle_solve_socp_ipm Python Example Results.
Solve a small SOCP problem.
E04PT, Interior point method for SOCP problems
Status: converged, an optimal solution found
Final primal objective value -1.951817E+01
Final dual objective value -1.951817E+01
"""
print(
'naginterfaces.library.opt.handle_solve_socp_ipm '
'Python Example Results.'
)print('Solve a small SOCP problem.')
# The problem size:
= 3
n
# Create the problem handle:
= opt.handle_init(nvar=n)
handle
# Set objective function
=[10.0, 20.0, 1.0])
opt.handle_set_linobj(handle, cvec
# Set box constraints
opt.handle_set_simplebounds(
handle,=[-2.0, -2.0, -1.e20],
bl=[2.0, 2.0, 1.e20]
bu
)
# Set linear constraints
opt.handle_set_linconstr(
handle,=[-1.e20, 1.0],
bl=[1.5, 1.e20],
bu=[1, 1, 1, 2, 2, 2],
irowb=[1, 2, 3, 1, 2, 3],
icolb=[-0.1, -0.1, 1.0, -0.06, 1.0, 1.0]
b
)
# Set cone constraint
opt.handle_set_group(
handle,='Q',
gtype=[3, 1, 2],
group=0
idgroup
)
# Set some algorithmic options.
for option in [
'Print Options = NO',
'Print Level = 1'
]:
opt.handle_opt_set(handle, option)
# Use an explicit I/O manager for abbreviated iteration output:
= utils.FileObjManager(locus_in_output=False)
iom
# Call SOCP interior point solver
=iom)
opt.handle_solve_socp_ipm(handle, io_manager
# Destroy the handle:
opt.handle_free(handle)
if __name__ == '__main__':
import doctest
import sys
sys.exit(
doctest.testmod(None, verbose=True, report=False,
=doctest.ELLIPSIS | doctest.REPORT_NDIFF,
optionflags
).failed
)