Re: [AMPL 18383] How to refer to certain rows in a column and order sets

39 views
Skip to first unread message
Message has been deleted

AMPL Google Group

unread,
Mar 15, 2019, 2:33:14 PM3/15/19
to Ampl Modeling Language
You can include a condition in the indexing set. For example:

{(i,j) in ARCS: i != j}
{(i,j) in ARCS: cost[i,j] <= limit}
{(i,j) in ARCS: i != j and cost[i,j] <= limit}

AMPL does not have a concept of ordered params. You can sometimes write an AMPL script to sort values, but the details depend on what you are trying to do. What is the context in which you need to sort the arcs by cost?

--
Robert Fourer
am...@googlegroups.com
{#HS:802287977-38521#}
On Thu, Mar 14, 2019 at 11:10 PM UTC, Ampl Modeling Language <am...@googlegroups.com> wrote:
Hi,
I'm new to AMPL and just need to know how you would refer to certain rows in a column like a WHERE clause in SQL?

Also, do you have an example of how to sort say cost in the data below:
param: c l u :=
[R9,A] 55 . 1
[R7,A] 35 . 1
[R4,A] 45 . 1
[R1,B] 54 . 1
[R8,B] 37 . 1


I tried using ORDERED here in the model but got a syntax error:
param c {ARCS} default 0, ordered;


--
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ampl+uns...@googlegroups.com.
To post to this group, send email to am...@googlegroups.com.
Visit this group at https://groups.google.com/group/ampl.
For more options, visit https://groups.google.com/d/optout.



Message has been deleted

AMPL Google Group

unread,
Mar 17, 2019, 9:52:29 AM3/17/19
to Ampl Modeling Language
If you have

set ORIG;
set DEST;
set ARCS within {ORIG,DEST};

then ARCS is a set of origin-destination pairs. Given this setup, you could define, for example,

var Use {(i,j) in ARCS: i = "A"} binary;

In fact you could write the same definition more concisely as

var Use {("A",j) in ARCS} binary;

Either way, the Use variables will be defined only over those arcs that have "A" as the origin. Normally it is desired to define a variable for every arc, however, so this may not be what you are looking for.

Unfortunately your concepts of "sort each column" and "a particular node or arc in a binary variable" and "switch it on if this node gets hit" are hard to understand in the context of AMPL. Perhaps you can give a specific example of the variables and constraints that you want to define, using some small sets of origins, destinations, and arcs.

--
Robert Fourer
am...@googlegroups.com
{#HS:802287977-38521#}
On Fri, Mar 15, 2019 at 9:44 PM UTC, Ampl Modeling Language <am...@googlegroups.com> wrote:
Thanks, I just wondered if there was an easy way to sort each column. If I wanted to refer to a particular node or arc in a binary variable how would I do that? I tried their example and below to switch it on if this node gets hit with no luck:
var Use {ORIG,DEST} binary;

Is {ORIG,DEST} not the name of the ARC? I'm just wanting a 1 if the node gets hit at all in the program sort of like a WHERE clause in SQL.

var Use {(i,j) in ARCS: i = 'ARC-or-NODE-Name?'} binary



On Fri, Mar 15, 2019 at 6:32 PM UTC, AMPL Google Group <am...@googlegroups.com> wrote:
You can include a condition in the indexing set. For example:

{(i,j) in ARCS: i != j}
{(i,j) in ARCS: cost[i,j] <= limit}
{(i,j) in ARCS: i != j and cost[i,j] <= limit}

AMPL does not have a concept of ordered params. You can sometimes write an AMPL script to sort values, but the details depend on what you are trying to do. What is the context in which you need to sort the arcs by cost?

--
Robert Fourer
am...@googlegroups.com


Reply all
Reply to author
Forward
0 new messages