Matlab revisited: Work with large model

Use this forum to post Vensim related questions.
Post Reply
arraywanted
Member
Posts: 36
Joined: Fri Aug 20, 2010 11:03 am

Matlab revisited: Work with large model

Post by arraywanted »

I opened a new thread since the other one meanwhile covers different subjects.

(For those who read my questions according Win7: I'm working with the WinXP-Computer again right now.)

Loading models into matlab, setting and getting variables does work in general. However, when I try to work with a certain very large an complex model, I face problems:

Loading the model works. Getting variables sometimes works as well, but other times it takes minutes to display the value. The same with setting values.

Trying to start a simulation produces the error: "Model has errors and cannot be simulated", although it does not have errors and can easily be simulated from within Vensim.
That's the main problem, because I cannot run my matlab programs without starting a simulation.

Can you offer any help here?

[Edited on 9-9-2010 by arraywanted]
Administrator
Super Administrator
Posts: 4590
Joined: Wed Mar 05, 2003 3:10 am

Post by Administrator »

The error message gives it away, there is an error in the model.

Are you sure you have published the correct model and any files it needs (eg Excel files) are in the same directory?
arraywanted
Member
Posts: 36
Joined: Fri Aug 20, 2010 11:03 am

Post by arraywanted »

Yes, I am sure. It is the right model and all needed excel files are in the same directory.

I should add that once or twice I was actually able to run a simulation. Other times I get the mentioned error. And sometimes (quite often) matlab simply freezes and does nothing, in which case I have to manually close matlab using the task manager.
Of course I didn't change the model in between.
Administrator
Super Administrator
Posts: 4590
Joined: Wed Mar 05, 2003 3:10 am

Post by Administrator »

Can you get it working in VB or VBA, and then port it to Matlab?

If you've actually had it running then I'd say the problem is with Matlab and not with Vensim.
bob@vensim.com
Senior Member
Posts: 1107
Joined: Wed Mar 12, 2003 2:46 pm

Post by bob@vensim.com »

The message you are getting occurs when a flag indicating that the model can be simulated has not been set. I can think of only two reasons you would get it.

1. Somehow the model was not checked when it was published. This should not happen, but you can test this by doing first a Model>Check Model and then File>Publish to see if it makes a difference.

2. Somehow the model is being corrupted when it is read. If, as suggested above, you can test the model using, for example, the Excel example, it should give some indication of what is happening.
arraywanted
Member
Posts: 36
Joined: Fri Aug 20, 2010 11:03 am

Post by arraywanted »

Meanwhile, I'm not getting the "model cannot be simulated"-error anymore. The situation is:
Directly after booting the computer calling vensim functions works just finde. But after a short time, everything slows down and it takes minutes just to retrieve one value. At some time matlab simply seems to freeze when starting a simulation - which worked at the beginning.
I really can't make sense of that behavior.

Somehow the model was not checked when it was published. This should not happen, but you can test this by doing first a Model>Check Model and then File>Publish to see if it makes a difference.
There are no errors in the model, but there are a lot of warnings of the kind "Variable X is not used in the model". I found out that the vensim.err file is full of these warnings. Could that have anything to do with my problem?
(By the way, I'm not responsible for the build-up of that model, so these warnings aren't my fault.)

Um, I didn't really understand what you meant by "get it working in VB or VBA, and then port it to Matlab".

[Edited on 9-13-2010 by arraywanted]
bob@vensim.com
Senior Member
Posts: 1107
Joined: Wed Mar 12, 2003 2:46 pm

Post by bob@vensim.com »

Starting fast and going slow sounds like a memory issue. If you open the windows task manager you may be able to track down what process is consuming the memory.
bob@vensim.com
Senior Member
Posts: 1107
Joined: Wed Mar 12, 2003 2:46 pm

Post by bob@vensim.com »

Oh, by running the model in VBA just substitute the model you are using for worldapp.vpm in the Excel97 sample and see how it behaves.
arraywanted
Member
Posts: 36
Joined: Fri Aug 20, 2010 11:03 am

Post by arraywanted »

If you open the windows task manager you may be able to track down what process is consuming the memory.
The process consuming up to 99% of CPU is a process called "system idle process". (I don't know if that is the exact translation, in german it is "Leerlaufprozess".)

What does that mean? I don't know much about these things.
Administrator
Super Administrator
Posts: 4590
Joined: Wed Mar 05, 2003 3:10 am

Post by Administrator »

arraywanted
Member
Posts: 36
Joined: Fri Aug 20, 2010 11:03 am

Post by arraywanted »

I discovered something new:

The model reads some data from excel files. I found out that I have to close all excel files before starting a new simulation from matlab, because otherwise the freezing happens.
That's why it worked right after booting the system, because then the excel files were closed.

What I still don't know is why it sometimes takes very long to retrieve variables.
Administrator
Super Administrator
Posts: 4590
Joined: Wed Mar 05, 2003 3:10 am

Post by Administrator »

The best thing to do is try it in Visual Basic/VBA (use the Excel97 sample as Bob suggests) and see if it works ok. If it does, the problem is with Matlab.
bob@vensim.com
Senior Member
Posts: 1107
Joined: Wed Mar 12, 2003 2:46 pm

Post by bob@vensim.com »

It sounds like Matlab may be interfering with interprocess communication. You can experiment with using DDE instead of OLE for this comunication (you will need to issue a SPECIAL>READINI command to do this). The setting in the .ini file is

XlsOptions=82,67,0,0,


for OLE

XlsOptions=82,67,0,1,

for DDE and

XlsOptions=82,67,0,2

for direct read (won't work with xlsx or named ranges). this assumes you are using 5.10 or higher.
Post Reply