FICO Xpress Optimization Examples Repository
 FICO Optimization Community FICO Xpress Optimization Home

Basic LP tasks: problem statement and solving; solution analysis

Description
Small, introductory problems to modeling with Python.

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

Source Files
By clicking on a file name, a preview is opened at the bottom of this page.

chess.py

'''*******************************************************
* Python Example Problems                             *
*                                                     *
* file chess.py                                       *
* Example for the use of the Python language          *
* (Small LP-problem)                                  *
*                                                     *
* (c) 2018-2024 Fair Isaac Corporation                *
*******************************************************'''

from __future__ import print_function
import xpress as xp

p = xp.problem()

# Now we have the constraints

p.addConstraint(3*small + 2*large <= 400)  # limit on available machine time
p.addConstraint(small + 3*large <= 200)  # limit on available wood

# Define the objective function
p.setObjective(5*small + 20*large, sense=xp.maximize)

p.optimize()

print('')
print("Here are the LP results")
print("Objective value is ", p.getObjVal())
print("Make ", p.getSolution(small), " small sets, and ",
p.getSolution(large), " large sets")

p.chgcoltype([small, large], ['I', 'I'])

p.optimize()

print('')
print("Here are the IP results")
print("Objective value is ", p.getObjVal())
print("Make ", p.getSolution(small), " small sets, and ",
p.getSolution(large), " large sets")