ATTENTIONThis 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 |
#1
|
|||
|
|||
For-loop between global tables
Hi all!
I want to update a specific global table (Demand_x) each time a replication in the Experimenter starts. The update comes from other global tables that are defined in the model (Demand_1, Demand_2,...). In the "Start of Replication"-Trigger of the Advanced Tab in the Experimenter I put: Code:
/**INPUT PARAMETER*/ double replication = parval(1); double scenario = parval(2); for(replication=1;replication<=10;replication++) { for (int period=1; period<=gettablerows("Demand_1"); period++) { for (int product=1; product<=gettablecols("Demand_1"); product++) { settablenum("Demand_x",period,product, gettablenum("Demand_1",period,product)); } } } How can I realize this? I thought of entering another 'for-loop' that loops between the global tables but I don't know how. Thank you very much for your advice! Simon |
#2
|
|||
|
|||
Do you want to aggregate the 10 demand profiles into one table?
If so, what do you want to do with the replications? If all the replications are reading from Demand_x, why not do that on start of experiment? If you just want to agregate them based on the table name you could use this: Code:
int numdemandtables=10; clearglobaltable("Demand_x"); for (int demand=1;demand<=numdemandtables;demand++) { treenode demandtable=reftable(concat("Demand_",numtostring(demand))); for (int period=1; period<=gettablerows(demandtable); period++) { for (int product=1; product<=gettablecols(demandtable); product++) { inc(gettablecell("Demand_x",period,product), gettablenum(demandtable,period,product)); } } } |
The Following User Says Thank You to Jason Lightfoot For This Useful Post: | ||
Simon Jutz (10-10-2014) |
#3
|
|||
|
|||
Thank you Jason!
In my model I have different scenarios and I want to test these scenarios under different demand patterns. That's why I want to replicate my model several times. I came myself to a solution (it is not very nice and maybe nasty but at least it seems that it works out): Code:
/**INPUT PARAMETER*/ double replication = parval(1); double scenario = parval(2); string Tablename; Tablename = concat("Demand_",numtostring(replication)); for (int period=1; period<=gettablerows(Tablename); period++) { for (int product=1; product<=gettablecols(Tablename); product++) { settablenum("Demand_x",period,product,gettablenum(Tablename,period,product)); } } I am using the replication pointer that counts each time a replication is performed and change it to a string. Not very nice but doable. But this is only a workaround of my original problem. I wanted my original global table "Demand_x" to update ITSELF before a replication is done. I don't want to replace the data by other data from another global table. This is done by my workaround now. I want the Experimenter to generate, each time a repliacation starts, a new demand profile (e.g. generally distributed, 15 products, 5000 periods) by a random number generator. Where do I have to code this? Again in the "Start of replication" trigger? Are there any examples, where I can get an idea of how this code might look? Thank you very much! Simon |
#4
|
|||
|
|||
Again, I found a solution to my above stated problem:
For each replication in the Experimenter I wanted to generate a new demand pattern for my model. Here is the code: Code:
/**INPUT PARAMETER*/ double replication = parval(1); double scenario = parval(2); treenode NumberofReplication = node("/Tools/Experimenter/NumberOfRunsPerScenario", model()); int R = getnodenum(NumberofReplication); int i = replication; for(i=1; i<=R; i++) { for (int period=1; period<=gettablerows("Demand"); period++) { for (int product=1; product<=gettablecols("Demand"); product++) { settablenum("Demand",period,product,fabs(round(normal(5,2,1)))); } } } Have fun! Simon |
The Following User Says Thank You to Simon Jutz For This Useful Post: | ||
sagar bolisetti (10-11-2014) |
#5
|
|||
|
|||
Hi
I was trying to do likewise, but I want to update the pattern by the scenario. It seems the value of scenario is not functioning. Any ideas? Currently I used a Global Variable as variable and assign a value to it. Though it works, but just to check anything wrong with the scenario variables at the Start of Run of Experiment.
__________________
Advent2 Labs David Last edited by David Chan; 04-02-2015 at 01:13 AM. Reason: Startofrun, scenario |
Thread | Thread Starter | Forum | Replies | Last Post |
global tables | riccardo torchio | Q&A | 2 | 09-05-2013 02:23 AM |
FS 5.0 Index in global tables | Nico Zahn | Gripes and Goodies | 4 | 05-04-2010 07:18 AM |
Limit in the completion hints? Global Tables, Global Variables, etc.? | Tom David | Gripes and Goodies | 6 | 09-09-2008 04:05 PM |
Automatically generated global tables | Sebastian Dransfeld | Gripes and Goodies | 1 | 09-01-2008 12:44 PM |
Excel and global tables | Bill Nordgren | Q&A | 2 | 10-15-2007 04:36 AM |