I am using various parts in the source in sequence along with shift calender and generators which i have to end by a method in the drain when the last part exits the drain.but i have a problem now.i dont know which part is going to be the last mu to exit hence i cannot write a method to terminate the eventcontroller.what could be the way to automatically find the last mu in the model and end the simulation???
Solved! Go to Solution.
its not working .There are 20 different parts with different name and class in source.i am using the method as
but instead of ending the simulation after last part.the model keep running forever
Where do you call the code?
The code you have written looks fine but it might be the condition is never true.
It could be that when the last MU enters the source (and triggers the method) that there are other MUs in the model which have not exited. Therefore when the last MU enters the source Frame.nummu > 1 and the event controller doesn't stop.
You could therefore put similar code in all of your objects and when it becomes true somewhere in the model the model will stop. However you will need to ensure that the code doesn't call when the first MU enters the system as the code would then stop the model before it got going.
Or you could just place the code in the drain(s) and the code should work fine but you wouldn't know where the MU was in the model when it became the last MU.
At the moment I can't think of a more elegant solution but someone here might come up with one. Have attached simple model showing the model stopping
You a probably aware of this but you can also use EventController.Stop which will stop the model straightaway instead of EventController.End
i am using workers in the models.are workers also counted in Nummu.when i check the MU by print command.it gives me 3 but there are no mus in the frame but only 3 workers.how can i deal with this??
Didn't know that workers counted as MUs myself. Makes sense as they are Moving units suppose
To solve your problem you should use Broker.MediatedCapacity in your code as this will get the numbers of workers the broker(s) has brokered.
Your if statement would therefore read:
If frame.numMu - Broker.MediatedCapacity = 1 then
If you have multiple brokers then you will need to add them to your code as well
You could also use the 'NumChildren' method of your MU classes to count the MUs in your simulation.
.MUs.Entitiy.NumChildren + .MUs.Container.NumChildren
the problem is i am using various container with different name and class and which container exits the drain last i cant predict .So in the method i cannot specify after whihc container the model has to stop.hence i was trying to find a way so that the model can identify the last Container in the frame irrespective of class.??
The method 'NumChildren' gives you the number of all the existing instances of your MU classes.
So if you create the sum of this value over all used MU classes you get the number of MUs still in your system.
(One important point is that there are no instances in other frames outside of your current simulation root.)