[AMPL 2936] checking intersection of two sets

View: New views
5 Messages — Rating Filter:   Alert me  

[AMPL 2936] checking intersection of two sets

by ruf@donax.ch :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Hello,

how can I check that the intersection of two sets is empty?

Thank you

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To post to this group, send email to ampl@...
To unsubscribe from this group, send email to ampl+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/ampl?hl=en
-~----------~----~----~----~------~----~------~--~---


[AMPL 2937] Re: checking intersection of two sets

by Paul A. Rubin :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


ruf@... wrote:
> Hello,
>
> how can I check that the intersection of two sets is empty?
>
> Thank you

set A;
set B;
# ...
set C := A inter B;
if card(C) == 0 then {
#...
}

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To post to this group, send email to ampl@...
To unsubscribe from this group, send email to ampl+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/ampl?hl=en
-~----------~----~----~----~------~----~------~--~---


RE: [AMPL 2941] Re: checking intersection of two sets

by Robert Fourer-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


In fact you can write the expression for the intersection of A and B
directly inside the cardinality function:

   if card(A inter B) = 0 then {
   #...
   }

That way you don't have to define another set just in order to assign it the
value of A inter B.

Bob Fourer
4er@...


> -----Original Message-----
> From: ampl@... [mailto:ampl@...]
> On Behalf Of Paul
> Sent: Friday, October 30, 2009 10:21 AM
> To: AMPL Modeling Language
> Subject: [AMPL 2937] Re: checking intersection of two sets
>
>
> ruf@... wrote:
> > Hello,
> >
> > how can I check that the intersection of two sets is empty?
> >
> > Thank you
>
> set A;
> set B;
> # ...
> set C := A inter B;
> if card(C) == 0 then {
> #...
> }
>


--

You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To post to this group, send email to ampl@....
For more options, visit this group at http://groups.google.com/group/ampl?hl=en.



[AMPL 2945] Re: checking intersection of two sets

by ruf@donax.ch :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thank you Paul and Bob for your replies.

In fact, I don't need the intersection to do something, but I must
ensure that the intersection is empty to keep my model coherent. So, I
think the "check" command is more useful in this case, since it throws
an error if the condition is not satisfied.

My problem is that I didn't find any example on the usage of the
"check" command applied to sets. Is that possible? Or can I throw an
error using the "if" statement as you proposed?

Thank you

Raffaele

On Nov 2, 1:45 am, "Robert Fourer" <4...@...> wrote:

> In fact you can write the expression for the intersection of A and B
> directly inside the cardinality function:
>
>    if card(A inter B) = 0 then {
>    #...
>    }
>
> That way you don't have to define another set just in order to assign it the
> value of A inter B.
>
> Bob Fourer
> 4...@...
>
> > -----Original Message-----
> > From: ampl@... [mailto:ampl@...]
> > On Behalf Of Paul
> > Sent: Friday, October 30, 2009 10:21 AM
> > To: AMPL Modeling Language
> > Subject: [AMPL 2937] Re: checking intersection of two sets
>
> > r...@... wrote:
> > > Hello,
>
> > > how can I check that the intersection of two sets is empty?
>
> > > Thank you
>
> > set A;
> > set B;
> > # ...
> > set C := A inter B;
> > if card(C) == 0 then {
> > #...
> > }
>
>

--

You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To post to this group, send email to ampl@....
For more options, visit this group at http://groups.google.com/group/ampl?hl=en.



RE: [AMPL 2955] Re: checking intersection of two sets

by Robert Fourer-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Raffaele,

You can write something like

   set A;
   set B;
      check: card(A inter B) = 0;

In fact you can write any statement of the form

   check: <expr1> = <expr2>;

where <expr1> and <expr2> are expressions that evaluate to numbers.  This
can be further generalized to allow an indexing expression between "check"
and ":" and to use any other numerical comparison operator, such as ">=" or
"<=".

Bob Fourer
4er@...


> -----Original Message-----
> From: ruf@... [mailto:rbo@...]
> Sent: Monday, November 02, 2009 2:42 AM
> To: AMPL Modeling Language
> Subject: [AMPL 2945] Re: checking intersection of two sets
>
> Thank you Paul and Bob for your replies.
>
> In fact, I don't need the intersection to do something, but I must
> ensure that the intersection is empty to keep my model coherent. So, I
> think the "check" command is more useful in this case, since it throws
> an error if the condition is not satisfied.
>
> My problem is that I didn't find any example on the usage of the
> "check" command applied to sets. Is that possible? Or can I throw an
> error using the "if" statement as you proposed?
>
> Thank you
>
> Raffaele
>
> On Nov 2, 1:45 am, "Robert Fourer" <4...@...> wrote:
> > In fact you can write the expression for the intersection of A and B
> > directly inside the cardinality function:
> >
> >    if card(A inter B) = 0 then {
> >    #...
> >    }
> >
> > That way you don't have to define another set just in order to assign it
> the
> > value of A inter B.
> >
> > Bob Fourer
> > 4...@...
> >
> > > -----Original Message-----
> > > From: ampl@... [mailto:ampl@...]
> > > On Behalf Of Paul
> > > Sent: Friday, October 30, 2009 10:21 AM
> > > To: AMPL Modeling Language
> > > Subject: [AMPL 2937] Re: checking intersection of two sets
> >
> > > r...@... wrote:
> > > > Hello,
> >
> > > > how can I check that the intersection of two sets is empty?
> >
> > > > Thank you
> >
> > > set A;
> > > set B;
> > > # ...
> > > set C := A inter B;
> > > if card(C) == 0 then {
> > > #...
> > > }
> >
> >
>
> --
>
> You received this message because you are subscribed to the Google Groups
> "AMPL Modeling Language" group.
> To post to this group, send email to ampl@....
> For more options, visit this group at
> http://groups.google.com/group/ampl?hl=en.
>


--

You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To post to this group, send email to ampl@....
For more options, visit this group at http://groups.google.com/group/ampl?hl=en.