Error Implicit conversion of Pyomo NumericValue type

823 views
Skip to first unread message

Deepak Agrawal

unread,
Feb 15, 2017, 4:02:26 PM2/15/17
to Pyomo Forum
Hi, 

I am trying to create a range using pyomo parameter. Following is the code and I am getting following error

TypeError: Implicit conversion of Pyomo NumericValue type `floor' to an integer is
disabled. This error is often the result of using Pyomo components as
arguments to one of the Python built-in math module functions when
defining expressions. Avoid this error by using Pyomo-provided math
functions.

I know the reason of the error is because I am using range with pyomo model. What can I do to solve this?

sum([(x[kj, lj, ij] ** i) / prod(j for j in range(1, i)) for i in range(0, math.floor(model.gamma[kj] * model.cap[kj, lj]))])

Thank you very much in advance.

David Woodruff

unread,
Feb 15, 2017, 4:07:59 PM2/15/17
to pyomo...@googlegroups.com
Your trouble is the use of
math.floor(model.gamma[kj]

If gamma is a Param (or a Python variable), then you can compute the floor outside of this expression. If gamma is a Var, then you have a modeling problem: you will need to
create an integer Var that is constrained to be the floor of gamma.
Dave


--
You received this message because you are subscribed to the Google Groups "Pyomo Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyomo-forum+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Deepak Agrawal

unread,
Feb 15, 2017, 4:18:00 PM2/15/17
to pyomo...@googlegroups.com, dlwoo...@ucdavis.edu
Hi, sorry I didn't clarify, both gamma and cap are Param.

Can you please explain how can I calculate floor outside this expression? I have written exactly what I am trying to do below.

def P1_rule(model, kj, lj, ij):
return 1 - exp(-alpha_rule(model, kj, lj, ij) * sum([(alpha_rule(model, kj, lj, ij) ** i) / prod(j for j in range(1, i)) for i in range(0, floor(model.gamma[kj]*model.cap[kj,lj]))]))


I checked in my code, I can calculate floor(model.gamma[kj]*model.cap[kj,lj]), but I get error when I do range(floor(...))
To unsubscribe from this group and stop receiving emails from it, send an email to pyomo-forum...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages