This FlexSim Community Forum is read-only. Please post any new questions, ideas, or discussions to our new community (we call it Answers) at 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.

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

Q&A Using Flexsim and building models

Old 10-27-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 batchsize and currentbacthsize variables?


I have a user command which is triggered by a user event every integer time period. This user command calculates the desired batch size to be released from a queue onto a processor. The idea being that once the batch size is sent to the queue, if the queue contains that number of items (or greater) it will immediately release those items as a batch to the processor, if the queue is lacking in that number of items then it waits until it gets the number of items and then releases the batch.

To do this I am using setnodenum command in the following code;
treenode current = ownerobject(c);
treenode Inventory_RM_A=node("/Inventory_RM_A", model());
treenode Inv_Level_RM_A=stats_content(Inventory_RM_A);
treenode Inventory_RM_B=node("/Inventory_RM_B", model());
treenode Inv_Level_RM_B=stats_content(Inventory_RM_B);
treenode Supplier_Reservoir_A=node("/Supplier_Reservoir_A", model());
treenode BatchSize_RM_A= node(">variables/batchsize",Supplier_Reservoir_A);
treenode Supplier_Reservoir_B=node("/Supplier_Reservoir_B", model());
treenode BatchSize_RM_B= node(">variables/batchsize",Supplier_Reservoir_B);
/**Custom Code*/
int Forecast_RM_A;
int Forecast_RM_B;
//Sets time as an integer which will be used to call the table rows
int Rownum;
int Rownumminus1;
//Fetches the forecast value from the forecasting table
Forecast_RM_A=gettablenum("Forecasting Data",Rownum,5);
Forecast_RM_B=gettablenum("Forecasting Data",Rownum,6);
//Grabs desired decision variables and admin inputs to calculate desired inventory level
double SSofRM;
SSofRM=gettablenum("Decision Variables",1,3);
int Inventory_Capacity_RM_A;
int Inventory_Capacity_RM_B;
Inventory_Capacity_RM_A=gettablenum("Admin Inputs",1,1);
Inventory_Capacity_RM_B=gettablenum("Admin Inputs",1,2);
int Desired_RM_A=SSofRM*Inventory_Capacity_RM_A;
int Desired_RM_B=SSofRM*Inventory_Capacity_RM_B;
//Grabs the current inventory levels
int Current_RM_A=getnodenum(Inv_Level_RM_A);
int Current_RM_B=getnodenum(Inv_Level_RM_B);
//Calculates the replenishment order size
int ReplenishmentOrderA;
int ReplenishmentOrderB;
So my question is, should I be sending the value 'ReplenishmentOrderA' and 'ReplenishmentOrderB' to the batchsize variable or the currentbatchsize variable?

What is happening in the model is it either releases one batch and then stops sending batches or it doesnt release any batches at all. Or maybe I should manually have send a message to the endcollectingtrigger? if so how could I do that?

Old 10-28-2010
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

The problem you're likely to have is that the test for meeting batchsize assumes it's greater than the current count. If you reduce it below the number already collected, the test condition of collected==batchsize will never be met. The currentbatchsize variable indicates the number collected so far.

To have better control over the release it maybe better to implement your own code to control the release - especially if:
  • You want multiple requests to stack up (if no items are available)
  • You want to prevent items being sent when no requests have been made

This is pretty easy if you just use a counter (on a label for example) to record how many you need downstream and control the release yourself.

I'd probably create a user command (called "sendbatch" ?) and pass in the queue object and the quantity while others would maybe send a message to the queue and pass in the amount required as a messageparameter - it's your choice.

The easiest method if your not using transport from the queue and are feeding onto a conveyor or processor, might be to start with a closed output on the queue (resettrigger). Then decrement the counter when an item leaves and close the output of the queue when the counter reaches zero (OnExit but via a delay). Then in the OnEntry trigger open the output when the content of the queue matches a non-zero counter value. In sendbatch user command increment the counter and if the queue has that number or more, open the output. If you're using transport of feeding to another queue I think you'll need another technique.

You can also do it by by returning -1 on the sendtoport trigger to prevent an item's release, and by using the command releaseitem() when the queue already has the amount required for a new request.

Last edited by Jason Lightfoot; 10-28-2010 at 06:11 AM. Reason: Simpler method added for a simpler case
The Following User Says Thank You to Jason Lightfoot For This Useful Post:
Steven Hamoen (10-28-2010)

Thread Thread Starter Forum Replies Last Post
Global variables juan alberto Q&A 5 11-10-2010 05:47 PM
Update of global variables BenjaminBuecklein Q&A 4 11-18-2008 03:43 AM
Static Variables in Flexscript? Joe Allen Q&A 7 09-18-2008 12:43 PM
Experimenter variables Xavier Jackson Gripes and Goodies 4 09-09-2008 10:00 AM
GUI & linked variables Iulian Marin Ion Q&A 2 11-27-2007 10:23 PM

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.