FICO
FICO Xpress Optimization Examples Repository
FICO Optimization Community FICO Xpress Optimization Home
Back to examples browserPrevious exampleNext example

Solving a quadratically constrained problem

Description
Define the well-known Rosenbrock function and minimize it.

Further explanation of this example: 'Xpress Python Reference Manual'

Rosenbrock_python.zip[download all files]

Source Files
By clicking on a file name, a preview is opened at the bottom of this page.
rosenbrock.py[download]





rosenbrock.py

# Define the well-known Rosenbrock function and minimize it
#
# (C) Fair Isaac Corp., 1983-2024

import xpress as xp

p = xp.problem()

x = p.addVariable(lb=-xp.infinity)
y = p.addVariable(lb=-xp.infinity)

# parameters of the Rosenbrock function
a = 1
b = 100

p.setObjective((a - x)**2 + b * (y - x**2)**2)

# Solve this problem with a local nonlinear solver.
p.controls.nlpsolver = 1

p.optimize()

print('solution: ', p.getSolution(), '; value: ', p.attributes.objval)

Back to examples browserPrevious exampleNext example