changing the values of a vector without loop

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

changing the values of a vector without loop

by Yasin053 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,
I would like to know if I can set the values of a vector x to those of a vector y without using a loop. In Java or C, this can be done with a single line: x=y.
Thank you,

[AMPL 2773] Re: changing the values of a vector without loop

by Robert Fourer-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



There is no assignment statement exactly of this kind in AMPL.  But you should
use an indexed assignment statement rather than a "for" loop; for example:

   let {p in PROD, t in 1..T} x[p,t] := y[p,t];


> -----Original Message-----
> From: ampl@... [mailto:ampl@...]
> On Behalf Of Yasin053 [yasin053@...]
> Sent: Monday, August 17, 2009 2:35 AM
> To: ampl@...
> Subject: [AMPL 2766] changing the values of a vector without loop
>
> Hi,
> I would like to know if I can set the values of a vector x to those of a
> vector y without using a loop. In Java or C, this can be done with a single
> line: x=y.
> 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
-~----------~----~----~----~------~----~------~--~---


Re: [AMPL 2773] Re: changing the values of a vector without loop

by Yasin053 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Is the below line computationally more efficient(i.e., does it reduce CPU time)?
Robert Fourer-2 wrote:

There is no assignment statement exactly of this kind in AMPL.  But you should
use an indexed assignment statement rather than a "for" loop; for example:

   let {p in PROD, t in 1..T} x[p,t] := y[p,t];


> -----Original Message-----
> From: ampl@googlegroups.com [mailto:ampl@googlegroups.com]
> On Behalf Of Yasin053 [yasin053@gmail.com]
> Sent: Monday, August 17, 2009 2:35 AM
> To: ampl@googlegroups.com
> Subject: [AMPL 2766] changing the values of a vector without loop
>
> Hi,
> I would like to know if I can set the values of a vector x to those of a
> vector y without using a loop. In Java or C, this can be done with a single
> line: x=y.
> 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@googlegroups.com
To unsubscribe from this group, send email to ampl+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/ampl?hl=en
-~----------~----~----~----~------~----~------~--~---

[AMPL 2777] Re: changing the values of a vector without loop

by Robert Fourer-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



It is more efficient to write

   let {p in PROD, t in 1..T} x[p,t] := y[p,t];

than

   for {p in PROD}
      for {t in 1..T}
         let x[p,t] := y[p,t];

and in general indexed "let" statements are more efficient than nested "for"
statements.  The difference in efficiency becomes substantial when the inner
assignment statement is executed many times (say, tens or hundreds of
thousands).

Bob Fourer
4er@...


> -----Original Message-----
> From: ampl@... [mailto:ampl@...]
> On Behalf Of Yasin053
> Sent: Wednesday, August 19, 2009 2:18 PM
> To: ampl@...
> Subject: [AMPL 2776] Re: changing the values of a vector without loop
>
>
> Is the below line computationally more efficient(i.e., does it reduce CPU
> time)?
>
> Robert Fourer-2 wrote:
> >
> > There is no assignment statement exactly of this kind in AMPL.  But you
> > should use an indexed assignment statement rather than a "for" loop; for
> > example:
> >
> >    let {p in PROD, t in 1..T} x[p,t] := y[p,t];
> >
> >
> >> -----Original Message-----
> >> From: ampl@... [mailto:ampl@...]
> >> On Behalf Of Yasin053 [yasin053@...]
> >> Sent: Monday, August 17, 2009 2:35 AM
> >> To: ampl@...
> >> Subject: [AMPL 2766] changing the values of a vector without loop
> >>
> >> Hi,
> >> I would like to know if I can set the values of a vector x to those of
> >> a vector y without using a loop. In Java or C, this can be done with a
> >> single
> >> line: x=y.
> >> 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
-~----------~----~----~----~------~----~------~--~---