I want do the following in JuMP but I don’t know how to do it. Suppose I already have a model m. In model m, I defined variables x (for simplicity let’s just represent all the variables in x, which is a R^n vector). I also have nonlinear constraints g(x)<=0 in model m. The nonlinear constraints are defined using macro @NLconstraint. In this case, g(x)<=0 could correspond to several @NLconstraint we defined in a JuMP model. Now, I want to generate a new model n based on model m. In model n, I have variables y, which is R^n, and variable lambda, which is R^1. I want to define constraint lambda*g(y/lambda)<=0 in model n, which is like the perspective function of g(x).
Suppose someone else give me a model m written in JuMP, it there some ways to generate the corresponding model n in JuMP automatically by writing a parser?
More specifically, I guess my question is 1. how to obtain the expression in NLconstraint?
2. Is there some symbolic library in Julia that can do the following: given an expression g(x), is there any ways to generate the expression lambda*g(x/lambda)? Also would the symbolic library work for the expression in JuMP? If not, how to translate a JuMP expression to an expression that can be parsed by the symbolic library?
By the way, if you’re dealing with perspective functions, I’d highly recommend considering conic formulations of the constraints instead of NLP formulations. Conic form deals with perspectives naturally and doesn’t suffer from the division-by-zero issues that you would get when an NLP solver asks for a derivative evaluation at lambda = 0. If you’re bored you can read more about conic form and its modeling side (DCP) in my thesis.