I am trying to solve a problem involving the equating of sums of exponentials.
This is how I would do it hardcoded:
@NLconstraint(m, exp(x[25])==exp(x[14])+exp(x[18]))
This works fine with the rest of the code. However, when I try to do it for an arbitrary set of equations like the above I get an error. Here's my code:
@NLconstraint(m,[k=1:length(LHSSum)],sum(exp.(LHSSum[k][i]) for i=1:length(LHSSum[k]))==sum(exp.(RHSSum[k][i]) for i=1:length(RHSSum[k])))
where LHSSum
and RHSSum
are arrays containing arrays of the elements that need to be exponentiated and then summed over. That is LHSSum[1]=[x[1],x[2],x[3],...,x[n]]
. Where x[i]
are variables of type JuMP.Variable
. Note that length(LHSSum)=length(RHSSum)
.
The error returned is:
LoadError: exp is not defined for type Variable. Are you trying to build a nonlinear problem? Make sure you use @NLconstraint/@NLobjective.
So a simple solution would be to simply do all the exponentiating and summing outside of the @NLconstraint
function, so the input would be a scalar. However, this too presents a problem since exp(x)
is not defined since x is of type JuMP.variable
, whereas exp expects something of type real. This is strange since I am able to calculate exponentials just fine when the function is called within an @NLconstraint()
. I.e. when I code this line@NLconstraint(m,exp(x)==exp(z)+exp(y))
instead of the earlier line, no errors are thrown.
Another thing I thought to do would be a Taylor Series expansion, but this too presents a problem since it goes into @NLconstraint
land for powers greater than 2, and then I get stuck with the same vectorization problem.
So I feel stuck, I feel like if JuMP would allow for the vectorized evaluation of @NLconstraint
like it does for @constraint
, this would not even be an issue. Another fix would be if JuMP implements it's own exp function to allow for the exponentiation of JuMP.Variable
type. However, as it is I don't see a way to solve this problem in general using the JuMP framework. Do any of you have any solutions to this problem? Any clever workarounds that I am missing?