Initializing help system before first use

Read problem data into matrix and vectors


Type: Programming
Rating: 2 (easy-medium)
Description: Obtain coefficient matrix, objective coefficients, and constraints' right-hand sides for a given problem.
File(s): example_getmatrix.py

example_getmatrix.py
import xpress as xp
import scipy.sparse

p = xp.problem()

p.read('prob1.lp')

# Obtain matrix representation of the coefficient matrix for problem.
# Restrict to one million coefficients.

coef, ind, beg = [], [], []

p.getrows(beg, ind, coef, 1000000, 0, p.attributes.rows - 1)

# The function getrows() provides a richer output by filling up ind
# not with numerical indices but with the Python objects
# (i.e. Xpress variables) corresponding to the variable
# indices. Convert them to numerical indices using the getIndex()
# function.

ind_n = [p.getIndex(v) for v in ind]

# Create a Compressed Sparse Row (CSR) format matrix using the data
# from getrows plus the numerical indices.

A = scipy.sparse.csr_matrix((coef, ind_n, beg))

# Convert the CSR matrix to a NumPy array of arrays, so that each row
# is a (non-compressed) array.

M = A.toarray()

print(A)
print(M)

b, c = [], []

p.getobj(c, 0, p.attributes.cols - 1)
p.getrhs(b, 0, p.attributes.rows - 1)

print(b)
print(c)

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