1

I have a set of nodes i and have created an alias (i,j). Now I have a parameter c(i,j) where I want i elements to be mapped to j distinctively. For example, set i /a,b,c/ ; alias (i,j) ; c(i,j) /#i.#j/ ;

Dot operator maps all elements such as a.a, b.b, c.c, which I don't want to include. How do I write a condition such that only a.b, a.c, b.c are considered?

Thanks

Manal Jain
  • 25
  • 3

1 Answers1

2

I was not exactly sure, what you want to do, but one of the two assignments in the following code should do what you need:

set i /a,b,c/ ;
alias (i,j) ;
set c(i,j);

c(i,j) = not sameas(i,j);
display c;
$ontext
Results in:
----      6 SET c

            a           b           c

a                     YES         YES
b         YES                     YES
c         YES         YES
$offtext

c(i,j) = ord(i) < ord(j);
display c;
$ontext
Results in:
----     27 SET c

            b           c

a         YES         YES
b                     YES
$offtext

Best, Lutz

Lutz
  • 2,197
  • 1
  • 10
  • 12
  • Thank you for the answer that worked. Also, I have a similar problem with assignment in one of the variables, when I try to input the same assignment for it an error pops up stating _a missing suffix_. Anyway to get around that? – Manal Jain Jun 22 '17 at 14:32
  • In contrast to sets and parameters, variables (and equations) have different attributes you can assign to, so you need to specify which field you want to address by using a suffix (see https://www.gams.com/latest/docs/userguides/userguide/_u_g__variables.html#UG_Variables_VariableAttributes). So lets say you want to set the upper bound of variable x dependent on i and j. Then you can do: x.up(i,j) = 50; – Lutz Jun 22 '17 at 14:47
  • My program has a set _i /a,b,c,d,e/_ and 3 alias sets of _j,u,v_ with _x(i,j)_ and _z(u,v,i,j)_ as binary variables. I am trying to solve in such a way that at any given point the assignment to the variable is always unique, for example in the case of _z(u,v,i,j)_, I want it to be _(a,d,b,c)_ or _(b,d,a,b)_. I want to have _i not equal to j_ and _u not equal to v_ in a constraint. – Manal Jain Jun 22 '17 at 15:08
  • That actually sounds to me, as if you need to formulate this in your model and cannot do it in an assignment. But one probably needs to see your code to get a better understanding of the problem and give a better hint for how you might change things. – Lutz Jun 22 '17 at 15:39
  • In response to your second question @ManalJain, you must create the set c(i,j) as defined above, then alias it to something else (I chose c_) and then use the conditional z(u,v,i,j)$(c(u,v) and c_(i,j)). You should probably also mark the answer as correct. – jebob Aug 08 '17 at 20:53