How to write a subset into DGX

Hi, I am using GDXMRW to link Matlab and GAMS, following the instruction given in www.gams.com/dd/docs/tools/gdxmrw.pdf. I encounter a problem on how to deal with subset.

If I define subset like this :


Xs.name = ‘X’;
Xs.ts = ‘all branches’;
Xs.val = [ linspace(1,6,6) ]';
Xs.type = ‘set’;
Xs.form = ‘sparse’;
Xs.uels = {‘L1’, ‘L2’,‘L3’,‘L4’,‘L5’,‘L6’};

Ks.name = ‘K(X)’;
Ks.ts = ‘new branches’;
Ks.val = [ linspace(1,3,3) ]';
Ks.type = ‘set’;
Ks.form = ‘sparse’;
Ks.uels = {‘L4’,‘L5’,‘L6’};

Matlab says

"??? Undefined function or variable ‘X’.

Error in ==> small5run at 117
wgdx (‘smalldat5’, Xs, Ys, K(X), ALs,loads,ress,capexs, opexs,curts,incids,volls,volus,ms,Ibs);"

If I define it as “Ks.name = ‘K’;”, in GAMS define K as a normal set, it will say “Domain violation for set”


Anyone has experience on this issue? Thanks a lot for sharing your solution!

Or if anyone has some ideas on how to solve it, please enlighten me, thanks a lot!

Yalin


To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at http://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/groups/opt_out.

\

On Tue, Jun 25, 2013 at 12:45 PM, Yalin Huang wrote:

Hi, I am using GDXMRW to link Matlab and GAMS, following the instruction given in www.gams.com/dd/docs/tools/gdxmrw.pdf. I encounter a problem on how to deal with subset.

If I define subset like this :


Xs.name = ‘X’;
Xs.ts = ‘all branches’;
Xs.val = [ linspace(1,6,6) ]';
Xs.type = ‘set’;
Xs.form = ‘sparse’;
Xs.uels = {‘L1’, ‘L2’,‘L3’,‘L4’,‘L5’,‘L6’};

Ks.name = ‘K(X)’;
Ks.ts = ‘new branches’;
Ks.val = [ linspace(1,3,3) ]';
Ks.type = ‘set’;
Ks.form = ‘sparse’;
Ks.uels = {‘L4’,‘L5’,‘L6’};

Matlab says

"??? Undefined function or variable ‘X’.

Error in ==> small5run at 117
wgdx (‘smalldat5’, Xs, Ys, K(X), ALs,loads,ress,capexs, opexs,curts,incids,volls,volus,ms,Ibs);"


Probably Matlab has no idea what K(X) is, since you have not defined a Matlab symbol X and probably not a function K either.


If I define it as “Ks.name = ‘K’;”, in GAMS define K as a normal set, it will say “Domain violation for set”


I don’t think we can see what you’re really running here. Can you send a small piece of M-script that illustrates the problem?


Anyone has experience on this issue? Thanks a lot for sharing your solution!

Or if anyone has some ideas on how to solve it, please enlighten me, thanks a lot!

Yalin


To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at http://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/groups/opt_out.





\

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

Thanks Steven Dirkse!

Here are the two M-files and a GAMs file, “small5data” is only for storing data, “smallmat5” is the MIP probalem where using subset is really necessary, probably u don’t need them, I attached also just in case.

Yalin


On Tuesday, 25 June 2013 18:45:52 UTC+2, Yalin Huang wrote:

Hi, I am using GDXMRW to link Matlab and GAMS, following the instruction given in www.gams.com/dd/docs/tools/gdxmrw.pdf. I encounter a problem on how to deal with subset.

If I define subset like this :


Xs.name = ‘X’;
Xs.ts = ‘all branches’;
Xs.val = [ linspace(1,6,6) ]';
Xs.type = ‘set’;
Xs.form = ‘sparse’;
Xs.uels = {‘L1’, ‘L2’,‘L3’,‘L4’,‘L5’,‘L6’};

Ks.name = ‘K(X)’;
Ks.ts = ‘new branches’;
Ks.val = [ linspace(1,3,3) ]';
Ks.type = ‘set’;
Ks.form = ‘sparse’;
Ks.uels = {‘L4’,‘L5’,‘L6’};

Matlab says

"??? Undefined function or variable ‘X’.

Error in ==> small5run at 117
wgdx (‘smalldat5’, Xs, Ys, K(X), ALs,loads,ress,capexs, opexs,curts,incids,volls,volus,ms,Ibs);"

If I define it as “Ks.name = ‘K’;”, in GAMS define K as a normal set, it will say “Domain violation for set”


Anyone has experience on this issue? Thanks a lot for sharing your solution!

Or if anyone has some ideas on how to solve it, please enlighten me, thanks a lot!

Yalin


small5data.m (2.89 KB)
small5run.m (3.57 KB)
smallmat5.gms (3.27 KB)

