Re: [Help-glpk] how to defne an array (something like pointer to pointer in C)
> thank you all,it worked well,but i have another question: > i have a parameter Ec: AB BC CD DE:= > AB 0 1 1 0 > BC 1 0 1 1 > CD 1 1 0 1 > DE 0 1 1 0; > and it means that for example nodes AB and BC are connected, and AB and > CD are also connected. Ec has a 1 value for each two nodes that are > connected. > the problem is that i want to define a var x like this: > var x {u in Vc, v in Vc} binary >=0; ""if (u,v) in Ec"" > and we have: Vc := AB BC CD DE; > i mean i want to have var x just for those pairs of Vc that have value 1 > in Ec, i want to define something like this: > if EC[u,v]==1 then var x {u in Vc, v in Vc} binary >=0; > but i don't know how to write if clauses. > i'd be really grateful if you could help me with this problem too. var x{u un Vc, v in Vc: EC[u,v] = 1}, binary; ___ Help-glpk mailing list Help-glpk@gnu.org http://lists.gnu.org/mailman/listinfo/help-glpk
Re: [Help-glpk] how to defne an array (something like pointer to pointer in C)
thank you all,it worked well,but i have another question: i have a parameter Ec: AB BC CD DE:= AB 0 1 1 0 BC 1 0 1 1 CD 1 1 0 1 DE 0 1 1 0; and it means that for example nodes AB and BC are connected, and AB and CD are also connected. Ec has a 1 value for each two nodes that are connected. the problem is that i want to define a var x like this: var x {u in Vc, v in Vc} binary >=0; ""if (u,v) in Ec"" and we have: Vc := AB BC CD DE; i mean i want to have var x just for those pairs of Vc that have value 1 in Ec, i want to define something like this: if EC[u,v]==1 then var x {u in Vc, v in Vc} binary >=0; but i don't know how to write if clauses. i'd be really grateful if you could help me with this problem too. Many thanks. -- View this message in context: http://www.nabble.com/how-to-defne-an-array-%28something-like-pointer-to-pointer-in-C%29-tp23479009p23501468.html Sent from the Gnu - GLPK - Help mailing list archive at Nabble.com. ___ Help-glpk mailing list Help-glpk@gnu.org http://lists.gnu.org/mailman/listinfo/help-glpk
Re: [Help-glpk] how to defne an array (something like pointer to pointer in C)
> I am new to glpk and MathProg. I am trying to model a problem in glpk > and solve it. The problem is that I don’t know how should I define the > following : > We have E[i] for each i that is member of N : > N is a set that contains A B C D E, > So, we have E[A], E[B], E[C], E[D], E[E] > The value for each of these members is as follows, for example: > E[A]:= AB > E[B] := AB BC > E[C] := BC CD > E[D] := CD DE > E[E] := DE > The problem is that I don’t know how to define E with the above > specifications! > I have tested the followings and it didn’t work: > 1) > param E:= > A AB; > B AB BC > C BC CD > D CD DE > E DE; > 2) > param E : > if i==A > then AB > else if i==B > then AB BC > else if i==C > then BC CD > else if i==D > then CD DE > else if i==E > then DE; > 3) > set EA; /*set of edges connected to node A*/ > set EB; /*set of edges connected to node B*/ > set EC; /*set of edges connected to node C*/ > set ED; /*set of edges connected to node D*/ > set EE; /*set of edges connected to node E*/ > set EA := AB; > set EB := AB BC; > set EC := BC CD; > set ED := CD DE; > set EE := DE; > and also we have: > u can be AB BC CD DE > and after defining the E, I have to check something like this: > for each I in N, for each u that is in E[i] ….some condition…… > I really don’t know how should I solve this problem,how to define E, > and it is very essential to solve this problem.. > Please do me a favor and help! > Many thanks in advance. You may try something like this: set N; set E{i in N}, dimen 2; display E; data; set N := A B C D E; set E[A] := (A,B); set E[B] := (A,B) (B,C); set E[C] := (B,C) (C,D); set E[D] := (C,D) (D,E); set E[E] := (D,E); ___ Help-glpk mailing list Help-glpk@gnu.org http://lists.gnu.org/mailman/listinfo/help-glpk
Re: [Help-glpk] how to defne an array (something like pointer to pointer in C)
Hello Maryam, you could use the following formulation set N; set E{n in N}; display E; data; set N:= A B C D E; set E[A]:= A AB; set E[B]:= AB BC; set E[C]:= BC CD; set E[D]:= CD DE; set E[E]:= DE; end; If you have large data sets consider using the table statement described in doc\tables.pdf to read the data from a SQL database or from a CSV file. Best regards Xypron Best regards Xypron Maryam Ahmadi wrote: > > Dear All, > > I am new to glpk and MathProg. I am trying to model a problem in glpk > and solve it. The problem is that I don’t know how should I define the > following : > We have E[i] for each i that is member of N : > N is a set that contains A B C D E, > So, we have E[A], E[B], E[C], E[D], E[E] > The value for each of these members is as follows, for example: > E[A]:= AB > E[B] := AB BC > E[C] := BC CD > E[D] := CD DE > E[E] := DE > The problem is that I don’t know how to define E with the above > specifications! > > I have tested the followings and it didn’t work: > 1) > param E:= > A AB; > B AB BC > C BC CD > D CD DE > E DE; > > 2) > param E : > if i==A > then AB > else if i==B > then AB BC > else if i==C > then BC CD > else if i==D > then CD DE > else if i==E > then DE; > 3) > set EA; /*set of edges connected to node A*/ > set EB; /*set of edges connected to node B*/ > set EC; /*set of edges connected to node C*/ > set ED; /*set of edges connected to node D*/ > set EE; /*set of edges connected to node E*/ > set EA := AB; > set EB := AB BC; > set EC := BC CD; > set ED := CD DE; > set EE := DE; > > and also we have: > u can be AB BC CD DE > and after defining the E, I have to check something like this: > for each I in N, for each u that is in E[i] ….some condition…… > > I really don’t know how should I solve this problem,how to define E, > and it is very essential to solve this problem.. > Please do me a favor and help! > Many thanks in advance. > Regards > > > ___ > Help-glpk mailing list > Help-glpk@gnu.org > http://lists.gnu.org/mailman/listinfo/help-glpk > > -- View this message in context: http://www.nabble.com/how-to-defne-an-array-%28something-like-pointer-to-pointer-in-C%29-tp23479009p23489985.html Sent from the Gnu - GLPK - Help mailing list archive at Nabble.com. ___ Help-glpk mailing list Help-glpk@gnu.org http://lists.gnu.org/mailman/listinfo/help-glpk
[Help-glpk] how to defne an array (something like pointer to pointer in C)
Dear All, I am new to glpk and MathProg. I am trying to model a problem in glpk and solve it. The problem is that I don’t know how should I define the following : We have E[i] for each i that is member of N : N is a set that contains A B C D E, So, we have E[A], E[B], E[C], E[D], E[E] The value for each of these members is as follows, for example: E[A]:= AB E[B] := AB BC E[C] := BC CD E[D] := CD DE E[E] := DE The problem is that I don’t know how to define E with the above specifications! I have tested the followings and it didn’t work: 1) param E:= A AB; B AB BC C BC CD D CD DE E DE; 2) param E : if i==A then AB else if i==B then AB BC else if i==C then BC CD else if i==D then CD DE else if i==E then DE; 3) set EA; /*set of edges connected to node A*/ set EB; /*set of edges connected to node B*/ set EC; /*set of edges connected to node C*/ set ED; /*set of edges connected to node D*/ set EE; /*set of edges connected to node E*/ set EA := AB; set EB := AB BC; set EC := BC CD; set ED := CD DE; set EE := DE; and also we have: u can be AB BC CD DE and after defining the E, I have to check something like this: for each I in N, for each u that is in E[i] ….some condition…… I really don’t know how should I solve this problem,how to define E, and it is very essential to solve this problem.. Please do me a favor and help! Many thanks in advance. Regards ___ Help-glpk mailing list Help-glpk@gnu.org http://lists.gnu.org/mailman/listinfo/help-glpk