Initializing help system before first use

Solve a polynomial optimization problem


Type: Programming
Rating: 2 (easy-medium)
Description: Create a random polynomial of degree k using the Dot operator and find its minimum using the Nonlinear solver.
File(s): polynomial_opt.py

polynomial_opt.py
#!/bin/env python

#
# Minimize a polynomial constructed with the Dot product
#

from __future__ import print_function

import xpress as xp
import numpy as np

#
# Generate a random coefficient tensor T of dimension k + 1 and sizes
# n+1 for each dimension except for the first, which is h, then use it
# to create h polynomial constraints. The lhs of each constraint has a
# polynomial of degree k, and not homogeneous as we amend the vector
# of variable with the constant 1. This is accomplished via a single
# dot product.
#

n = 10  # dimension of variable space
h = 3   # number of polynomial constraints
k = 4   # degree of each polynomial

# Vector of n variables

x = np.array([1] + [xp.var(lb=-10, ub=10) for _ in range(n-1)])

sizes = [n]*k  # creates list [n,n,...,n] of k elements

# Operator * before a list translates the list into its
# (unparenthesized) tuple, i.e., the result is a reshape list of
# argument that looks like (h, n, n, ..., n)

T = np.random.random(h * n ** k).reshape(h, *sizes)

print(T)

T2list = [x]*k

compact = xp.Dot(T, *T2list) <= 0

p = xp.problem()

p.addVariable(x[1:])
p.addConstraint(compact)

p.write('polynomial', 'lp')

© 2001-2020 Fair Isaac Corporation. All rights reserved. This documentation is the property of Fair Isaac Corporation (“FICO”). Receipt or possession of this documentation does not convey rights to disclose, reproduce, make derivative works, use, or allow others to use it except solely for internal evaluation purposes to determine whether to purchase a license to the software described in this documentation, or as otherwise set forth in a written software license agreement between you and FICO (or a FICO affiliate). Use of this documentation and the software described in it must conform strictly to the foregoing permitted uses, and no other use is permitted.