How to obtain the simulation data after executing go() in script console?

How to obtain the simulation data after executing go() in script console?

zhu_m3
Not applicable
633 Views
12 Replies
Message 1 of 13

How to obtain the simulation data after executing go() in script console?

zhu_m3
Not applicable

[ FlexSim 20.1.3 ]

Dear all,

When using go () to run the model in the script console, I want to get the simulation output data immediately. The details are as follows: before executing FlexScript, Table("Result")[9][1] is 699.

1646616270851.png

After executing FlexScript, the printed table ("result") [9] [1] is still 699 instead of the new value 517.

1646616386389.png

I found that FlexScript will execute the next code immediately after executing go(), regardless of whether the simulation ends or not. Is there any way to get the simulation results in the code after go()?

I've been troubled by this problem for several days. This is my model, Mymodel.fsm

Please help me, thanks.@Phil BoBo @Ben Wilson


0 Likes
Accepted solutions (1)
634 Views
12 Replies
Replies (12)
Message 2 of 13

joerg_vogel_HsH
Mentor
Mentor
Please work with the experimenter tool!!! The script console has not got a feature like wait until finished. You expect an behavior that does not exist in this environment.
0 Likes
Message 3 of 13

zhu_m3
Not applicable

Thank you very much for reminding me. But I don't know how to run Experimenter through FlexScript. Because this is only part of my research, I will use Experimenter to get the output when necessary. So I need to call Experimenter through FlexScript and get its result.

0 Likes
Message 4 of 13

jason_lightfoot_adsk
Autodesk
Autodesk
If you explain more about what you're trying to do you'll get a better answer. It sounds like a move to the latest beta may help you if you have access to current versions.
0 Likes
Message 5 of 13

philboboADSK
Autodesk
Autodesk
Accepted solution

The simulation is not run entirely within the call to the go() command.

The go() command sets a variable in the program that tells it to start processing simulation events. The event processing does not happen in-line within the execution of that FlexScript function.

If you want a callback when your model is finished, then you need to add code somewhere else that fires when your model is finished. 'When your model is finished' will depend on the model. It is up to you to determine when that is and where your code should go. Perhaps in a user event at a specific time, you should stop the model and record the results.



Phil BoBo
Sr. Manager, Software Development
0 Likes
Message 6 of 13

zhu_m3
Not applicable

My study is simulation-based optimization, which uses the simulation output results as the objective function. Therefore, I need to execute the simulation circularly when necessary and get the output data immediately.

0 Likes
Message 7 of 13

zhu_m3
Not applicable

Thank you for your answer. I see.

So there's no way to get simulation results in the script console, right? Because the problem I study is simulation-based optimization, it needs to run the model constantly to obtain the output data. Is there any way to solve this problem?

0 Likes
Message 8 of 13

ralf_gruber
Collaborator
Collaborator
Steven,

the easiest solution would be to use FlexSim´s built-in optimizer, OptQuest. It is not free of charge, though, but you won´t have to worry about communication timing, as you have to now. I assume you are trying to connect to an external optimizer?

Good luck


0 Likes
Message 9 of 13

joerg_vogel_HsH
Mentor
Mentor

@Steven, your last comment is in fact a really good new question. Please consider it to ask this in a new thread, because there have been similar questions in the past. It would be nice to collect currently supported methods to optimize internally and externally with FlexSim.

Regards Joerg

0 Likes
Message 10 of 13

zhu_m3
Not applicable

Yeah, OptQuest is not free, so I don't consider using it.

Actually, I have solved my problem in the c++ program which is a heuristics algorithm by using a bat file that launches flexsim and runs the model, but it consumes a lot of time because it needs to open and close flexsim constantly. therefore, I want to reprogramme with flexscript in the script console, which can save time to open flexsim.

So I encountered the problem mentioned at the beginning

0 Likes
Message 11 of 13

zhu_m3
Not applicable
yeah, it's a good idea, maybe there is a good way!
0 Likes
Message 12 of 13

philboboADSK
Autodesk
Autodesk

At the end of a model run, record the results and then programmatically reset and run the model again.

See Creating a loop for model execution - FlexSim Community



Phil BoBo
Sr. Manager, Software Development
0 Likes
Message 13 of 13

zhu_m3
Not applicable

actually, i have finished this by custom code in ProcessFlow, but the key problem is in script console i can't obtain the result of the simulation which is launched by go();

go() is only responsible for starting the simulation, but when it ends is unknown. even if knowing, I can't control flexsim to execute the next code of go () at the end of the simulation.

0 Likes