Skip to content

Commit

Permalink
document Expr input
Browse files Browse the repository at this point in the history
  • Loading branch information
mlubin committed Jul 31, 2016
1 parent 23efed5 commit d1c9a85
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions doc/nlp.rst
Expand Up @@ -263,3 +263,23 @@ which can be queried using the ``JuMP.NLPEvaluator``.
If you are writing a "solver", we *highly encourage* use of the `MathProgBase nonlinear interface <http://mathprogbasejl.readthedocs.org/en/latest/nlp.html>`_ over querying derivatives using the above methods. These methods are provided for convenience but do not fully integrate with JuMP's solver infrastructure. In particular, they do not allow users to specify your solver to the ``Model()`` constructor nor to call it using ``solve()`` nor to populate the solution back into the model. Use of the MathProgBase interface also has the advantage of being independent of JuMP itself; users of MathProgBase solvers are free to implement their own evaluation routines instead of expressing their model in JuMP. You may use the ``JuMP.build`` method to ask JuMP to populate the "solver" without calling ``optimize!``.

.. [1] Dunning, Huchette, and Lubin, "JuMP: A Modeling Language for Mathematical Optimization", `arXiv <http://arxiv.org/abs/1508.01982>`_.
Raw expression input
^^^^^^^^^^^^^^^^^^^^

In addition to the ``@NLobjective`` and ``@NLconstraint`` macros, it is also
possible to provide Julia ``Expr`` objects directly by using
``JuMP.setNLobjective`` and ``JuMP.addNLconstraint``. This input form
may be useful if the expressions are generated programmatically.
JuMP variables should be spliced into the expression object. For example::

@variable(m, 1 <= x[i=1:4] <= 5)
JuMP.setNLobjective(m, :Min, :($(x[1])*$(x[4])*($(x[1])+$(x[2])+$(x[3])) + $(x[3])))
JuMP.addNLconstraint(m, :($(x[1])*$(x[2])*$(x[3])*$(x[4]) >= 25))

# Equivalent form using traditional JuMP macros:
@NLobjective(m, Min, x[1]*x[4]*(x[1]+x[2]+x[3]) + x[3])
@NLconstraint(m, x[1]*x[2]*x[3]*x[4] >= 25)

See the Julia documentation for more examples and description of Julia expressions.

0 comments on commit d1c9a85

Please sign in to comment.