Optical frequency simulation Topic is solved

questions about GAMS' tools
Post Reply
juldavarias
User
User
Posts: 2
Joined: 1 year ago

Optical frequency simulation

Post by juldavarias »

Hey guys. I´m a newbie in GAMS and this is my first post.
Recently i did an allocation algorithm for my thesis in GAMS.
The algorithm is working with 20 demands in a frequency comb of 50 "pulses". We´d like to try it for 200 demands and 500 pulses.
In order to avoid typing all of this, i´d like to simulate an optical frequency comb and continue trying the algorithm.
Before I import the data from Excel, I´d like to try it in GAMS (It should be easy i guess... but i´m missing something). The code seems simple.
The intent of the code is to generate 10 random numbers in ascending order and then, make a mirror of those numbers. So it looks like the image:

The code is here:
GenPeine.gms
(301 Bytes) Downloaded 140 times
set i /1*10/;
parameter x(i);
x('1') = uniformint(5, 10);
loop(i$(ord(i) > 1),
x(i) = x(i-1) + uniformint(0,3);
);
display x;

parameter y(i);
y(i)$(ord(i) <= card(i)) = x(i);
y(i)$((ord(i) > card(i))) = x(2*card(i)-(ord(i)+1));

display y;

The errors are 2 lines after the parameter designation of "y(i)" :

* Set identifier or quoted element expected
* Dimension different - The symbol is referenced with more/less
indices as declared
* ')' expected
* Too many ),] or }

Any advise?
Attachments
Optical frequency comb image
Optical frequency comb image
image.png (8.85 KiB) Viewed 5666 times
User avatar
bussieck
Moderator
Moderator
Posts: 1037
Joined: 7 years ago

Re: Optical frequency simulation

Post by bussieck »

You did an index calculation for the second half of y. GAMS works with lag and leads (https://www.gams.com/latest/docs/UG_Ord ... ssignments). This requires x(i-(expr)) (or +). The following code does the trick (works even if card(i) is odd):

Code: Select all

set i /1*10/;
parameter x(i);

x('1') = uniformint(5, 10);

loop(i$(ord(i) > 1),
  x(i) = x(i-1) + uniformint(0,3);
);

display x;

* Agregar el mismo vector en espejo
parameter y(i);
y(i)$(ord(i) <= card(i)/2) = x(i);
y(i)$(ord(i) > card(i)/2) = x(i+(card(i) - 2*ord(i) + 1));

display y;
-Michael
juldavarias
User
User
Posts: 2
Joined: 1 year ago

Re: Optical frequency simulation

Post by juldavarias »

Thanks a lot Mr. Michael. It worked perfectly. Have a great day
Post Reply