Loading...
Searching...
No Matches
transport1.m
1function transport1(varargin)
2
3 % check workspace info from arguments
4 if nargin > 0
5 wsInfo = gams.control.WorkspaceInfo();
6 wsInfo.systemDirectory = varargin{1};
7 ws = gams.control.Workspace(wsInfo);
8 else
9 ws = gams.control.Workspace();
10 end
11
12 % create Job 't1' from 'trnsport' model in GAMS Model Libraries
13 t1 = ws.addJobFromGamsLib('trnsport');
14 % run Job 't1'
15 t1.run();
16
17 % retrieve Variable 'x' from Job's output databases
18 fprintf('Ran with Default:\n');
19 for x = t1.outDB.getVariable('x').records
20 fprintf('x(%s,%s): level=%g marginal=%g\n', x{1}.keys{:}, x{1}.level, x{1}.marginal);
21 end
22
23 % clear database
24 t1.outDB.dispose();
25
26 % create Options 'opt1'
27 opt1 = ws.addOptions();
28 % set all model types of 'opt1' for 'xpress'
29 opt1.setAllModelTypes('xpress');
30 % run Job 't1' with Options 'opt1'
31 t1.run(opt1);
32
33 % retrieve Variable 'x' from Job's output databases
34 fprintf('\nRan with XPRESS:\n');
35 for x = t1.outDB.getVariable('x').records
36 fprintf('x(%s,%s): level=%g marginal=%g\n', x{1}.keys{:}, x{1}.level, x{1}.marginal);
37 end
38
39 % clear option and database
40 opt1.dispose();
41 t1.outDB.dispose();
42
43 % write file 'xpress.opt' under Workspace's working directory
44 fid = fopen(fullfile(ws.workingDirectory, 'xpress.opt'), 'w');
45 fprintf(fid, 'algorithm=barrier');
46 fclose(fid);
47
48 % create Options 'opt2'
49 opt2 = ws.addOptions();
50 % set all model types of 'opt2' for 'xpress'
51 opt2.setAllModelTypes('xpress');
52 % for 'opt2', use 'xpress.opt' as solver's option file
53 opt2.optFile = 1;
54
55 % run Job 't2' with Options 'opt2' and capture log into 'transport1_xpress.log'.
56 output = gams.control.PrintStream(fullfile(ws.workingDirectory, 'transport1_xpress.log'));
57 t1.run(opt2, output);
58 output.close();
59
60 % retrieve Variable 'x' from Job's output databases
61 fprintf('\nRan with XPRESS with non-default option:\n');
62 for x = t1.outDB.getVariable('x').records
63 fprintf('x(%s,%s): level=%g marginal=%g\n', x{1}.keys{:}, x{1}.level, x{1}.marginal);
64 end
65
66 % clear option and database
67 opt2.dispose();
68 t1.outDB.dispose();
69
70 % remove working directory
71 rmdir(ws.workingDirectory, 's');
72end