(!******************************************************
Mosel Matlab Example Problems
=============================
file example_m2.mos
`````````````````````
Printing a MATLAB string variable
(c) 2014 Fair Isaac Corporation
author: L.Bertacco, Apr. 2014
*******************************************************!)
model "example_m2"
uses "mmsystem";
fcopy("matlab.mws:message", "")
writeln
end-model |
%*******************************************************
% Mosel Matlab Example Problems
% =============================
%
% file example_m3.m
% ``````````````````
% Executing a Mosel program contained
% in a MATLAB cell array of strings
%
% (c) 2014 Fair Isaac Corporation
% author: L.Bertacco, Apr. 2014, rev. Sep. 2017
%*******************************************************
mos={
'model "example_m3" '
' uses "mmxprs", "mmnl"; '
' declarations '
' a:mpvar '
' end-declarations '
' minimize(a*a-5*a+10) '
' writeln(getobjval) '
'end-model '
};
moselexec('matlab.mws:mos')
|
(!******************************************************
Mosel Matlab Example Problems
=============================
file example_m4.mos
```````````````````
Initializiations from MATLAB expressions
(c) 2014 Fair Isaac Corporation
author: L.Bertacco, Apr. 2014
*******************************************************!)
model "example_m4"
declarations
answer: integer
foo: real
var: real
today: string
i: range
data: array(i) of real
end-declarations
initializations from "matlab.mws:"
answer as "42"
foo
var as "bar"
today as "date"
data as "sum(magic(foo*bar))"
end-initializations
writeln("answer to ultimate question: ", answer)
writeln("foo: ", foo)
writeln("bar: ", var)
writeln("today: ", today)
writeln("data: ", data)
end-model
|
%*******************************************************
% Mosel Matlab Example Problems
% =============================
%
% file example_m5.m
% ``````````````````
% Initialization from a MATLAB sparse matrix
%
% (c) 2014 Fair Isaac Corporation
% author: L.Bertacco, Apr. 2014
%*******************************************************
mos={
'model "example_m5" '
' declarations '
' i,j: range '
' sparse: dynamic array(i,j) of real'
' end-declarations '
' initializations from "matlab.mws:" '
' sparse as "sprand(4,4,.5)" '
' end-initializations '
' writeln("sparse is: ", sparse) '
' writeln("row indices: ", i) '
' writeln("col indices: ", j) '
'end-model '
};
moselexec('matlab.mws:mos'); |
%*******************************************************
% Mosel Matlab Example Problems
% =============================
%
% file example_m6.m
% ``````````````````
% Accessing Mosel arrays
%
% (c) 2014 Fair Isaac Corporation
% author: L.Bertacco, Apr. 2014, rev. Sep. 2018
%*******************************************************
mos={
'model example '
' public declarations '
' CITIES = {"london", "paris", "madrid", "rome", "florence"} '
' ZONES = {"north", "south", "east", "west"} '
' VALUE: dynamic array(CITIES,ZONES) of real '
' end-declarations '
' '
' VALUE("london", "east") := 1 '
' VALUE("rome", "west") := 2 '
' VALUE("paris", "south") := 3 '
' VALUE("madrid", "east") := 4 '
'end-model '
};
mosel = com.dashoptimization.XPRM;
mosel.compile('', 'matlab.mws:mos', 'example_m6.bim');
mod = mosel.loadModel('example_m6.bim');
mod.run;
value = mod.findIdentifier('VALUE');
value_iter = value.indices(true);
sets = value.getIndexSets();
while value_iter.hasNext
indices = value_iter.next;
fprintf(1, 'VALUE ( ');
for i=1:size(indices,1)
fprintf(1, '%s ', char(sets(i).get(indices(i))));
end
fprintf(1, ') = %g\n', value.getAsReal(indices));
end
|