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
FAQ Downloads Calendar Search Mark Forums Read

Q&A Using Flexsim and building models

Reply
 
Thread Tools Display Modes
  #1  
Old 11-20-2007
Cliff King's Avatar
Cliff King Cliff King is offline
Vice President Technical Services
 
Join Date: Jul 2007
Location: Utah
Posts: 272
Downloads: 158
Uploads: 14
Thanks: 102
Thanked 304 Times in 110 Posts
Rep Power: 408
Cliff King has much to be proud ofCliff King has much to be proud ofCliff King has much to be proud ofCliff King has much to be proud ofCliff King has much to be proud ofCliff King has much to be proud ofCliff King has much to be proud ofCliff King has much to be proud ofCliff King has much to be proud of
Default Repeat Random Streams

There is a menu option in the Statistics menu of Flexsim title "Repeat Random Streams" which forces all random number streams (currently Flexsim has 100 streams also known as generators available, but will allow this to be a user-defined quantity in the next release) to reset back to the beginning of their stream as determined by a unique default seed value for each of the streams. This option is useful when debugging your model so that you can isolate the effects to your model caused by changes you've made versus changes caused soley due to new random numbers.

François Perron recently emailed me the following concern. I would like to answer it here on the forum so others can also benefit from the discussion as I suspect others have experienced this same problem.

Quote:
I’m trying to have my simulation use the same stream of random numbers each time I run. Even if I check the option "Repeat Random Streams" I don’t get all the time the same numbers. Moreover, I wish to be able to repeat the exact sequence between 2 computers. I tried to use the randinit() command without success. What can I do to have full control over the random generator ? Please advice.
Do you have transports or operators in your model that start from a new location every time you run ? By default, transports will stay where they were at the end of the previous run, and therefore begin each successive run from a different location which means they will have to travel a slightly different distance each time, which of course can change your results from run to run.

With regards to the randinit() command, you can use the command to initialize a specific random number stream. For instance, randinit(0,345) will initialize random stream 0 with a seed value of 345, which will generate the number 0.2693 as its first random number in its new stream of numbers as can be verified by executing the randnext(0); command from the Script console immediately after executing the randinit(0,345); command.

Essentially, by selecting the "Repeat Random Streams" menu option, you are executing the randinit() command for all streams 0 through 99 each time you Reset the model. I can not tell you what the exact seed numbers are for each of the generators off the top of my head, but the important thing for you to know is that they are the same each time.

Let me know if after right-clicking on all your task executers in your model and "Set Object Reset Position" you still get varied results with each run even though you have selected "Repeat Random Streams", and we can investigate other possibilities.
Reply With Quote
  #2  
Old 11-20-2007
Francois Perron's Avatar
Francois Perron Francois Perron is offline
Flexsim Distrib. Canada
 
Join Date: Aug 2007
Location: Montreal, Qc, Canada
Posts: 5
Downloads: 42
Uploads: 0
Thanks: 1
Thanked 0 Times in 0 Posts
Rep Power: 0
Francois Perron is on a distinguished road
Default

Thank you Cliff for the precision. In fact, you solved my issue in your first sentence. I was using a random stream # that was greater than 100. I don't know why if the # stream is > 100, it seems to ignore the "Repeat Random Stream" option, but if I use a number between 0 and 99, everything works properly as described in your answer.

Thanks

Francois
Reply With Quote
  #3  
Old 11-20-2007
Cliff King's Avatar
Cliff King Cliff King is offline
Vice President Technical Services
 
Join Date: Jul 2007
Location: Utah
Posts: 272
Downloads: 158
Uploads: 14
Thanks: 102
Thanked 304 Times in 110 Posts
Rep Power: 408
Cliff King has much to be proud ofCliff King has much to be proud ofCliff King has much to be proud ofCliff King has much to be proud ofCliff King has much to be proud ofCliff King has much to be proud ofCliff King has much to be proud ofCliff King has much to be proud ofCliff King has much to be proud of
Default

