Function Definition

22 views
Skip to first unread message

Anna Thuenen

unread,
Apr 14, 2021, 8:50:37 AM4/14/21
to AMPL Modeling Language
Hello all,

I would like to define a custom function to simplify the definition of my NLP.

Let say: f(a)= a (if a \in [0,b]) and 2b-a (if a \in [b,2b]) where b is a model parameter.

In the ISMP 2018 talk of Dr. Gay was an option to define functions that was included in AMPL beta.

* Is this feature already in the regular distribution? If no, how do I access the beta version?
* I would also appreciate an other example code. Do I write the function in the .mod file?

Besides:
* Is there a recommended way to define cases?


Thanks a lot and best wishes,

Anna

AMPL Google Group

unread,
Apr 15, 2021, 9:34:44 AM4/15/21
to AMPL Modeling Language
General AMPL functions, as described in the slides that you reference, are not yet available. At this point, we do not have a definite date for releasing a beta version that willgeneral functions. Any beta release that does become available will be announced on this forum.

For your example, you have a simple piecewise-linear function, with slope 1 on [0,b] and slope -1 on [b,2b]. Thus if you have defined "var a >= 0, <= 2*b;", then you can use AMPL's piecewise-linear notation to write this function as

<<b; 1,-1>> a

Concerning your other question, if your cases are different files of data for the same model, you can read the files in a loop; see the example with "set CASES" on page 273 of the AMPL book. If your cases are models that have different combinations of constraints, they can be defined as different named problems that you can switch between by using "problem" statements. If neither of these options offers what you are looking for, then I suggest opening a new thread in this forum with a more specific question about cases.


--
Robert Fourer
am...@googlegroups.com
{#HS:1483785389-103559#}
Reply all
Reply to author
Forward
0 new messages