AMPL alternative to OPL expressions ("dexpr")?

102 views
Skip to first unread message

Tiziano Parriani

unread,
Jun 5, 2014, 3:21:02 AM6/5/14
to am...@googlegroups.com
Dear all,

I am moving from OPL to AMPL. I find useful the possibility, in OPL, of defining expressions (that is, the "dexpr" command).
Is there something similar in AMPL?

Thank you.

Best,
Tiziano

fbahr

unread,
Jun 5, 2014, 4:10:57 AM6/5/14
to am...@googlegroups.com
Sth. like

dexpr productionCost = sum ( p in products ) cost[p] * quantity[p];
dexpr revenues = sum ( p in products ) price[p] * quantity[p];
maximize revenues - productionCost;

(in OPL) can be formulated as

var productionCost = sum { p in products } cost[p] * quantity[p];
var revenues = sum { p in products } price[p] * quantity[p];
maximize obj: revenues - productionCost;

(in AMPL).

--fbahr

Tiziano Parriani

unread,
Jun 5, 2014, 4:26:25 AM6/5/14
to am...@googlegroups.com
Thank you fbahr, but I am afraid it is not the same thing.
OPL expressions do not add new variables and constraints to the model (and do not need memory allocation), while AMPL variable definition does.

I know it seems a detail since variables defined that way would be quickly removed during pre-processing. Nevertheless in my case the number of overhead variables generated by a direct "one to one" dexpr-to-var translation would be huge, and I am quite worried about memory consumption, more the about resolution times.

Best,
Tiziano

Robert Fourer

unread,
Jun 6, 2014, 11:45:30 AM6/6/14
to am...@googlegroups.com
If you have a huge number of simple defined variables, like

var y {i in I, j in J, k in K, l in L} = a[i,j,k,l] * x[i,j,k,l];

then your best approach may be to substitute these variables out of the problem "by hand". But not all situations are so clear-cut. Usually it is best to make some experiments rather than rely on assumptions about what will be efficient. Setting "option times 1;" will show the time and memory use in each phase of the model translation.

Bob Fourer
am...@googlegroups.com

=======

Tiziano Parriani

unread,
Jun 6, 2014, 12:46:36 PM6/6/14
to am...@googlegroups.com, 4...@ampl.com
Thank you mr. Fourer for your reply.

Fair enough. I think I will follow your suggestion.
I guess I will post the outcome here to complete the discussion.

The "option times 1" is going to be very useful.

Best,
Tiziano
Reply all
Reply to author
Forward
0 new messages