Examples of use
p.addVariable (x)
# vectors can be used whole or addressed with their index
c0 = xp.Sum (x) <= 10
cc = [x[i]/1.1 <= x[i+1]*2 for i in range (N-1)]
p.addConstraint (c0, cc)
p.setObjective (3 - x[0])
mysol = [0, 0, 1, 1, 1, 1.4]
# add a variable with its coefficients
p.addcols ([4], [0,3], [c0,4,2], [-3, 2.4, 1.4], [0], [2], [’Y’], [’B’])
p.write ("problem1", "lp")
# load a MIP solution
p.loadmipsol ([0,0,1,1,1,1.4])
We now add a quadratic term x
2
0
− 2x
0
x
3
+ x
3
1
to the second constraint. Note that the -2 coefficient
for an off-diagonal element must be passed divided by two.
The same effect would be obtained with p.addqmatrix (cc[0], [x[0],x[3],x[3]],
[x[0],x[0],x[3]], [1,-1,1])
As constraint vector cc was added after c0, it is the latter which has index 0 in the problem, while
cc[0] has index 1.
We then add the seventh and eighth constraints:
subject to: x
0
+ 2 x
1
+ 3x
2
≥ 4
4x
0
+ 5x
1
+ 6x
2
+ 7 x
3
+ 8 x
4
+ y ≤ 4.4
Note the new column named ’Y’ is added with its index 5 (variables’ indices begin at 0). The same
would happen if 5 were substituted by Y.
p.addqmatrix (1, [x[0],x[3],x[3]], [x[0],x[0],x[3]], [1,-1,1])
p.addrows (qrtype = [’G’, ’L’],
rhs = [4, 4.4],
mstart = [0, 3, 9],
mclind = [x[0],x[1],x[2], x[0],x[1],x[2],x[3],x[4], 5],
dmatval = [1,2,3,4,5,6,7,8,-3],
names = [’newcon1’, ’newcon2’])
p.solve ()
p.write ("amended", "lp")
slacks = []
p.calcslacks (solution = mysol, calculatedslacks = slacks)
print ("slacks:", slacks)
The code below add five columns, then solves the problem and prints the solution, if one has
been found.
p.addcols ([4], [0,3], [c0,4,2], [-3, -2, 1], [0], [2], [’p1’], [’I’])
p.addcols ([4], [0,3], [c0,4,2], [-3, 2.4, 1.4], [0], [10], [’p2’], [’C’])
p.addcols ([4], [0,3], [c0,4,2], [-3, 2, 1], [0], [1], [’p3’], [’S’])
p.addcols ([4], [0,3], [c0,4,2], [-3, 2.4, 4], [0], [2], [’p4’], [’P’])
p.addcols ([4], [0,3], [c0,4,2], [-3, 2, 1], [0], [2], [’p5’], [’R’])
Fair Isaac Corporation Confidential and Proprietary Information 33