Yalin,

Attached is a small example of how I would do this. Note well that the subset relationship is not something you can store in the GDX file when you create it with GDXMRW. Instead, in the code reader.gms to read the GDX into GAMS, K is declared as a subset of X and the $loaddc call will check that the data has the subset relationship and error out if not. Also note the alternate ways to specify the set K in Matlab. I prefer the second one slightly since it is uses the subset relationship but both are fine.

-Steve


On Wed, Jun 26, 2013 at 4:15 AM, Yalin Huang wrote:

Thanks Steven Dirkse!

Here are the two M-files and a GAMs file, “small5data” is only for storing data, “smallmat5” is the MIP probalem where using subset is really necessary, probably u don’t need them, I attached also just in case.

Yalin


On Tuesday, 25 June 2013 18:45:52 UTC+2, Yalin Huang wrote:

Hi, I am using GDXMRW to link Matlab and GAMS, following the instruction given in www.gams.com/dd/docs/tools/gdxmrw.pdf. I encounter a problem on how to deal with subset.

If I define subset like this :


Xs.name = ‘X’;
Xs.ts = ‘all branches’;
Xs.val = [ linspace(1,6,6) ]';
Xs.type = ‘set’;
Xs.form = ‘sparse’;
Xs.uels = {‘L1’, ‘L2’,‘L3’,‘L4’,‘L5’,‘L6’};

Ks.name = ‘K(X)’;
Ks.ts = ‘new branches’;
Ks.val = [ linspace(1,3,3) ]';
Ks.type = ‘set’;
Ks.form = ‘sparse’;
Ks.uels = {‘L4’,‘L5’,‘L6’};

Matlab says

"??? Undefined function or variable ‘X’.

Error in ==> small5run at 117
wgdx (‘smalldat5’, Xs, Ys, K(X), ALs,loads,ress,capexs, opexs,curts,incids,volls,volus,ms,Ibs);"

If I define it as “Ks.name = ‘K’;”, in GAMS define K as a normal set, it will say “Domain violation for set”


Anyone has experience on this issue? Thanks a lot for sharing your solution!

Or if anyone has some ideas on how to solve it, please enlighten me, thanks a lot!

Yalin


data.zip (1.03 KB)

Thanks a lot Steve, now it’s solved!! And I prefer the second approach too:)

Yalin

On Wednesday, 26 June 2013 18:11:19 UTC+2, Steven Dirkse wrote:

Yalin,

Attached is a small example of how I would do this. Note well that the subset relationship is not something you can store in the GDX file when you create it with GDXMRW. Instead, in the code reader.gms to read the GDX into GAMS, K is declared as a subset of X and the $loaddc call will check that the data has the subset relationship and error out if not. Also note the alternate ways to specify the set K in Matlab. I prefer the second one slightly since it is uses the subset relationship but both are fine.

-Steve


On Wed, Jun 26, 2013 at 4:15 AM, Yalin Huang wrote:

Thanks Steven Dirkse!

Here are the two M-files and a GAMs file, “small5data” is only for storing data, “smallmat5” is the MIP probalem where using subset is really necessary, probably u don’t need them, I attached also just in case.

Yalin


On Tuesday, 25 June 2013 18:45:52 UTC+2, Yalin Huang wrote:

Hi, I am using GDXMRW to link Matlab and GAMS, following the instruction given in www.gams.com/dd/docs/tools/gdxmrw.pdf. I encounter a problem on how to deal with subset.

If I define subset like this :


Xs.name = ‘X’;
Xs.ts = ‘all branches’;
Xs.val = [ linspace(1,6,6) ]';
Xs.type = ‘set’;
Xs.form = ‘sparse’;
Xs.uels = {‘L1’, ‘L2’,‘L3’,‘L4’,‘L5’,‘L6’};

Ks.name = ‘K(X)’;
Ks.ts = ‘new branches’;
Ks.val = [ linspace(1,3,3) ]';
Ks.type = ‘set’;
Ks.form = ‘sparse’;
Ks.uels = {‘L4’,‘L5’,‘L6’};

Matlab says

"??? Undefined function or variable ‘X’.

Error in ==> small5run at 117
wgdx (‘smalldat5’, Xs, Ys, K(X), ALs,loads,ress,capexs, opexs,curts,incids,volls,volus,ms,Ibs);"

If I define it as “Ks.name = ‘K’;”, in GAMS define K as a normal set, it will say “Domain violation for set”


Anyone has experience on this issue? Thanks a lot for sharing your solution!

Or if anyone has some ideas on how to solve it, please enlighten me, thanks a lot!

Yalin


To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+...@googlegroups.com.
To post to this group, send email to gams...@googlegroups.com.
Visit this group at http://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/groups/opt_out.





\

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


To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at http://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/groups/opt_out.

\