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

Create a problem with general constraints with operator max by using the API

Description
Create a simple problem using the API function problem.addgencons for creating max general constraints.

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

general_constraint_max_api.zip[download all files]

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





general_constraints_max_api.py

# Here we use the max operator of the Python interface to create a new
# optimization problem.
#
# (C) Fair Isaac Corp., 1983-2024

# Find the point that minimizes the maximum variable within a given
# polytope.

import xpress as xp

p = xp.problem()

# Read data from a problem of MIPLIB 2017
p.read('pk1.mps.gz')

# Retrieve all variables of the original problem
x = p.getVariable()

# Change objective function to the maximum of all variables, to
# be minimized.
p.setObjective (xp.max(*x))

# Set time limit to 5 seconds
p.controls.timelimit = 5
p.optimize()

print("solution: x = ", p.getSolution())

Back to examples browserPrevious exampleNext example