How to define incomplete sets in GAMS?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



How to define incomplete sets in GAMS?



There is an incomplete graph (e.g. including 5 vertices). The adjacency matrix "a" is available. I want to define the set which includes all edges but exclude any other pair of vertices. That is, the pair of vertices belongs to the set of edges iff the element in matrix "a" is positive.
The last line of following code does not work!


sets i "Set of vertices" /1*5/ ;
alias(i,j);
set a(i,j) "Adjacency matrix" ;
Table a(i,j)
1 2 3 4 5
1 0 1 0 1 1
2 1 0 1 0 0
3 0 1 0 0 0
4 1 0 0 0 1
5 1 0 0 1 0;
Set edges(i,j);
edges(i,j) = a(i,j)$(a(i,j)>0);




2 Answers
2



If you want to have edge , you must define a set and parameter like this :


sets i "Set of vertices" /1*5/ ;
alias(i,j);
set a(i,j) "Adjacency matrix" ;
Table a(i,j)
1 2 3 4 5
1 0 1 0 1 1
2 1 0 1 0 0
3 0 1 0 0 0
4 1 0 0 0 1
5 1 0 0 1 0;
Set edges(i,j);
edges(i,j) $ a(i,j) =yes;





Thank you Richard. But, there are many graphs to be solved. Further, the incidence matrix of each graph is large and saved in Excel. So it is not efficient to define the edges manually in GAMS. I need an automatic set definition.
– Mehdi
Aug 5 at 8:31






@Mehdi hi you're welcome , you can export matrix from excel to game . I mean you can define parameter edge(I,j) , and then export data . for example: $call gdxxrw.exe results.xls par=edge rng=sheet1!A1:E33 Parameter edg(i,j); $gdxin results.gdx $load edge $gdxin
– Richard
Aug 5 at 11:15





@Mehdi see gams.com/latest/docs/UG_DataExchange_Excel.html
– Richard
Aug 5 at 11:16





Thank you. I 'm sorry but I think I misled you. Consider a graph with n vertices and an incidence matrix. Assume that the set of vertices and the incidence matrix is created in GAMS (e.g. imported from Excel). I need a conditional set definition method to exclude row-column pairs of vertices with zero intersection element from the edges set and include others.
– Mehdi
Aug 5 at 11:53






Mehdi, maybe it helps if you post the code you tried and explain based on that what does not work for you.
– Lutz
Aug 6 at 7:10



You can simplify your last line to


edges(i,j) = a(i,j);



This automatically acts as if you wrote something like $(a<>0). However, since you defined your symbol a as set already and not as parameter, I think you actually do not have to do anything. A just is what you are looking for. Just do


display a;



and look at the result in the lst file.





It works. thank you.
– Mehdi
Aug 7 at 3:52






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

make 2 or more post in bootsrap

Store custom data using WC_Cart add_to_cart() method in Woocommerce 3

Firebase Auth - with Email and Password - Check user already registered