Sorry for the confusion. I explain the problem a little more in this post.
Reply With Quote
  #4  
Old 02-21-2008
AlanZhang's Avatar
AlanZhang AlanZhang is offline
Flexsim Super Moderator
 
Join Date: Aug 2007
Location: CA
Posts: 289
Downloads: 64
Uploads: 0
Thanks: 88
Thanked 91 Times in 47 Posts
Rep Power: 221
AlanZhang is a jewel in the roughAlanZhang is a jewel in the roughAlanZhang is a jewel in the rough
Default

One tip from Anthony, if you want Repeat Random Stream and if you have code to access the location of moving objects (operators, things like processors carrying flowitems), you should call updatelocations() before using xloc, yloc, zloc etc. Otherwise, you won't be able to repeat your model run even with Repeat Random Stream checked.

Other things need to be aware of.

1. Repeat Random Stream default is not checked. You have to manually check it after you start the Flexsim.
2. Repeat Random Stream will always reset the random stream to same set of initial values.
3. Repeat Random Stream cannot be used with experimenter. So if you have experimenter checked, checking Repeat Random Stream will do nothing. And current version v4.3 will not give you any warning message.
__________________
Best,
Alan
Reply With Quote
  #5  
Old 06-24-2008
Anthony Timmiss Anthony Timmiss is offline
Flexsim User
 
Join Date: Aug 2007
Location: Sunderland - UK
Posts: 78
Downloads: 41
Uploads: 0
Thanks: 65
Thanked 45 Times in 28 Posts
Rep Power: 183
Anthony Timmiss will become famous soon enoughAnthony Timmiss will become famous soon enough
Default Random Numbers and Experimenter

Quick question loosely linked to earlier posts in this thread.

Is it possible to control which random number streams are being used when using the experimenter.

For example- I want to run 6 experiments, each one having 10 replications. I want to use the same random number streams for each of the 6 experiments in order to get a fair comparison.

2 Questions

1. Is Flexsim doing this anyway?

If not...

2. Is it possible to do this?

Thanks

Anthony
Reply With Quote
  #6  
Old 06-24-2008
Brandon Peterson's Avatar
Brandon Peterson Brandon Peterson is offline
The Flexsim Consultant
 
Join Date: Jul 2007
Location: Salt Lake City, Utah
Posts: 382
Downloads: 29
Uploads: 6
Thanks: 192
Thanked 516 Times in 235 Posts
Rep Power: 486
Brandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant future
Default

Anthony,

As Alan suggested the experimenter is not doing what you would want it to do which is more of a repeater and not an experimenter. To get the experimenter to do what you want you may want to create an even at time zero or use the On Reset model trigger to call the randinit() command for all of the random number streams you are using. To change the seed value based on the replication and scenario you can look up the current scenario and replication of the experiment at the following locations:

Scenario: MAIN:/project/exec/replications/18

Replication: MAIN:/project/exec/replications/19

Good Luck,
Brandon
__________________
thats not normal.
Reply With Quote
The Following User Says Thank You to Brandon Peterson For This Useful Post:
Dustin Derrick (08-26-2008)
  #7  
Old 06-24-2008
Anthony Johnson's Avatar
Anthony Johnson Anthony Johnson is offline
Manager of Product Development
 
Join Date: Jul 2007
Posts: 440
Downloads: 86
Uploads: 4
Thanks: 171
Thanked 899 Times in 288 Posts
Rep Power: 731
Anthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond repute
Default

Everyone,
On a side note, Cliff said that Flexsim only has 100 random number streams, which is incorrect. By default, Flexsim only has 100 random number streams, but you can already specify as many random number streams as you want to use. You must call the randinit() function to tell Flexsim how many streams you want to use. For example, if you call randinit(2000, 0), Flexsim will allocate space for all random streams up to and including that 2000th. You only need to call it once to set the number of random streams, and that number will remain either until you compile, or until you close Flexsim. However, right now, Repeat Random Streams will not reset the random number streams above 100, so you will have to explicitly initialize those random number streams on reset if you want those streams to repeat.

