Initializing help system before first use

Loading a problem


Type: Programming
Rating: 2 (easy-medium)
Description: Shows how directly load a problem and solve it in Python
File(s): example_loadlp.py, example_loadqp.py, example_loadqcqp.py, example_loadmiqcqp.py, example_loadmiqcqp_sos.py


example_loadlp.py
# Example of the loadproblem() functionality.
#
# (C) Fair Isaac Corp., 1983-2024

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.optimize()

# Get a variable and modify the objective
# function. Note that the objective function is replaced by, not
# amended with, the new objective

x1 = p.getVariable(0)

p.setObjective(x1**2 + 2*x1 + 444)
p.optimize()
p.write("updated", "lp")

example_loadqp.py
# Example of loadproblem() that adds a quadratic objective
#
# (C) Fair Isaac Corp., 1983-2024

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
              [0, 0, 0, 1, 1, 2],  # mqobj1
              [0, 1, 2, 1, 2, 2],  # mqobj1
              [2, 1, 1, 2, 1, 2])        # dqe

p.write("loadedq", "lp")
p.optimize()

example_loadqcqp.py
# Example using loadproblem to create a quadratically constrained
# quadratic problem.
#
# (C) Fair Isaac Corp., 1983-2024

import xpress as xp

p = xp.problem()

# fill in a problem with three variables and four constraints

p.loadproblem("",  # probname
              ['G', 'G', 'L', '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
              [0, 0, 0, 1, 1, 2],  # mqobj1
              [0, 1, 2, 1, 2, 2],  # mqobj1
              [2, 1, 1, 2, 1, 2],  # dqe
              [2, 3],  # qcrows
              [2, 3],  # qcnquads
              [1, 2, 0, 0, 2],  # qcmqcol1
              [1, 2, 0, 2, 2],  # qcmqcol2
              [3, 4, 1, 1, 1])           # qcdqval

p.write("loadedqc", "lp")
p.optimize()

example_loadmiqcqp.py
# Example: create a MIQCQP using the loadproblem() function
#
# (C) Fair Isaac Corp., 1983-2024

import xpress as xp

p = xp.problem()

# fill in a problem with three variables and four constraints

p.loadproblem("",  # probname
              ['G', 'G', 'L', '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
              [0, 0, 0, 1, 1, 2],  # mqobj1
              [0, 1, 2, 1, 2, 2],  # mqobj1
              [2, 1, 1, 2, 1, 2],  # dqe
              [2, 3],  # qcrows
              [2, 3],  # qcnquads
              [1, 2, 0, 0, 2],  # qcmqcol1
              [1, 2, 0, 2, 2],  # qcmqcol2
              [3, 4, 1, 1, 1],  # qcdqval
              ['I', 'B'],  # qgtype
              [0, 1],  # mgcols
              [0, 2],  # dlim
              colnames=['y01', 'y02', 'y03'],  # column names
              rownames=['row01', 'row02', 'row03', 'row04'])  # row    names

p.write("loadedqcg", "lp")
p.optimize()
print(p.getSolution())

example_loadmiqcqp_sos.py
# Example that uses loadproblem() to create a Mixed Integer
# Quadratically Constrained Quadratic Programming problem with two
# Special Ordered Sets
#
# (C) Fair Isaac Corp., 1983-2024

import xpress as xp

p = xp.problem()

p.loadproblem("",  # probname
              ['G', 'G', 'L', '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
              [0, 0, 0, 1, 1, 2],  # mqobj1
              [0, 1, 2, 1, 2, 2],  # mqobj1
              [2, 1, 1, 2, 1, 2],  # dqe
              [2, 3],  # qcrows
              [2, 3],  # qcnquads
              [1, 2, 0, 0, 2],  # qcmqcol1
              [1, 2, 0, 2, 2],  # qcmqcol2
              [3, 4, 1, 1, 1],  # qcdqval
              ['I', 'S'],  # qgtype
              [0, 1],  # mgcols
              [0, 2],  # dlim
              ['1', '1'],  # qstype
              [0, 2, 4],  # msstart
              [0, 1, 0, 2],  # mscols
              [1.1, 1.2, 1.3, 1.4])      # dref

p.write("loadedqcgs", "lp")
p.optimize()

© 2001-2024 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.