ATTENTION

This FlexSim Community Forum is read-only. Please post any new questions, ideas, or discussions to our new community (we call it Answers) at https://answers.flexsim.com/. Our new Question & Answer site brings a modern, mobile-friendly interface and more focus on getting answers quickly. There are a few differences between how our new Q&A community works vs. a classic, threaded-conversation-style forum like the one below, so be sure to read our Answers Best Practices.


flexsim.com

Go Back   FlexSim Community Forum > FlexSim Software > Q&A
Downloads

Q&A Using Flexsim and building models

  #1  
Old 10-13-2010
Albert Munoz Albert Munoz is offline
Flexsim User
 
Join Date: Sep 2010
Posts: 14
Downloads: 5
Uploads: 0
Thanks: 6
Thanked 0 Times in 0 Posts
Rep Power: 117
Albert Munoz is on a distinguished road
Question Modelling Equations

Hello,

Being new to Flexsim of course I will have a ton of questions. I have been trawling through the threads and reading up the user manual but there are a few things I still havent been able to master, one of them being the modelling of an equation as such.

Basically I need to model a forecasting algorithm for exponential smoothing as one part of a larger model. The Equation goes like this

Forecast(t+1)=Constant*ActualDemand(t) + (1-Constant)*Forecast(t)

Where Forecast(t) will be called from a table with (t) being the row number. Actual demand(t) will be a message parameter sent from another part of the model and the constant will be given by the user via the GUI. The equation needs to be executed at every time period. Aside from the equation being executed, the resulting Forecast value needs to be stored in a table with the row number of the table being the current time period as an integer.

I have developed this model in another software (ExtendSim) but licensing preferences in my university have meant that I need to rebuild the same model in Flexsim (and fortunately, get paid to learn a new software!). In Extendsim I used an equation block whose role was to; call upon a database table for Forecast(t), receive ActualDemand(t) from another block (via an information flow link, similar to a centreport), receive the constant from another database table, and execute the equation code periodically.

I realise there are several steps to this, but any help to get me going will be greatly appreciated.

Thanks
Albert Munoz
  #2  
Old 10-13-2010
Steven Hamoen's Avatar
Steven Hamoen Steven Hamoen is offline
Talumis, Flexsim Distributor, The Netherlands
 
Join Date: Aug 2007
Location: Soest, NL
Posts: 854
Downloads: 43
Uploads: 0
Thanks: 391
Thanked 661 Times in 379 Posts
Rep Power: 684
Steven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond repute
Default

Ok, to break it down in parts:
For the constant I would use a global variable. For now just set it, later on you can use a GUI to do so. Global variables can be found under tools.

For the function itself you could create a usercommand (also under tools) which is function and you pass in the parameters when calling that function.

To let it trigger every so many times you could use a userevent (also under tools) or use a senddelayedmessage function.

your function could look something like:

//Get the parameters/arguments
int RowNr = parval(1);
double ActualDemand = parval(2);

//Get the previous forecast from a global table
double ForecastPrev = gettablenum( "YourTableName", RowNr, x ); //x being the column

//Calculate the new forecast
double Forecast = Constant * ActualDemand + ( 1- Constant ) * ForecastPrev;

//Write the forecast to table
int NewRowNr = ??? (I don't know anything about your time periods, flexsim gives you seconds with the function time())

settablenum( "YourTableName", NewRowNr, x, Forecast );

return Forecast;


Return is not necessary but gives you a result you can test.

You could also use a messagetrigger on a object if that sounds or is easier. You can simply write the code on that trigger and let it call itself or let it be called from outside.

Hope this helps you on your way
The Following User Says Thank You to Steven Hamoen For This Useful Post:
Albert Munoz (10-13-2010)
  #3  
Old 10-13-2010
Albert Munoz Albert Munoz is offline
Flexsim User
 
Join Date: Sep 2010
Posts: 14
Downloads: 5
Uploads: 0
Thanks: 6
Thanked 0 Times in 0 Posts
Rep Power: 117
Albert Munoz is on a distinguished road
Default

Thank you so much, that does help a great deal.

Taking a step back for a bit, are there any tutorials for creating and executing user commands out there? Maybe in the user manual?

Having very little coding experience I am a little lost when it comes to passing parameters onto a function from an object (i.e. using parval()) and executing a user command function from an object trigger.

Thanks
Albert
  #4  
Old 10-14-2010
Steven Hamoen's Avatar
Steven Hamoen Steven Hamoen is offline
Talumis, Flexsim Distributor, The Netherlands
 
Join Date: Aug 2007
Location: Soest, NL
Posts: 854
Downloads: 43
Uploads: 0
Thanks: 391
Thanked 661 Times in 379 Posts
Rep Power: 684
Steven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond repute
Default

I would like to point you the download section of this forum. There is lots of information there. either in the form of movies or all kinds of models showing small bits of information. I'm pretty sure that a usercommand is used in there somewhere but it might be a bit difficult to find out in which model so I'll explain it a littlebit here.

using a usercommand is very simple. Suppose you have a usercommand that is called: "CalculateForecast" and it returns a double you can use it like:

double Result = CalculateForecast( value1, value2);
or
CalculateForecast( value1, value2);

if you don't need or want a return value

Inside the function you use parval(1) to extract value1 and parval(2) to extract value2. You can pass up to 10 parameters and they can be double, strings or treenodes, you just have to extract them with the right command (parval, parstr, parnode) (when using c++ this is a bit different but search on "passing strings" in this forum and you find answers)

so in this case inside your function you use:
double MyVal1 = parval(1);
double MyVal2 = parval(2);

etc.

Check out the demo and concept models in the download section and check the triggers etc, to find out how the programming works in Flexsim


Thread Thread Starter Forum Replies Last Post
Modelling a 12-joint robot! Kenny Macleod Q&A 4 07-20-2010 11:30 AM


All times are GMT -6.
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.
Copyright 1993-2018 FlexSim Software Products, Inc.