Sets in LINGO Programming - optimization

I need help on Lingo programming.I have a mixed integer programming to solve it using sets in Lingo.One of the constraints is:
S(i,k,w) >= m(i,j) * X(i,t), for i=1,...,I; j=1,...,J; t=1,..,T; k=t+K(j,w)-1,..,t+K(j,w)+S(j)-2; w=1,..,W.
Here m(i,j), K(j,w) and S(j) are parameters.The problem is i do not know how to enter index k using sets in Lingo.Any help would be highly appreciated.

Related

Solve for q: (log(n))^q = log(log(n))

I'm proving the big O runtime of an algorithm for an assignment but am unfortunately quite rusty when it comes to logs. Currently, I have:
(log(n))^q <= log(log(n))
I am trying to isolate q in terms of n (where I'm hoping n will cancel out). Can someone please explain to me how to do this (and not just provide an answer)? Thanks!
This would've been prettier on math stackexchange (because we can use latex), but you can just log both sides to bring the q exponent down (since log(x^n) = nlog(x) is a property of logs over the reals):
q log(log(n)) <= log(log(log(n)))
Now you can divide both sides to isolate q:
q <= log(log(log(n)))/log(log(n))

Can't understand this code — is it C?

Can anyone help me understand this snippet? Is it even C?
lcd_bl: backlight {
compatible = "pwm";
level = <8>;
};
Specifically:
What is lcd_bl?
I am assuming that lcd_bl is a label, but there is no goto lcd_bl. lcd_bl is referenced in this snippet which is in the same file as the one above
lcd0: display {
back = <&lcd_bl>;
};
What data structure is backlight?
Why are <> used when assigning a number to a variable?
What is happening in the second snippet?
Any help on this would be appreciated.
Yes, this code is C programming language. It's used for the development of the board AM437x. more info about the board
take a look at am4372.dtsi,dt-bindings/pinctrl/am43x and pwm C libraries to understand this code if you are a senior C developer otherwise forget about it it's not novice level.

re-use the same set name multiple times in Gams

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

Automated VBA Solver in Excel

I am currently working on a project which has some requirements for VBA. The data is found in excel. What I need to ask/bounce ideas off of is for a way to write some code that will abide to the following conditions:
where Xmw and Ymw are in megawatt, and X and Y are generation plants
Xmw=<1000 -always true
and
Ymw=<1000 -always true
2000=Xmw+Ymw -Equation 1
and
10=X+Y -Equation 2
Essentially, since the maximum absolute value of generation to increase and decrease is 2000, and the maximum amount of plants that can be used is 10. I'm stuck at this point because I can't find the relation between the 2 equations. Additionally, the existing program identifies generation to use, but it doesn't follow it to the 2 provided equations.
Existing programming identifies which generation plants are in the "pools" of X and Y.
Any help would be greatly appreciated.
I am posting this in an answer because it would be too much to post in a comment (please comment and let me know if this hits the mark)
You could use a conditional that looks something like this:
power_generated=Ymw+Xmw
if power_generated<>2000 then
'do stuff here to add another power plant to generation
'
'
if X+Y>10 then
'deal with the fact that you have not enough power plants to deal with your draw
end if
end if

How to correctly name a variable which represents a value of 1 - n?

It obviously depends on the context you are using them in but, I was wondering if there is a universally accepted way to name such variables, or at least in a mathematical context.
I've often seen:
float k = someValue;
float oneMinusK = 1 - k;
...which seems as descriptive as much as meaningless to me.
Please note that I'm not asking how to name a variable, but how to do it in this very case. Examples and contexts where you used them will be much appreciated,
Thanks.
In probability 1-k is the probability of X not occurring, given that k is the probability of X occurring.
So
float will_win_lottery = 0.00000000001;
float will_not_win_lottery = 1 - will_win_lottery;
You should name your variables based on what it means in terms of the domain you are working on not the algorithm you used to produce it. Thus if k represented your house number k-1 may represent your next door neighbors house number. Name it accordingly.
I would call it the Complement.
I would probably calculate that when I needed it. How much time do you think it saves to store it in a variable? Remember that premature optimization is the root of all evil.
There is no way to answer your question without knowing what "k" represents. Ironicly, the reason why that is not possible is the poor naming of the variable "k" in the first place, so that is what you should worry about instead. If you give "k" a more describing name, a good choise of naming for "k-1" should come naturally, like in the example of "will_win_lottery" and "will_not_win_lottery".
Your usage already seems descriptive enough, just go with it.
Are these supposed to be constants ?
If you are doing it for legibility reasons exclusively why not create a method a la Dan's suggestion.
float complement(float n) { return (1.0 - n); }
Does it really matter? Use i; it's not any less descriptive than k. Things like this need to be documented/commented if you're that OCD about code descriptiveness.