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

Loading a problem

Description
Shows how directly load a problem and solve it in Python

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

LoadLP_python.zip[download all files]

Source Files





example_loadlp.py

#!/bin/env python

import xpress as xp

p = xp.problem()

# fill in a problem with three variables and four constraints

p.loadproblem("",  # probname
              ['G', 'G', 'E', 'L'],  # qrtypes
              [-2.4, -3, 4, 5],  # rhs
              None,  # range
              [3, 4, 5],  # obj
              [0, 2, 4, 8],  # mstart
              None,  # mnel
              [0, 1, 2, 3, 0, 1, 2, 3],  # mrwind
              [1, 1, 1, 1, 1, 1, 1, 1],  # dmatval
              [-1, -1, -1],  # lb
              [3, 5, 8],  # ub
              colnames=['x1', 'x2', 'x3'],  # column names
              rownames=['row1', 'row2', 'row3', 'constr_04'])  # row    names

p.write("loadlp", "lp")
p.solve()

# Create another variable and add it, then modify the objective
# function. Note that the objective function is replaced by, not
# amended with, the new objective

x = xp.var()
p.addVariable(x)
p.setObjective(x**2 + 2*x + 444)
p.solve()
p.write("updated", "lp")

Back to examples browserPrevious exampleNext example