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

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

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

What You See Productions
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/ampl.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

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

AMPL mailing list
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
[hidden email]
{#HS:802287977-38521#}
On Thu, Mar 14, 2019 at 11:10 PM UTC, Ampl Modeling Language <[hidden email]> 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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/ampl.
For more options, visit https://groups.google.com/d/optout.



--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/ampl.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

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

What You See Productions
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

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/ampl.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

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

AMPL mailing list
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
[hidden email]
{#HS:802287977-38521#}
On Fri, Mar 15, 2019 at 9:44 PM UTC, Ampl Modeling Language <[hidden email]> 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 <[hidden email]> 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
[hidden email]


On Thu, Mar 14, 2019 at 11:10 PM UTC, Ampl Modeling Language <[hidden email]> 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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/ampl.
For more options, visit https://groups.google.com/d/optout.