re-use the same set name multiple times in Gams - optimization

I defined a set in GAMS to represent users number. I need to use the set multiple times to define transmission power for each user, the channel quality...etc. However, I think in GAMS you can not use the name of the set for different variables, My question is do I need to define a different set for each variable?
Code example:
set I number of users /i1,i2/ ;
Parameters
CP(I) circuit power per user /
i1 10
i2 10 /
h(I) channel quality /
i1 48.9318
i2 106.2280/ ;
Thank you in advance for any help or for any hints.

No, you don't need to define different sets if you always want to refer to the same elements (users in your case). It is actually the idea of sets to do exactly this. So, your example code is just right.
You can also look at a simple example like this one here: http://www.gams.com/modlib/libhtml/trnsport.htm
There you will see, that the sets i and j are used all over for different parameters, variables and equations.
I hope that helps,
Lutz

Related

X and Y inputs in LabVIEW

I am new to LabVIEW and I am trying to read a code written in LabVIEW. The block diagram is this:
This is the program to input x and y functions into the voltage input. It is meant to give an input voltage in different forms (sine, heartshape , etc.) into the fast-steering mirror or galvano mirror x and y axises.
x and y function controls are for inputting a formula for a function, and then we use "evaluation single value" function to input into a daq assistant.
I understand that { 2*(|-Mpi|)/N }*i + -Mpi*pi goes into the x value. However, I dont understand why we use this kind of formula. Why we need to assign a negative value and then do the absolute value of -M*pi. Also, I don`t understand why we need to divide to N and then multiply by i. And finally, why need to add -Mpi again? If you provide any hints about this I would really appreciate it.
This is just a complicated way to write the code/formula. Given what the code looks like (unnecessary wire bends, duplicate loop-input-tunnels, hidden wires, unnecessary coercion dots, failure to use appropriate built-in 'negate' function) not much care has been given in writing it. So while it probably yields the correct results you should not expect it to do so in the most readable way.
To answer you specific questions:
Why we need to assign a negative value and then do the absolute value
We don't. We can just move the negation immediately before the last addition or change that to a subtraction:
{ 2*(|Mpi|)/N }*i - Mpi*pi
And as #yair pointed out: We are not assigning a value here, we are basically flipping the sign of whatever value the user entered.
Why we need to divide to N and then multiply by i
This gives you a fraction between 0 and 1, no matter how many steps you do in your for-loop. Think of N as a sampling rate. I.e. your mirrors will always do the same movement, but a larger N just produces more steps in between.
Why need to add -Mpi again
I would strongly assume this is some kind of quick-and-dirty workaround for a bug that has not been fixed properly. Looking at the code it seems this +Mpi*pi has been added later on in the development process. And while I don't know what the expected values are I would believe that multiplying only one of the summands by Pi is probably wrong.

Function iMA is returning different return value from expected (MQL5)

I'm using MQL5 (my first code).
I want to use a script that uses MA, but first, I wanted to confirm the value to verify I'm doing correctly. Using a very basic code into script:
double x=0;
x = iMA(Symbol(),Period(),100,0,MODE_SMA,PRICE_CLOSE);
Alert("The actual MA from last 100 points of EURUSD actually is: " + x;
The expected value is near the actual price... 1.23456, but this function is returning 10.00000 or 11.0000.
I believe I'm missing something, and https://www.mql5.com/es/docs/indicators/ima helplink is not quite clear enough.
I already saw another similar function: MA[0] which seems to bring the moving average from specific candle, but, I don't know how to manage the Period range (100) or if is related to Close/Open variables on it. I didn't find any specific helplink to review.
Any ideas are very appreciated!!!
x should be int, it is a handler of the MA. So each indicator when created in MT5 receives its handler, and you can use it later to get what you need. If you need several MA's - create several handlers and give each of them different names (x1, x2 or add some sense). Expert advisors in the default build of MT5 are good examples on what to do.
The iMA function Returns the handle of a specified technical indicator, not the "moving average" value.
For example, to get the value of the Moving average you can use this (in MQ4):
EMA34Handler = iMA(NULL,0,34,0,MODE_EMA,PRICE_CLOSE);
EMA34Value = CopyBuffer(EMA34Handler, 0,0);

Scilab Xcos, insert a difference equation in Xcos diagram

How can I insert a difference equation in Xcos diagram, like:
y(k+1) = y(k)[a sqrt(y(k-1))] + b *y(k-1) ;
?
Thanks, Best Regards
EDIT
Finding on Internet I think that the best way to address my problem is use:
scifunck block.
I would actually do something like that:
where the delay blocks are set to the sample time of your model (I assume we are dealing with discrete signals here) and appropriate initial conditions. Make sure to choose a discrete solver and use the same (appropriate for your problem) sample time for the model and the delay blocks.

Maximal input length/Variable input length for TinyGP

i am planning to use tinyGP as a way to train a set of Input variables (Around 400 or so) to a value set before. Is there a maximum size of Input variables? Do i need to specify the same amount of variables each time?
I have a lot of computation power (500 core cluster for a weekend) so any thoughts on what parameters to use for such a large problem?
cheers
In TinyGP your constant and variable pool share the same space. The total of these two spaces cannot exceede FSET_START, which is essentially the opcode of your first operator. By default is 110. So your 400 is already over this. This should be just a matter of increasing the opcode of the first instruction up to make enough space. You will also want to make sure you still have a big enough "constant pool".
You can see this checked with the following line in TinyGP:
if (varnumber + randomnumber >= FSET_START )
System.out.println("too many variables and constants");

Attach variables

I want to take two variables (in and in2) and put them together, for example:
in = 1;
in2 = 3;
pin = in.in2; // I want this to set pin to 13
The arduino IDE tells me that in is not a class, so what syntax would I use to accomplish this?
EDIT: I figured out a different way to do it, you can just take in. multiply it by 10 and then set pin to the sum of in plus in2
If your two variables are definitely integers then pin = (in*10)+in2; would work.
If not, read them into strings (maybe with in.toString(), language dependent) and just do pin = int.parse(in.toString()+in2.toString());
(Although, again dependent on language, you may have to do something other than int.parse [in C# you should use int.TryParse() for example])
Try this, I wrote it in C but you get the gist. turn the two items into strings then concatenate and parse it as an integer.
pin = int.Parse((string)in + (string)in2);