question

Yokota T avatar image
0 Likes"
Yokota T asked Yokota T commented

How can webserver's job access the model parameters and performance measures?

Hi everyone.

I'm trying to submitting jobs to FlexSim webserver. I've succeeded in creating an instance of my model and running the simulation. But I'm having difficulty changing the values of model parameters and getting the values of the performance measures by JSON data. What should I do?

My HTML form and the result of the job are below.


<form action="http://127.0.0.1/webserver.dll?submitjob" method="POST">

<input type="hidden" name="job" value='{"modelname":"my%20model%20parameter","timeout":3600,"priority":5,"setupcommands":

[{"command":"settable=/Tools/ParameterTables/Parameters","data":"values=[\"Parameter1\", 10]"},

{"command":"setrunspeed=1000000"},{"command":"setstoptime=86400"},{"command":"toolsnodefunction=setupscript"},{"command":"run"}],

"resultcommands":[{"command":"getnodedata=/Tools/PerformanceMeasureTables/PerformanceMeasures"}]}'>

<input type="submit">

</form>


{"status":"complete","setupcommands":[{"command":"settable=/Tools/ParameterTables/Parameters","data":"values=[\"Parameter1\", 10]","verb":"GET","reply":"HTTP/1.1 404 Not Found"},{"command":"setrunspeed=1000000","data":"","verb":"GET","reply":"HTTP/1.1 200 OK"},{"command":"setstoptime=86400","data":"","verb":"GET","reply":"HTTP/1.1 200 OK"},{"command":"toolsnodefunction=setupscript","data":"","verb":"GET","reply":"HTTP/1.1 200 OK"},{"command":"run","data":"","verb":"GET","reply":"HTTP/1.1 200 OK"}],"resultcommands":[{"command":"getnodedata=/Tools/PerformanceMeasureTables/PerformanceMeasures","data":"","verb":"","reply":"{\"name\":\"PerformanceMeasures\",\"classes\":[\"PerformanceMeasureTable\"],\"superclasses\":[\"FlexSimEventHandler\"],\"behaviour\":\"behaviour\",\"spatial\":[0,0,0,1,1,1,0,0,0],\"special\":[\"\",\"VIEW:/standardviews/tools/PerformanceMeasureTable\",\"VIEW:/standardviews/tools/PerformanceMeasureTable\"],\"variable_performanceMeasures\":[[\"PerformanceMeasure1\",[1,\"reference\",\"extraData\"],\"\",\"\"]]}"}]}
FlexSim 21.0.6
webserverflexsimserver
· 1
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Jeanette F avatar image Jeanette F ♦♦ commented ·

Hi @Yokota T, was Phil BoBo's answer helpful? If so, please click the red "Accept" button at the bottom of their answer. Or if you still have questions, add a comment and we'll continue the conversation.

If we haven't heard back from you within 3 business days we'll auto-accept an answer, but you can always unaccept and comment back to reopen your question.

0 Likes 0 ·

1 Answer

Phil BoBo avatar image
0 Likes"
Phil BoBo answered Yokota T commented

You can use FlexScript to set model parameters and get performance measures.

For example:

Model.parameters["ParamName"].value = 5;
Array pfms = function_s(Model.find("Tools/PerformanceMeasureTables/1"), "getAllPFMs");
for (int i = 1; i <= pfms.length; i++) {
    string name = pfms[i].up.first.value;
    string value = pfms[i].value;
}

To execute FlexScript using a default query handler, you can use the "toolsnodefunction" query handler.

The FlexScript function you want to execute needs to be in the model before you run it. Add FlexScript functions to the model that you will execute with the "toolsnodefunction" query handler.

Attached is an example model and webpage with example code that submits a job to the webserver to open the model, set the values of the model parameters, run the model, and get the results of the performance measures.

set_param_get_perf_example.zip

The model has a "setupscript" nodefunction for setting the model parameters based on the job specification, a "processresults" nodefunction for getting the performance measures when the model is finished running, and a "modeloutput" node where it stores those values.

Values can be passed using a web form:

Results can be retrieved:

The setup script and results processing scripts are defined within the model and executed by the "toolsnodefunction" query handler.

If you want to configure FlexSim to be able to do this for any arbitrary model without any modifications to the model, then you should use the Module SDK to add query handlers to FlexSim instead of putting them in the model. Otherwise, you should configure the model itself with setup and result scripts as shown in the attached example.

· 1
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Yokota T avatar image Yokota T commented ·

I'm sorry I didn't notice your answer immediately.

I understand. Thank you for your advice.

0 Likes 0 ·