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
|
|||
|
|||
I think an easy question... - how to pointer to objects
I can't figure out how to get a reference to an arbitrary object. For example, if I write a User Event function that needs to send a message to a particular object, how do I get the "object". For instance, the sendmessage() function wants the "toobject" and "fromobject"...I think I can put any number I want in for the "fromobject", but I need to know how to address the message to the "toobject". There's no "parnode()" to grab a hold of. I know what I named it, but I can't find a "getobject()" function or anything equivalent. I've looked thru the help and can't find any examples.
I don't think the first(), last(), inobject(), outobject(), centerobject(), or next() will do me any good because I'm in the middle of a user function that doesnt' have anything from which to reference those objects. I can't believe there's no way to get a reference using the name of the object, but I can't seem to find anything. Thanks for your help in advance. |
#4
|
||||
|
||||
another simple solution (and faster in execution) is by going to global variables and define a global pointer to your object. Then you can reference that object anywhere within Flexsim with that variable.
Steven |
The Following 2 Users Say Thank You to Steven Hamoen For This Useful Post: | ||
Jörg Vogel (07-03-2008) |
#5
|
||||
|
||||
Does this work for groups as well, because I want to have a visual tool display a group statistic.
__________________
Each morning after drudging through his morning routine the mild-mannered Xavier Jackson arrives at work and when he sits down at his computer it powers up and he becomes the great Flexavier Jacksim Optimizer Extraordinaire
|
#6
|
|||
|
|||
Here's a template for summing up something for each object in a group. Obviously, replace Group_1 with your group name, and you can do something different than adding up labels.
Code:
treenode group=node("MAIN:/project/model/Tools/Groups/Group_1"); //double sum=0; forobjecttreeunder(group){ treenode groupmember=ownerobject(tonode(getnodenum(a))); pt(getnodename(groupmember));pr(); //update your calculation here //sum+=getlabelnum(groupmember,"labelname"); } |
The Following 2 Users Say Thank You to Alex Christensen For This Useful Post: | ||
Xavier Jackson (07-22-2008) |
#7
|
||||
|
||||
Thanks but could you explain what the code does in a little simpler terms?
__________________
Each morning after drudging through his morning routine the mild-mannered Xavier Jackson arrives at work and when he sits down at his computer it powers up and he becomes the great Flexavier Jacksim Optimizer Extraordinaire
|
#8
|
|||
|
|||
When you set a group in the toolbar on the left side of an ortho or perspective view, it adds a node at the end of each object's attribute tree called "Groups", and it makes couplings with subnodes of the "Groups" node.
The couplings are stored in MAIN:/project/model/Tools/Groups. If you look there (and you have some groups set), you will see subnodes with your group names, and under those you will see subnodes with large numbers in their data. Those are the addresses of the nodes in the objects in the group under object>Groups. Calling tonode on these numbers converts the numbers into node pointers, in case you compile this code as c++ code. The ownerobjects of these nodes are the objects in the groups. I guess that's a little simpler, but couplings are still a little confusing sometimes. |
The Following 2 Users Say Thank You to Alex Christensen For This Useful Post: | ||
Xavier Jackson (07-23-2008) |
#9
|
||||
|
||||
will code like that allow me to make a connection to a group such as an input or output connection (assuming that each member of a group is capable of such a task) and central connections?
__________________
Each morning after drudging through his morning routine the mild-mannered Xavier Jackson arrives at work and when he sits down at his computer it powers up and he becomes the great Flexavier Jacksim Optimizer Extraordinaire
|
#10
|
||||
|
||||
You can use the side bar of the Ortho view to create connections to the selected objects. Use your groups to select objects, then in the Edit Selected Objects, select Connections from the combobox and create connections that way using the highlighted object and selected objects.
|
The Following User Says Thank You to Phil BoBo For This Useful Post: | ||
Xavier Jackson (07-23-2008) |
#11
|
||||
|
||||
Alright, lets see if i can ask the right question.
How can I use a visual tool to display the average, average process time of 16 separate processors. I essentially need to know how say that the object I want statistics for is a group. The experimenter can do it so I know it can be done but I have not been able to figure it out.
__________________
Each morning after drudging through his morning routine the mild-mannered Xavier Jackson arrives at work and when he sits down at his computer it powers up and he becomes the great Flexavier Jacksim Optimizer Extraordinaire
|
#12
|
||||
|
||||
Here's a little sample model to show how you can write custom code for the visual tool to display whatever you want.
The visual tool adds up all the staytime averages for its center ports and then divides that by the number of center ports it has. double totaltime = 0; for(int i = 1; i<=nrcp(current); i++) { totaltime += get(stats_staytimeavg(centerobject(current,i))); } string thetext = concat("Average Process Time: ",numtostring(totaltime/nrcp(current),0,2)); setnodestr(textnode,thetext); |
The Following 3 Users Say Thank You to Phil BoBo For This Useful Post: | ||
Xavier Jackson (07-23-2008) |
#13
|
||||
|
||||
Here's another little sample model to show how you can combine Alex's code with the Visual Tool's Text Display trigger to display group statistics.
The visual tool adds up all the staytime averages for the group and then divides that by the number of objects in the group. treenode group=node("MAIN:/project/model/Tools/Groups/Group_1"); double totaltime = 0; forobjecttreeunder(group) { treenode groupmember=ownerobject(tonode(getnodenum(a))); totaltime += get(stats_staytimeavg(groupmember)); } string thetext = concat("Average Process Time: ",numtostring(totaltime/content(group),0,2)); setnodestr(textnode,thetext); |
The Following 3 Users Say Thank You to Phil BoBo For This Useful Post: | ||
Xavier Jackson (07-23-2008) |
#14
|
||||
|
||||
Time of operator request
Hello,
I have another simple question: -When is the exact time point that a fixed resource requests a TE? To state my question more clearly: I'd like to measure the time between a TE-request by a queue and execution of the task by TE. -does the queue request a TE as soon as an item enters it and queues up? -or does the queue request the TE as soon as the downstream object is available? Thanks |
#15
|
||||
|
||||
Yasemin,
The queue will request the TE when both the queue and the down stream object the flowitem is headed to are ready. To test this you could put a print statement in the Request Transport From trigger to print the current time. I hope that this helped, Brandon
__________________
thats not normal. |
The Following User Says Thank You to Brandon Peterson For This Useful Post: | ||
Yasemin Vatandas (08-02-2008) |
#16
|
||||
|
||||
summing up labels
Quote:
I wouldn't like to bother you with my unsuccessful attempts of code-writing, but once again I need help. This time, I am trying to write a script for the following situation: the sum of label-values of items in a Queue-object are compared to an upper limit and the items, the sum of whose label values do not exceed that upper limit, are released to the processor. Let's say there are 3 items with label values 10, 15, 15 respectively and the upper limit is 30. So only the first two items with labels 10 and 15 should be released, since the inclusion of the third item would cause the sum of label values (40) to exceed the upper limit of 30. I thought I could use the above template that Alex provided as a starting point, but my following attempt failed (it is written in OnMessage trigger of a Queue): Code:
treenode current = ownerobject(c); int sum = 0; forobjecttreeunder(current){ sum = sum + getlabelnum(item,"PT"); if(sum<=120) { releaseitem(item); } } I'd appreciate any idea, thanks. |
#17
|
||||
|
||||
Yasemin,
In your code is no pointer to item, so your releaseitem(item) does nothing and also the calculation of sum is always zero. The pointer in forobjecttreeunder() is “a”. So it is like a for-loop and the pointer “a” changes to the different items depending on there rank in the tree. I did not check the code, but I guess it has to be something like this: Code:
treenodecurrent = ownerobject(c); int sum = 0; forobjecttreeunder(current) { sum = sum + getlabelnum(a,"PT"); if(sum <= 120) { releaseitem(a); } } Sometimes it is also a good idea to check if an item exists (objectexists()) before pointer to it. In the above case this seems not to be necessary. Good success!
__________________
tom the (A)tom: "We have solved our problems ... now we have to fight the solutions." |
The Following User Says Thank You to Tom David For This Useful Post: | ||
Yasemin Vatandas (08-17-2008) |
#18
|
||||
|
||||
Tom, Danke for the explanation. I wasn't aware of the "a".
Having replaced 'item' with 'a', function adds up the values for each item but I still have to work on the 'release' part of the function, since it doesn't work at all. |
#19
|
||||
|
||||
Yasemin,
You don't want to use the forobjecttreeunder command for what you are trying to do. You would be better off with the following code: double sum = 0; double target = 30; for(int index = 1; index <= content(current); index++) { sum += getlabelnum(rank(curren, index), "PT");} You need to be aware that you could run into problems where you are trying to releas items more than once if you are not careful. Good Luck, Brandon
__________________
thats not normal. |
The Following User Says Thank You to Brandon Peterson For This Useful Post: | ||
Yasemin Vatandas (08-18-2008) |
#20
|
||||
|
||||
Brandon,
thank you for your answer. Actually I had tried the 'for-loop' approach at first. Since it didn't work, I started to look for alternative ways. Now I see that I wasn't wrong in trying the for-loop, since you too suggest me to do so The problem is that I haven't been able to make it work so far. Attached is a simple trial model. I can't see where my mistake is. |