Hi,
I have a problem where I have to calculate the diameter of a pipe, using the equations I will find the diameter value that is a decimal number.
But the diameter I will use is the commercial value, always selecting the next commercial size of the value found by the equations.
Then I must analyze the cost of these pipes as a function of the diameter and the length of the mesh.
d (mm) preço($/m)
100 7,5
150 10,25
...
I don't know how to enter this information.
If I must use the dollar, table, scalar, equation or upper and lower limit condition.
which of these methods is the best practice to use in GAMS because I would use (VLOOKUP, ..., IF...) table between intervals in EXCEL.
commercial diameter  declare

 User
 Posts: 19
 Joined: 11 months ago
Re: commercial diameter  declare
I founded the answer:
Special Features for Mathematical Programs:
https://www.gams.com/latest/docs/UG_Lan ... tures.html
Special Features for Mathematical Programs:
https://www.gams.com/latest/docs/UG_Lan ... tures.html

 User
 Posts: 19
 Joined: 11 months ago
Re: commercial diameter  declare
My problem with the syntax in GAMS is how can I limit the result to being specific values, like for example:
the result of the diameter should be 150mm, or 200mm or 250mm or 300mm or 350mm or 400 or 500.
In my case the diameter is a variable, so reading the McCarl GAMS User guide I found two ways to solve the problem, however I don't know how to write. Using
1) the function (.prior);
2) using the Control Variables;
Because each diameter have a price, the bigger the diameter of the tube, more expensive it is.
I already tried Tables (diameter,Price) but it is not a Set, so tables isn't my solution.
If I use Dollar control, the code should be bigger. And I don't know where I should declare this condition, something like that:
ex. dr(n,nd)=150 $ (dcal(n,nd)<=150)
if (150, 200] dr(n.nd) = 200
if (200, 250] dr(n.nd) = 250
if (250, 300] dr(n.nd) = 300
if (300, 400] dr(n.nd) = 400 and
if (400, 500] dr(n.nd) = 500
because then I must apply the prices, ex:
Regards,
the result of the diameter should be 150mm, or 200mm or 250mm or 300mm or 350mm or 400 or 500.
In my case the diameter is a variable, so reading the McCarl GAMS User guide I found two ways to solve the problem, however I don't know how to write. Using
1) the function (.prior);
2) using the Control Variables;
Because each diameter have a price, the bigger the diameter of the tube, more expensive it is.
I already tried Tables (diameter,Price) but it is not a Set, so tables isn't my solution.
If I use Dollar control, the code should be bigger. And I don't know where I should declare this condition, something like that:
ex. dr(n,nd)=150 $ (dcal(n,nd)<=150)
if (150, 200] dr(n.nd) = 200
if (200, 250] dr(n.nd) = 250
if (250, 300] dr(n.nd) = 300
if (300, 400] dr(n.nd) = 400 and
if (400, 500] dr(n.nd) = 500
because then I must apply the prices, ex:
Code: Select all
Dcom dcust
* (m) (US$ per m)
0.15 10
0.20 20
0.25 30
0.30 45
0.35 65
0.40 95
0.50 105;
Re: commercial diameter  declare
Hi Alexanre,
Not sure if I understand your question correctly, but maybe need something like this:
dr(n,nd)$(dcal(n,nd) gt 150 and dcal(n,nd) le 200) = 200;
etc.
Beware of the "ge" (greater or equal than) and "le" (less or equal than). Depending on what you want you also might need "gt" (striclty greater than) or "lt" (striclty less than)
So in your example:
if (150, 200] dr(n.nd) = 200
if (200, 250] dr(n.nd) = 250
What if the value is 200? Maybe you want "le" 200 = 200 and "gt" 200 = 250 (so there is no overlap for the value 200).
See also: https://www.gams.com/latest/docs/UG_CondExpr.html
Regards,
GFA
Not sure if I understand your question correctly, but maybe need something like this:
dr(n,nd)$(dcal(n,nd) gt 150 and dcal(n,nd) le 200) = 200;
etc.
Beware of the "ge" (greater or equal than) and "le" (less or equal than). Depending on what you want you also might need "gt" (striclty greater than) or "lt" (striclty less than)
So in your example:
if (150, 200] dr(n.nd) = 200
if (200, 250] dr(n.nd) = 250
What if the value is 200? Maybe you want "le" 200 = 200 and "gt" 200 = 250 (so there is no overlap for the value 200).
See also: https://www.gams.com/latest/docs/UG_CondExpr.html
Regards,
GFA

 User
 Posts: 19
 Joined: 11 months ago
Re: commercial diameter  declare
Thanks!! that's right!!
I understood and it is perfect!
But Where should I declare this?? In Equation??
Like
I understood your comment and it makes perfect sense so in this case
I think that using more than one decimal place can solve at least my problem.
But it doesn't look very elegant. Some one have other options?!?
Regards,
Alexandre
I understood and it is perfect!
But Where should I declare this?? In Equation??
Like
Code: Select all
Equation
eq1(n,nd) equation 1
eq2(n,nd) equation 2
...;
eq1(n,nd).. dr(n,nd)$(dcal(n,nd) gt 150 and dcal(n,nd) le 200.01) = 200;
eq2(n,nd).. dr(n,nd)$(dcal(n,nd) gt 200 and dcal(n,nd) le 250.01) = 250;
etc ...
I think that using more than one decimal place can solve at least my problem.
But it doesn't look very elegant. Some one have other options?!?
Regards,
Alexandre
GFA wrote: ↑3 months agoHi Alexanre,
Not sure if I understand your question correctly, but maybe need something like this:
dr(n,nd)$(dcal(n,nd) gt 150 and dcal(n,nd) le 200) = 200;
etc.
Beware of the "ge" (greater or equal than) and "le" (less or equal than). Depending on what you want you also might need "gt" (striclty greater than) or "lt" (striclty less than)
So in your example:
if (150, 200] dr(n.nd) = 200
if (200, 250] dr(n.nd) = 250
What if the value is 200? Maybe you want "le" 200 = 200 and "gt" 200 = 250 (so there is no overlap for the value 200).
See also: https://www.gams.com/latest/docs/UG_CondExpr.html
Regards,
GFA