use if/then as conditional within an assignment

Hi,

I’m trying to write an assignment whose value is dependent upon the
indices. The value isn’t a function of the indices, though. Rather,
it is a logical type of dependency. Basically, these paths in my
model have a start and an end. If the index for the assignment is
“Start”, then I want the assignment to use the opposite value, “End”.

I see in McCarl’s user guide that I can use if/then statements, but it
isn’t clear to me from the user guide if I can put them directly into
a direct assignment. What I need is a line of code that works as
follows:

TestValue(n,p) $(sameas(p,“Start”) or sameas(p,“End”)) = If(sameas
(p,“Start”),Param(n,“Start”); else Param(n,“End”));

I get all kinds of errors when I try to compile this though. I wanted
to see if anyone knew a way to get this to work. If I can’t do this
with the if/then statement, is there another way to do this?

Thanks for any help. My entire code is shown below.


Sets
n lines / 1*3 /
p params / R, X, B, Start, End, Imax /

Table Param(n,p) line param p for line n
R X B Start End Imax
1 0.01 0.03 0.8 1 2 7
2 0.01 0.03 0.8 1 3 7
3 0.01 0.03 0.8 2 3
7 ;

Parameter TestValue(n,p);

TestValue(n,p) $(sameas(p,“Start”) or sameas(p,“End”)) = If(sameas
(p,“Start”),Param(n,“Start”); else Param(n,“End”));

execute_unload ‘TestOutput’;

To post to this group, send email to gamsworld@googlegroups.com.
To unsubscribe from this group, send email to gamsworld+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/gamsworld?hl=en.


\

Tom,

You say

If the index for the assignment is
“Start”, then I want the assignment to use the opposite value, “End”.

but your code doesn’t read that way, so I’m not sure what you are
after. But consider these statements, perhaps one will get you
started on the right path.

TestValue(n,‘start’) =Param(n,“start”);
TestValue(n,‘start’) =Param(n,“End”);
TestValue(n,‘end’) =Param(n,“End”);

And you can put dollar conditions on the right or left if too many
values are being assigned.

-Steve

On Wed, Dec 30, 2009 at 3:33 PM, tom smith wrote:

Hi,

I’m trying to write an assignment whose value is dependent upon the
indices. The value isn’t a function of the indices, though. Rather,
it is a logical type of dependency. Basically, these paths in my
model have a start and an end. If the index for the assignment is
“Start”, then I want the assignment to use the opposite value, “End”.

I see in McCarl’s user guide that I can use if/then statements, but it
isn’t clear to me from the user guide if I can put them directly into
a direct assignment. What I need is a line of code that works as
follows:

TestValue(n,p) $(sameas(p,“Start”) or sameas(p,“End”)) = If(sameas
(p,“Start”),Param(n,“Start”); else Param(n,“End”));

I get all kinds of errors when I try to compile this though. I wanted
to see if anyone knew a way to get this to work. If I can’t do this
with the if/then statement, is there another way to do this?

Thanks for any help. My entire code is shown below.


Sets
n lines / 1*3 /
p params / R, X, B, Start, End, Imax /

Table Param(n,p) line param p for line n
R X B Start End Imax
1 0.01 0.03 0.8 1 2 7
2 0.01 0.03 0.8 1 3 7
3 0.01 0.03 0.8 2 3
7 ;

Parameter TestValue(n,p);

TestValue(n,p) $(sameas(p,“Start”) or sameas(p,“End”)) = If(sameas
(p,“Start”),Param(n,“Start”); else Param(n,“End”));

execute_unload ‘TestOutput’;

To post to this group, send email to gamsworld@googlegroups.com.
To unsubscribe from this group, send email to gamsworld+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/gamsworld?hl=en.




– Steven Dirkse, Ph.D. GAMS Development Corp., Washington DC Voice: (202)342-0180 Fax: (202)342-0181 sdirkse@gams.com http://www.gams.com