Source code for naginterfaces.library.examples.opt.handle_solve_socp_ipm_ex
#!/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
[docs]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:
n = 3
# Create the problem handle:
handle = opt.handle_init(nvar=n)
# Set objective function
opt.handle_set_linobj(handle, cvec=[10.0, 20.0, 1.0])
# Set box constraints
opt.handle_set_simplebounds(
handle,
bl=[-2.0, -2.0, -1.e20],
bu=[2.0, 2.0, 1.e20]
)
# Set linear constraints
opt.handle_set_linconstr(
handle,
bl=[-1.e20, 1.0],
bu=[1.5, 1.e20],
irowb=[1, 1, 1, 2, 2, 2],
icolb=[1, 2, 3, 1, 2, 3],
b=[-0.1, -0.1, 1.0, -0.06, 1.0, 1.0]
)
# Set cone constraint
opt.handle_set_group(
handle,
gtype='Q',
group=[3, 1, 2],
idgroup=0
)
# 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:
iom = utils.FileObjManager(locus_in_output=False)
# Call SOCP interior point solver
opt.handle_solve_socp_ipm(handle, io_manager=iom)
# Destroy the handle:
opt.handle_free(handle)
if __name__ == '__main__':
import doctest
import sys
sys.exit(
doctest.testmod(
None, verbose=True, report=False,
optionflags=doctest.ELLIPSIS | doctest.REPORT_NDIFF,
).failed
)