Release resources when a resource is destroyed in Anylogic - anylogic

The current model I am working on involves equipments seizing resources (materials, operators) to perform taskings within the equipment. During the model run, the number of equipment (a resource as well) will be varied using a slider. Upon reduction of the resourcepool quantity, excess equipments will be destroyed. How do I release all the resources that are still seized by this equipment after it is destroyed so that the resources can continue to be utilised by the rest of the model?

As far as I know when you reduce the number of resource units in a resource pool they will only be destroyed once the current agents that are seizing them have released them. Thus you don't need to worry about releasing all the resources that are still seized by this equipment.

This looks like a design problem, but you don't really explain how your flows are linked (or when your equipment agents enter the top flow).
Your information suggests that your equipment agents go through the top flow (seizing materials and operators); your bottom flow is presumably triggered after an 'EQ run' to simulate operators doing something at the machine before unload can start/complete(?) by releasing the Hold in the top flow.
The problem is that you should never have resources (i.e., agents that are part of a resource pool) flowing through processes; agents are either flow-through-processes agents or resource agents. Changing resource pool sizes will do nothing to affect those agents if they're in a process flow because AnyLogic is only concerned about tasks those resources are doing as resources.
In your case, it depends what 'removing the machine' represents in real-life (given the machine is potentially processing things at the time). That will determine what 'sub-flow' you need to enact in that case to free resources, etc. This is likely to mean in your case:
Have some trigger (e.g., event, schedule action, button action, some specific state elsewhere in your model) which means an equipment is now 'removed'.
This then needs code to know what block that equipment is currently in (agents have a currentBlock function for this purpose), remove it from that block (typically using the remove function provided by most blocks, but this is not consistent across all blocks) and then probably send it into a 'clean-up' process flow (using an Enter block, with a Sink block at the end to delete it) to do whatever needs doing (like releasing all resources).
Some of the code needed here is slightly complex (removing agents from within a process flow is not something 'cleanly' supported by AnyLogic except in the Pedestrian library) and will involve casting (since currentBlock returns you the block as a generic FlowchartBlock supertype).
P.S. A more 'radical' design rework (but probably a better one for what you want) is to keep equipments as resource agents but redesign your top flow so that the agent represents, say, a 'request for machine processing (of something)'. Your top flow will then be seizing/releasing equipment resources along with everything else, and you can use dynamic resource pool capacity changes as you were trying to. (It is quite common in process modelling to need to 'reframe' the processes via agents which represent some abstract 'request', rather than a physical thing.)

Related

Anylogic forklift collision logging

