I'm trying to run games from matlab and I'm a little bit confused as to the right function to call and the difference between them...
The Vensim DSS Reference Supplement gives examples (p110 and 111 using VB) with GAME>GAMEINTERVAL, GAME>GAMEON, vensim_continue_simulation, vensim_start_simulation, etc.
But what is the difference between MENU>GAME and vensim_start_simulation? or between GAME>GAMEON and vensim_continue_simulation?
I have created some code in matlab that passes a value to a game variable and run my Vensim model for a specified time interval but when I want to change the value of that variable and run the model for a subsequent time interval, i'm having some issues.
Here is my code:
Code: Select all
clear all
time = zeros(40);
NbAC = zeros(40);
if not(libisloaded('VenDLL32'))
hfile = ['C:\Documents and Settings\opinon\My Documents\MatlabResearch\vendll.h'];
loadlibrary('VenDLL32',hfile);
end
%******************* LOAD THE MODEL *******************
LoadModel(50); %Load the model and set the final time
SetupGame(10); %Set the game interval
%******************* PASS VALUES TO THE MODEL *******************
Model(0); %Pass growth rate
game = ['MENU>GAME'];
lp4=libpointer('voidPtr',[int8(game) 0]);
calllib('VenDLL32','vensim_command',game);
%************* CONTINUE ***************
ContinueGame(); %GameOn
SetupGame(4); %Set the game interval
Model(100);
ContinueGame(); %GameOn
%*********************RETRIEVE DATA *************************
rvalPtr1 = libpointer('singlePtr', NbAC);
tvalPtr1 = libpointer('singlePtr', time);
tpoints1 = calllib('VenDLL32','vensim_get_data','Olive2.vdf','Number of aircraft arriving','time',rvalPtr1(1),tvalPtr1(1),40);
rvalPtr1(1).Value
%******************** END THE GAME ********************
result2 = ['GAME>ENDGAME'];
calllib('VenDLL32','vensim_command', result2);
Code: Select all
function LoadModel(FinalTime)
str=['SPECIAL>LOADMODEL|C:\Documents and Settings\opinon\My Documents\MatlabResearch\WorkInProgress\ArrivingAC.vpm'];
calllib('VenDLL32','vensim_be_quiet',0);
calllib('VenDLL32','vensim_command',str);
comstr3 = ['SIMULATE>SETVAL|FINAL TIME =', num2str(FinalTime)];
calllib('VenDLL32','vensim_command',comstr3);
end
function SetupGame(TimeInterval)
gameinterval = ['GAME>GAMEINTERVAL|',num2str(TimeInterval)];
lp5=libpointer('voidPtr',[int8(gameinterval) 0]);
calllib('VenDLL32','vensim_command',gameinterval);
end
function Model(growthrate)
comstr = ['SIMULATE>SETVAL|Growth rate = ', num2str(growthrate) ];
calllib('VenDLL32','vensim_command',comstr);
end
I would really appreciate your help on this as well as regarding the functions i'm using (should i be using vensim_continue_simulation instead?)
Thank you,
Olivia