Also, in regards to Anthony's question, it seems easier to me to just explicitly call randinit on reset (or on an Experimenter trigger) for the streams that you want to repeat, instead of going into the tree and setting values there.
Reply With Quote
The Following User Says Thank You to Anthony Johnson For This Useful Post:
Jörg Vogel (07-03-2008)
  #8  
Old 08-26-2008
Yasemin Vatandas's Avatar
Yasemin Vatandas Yasemin Vatandas is offline
Flexsim User
 
Join Date: Jul 2008
Location: Hamburg, Germany
Posts: 36
Downloads: 9
Uploads: 0
Thanks: 29
Thanked 3 Times in 3 Posts
Rep Power: 142
Yasemin Vatandas is on a distinguished road
Question

Hello all,
after having read the threads on random number streams, I've just got confused about some points:

- Is it better to use the same random number stream in the experiments in terms of accuracy of the comparison?

- When we define the random number stream manually (when we use a distribution like duniform(10,20,1) ), does the experimenter use this specified stream in every replication, even if we do not use randinit() command in any OnReset triggers?

- Let's say I have a model and want to compare two different configurations of it (e.g. different item release strategies). Since I cannot define these configurations in the experimenter as experiment variables, I should have two different models and run them separately. Now my question is: does these two models use the same random number stream when I define, for example, the inter-arrival time as exponential(0,20,1) in each source respectively?

- Does the recorder has anything to do with collecting data for the experimenter? When should we use it?

I hope I could express my questions clearly.
Thanks.

Last edited by Yasemin Vatandas; 08-26-2008 at 06:21 AM. Reason: adding a new question
Reply With Quote
  #9  
Old 08-26-2008
Brandon Peterson's Avatar
Brandon Peterson Brandon Peterson is offline
The Flexsim Consultant
 
Join Date: Jul 2007
Location: Salt Lake City, Utah
Posts: 382
Downloads: 29
Uploads: 6
Thanks: 192
Thanked 516 Times in 235 Posts
Rep Power: 486
Brandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant future
Default

Yasemin,

The random number stream used by a function call is defined in the use of the function (ie normal(15, 2, stream)), so each experiment would use the same stream. However, each experiment will start at a different place in the stream unless you have repeat random streams checked or set the starting point yourself. The whole idea of simulation is to get a feel for what may happen given a set of variable events, so you would want to have different starting point for each itteration of an experiment so that you can see what happens when the numbers change. You don't want to repeat random streams unless you are debugging your model or have some other significant reason.