I need to measure the time forklift spends in collision, however movement_log
for agent type that is a forklift managed by transporter, fleet is not available. I also can not use statecharts because it uses much performance.
Situation: I am simulating a warehouse with one-way aisles and the capacity of these one-way aisles is 2 vehicles. There are situations
where a forklift (the yellow one) needs to wait behind another one in one-way aisle, I currently have that modeled properly I just don't know how to detect this situation and log it.
Thank you
I would do it as following:
Create a new 2-dimensional variable called collisionLog.
Check the speed [getSpeed() function] and state [TransporterState getState() function] every 1 second.
Write these into the collisionLog.
Once the simulation is completed, remove the rows with idle status.
Then do the calculations based on the fact that when speed is zero and transporter is busy, then you have the waiting vehicle.
There is no accessible trigger point (typically an action of a block) to trap when transporters have collisions. Yes, that situation obviously has to be captured internally to enable the transporters to avoid collisions, but in this situation that is not exposed as a block action, or action anywhere else. (AnyLogic space markup elements never have actions, except for some of the newer Material Handling library ones like Station, because these effectively represent a process step.)
The Transporter Control block has all the settings for collision detection and avoidance, but no related actions.
So your alternatives are really
'Scan' for this situation occurring: Yashar's answer, inferring that zero speed when non-idle means 'waiting due to collision' (which may or may not be 100% robust) being one way.
Explicitly break down the movement (from the process perspective) to define the potential 'conflicts' and decision-making within the process flow (e.g., if you're trying to move to an aisle, move to an entrance node, reserve a space in the aisle using resource pools or similar, and only enter when free). Clearly that doesn't cover every possible case, but may be useful in some situations.
The actions that do exist in the Transporter Control block could help a bit here (for both alternatives) since at least you have action points on entering paths and nodes. (You could also raise an enhancement request with AnyLogic to add collision-related actions here....)
I have a huge model with large number of forklifts, checking any attribute every second would result in huge performance loss
I also can not use statecharts because it uses much performance
Have you actually tried it though? Some things do not result in as much of a performance hit as you might think, and performance should not be an a priori 'that will be too slow' thing; ideally you have requirements for acceptable performance and you work round that. (There are always trade-offs between performance, functionality and maintainability.)
[You also don't say how you think using statecharts could have helped. Did you mean doing the 'scanning' approach via a statechart, say with cyclic entry/exit from a Scan state?]

Method to create a list of taskings for resource to work on when resource becomes idle

Image to illustrate point of freezing Context:
Creating a scalable model for a production line to increase Man Machine Optimization ratio. Will be scaling the model for an operator (resource) to work on multiple machines (of the same type). During the process flow at a machine, the operator will be seized and released multiple times for different taskings.
Problem:
Entire process freezes when the operator is being seized at multiple seize blocks concurrently.
Thoughts:
Is there a way to create a list where taskings are added in the event the resource is currently seized. Resource will then work on the list of taskings whenever it becomes idle. Any other methods to resolve this issue is also appreciated!
If this is going to become a complex model, you may want to consider using a pure agent-based approach.
Your resource has a LinkedList of JobRequest agents that are created and send by the machines when necessary. They are sorted by some priority.
The resource then simply does one JobRequest after the next.
No ResourcePools or Seieze elements required.
This is often the more powerful and flexible approach as you are not bound to the process blocks anymore. But obviously, it needs good control and testing from you :)
Problem: Entire process freezes when the operator is being
seized at multiple seize blocks concurrently.
You need to explain your problem better: it is not possible to "seize the same operator at multiple seize blocks concurrently" (unless you are using a resource choice condition or similar to try to 'force' seizing of a particular resource --- even then, this is more accurately framed as 'I've set up resource choice conditions which mean I end up having no valid resources available').
What does your model "freezing" represent? For example, it could just be a natural consequence of having no resources available, especially if you have long delay times or are using Delay blocks with "Until stopDelay() is called" set --- i.e., you are relying on events elsewhere in your model to free agents (and seized resources) from blocks, which an incorrect model design might mean never happen in some circumstances. (If your model is "freezing" because of no resources being available, it should 'unfreeze' when one does.)
During the process flow at a machine, the operator will be
seized and released multiple times for different taskings.
You can just do this bit by breaking down the actions at a machine into a number of Seize/Delay/Release actions with different characteristics (or a process flow that loops around a set of these driven by some data if you want it to be more flexible / data-driven).

How is the state of a BPMN process defined?

Assuming a BPMN process describing activities, gateways, start and end events. As follow:
Each step is managed by a BPMN engine. At one point, how can we tell which is the state of the process ? Activities seem to define some state embodied as actions (e.g. evaluating request). Am I correct ?
Also, if we assume activity represents the state, how do we get a listing of next possible states if we were to navigate through a dedicated follow-up application ?
Should the process be modeled in a more workflow oriented way to express those state/actions possibilities ? I have the intuition that events could also be used to manage states and possible related actions.
Since I am not sure what exactly you understand as state of the process, I will try to define that first. I guess you are aware of the token concept, see a discussion in the Camunda forum:
A token is a BPMN concept that represents a state within a process instance. It does not have any variables or any message.
You may now define the state of the process as a statistics how many tokens at a given time are existing, and how many are currently in a given activity or event.
This statistics can be extracted from your favorite BPMN engine (and seen e.g. in Camunda's Cockpit as little colorful bubbles). With that statistics in hand, you could in principle generate forecast on next possible states, i.e. determine scenarios how many tokens will be in the next time instance probably in each activity.
State has a different meaning in BPMN, it could mean:
1 - Where is the token in the flow?
2 - Is the process flow running correctly or not?
3 - Or, by a specific variable (field) in the forms.
If you mean the third case, which is common in processes, you have to define a field in your data model as enum (depends on the engine) and manually or automatically change its value in the forms.
Obviously, the rather abstract Petri-Net-style token flow semantics of BPMN does not capture the real semantics of business processes. It has just been artificially imposed on BPMN due to academic pressure groups. A really meaningful semantics must refer to the information context of a process in the business system that owns it.
Of course, a business system that is the owner of a process (type), is, at any point during a running process, in a certain complex dynamic information state, some part of which forms the context of the process and can therefore be considered its state.
In fact, the (information) state of a process is essentially given by all the property-value slots of objects that are used or affected by (events/activities of) the process. In addition to these "global variables", the state of a process also includes
the values of (auxiliary) process variables,
the information, which activities have been started (and are ongoing).
Take a look into the Imixs-Workflow project. It is a event orientated workflow engine instead of the task orientated design often seen in BPM engines.
Each task in this kind of workflow engine defines a state in your process model. The workflow engine holds this state until a event is fired. An event defines the transition from one state to another.
You can find examples how to model different szenarious in a event driven workflow model here.

Moving agents with other agents using Pickup/Dropoff from PML in Anylogic without duplicate code

Info: The question was updated with more explanation
I want to transport a agent (e.g. bananas) with a moving agent (e.g. truck) from place A to place B, where, for example, place A is where the bananas where plucked and place B is some storage for the bananas. So the bananas are simply being transported by the truck. Especially, the agent to be moved (the bananas) are not a resource (in the sense of Anylogic PLM) and have no upper amount limit.
There are various ways to solve this problem, but most of them either require some element in the model that I don't need or want (for example, a rack/pallet system in the case of the block 'Rack Store') or require the agents to be Anylogic resources.
As described in this answer, it kinda makes sense to use pickup and dropoff for this task. The problem is that the agent to be moved is not being transported, so that answer does not solve my question. To explain further, when the agent to be moved (the bananas) are being dropped off at the target location (place B), they simply re-appear at their original location (place A), even though the truck which picked them up via the pickup block has moved to place B.
I made a minimal example of this here.
As I described, the 'transportation' only works if I add the separate 'moveTo1' block for the dropped off agents.
Is there any simple and obvious way to handle this rather simple task of transportation in Anylogic without having multiple move blocks or other workarounds? I know there is 'ResourceAttach', but that requires the agent to be moved to be resources, and there is 'RackStore', which requires a rack/pallet system, which I don't need or want in my model.
What I want to know is what the 'standard' Anylogic way would be to do this.
Thanks a lot in advance!
Now I understand what your problem is...
When you use dropoff, the block that comes after it needs to define the new location of the agents, otherwise they stay in the same place.. You can use the moveTo block with a jump so the agents are teleported to the location you want them to be:
In almost all the blocks of the PML you can define the agent location in the properties, and this is a case where using that property is necessary.
You can set the position of the bananas to the position of the truck.
e.g. using agent.setXY(container.getX(), container.getY()) in the "On dropoff" field.
It seems to work for a simple test model.

How to represent part of BPMN workflow that is automated by system?

I am documenting a user workflow where part of the flow is automated by a system (e.g. if the order quantity is less than 10 then approve the order immediately rather than sending it to a staff for review).
I have swim lanes that goes from people to people but not sure where I can fit this system task/decision path. What's the best practice? Possibly a dumb idea but I'm inclined to create a new swim lane and call it the "system".
Any thoughts?
The approach of detaching system task into separate lane is quite possible as BPMN 2.0 specification does not explicitly specify meaning of lanes and says something like that:
Lanes are used to organize and categorize Activities within a Pool.
The meaning of the Lanes is up to the modeler. BPMN does not specify
the usage of Lanes. Lanes are often used for such things as internal
roles (e.g., Manager, Associate), systems (e.g., an enterprise
application), an internal department (e.g., shipping, finance), etc.
So you are completely free to fill them with everything you want. However, your case is quite evident and doesn't require such separation at all. According to your description we have typical conditional activity which can be expressed via Service task or Sub-process. These are 2 different approaches and they hold different semantics.
According to BPMN specification Service Task is a task that uses some sort of service, which could be a Web service or an automated application. I.e it is usually used when modeller don't want to decompose some process and is intended to outsource it to some external tool or agent.
Another cup of tea is Sub-process, which is typically used when you
want to wrap some complex piece of workflow for reuse or if that
piece of workflow can be decomposed into sub-elements.
In your use case sub-process is a thing of choice. It is highly adjustable, transparent and maintainable. For example, inside sub-process you can use Business Rules Engine for your condition parameter (Order Quantity) and flexibly adjust its value on-the-fly.
In greater detail you can learn the difference of these approcahes from this blog.
There is a technique of expressing system tasks/decisions via dedicated participant/lane. Then all system tasks are collocated on a system lane.
System tasks (service tasks in BPMN) are usually done on behalf of an actor, so in my opinion it is useful to position them in the lane for that actor.
Usually such design also help to keep the diagram easy to read by limiting the number of transition between "users" lanes and "system" lane.