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 > Tips and Tricks
Downloads

Tips and Tricks Share helpful modeling ideas

  #1  
Old 06-17-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: 490
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 Pulling from a Queue vs Sorting the Queue

All,

This model was created to demonstrate to another group how to use pull logic to pull the lowest itemtype value from a queue and how that same task can be done by sorting the queue on entry.

The top group of objects uses pull logic to pull the flowitem in the queue with the lowest itemtype value (darkest color) first. The bottom group uses the on entry trigger of the queue to sort the flowitems as they enter so that the items with the lowest itemtype values are on the bottom (first).

The pull requirement code is fired for each item in the up stream object until the code returns TRUE. When searching for a low, high, or other value it is very easy to write inefficient code. The pull logic in the top processor was written to be efficient. It does this by only searching for the item with the lowest itemtype value during the execution for the first item. It then saves the rank of the lowest value item in a label on the processor. The remaining executions of the pull requirement code will only check to see if the rank of the item it is checking for is equal to that label value. This way you are not executing a search algoithm for each flowitem.

This seems to be a very common problem that people run into. The purpose of this model was to show two of the many different ways that this problem can be solved and to show how to write more efficient code in the pull requirement field.

Let me know if there are any questions or comments,
Brandon
Attached Files
File Type: zip XT Pull vs Sort.zip (48.3 KB, 727 views)
__________________
thats not normal.

Last edited by Brandon Peterson; 06-17-2008 at 12:24 PM.
The Following 4 Users Say Thank You to Brandon Peterson For This Useful Post:
Tom David (06-17-2008)
  #2  
Old 06-17-2008
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: 412
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

Brandon this is an excellent example, and you always do such a nice job of organizing and documenting your example models.

There's two excellent points I think you make with this example:
  1. Sorting the flowitems as they enter the upstream queue (as in the bottom of the two examples in your model) is going to be the most efficient because the OnEntry code of the queue which sorts the incoming flowitems is only executed once per flowitem that enters.
  2. When you do use Pull logic (as in the top example) it's important to remember that not only the Pull From Port field is executed, but the Pull Requirement will be executed for EVERY released flowitem in the upstream queue until it evaluates as "true" with EVERY time the processor is ready to receive a new flowitem. Your idea to only search the queue once when the first flowitem in the queue gets evaluated and save the minimum itemtype value in a label of the processor for reference when the subsequent flowitems are evaluated is very good.
I think it would be a good idea to include your code as a standard picklist option in the next software release. I can think of a few more examples that might be useful.
  1. Pulling the item with the minimum or maximum label/itemtype value out of multiple upstream queues.
  2. Pulling the longest waiting item with a user specified label/itemtype value out of multiple upstream queues.
The Following 3 Users Say Thank You to Cliff King For This Useful Post:
Tom David (06-17-2008)
  #3  
Old 06-23-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: 490
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

Cliff,

Here is a model that answers your questions below. This model has three sources and queues that feed one processor. The processor's job is to pull the item with the lowest item type. If there is more than one item with that itemtype then it is to take the one what has been waiting the longest.

The processor has some custom code on the Pull From Port and Pull Requirement fields. Please note that the Pull requirement could have been left at the default "Any Port" and the code to decide the port could have been done in the Pull Requirement field.

While this model isn't exactly like either of Cliff's examples it can be easily modified to do either. If someone would like to see either of them exactly or would like to see how all of the code in this model could have been done on the Pull Requirement field please let me know.

As always the code is commented like crazy and I appreciate any of your questions or comments,
Brandon

P.S. - This model was not included in the Zip file that had all of the other XT example models in another post.
Attached Files
File Type: zip XT Pull longest waiting with lowest itemtype.zip (51.7 KB, 522 views)
__________________
thats not normal.
The Following 2 Users Say Thank You to Brandon Peterson For This Useful Post:
zhang xin (12-26-2009)
  #4  
Old 03-03-2010
albertain albertain is offline
Flexsim User
 
Join Date: Feb 2010
Posts: 2
Downloads: 0
Uploads: 0
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
albertain is on a distinguished road
Default

sounds good to me
__________________
ccna and ccnp with lot more about mcse


Thread Thread Starter Forum Replies Last Post
a question on queue KelvinHo Q&A 15 11-09-2011 07:16 AM
Queue Sorting Jeff Nordgren Q&A 12 05-22-2008 03:21 PM
Queue (standard, LIFO, FIFO) Tom David Q&A 2 05-15-2008 10:30 AM
How to get interval average,max,etc of a queue content ? qin tian Q&A 5 02-14-2008 10:11 PM
Queue stacking Paul Dowling Q&A 2 11-27-2007 11:57 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.