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-10-2014
Simon Jutz Simon Jutz is offline
Flexsim User
 
Join Date: Nov 2013
Location: Innsbruck/Austria
Posts: 33
Downloads: 29
Uploads: 0
Thanks: 25
Thanked 5 Times in 4 Posts
Rep Power: 83
Simon Jutz is on a distinguished road
Default 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));
	}
	}
}
This code updates me my global table "Demand_x" with the input data from "Demand_1". But I have ten other global tables (Demand_2,..., Demand_10) that should be used for updating "Demand_x" each time a replication starts.

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  
Old 10-10-2014
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: 773
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

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  
Old 10-10-2014
Simon Jutz Simon Jutz is offline
Flexsim User
 
Join Date: Nov 2013
Location: Innsbruck/Austria
Posts: 33
Downloads: 29
Uploads: 0
Thanks: 25
Thanked 5 Times in 4 Posts
Rep Power: 83
Simon Jutz is on a distinguished road
Default

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  
Old 10-11-2014
Simon Jutz Simon Jutz is offline
Flexsim User
 
Join Date: Nov 2013
Location: Innsbruck/Austria
Posts: 33
Downloads: 29
Uploads: 0
Thanks: 25
Thanked 5 Times in 4 Posts
Rep Power: 83
Simon Jutz is on a distinguished road
Default

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))));
		}
	}	
}
Maybe somebody is in need of something similar...

Have fun!
Simon
The Following User Says Thank You to Simon Jutz For This Useful Post:
sagar bolisetti (10-11-2014)
  #5  
Old 04-02-2015
David Chan David Chan is offline
Flexsim Distributor
 
Join Date: Sep 2007
Posts: 326
Downloads: 74
Uploads: 0
Thanks: 217
Thanked 73 Times in 44 Posts
Rep Power: 218
David Chan has a spectacular aura aboutDavid Chan has a spectacular aura aboutDavid Chan has a spectacular aura about
Default

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


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.