1function alias(varargin)
3 % check workspace info from arguments
5 wsInfo = gams.control.WorkspaceInfo();
6 wsInfo.systemDirectory = varargin{1};
7 ws = gams.control.Workspace(wsInfo);
9 ws = gams.control.Workspace();
16 'alias (i,ii), (j,jj), (ij,iijj);'
18 ' a(i) / #i 1 /, aa(ii) / #ii 2 /;'};
19 data = sprintf(
'%s\n', data{:});
57 gdxdump1 = sprintf('%s\n
', gdxdump1{:});
74 gdxdump2 = sprintf('%s\n
', gdxdump2{:});
76 % Create initial data containing a Alias
77 % The OO API does not know about Aliases and will retrieve it as a set
78 j1 = ws.addJobFromString(data);
81 checkAliasLogic('j1.outDB
', j1.outDB);
83 j1.outDB.export('outDB.gdx
');
84 assert(SameGdxDump(ws, 'outDB.gdx
', gdxdump1), 'Unexpected result of gdxdump outDB.gdx
');
86 % Copy constructor should preserve aliases and other
87 db = ws.addDatabase(j1.outDB);
88 checkAliasLogic('db
', db);
90 assert(SameGdxDump(ws, 'db.gdx
', gdxdump1), 'Unexpected result of gdxdump db.gdx
');
92 db2 = ws.addDatabase();
93 ii = db2.addSet(db.getSet('ii
').name, db.getSet('ii
').text, '*
');
94 db.getSet('ii
').copySymbol(ii);
96 aaOriginal = db.getParameter('aa
');
97 aa = db2.addParameter(db.getParameter('aa
').name, db.getParameter('aa
').text, ii);
98 aaOriginal.copySymbol(aa);
99 db2.export('db2.gdx
');
101 assert(SameGdxDump(ws, 'db2.gdx
', gdxdump2), 'Unexpected result of gdxdump db2.gdx
');
103 % If the domain is an alias, domains should return the aliased set,
104 % but getDomainsAsStrings should return the name of the alias
105 assert(isa(aaOriginal.domains{1}, 'Set
'), 'The domain
set should be a Set
');
106 assert(strcmp(aaOriginal.domains{1}.name, 'i
'), 'The domain
set should be the original
set');
107 assert(strcmp(aaOriginal.domainsAsStrings{1}, 'ii
'), 'The domain as
string should be the alias name
');
110function checkAliasLogic(prefix, aliasDB)
111 % Check number of symbols
112 assert(aliasDB.numberOfSymbols == 5, '%s aliasDB should have NrSymbols=5: i,j,ij,a,aa.
', prefix);
113 assert(numel(aliasDB.symbols) == 5, '%s there sould be 5 Symbols in aliasDB: i,j,ij,a,aa.
', prefix);
115 % See if we can retrieve alias sets
116 assert(strcmp(aliasDB.getSet('ii
').name, 'i
'), '%s We should
get set i when asking
for alias ii.
', prefix);
117 assert(strcmp(aliasDB.getSet('jj
').name, 'j
'), '%s We should
get set j when asking
for alias jj.
', prefix);
118 assert(strcmp(aliasDB.getSet('iijj
').name, 'ij
'), '%s We should
get set ij when asking
for alias iijj.
', prefix);
121 assert(aliasDB.checkDomains(), '%s Check domains should be
true', prefix);
122 domains = aliasDB.getParameter('aa
').domains;
123 assert(isa(domains{1}, 'gams.control.Set
'), '%s domain[0] of aa should be
set', prefix);
124 assert(strcmp(domains{1}.name, 'i
'), '%s domain[0] of aa should point to i
', prefix);
126 aliasDB.getSet('ii
').deleteRecord('i1
');
127 assert(~aliasDB.checkDomains(), '%s Check domains should be
false after removal of i1
', prefix);
128 aliasDB.getSet('ii
').addRecord('i1
');
129 assert(aliasDB.checkDomains(), '%s Check domains should be
true after adding i1 again
', prefix);
132function is_equal = SameGdxDump(ws, gdxfile, expectedResult)
133 cmd = fullfile(ws.systemDirectory(), 'gdxdump
');
134 cmd_arg = fullfile(ws.workingDirectory(), gdxfile);
136 [status, cmdout] = system([cmd, ' ', cmd_arg]);
137 cmdout = strsplit(cmdout, char(10));
139 for i = numel(cmdout):-1:1
143 if strcmp(cmdout{i}, '$onempty
')
147 expectedResult = strsplit(expectedResult, char(10));
150 if numel(expectedResult) ~= numel(cmdout)
154 for i = 1:numel(cmdout)
155 if ~strcmp(cmdout{i}, expectedResult{i})