aochagavia
aochagavia

Reputation: 6246

Sub-breeds in NetLogo

I am new to NetLogo and I have some questions about the following piece of code:

people-own [
  walker-type   ;; can be "cautious", "adaptive" or "reckless"
  walked-through-red?
  own-profit
  adaptive-threshold-time-gained
  adaptive-threshold-time-gained-people-crossing
  adaptive-gone-reckless
  cooldown
]

With an OO background, I see this as some kind of enumeration of the properties of an object (the people breed). You can clearly see that there are three types of people: cautious walkers, adaptive walkers and reckless walkers. Also, the properties beginning with adaptive (adaptive-threshold-time-gained and such) have only meaning when the current person is adaptive.

I would expect that there is some way to express this more elegantly. In an OO programming language you would use inheritance to create three subclasses (one for each walker-type), but for so far I know that doesn't exist in NetLogo.

What is the recommended way of expressing this?

Upvotes: 4

Views: 842

Answers (1)

Alan
Alan

Reputation: 9620

Lack of inheritance (perhaps as sub-breeds) is a serious limitation of NetLogo, although in the end it has only occasionally mattered to me. There are a couple possible work-arounds, depending on the application.

  1. If you just want some different data attributes, and the related types are the only turtles in the simulation, you can have turtles-own the common characteristics and have breeds-own only the type specific characteristics.

  2. If the data attributes are all shared but the behavior differs, you can create your own agentsets (in your case, subsets of people) and call different procedures on each agent set (or write procedures that branch on a member? test). Unfortunately, these agentsets will have to be explicitly augmented if any new members are created, so you lose that nice "special agentset" feature of breeds.

hth.

Upvotes: 5

Related Questions