Forum Discussion
FICO
1 year agoCommunity Manager
Issue building a nonlinear expressions with Xpress python package
Hello,
I was building a nonlinear expression but came across a strange behavior. I am trying to produce (1 / (a + b) ) but all that I am getting is (1 / a + b ).
Below is a minimal example that shows the issue. What am I doing wrong?
CODE:
import xpress as xp
idx = ['A', 'B', 'C', 'D', 'E']
with xp.problem("test") as p:
l = xp.vars(idx, vartype=xp.continuous, lb=-10, ub=10, name='lambda')
p.addVariable(l)
f = 1 / (l['A'] + l['B'])
g = 10 * (l['A'] + l['B']) / (l['C'])
print('f =', f)
print('g =', g)
OUTPUT:
f = (1 / lambda(A) + lambda(B))
g = ( 10 lambda(A) +10 lambda(B) / lambda(C))
Thank you,
Miroslav
2 Replies
- FICOCommunity Manager
Thanks for reporting this! This seems to be a bug in printing expressions in Python :-(
The bug is only in printing expressions in Python. If I add these lines to your code:
p.addConstraint(f == 1) p.addConstraint(g == 1) p.write('nonlinear.lp')then the generated nonlinear.lp file contains these lines, which look correct:
R1: { 1 / ( lambda(A) + lambda(B) ) } = 1 R2: { ( 10 * lambda(A) + 10 * lambda(B) ) / lambda(C) } = 1I will file an internal defect to get this fixed.
- FICOCommunity Manager
Hi Daniel,
This is great news. Thank you for the quick response and showing how to test it!
Regards,
Miroslav
