tanaka zhou
tanaka zhou

Reputation: 1

How can we count agents in a statechart based on their fill color in AnyLogic?

I am modelling an Agent based model in AnyLogic. I am trying to count the number of agents in a statechart with similer fill color as the agents will be assigned different fill colors as they enter different states using the setFillColor() command. I have tried the command item.statechart.equals(Color.red) but its not bringing up any value

Upvotes: 0

Views: 196

Answers (2)

Jaco-Ben Vosloo
Jaco-Ben Vosloo

Reputation: 3975

I would suggest making use of a variable, even if it is a variable of type Color and rather count agents with the variable set to a specific color. It will be easier to count e.g agents.stream().filter(e -> colorVariable.equals(blue)).count()

but you can also do this with the rectangle

agents.stream().filter(e -> e.rectangle.getFillColor().equals(blue)).count()

Upvotes: 1

Benjamin
Benjamin

Reputation: 12605

It depends on what element you fill the color with. If you have a rectangle in an and call rectangle.setFillColor(blue), then you can count all agents using item.rectangle.getFillColor().equals(blue)

Note that you cannot count by the color of statechart states. For that, you can (and should) check if an agent is in a given state using item.statechart.isStateActive(someState)

Upvotes: 0

Related Questions