Yes they would use the same random number stream, but again, they would start in a different place in the stream unless you where to specifically set the starting point yourself. The one exception to this may be (I'm pretty sure but not 100%) if you were to open Flexsim hit reset and run in the same fashion for each model then they would both start with the same random number stream and in the same spot because Flexsim starts with the same random seed each time it is opened. This is where you get into why you select other random streams besides 1. If all of your stochastic calls use random stream 1 then the models would only run the same until one of them makes a stochastic function call in a different order then each model would be off from the other.

No, the recorder does not record data it merely displays data that is in the model. I use it when I want to display model data in 3D.

I hope that this helps,
Brandon
__________________
thats not normal.
Reply With Quote
The Following 3 Users Say Thank You to Brandon Peterson For This Useful Post:
Congshi Wang (12-17-2010), Dustin Derrick (08-26-2008), Yasemin Vatandas (08-26-2008)
  #10  
Old 08-26-2008
Martijn van Oostenbrugge's Avatar
Martijn van Oostenbrugge Martijn van Oostenbrugge is offline
Talumis, Flexsim Distributor, The Netherlands
 
Join Date: Aug 2007
Posts: 71
Downloads: 12
Uploads: 0
Thanks: 44
Thanked 44 Times in 24 Posts
Rep Power: 264
Martijn van Oostenbrugge is a name known to allMartijn van Oostenbrugge is a name known to allMartijn van Oostenbrugge is a name known to allMartijn van Oostenbrugge is a name known to allMartijn van Oostenbrugge is a name known to allMartijn van Oostenbrugge is a name known to all
Default

I use the repeat random streams frequently for debugging purposes. But on a number of occasions I had a bug during a normal simulation. The problem often is, that when I select the repeat random streams I do not get to this bug and so it is quite difficult debugging. If there's a possibility to implement this I would like to see an option in which I can repeat the last simulation.

Martijn
Reply With Quote
The Following 4 Users Say Thank You to Martijn van Oostenbrugge For This Useful Post:
Danny Pavan (08-28-2008), RalfGruber (08-26-2008), Steven Hamoen (08-26-2008), Tom David (08-27-2008)
  #11  
Old 08-26-2008
RalfGruber's Avatar
RalfGruber RalfGruber is offline
FlexSim Software Products
 
Join Date: Jul 2007
Location: Orem, UT, USA
Posts: 195
Downloads: 37
Uploads: 0
Thanks: 518
Thanked 294 Times in 124 Posts
Rep Power: 341
RalfGruber is a splendid one to beholdRalfGruber is a splendid one to beholdRalfGruber is a splendid one to beholdRalfGruber is a splendid one to beholdRalfGruber is a splendid one to beholdRalfGruber is a splendid one to beholdRalfGruber is a splendid one to behold
Default

If this becomes the wish list for Random streams, I want to add one too:

If Martins suggestions was not too hard to implement I would like that expanded THIS way:
- Add a button to the RunControl like "Repeat" with the functionality to reset the model, initialize the random stream with the same value of the last simulation run and run the model.
- Drop the menu option "repeat random stream"

The advantages I see are:
1. You don´t have to care about the setting of repeat random stream anymore, because you can repeat any simulation run and don´t need to worry what the current setting is.
2. You are able to cover the situation Martin described above, finding a strange situation in a non repetitive simulation run.

Thanks

Ralf aka ralle
Reply With Quote
  #12  
Old 08-26-2008
Jason Lightfoot Jason Lightfoot is offline
Flexsim Consultant
 
Join Date: Aug 2007
Location: Somerset, UK
Posts: 719
Downloads: 20
Uploads: 0
Thanks: 123
Thanked 953 Times in 446 Posts
Rep Power: 769
Jason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond repute
Default

For what its worth I think repeat streams should be on all the time.

The user should then have the option of the choosing the starting replication (for when you hit 'run' - default 1) and the number of streams to initialise automatically on reset (default is 101 currently - numbers 0 to 100). Flexsim can then handle the initialisation and repeatability by using an adapted version of the following code from the Pseudo Randomness thread in this forum:

Code:
Removed - see below

Last edited by Jason Lightfoot; 02-13-2012 at 06:45 PM. Reason: Updated code to avoid correlation
Reply With Quote
  #13  
Old 08-27-2008
AlanZhang's Avatar
AlanZhang AlanZhang is offline
Flexsim Super Moderator
 
Join Date: Aug 2007
Location: CA
Posts: 289
Downloads: 64
Uploads: 0
Thanks: 88
Thanked 91 Times in 47 Posts
Rep Power: 221
AlanZhang is a jewel in the roughAlanZhang is a jewel in the roughAlanZhang is a jewel in the rough
Default

Ralf's suggestion looks good for me. All that Flexsim should do is to store the random streams' states when user hits the reset button, and then use those values to initialize random streams if user hits the Repeat button. In many occasions, we suddenly notice a problem/bug but we find the "Repeat Random Stream" is not checked. But then after we check the option, we cannot reproduce the problem/bug any more.
__________________
Best,
Alan
Reply With Quote
  #14  
Old 02-12-2012
Jason Lightfoot Jason Lightfoot is offline
Flexsim Consultant
 
Join Date: Aug 2007
Location: Somerset, UK
Posts: 719
Downloads: 20
Uploads: 0
Thanks: 123
Thanked 953 Times in 446 Posts
Rep Power: 769
Jason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond repute
Default

Place this code in the model OnReset trigger for replication repeatability across scenarios and the ability to repeat a single replication in isolation. This update to the code originally posted above allows you to use antithetic versions of the (odd) streams in the even numbered replications and avoids stream correlation:

Code:
int  totalstreams=50;        //the number of streams you want to initialize
int  streambase=100;          //The starting stream offset 
int  firstreplication=getnodenum(node("/project/exec/replications/Current",maintree()));
int  replication=0;
int useantithetic=1; 

if  (firstreplication==0)
         replication=1;      //reset button has probably been hit
else
       replication=getnodenum(node("/project/exec/replications/CurrentRunOfScenario",maintree()));
//replication=30;            // un-comment this line to initialise the streams for a particular replication
int thisrepisantithetic=fmod(1+replication,2);
if (useantithetic)
	replication=(1+replication)/2;
double repseed=replication;
for (int n=replication;n>0;n--){
	repseed=fmod(16807.0*repseed, pow(2,31)-1.0);
}
for (int n=1;n<=totalstreams;n++){
	repseed=fmod(742938285.0*repseed, pow(2,31)-1.0);
       randinit(streambase+n,repseed);
}
if (useantithetic){
	randantithetic(thisrepisantithetic);
}

Last edited by Jason Lightfoot; 02-13-2012 at 07:27 PM. Reason: Prevent correlation
Reply With Quote
  #15  
Old 08-30-2012
AlanZhang's Avatar
AlanZhang AlanZhang is offline
Flexsim Super Moderator
 
Join Date: Aug 2007
Location: CA
Posts: 289
Downloads: 64
Uploads: 0
Thanks: 88
Thanked 91 Times in 47 Posts
Rep Power: 221
AlanZhang is a jewel in the roughAlanZhang is a jewel in the roughAlanZhang is a jewel in the rough
Default

Just want to share a couple of updates on this post:
1. It appears Jason's code does not work any more perhaps due to the fact that now multiple threads are used for experimenter. I tested the code and got the same simulation result across all runs/replications.
2. It seems now Flexsim automatically handle the replication repeatability by default. For example Replication 3 of Scenario 2 will have the same random stream as Replication 3 of Scenario 1. Can anyone in Flexsim confirm this? How many random streams have been automatically handled by Flexsim for this repeatability issue? Is it 100?
3. It would be nice that we can repeat random stream for any particular replication of a scenario as Jason tried in his code. With the new experimenter, how can we do that? Will Flexsim develop something like that in the near future?

Thanks,

Alan
__________________
Best,
Alan
Reply With Quote
  #16  
Old 08-30-2012
Jason Lightfoot Jason Lightfoot is offline
Flexsim Consultant
 
Join Date: Aug 2007
Location: Somerset, UK
Posts: 719
Downloads: 20
Uploads: 0
Thanks: 123
Thanked 953 Times in 446 Posts
Rep Power: 769
Jason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond repute
Default

All the above is handled automatically now. (without antithetic streams)

Under the Experimenter's Advanced tab you can select an individual replication to run interactively (it's called 'Repeat Streams of Replication'). You can also select the Scenario to run on the Scenarios tab.

Yes -the streams are the same for a given replication number regardless of which scenario it is.

You can specify the number of streams Flexsim should initialize under the File->Model Settings menu option.
Reply With Quote
The Following User Says Thank You to Jason Lightfoot For This Useful Post:
AlanZhang (08-30-2012)
  #17  
Old 08-30-2012
AlanZhang's Avatar
AlanZhang AlanZhang is offline
Flexsim Super Moderator
 
Join Date: Aug 2007
Location: CA
Posts: 289
Downloads: 64
Uploads: 0
Thanks: 88
Thanked 91 Times in 47 Posts
Rep Power: 221
AlanZhang is a jewel in the roughAlanZhang is a jewel in the roughAlanZhang is a jewel in the rough
Default

Jason,

Thanks very much for your reply. I really like the new experimenter design.

Alan
__________________
Best,
Alan
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 06:38 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.
Copyright 1993-2018 FlexSim Software Products, Inc.