statechart | Statechart implementation in JavaScript
kandi X-RAY | statechart Summary
kandi X-RAY | statechart Summary
Statechart implementation in JavaScript
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of statechart
statechart Key Features
statechart Examples and Code Snippets
Community Discussions
Trending Discussions on statechart
QUESTION
In my model, I have some agents;
"Demand" agent,
"EnergyProducer1" agent
"EnergyProducer2" agent.
When my hourly energy demands are created in the Main agent with a function, the priority for satisfying this demand is belongs to "EnergyProducer1" agent. In this agent, I have a function that calculate energy production based on some situtations. The some part of the inside of this function is following;
**" if (statechartA.isStateActive(Operating.busy)) && ( main.heatLoadDemandPerHour >= heatPowerNominal) { producedHeatPower = heatPowerNominal;
naturalGasConsumptionA = naturalGasConsumptionNominal;
send("boilerWorking",boiler);
} else ..... "**
Here my question is related to 4th line of the code. If my agent1 fails to satisfy the hourly demand, I have to say agent2 that " to satisfy rest of demand". If I send this message to agent2, its statechart will be active and the function of agent2 will be working. My question is that this all situations will be realized at the same hour ??? İf it is not, is accessing variables and parameters of other agent2 more appropiaote way???
I hope I could explain my problem. thanks for your help in advance...
**Edited question...
...ANSWER
Answered 2021-May-18 at 10:50As a general comment on your question, within AnyLogic environment sending messages is alway preferable to directly accessing variable and parameters of another agent.
Specifically in the example presented the send()
function will schedule message delivery the next instance after the completion of the current function.
Update: A message in AnyLogic can be any Java class. Sending strings such as "boilerWorking" used in the example is good for general control, however if more information needs to be shared (such as a double value) then it is good practice to create a new Java class (let's call is ModelMessage and follow these instructions) with at least two properties msgStr and msgVal. With this new class sending a message changes from this:
QUESTION
I have 2 statecharts, one being the parent and the other being the child. When the parent statechart is created, it also creates a child statechart using
...ANSWER
Answered 2021-May-14 at 09:51There are basically two approaches.
The first approach is to define an explicit reference from the child statechart to the parent. Like you did for the parent.
QUESTION
I use a software (AnyLogic) to export runnable jar files that themselves repeated re-run a set of simulations with different parameters (so-called parameter variation experiments). The simulations I'm running have very RAM intensive, so I have to limit the number of cores available to the jar file. In AnyLogic, the number of available cores is easily set, but from the Linux command line on the servers, the only way I know how to do this is by using the taskset
command to just manually specify the available cores to use (using a CPU affinity "mask"). This has worked very well so far, but since you have to specify individual cores to use, I'm learning that there can be pretty substantial differences in performance depending on which cores you select. For example, you would want to maximize the use of CPU cache levels, so if you choose cores that share too much cache, you'll get much slower performance.
Since AnyLogic is written in Java, I can use Java code to specify the running of simulations. I'm looking at using the Java ExecutorService to build a pool of individual runs such that I can just specify the size of the pool to be whatever number of cores would match the RAM of the machine I'm using. I'm thinking that this would offer a number of benefits, most importantly perhaps the computer's scehduler can do a better job of selecting the cores to minimize runtime.
In my tests, I built a small AnyLogic model that take about 10 seconds to run (it just switches between 2 statechart states repeatedly). Then I created a custom experiment with this simple code.
...ANSWER
Answered 2021-Apr-25 at 16:04I'm guessing Simulation
extends from ExperimentParamVariation. The key to achieve what you want would be to determine when the experiment has ended.
The documentation shows some interesting methods like getProgress() and getState(), but you would have to poll those methods until the progress is 1
or the state is FINISHED
or ERROR
. There are also the methods onAfterExperiment() and onError() that should be called by the engine to indicate that the experiment has ended or there was an error. I think you could use these last two methods with a Semaphore to control how many experiments run at once:
QUESTION
I am currently working on a simulation model of a battery swapping station.
So, In my model I have declared charger as an agent type with its own parameter and a flow diagram and the "main" has 2 flow diagrams (total 3).
I have 2 sets of enter and exit blocks, one of them is for sending the fully charged battery from "main flow diagram" to "Charger flow diagram" and the other set sends a discharged battery from the "charger flow diagram" to the "main flow diagram".
I have added 5 charger agents in my main flow diagram with name Spot_1, Spot_2...., I want to access these enter-exit blocks of both main and charger. Initially I tried to access them in the main diagram only , but was unsuccessful(Syntax: Spot_1.enter.take(this)). Then I constructed a statechart in the "Car" agent type and tried to access these blocks from there but was not able to do so.
current syntax that are showing error:
main.Old_Battery_In.take(this);
main.Check_for_Availability.isBlocked() == false ;
main.Spot_1.New_Battery_In.take (this);
I am also adding an image that has the statechart and the codeenter image description here
Old_Battery_In is an enter block in main, Check_for_Availability is a hold block in main, New_Battery_In is an enter block in charger
Please, can anyone suggest a solution
...ANSWER
Answered 2021-Apr-21 at 16:43To be able to access a block in main from an Agent Type, you need to have a population of that type in main, even if empty. Drag and drop the "Agent" element from the Agent palette to main, choose the type that is trying to access main and make it initially empty. After that, if you run again, main should become accessible.
QUESTION
I have a Pedestrian agent which has two states: Healthy and Injured. I have connected this statechart to the Ped flow chart. When Ped goes to the injured state, it needs to deleteSelf()
and a new agent should be addded to the ped population. This population has one ped when its injured a new ped comes to the model.
However, I realized that I can not use deleteSelf()
in the injured state while ped is in a block in the flowchart. Instead of that I used cancel(this)
in the injured state; for all the blocks that ped might be there when injured. For example;
ANSWER
Answered 2021-Mar-02 at 15:10deleteSelf
is really a low-level internal function that you shouldn't typically need to explicitly call yourself. It just removes them from their population and has no 'synchronisation' with the process flow (i.e., it doesn't also remove them from the process flow); all process flows expect the agents therein to exist in a population throughout their process lifecycle, hence you get the error you mentioned if you try to remove them from their population whilst they're in a flow.
In general for process flows, you should delete agents in one via the standard mechanism for all process flows: flowing into a sink block. (And use exit blocks if you want them to leave the flow but remain in existence.)
In the Pedestrian library case, use the built-in cancel ports (as you were attempting) and send them to a PedSink block from these ports.
(If you had other possible reasons to cancel peds from blocks that's fine; you just have conditional logic in the cancel flow to do whatever is needed depending on why you had to cancel them, which might mean storing the cancellation reason in the ped agent...)
AnyLogic libraries also allow you to remove agents from the process using the remove
function of blocks, which I think exists for all blocks in all libraries that an agent could spend time in (and thus it make sense to remove them from). But then, if you want to delete them, you have to handle that part explicitly yourself:
If the pedestrians had been added to the (hidden) default population via a
PedSource
block, then here you would have to usedeleteSelf
.If the pedestrians had been added to the process via a
PedEnter
, or thePedSource
had been set to add them to a custom population (which is a common thing to do so your ped agents exist in a single named population), you'd delete them via the standardremove_
function created by AnyLogic when you define a population --- see the AnyLogic Help > Agent Based Modeling > Adding and removing agents from population dynamically help page.
Note that using a sink block also visually represent the 'remove and delete' possibility (and logic) in the process flow which is better IMO.
NB: Having said this, only the Pedestrian library has this special universal cancel-from-blocks-into-a-special-visual-flow mechanism so, when using process flows from other libraries (e.g., the standard Process Modeling Library), it may be more convenient to use remove
if the need to remove them (and delete them or not) is determined by logic outside the process flow (such as in agent statecharts).
QUESTION
I want to calculate the distance between two agents or between the two points of the agents using the network paths.
I tried getDistance(Point source, Point target, ShortestPathData data)
-> getDistance(Point(vx,vy), Point(a.getX(),a.getY()), d);
with double d = 0.0;
, vx = a.getX()
and vy = a.getY()
. vx and vy are the coordinates of the second agent. The agents are from the same type, let's call it type one. I typed the code in the statechart of the agent type two.
=> Problem-description: The method Point (double, double) is undefined for type two.
How do I solve this problem? Or is there another function i could use ?
ANSWER
Answered 2021-Feb-02 at 13:53This is doable using the function you are trying to use, but that function is effectively complex internal (undocumented) AnyLogic code relating to how agents move across networks 'under the covers' (when asked to do so via blocks or moveTo
function calls). I wouldn't want to guarantee that this will stay the same in future releases (and requires a good understanding of Java).
(Agents in GIS space have a distanceByRoute
function to get the distance via the GIS space to another agent, but there is no equivalent for agents in networks I am aware of. Typically, though, you don't need to use the distance-by-path, so what exactly is your reason for needing it? Even where you do, it may often be good enough just to use the straight-line distance, which you can get via the getDistance
functions in agents, not the getDistance
functions for a network.)
That said, this can work as below...
The getDistance
function (Java method) you are trying to call only exists on a Network
object (where the network is the 'parent' of all the nodes and paths in a connected network). Plus you have to create (instantiate) Point
objects (there is no Point
function) and get the ShortestPathData
for the network and from/to points in question. (This shortest-path-data represents the calculated route between two points, and you can then get the distance between any set of points on that route.)
So you'd have code something like the below, where agent1
and agent2
are references to your two agents in question, and network
is the nodes/paths network (assuming this code is in the agent that contains this network):
QUESTION
I am modeling order picking in anylogic: At the moment I create a population of agents and give them to the enter-block via an event. This block is connected with a rackstore block and puts the agents in the racksystem. In a statechart of a person (when the person arrives at the agent location), the agent is taken and put into another enterblock, which is just connected with a sink -> the agent is removed from the racksystem.
Problem: If I want to store agents in the racksystem again, the cells (where agents where before) are occupied. I think the reservation of the cell is not discarded. How can I solve the problem?
Or: Is there a better solution to store and/or remove the agents ? Maybe without using flowcharts at all?
...ANSWER
Answered 2021-Jan-05 at 23:53Unless you're removing agents in racks via a RackPick
block, you aren't actually removing them from the rack system (even if the agent is moving 'past' the RackStore
block in the process flow). So your process would need to be something like:
- There is a
Wait
block following theRackStore
(which holds them in the process until required). - When the "person arrives at the agent location" (your trigger for removing the agent from the rack, though it's not clear what this means --- what is the "agent location" since it's in a rack?), you
free
them from theWait
block. - The
Wait
block is followed by aRackPick
block which will remove them from the rack. - The removed agent carries on in whatever the follow-on flow is (which might just be a
Sink
in your case).
NB: Also, part of the functionality of RackStore
and RackPick
blocks is to use resource agents to move to the rack and deposit/retrieve the agent, so it's likely you don't need a "person agent" to be explicitly moving to the agent location (outside of these blocks), though that depends on the exact specification of what you want your model to do.
QUESTION
I am digging deeper into Agent Inheritance and I am still at the exploration level so my question will not be specific to an example but rather conceptual.
My objective is to create a model with an Agent Type called Machine. However, there will be different types of Machines and some may have different statecharts or different parameters. So, initially I thought it would be a good idea to create an Agent Type called Machine and then, using Agent inheritance, create Agent Types that extend from it (e.g. Machine 1, Machine 2, etc.).
The result is that if I have one machine of each type, the Machine Agent Type population will be empty, while Machine 1 and Machine 2 each will have a population of 1. I understand AnyLogic is designed that way, but ideally, I would like to see the population of the Machine Agent Type with a population of 2, one of type Machine 1 and the other of type Machine 2.
Agent inheritance might not be the answer, but I was hoping I could find a solution to this problem where I can have one main population with different sub-types.
You may ask why would that be needed. The answer is that all machines should have a similar behavior. Comparing this to DES, it's like having different Resources. All will have similar behavior (e.g. can be seize, released, attached, etc.) but each can be unique.
Your thoughts/suggestions would be appreciated.
Thanks!
...ANSWER
Answered 2021-Jan-04 at 15:53If you want to use agent inheritance, then you would need to have 2 different populations. A population of type Machine will have agents of type Machine, not their child agent types. I typically deal with this by having the populations for the child agents, and then storing all agents in a list (i.e., array list - allMachines).
You mention different state charts, which is a good reason to use inheritance. Many people will try to inherit because one delay block takes X minutes, while another is Y. In those cases, just parametrize your one agent type. If the logical differences between these machines is small, I would consider just 1 class, with a few extra decides/branches to get the behavior you want. It can sometimes be tricky in AL to have process blocks/visual elements in a parent connect to areas in a child - not impossible, but not as easy as pure Java code where you can override and call super.function().
QUESTION
In a model I have two agent populations: OriginalAgent
and CopiedAgent
. They are different agent types. Each CopiedAgent
is copied from a OrginalAgent
, and they share the same values for p_id
.
What I want to achieve is to remove an instance of CopiedAgent
once OriginalAgent
enters a final state in its statechart.
I have created a function myfunction
that is called in the Action
field of the final state in the statechart of OriginalAgent
. The function errors when called, but it shows what I've tried:
ANSWER
Answered 2020-Nov-26 at 10:29try this maybe?
QUESTION
I am building a DES-ABM hybrid model in AnyLogic. The agents go through the DES blocks, among which multiple Delay blocks.
How do I
- access an agent which is in a Delay block or peferrably
- acces the specific agent which triggered the 'on enter' action of the delay block?
My ultimate goal is to open or close a valve object on the agent frame So can I/ how do I A. open or close the valve on the agent frame directly form the main/root frame (on which the Delay block is located) or if that is not possible B. send a message or trigger a statechart within the specific agent which will then open or close the valve from the agent's own frame?
I have tried to use the 'DelayBlockName'.agents() function, but this does not work and returns [] when I check it using traceln.
...ANSWER
Answered 2020-Nov-04 at 17:51access an agent which is in a Delay block or peferrably
use the keyword agent
. These keywords differ for different library blocks so best start learning about the lightbulb and how it can help, see here.
acces the specific agent which triggered the 'on enter' action of the delay block?
When you write agent.
in the "On enter" block, every agent coming through will execute that code, so by definition, it is always the specific agent :)
My ultimate goal is to open or close a valve object on the agent frame So can I/ how do I A. open or close the valve on the agent frame directly form the main/root frame (on which the Delay block is located) or if that is not possible B. send a message or trigger a statechart within the specific agent which will then open or close the valve from the agent's own frame?
this is something completely different to your original question and just... messy. Please limit questions to 1 topic so it is easy for us to answer :) (see this guide for more)
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install statechart
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page