Print

Print


Annetta:

Nothing stands out as obvious why that code wouldn't work, but there's a
lot of context missing and I'm assuming that the values such as 'sickHigh'
are defined elsewhere. Do you have the project on Github or another
location?

Also, that 'else return' statement will never trigger... but if you are
really worried about performance, you might want to just look at mapping
the the range of values to an array and then just bound checking as needed.
Returning the value from the array is always going to be faster than any
sort of conditional logic. However, typically the rule of thumb is to avoid
premature optimization of the code in general - readable code in models is
always preferable when it comes to peer review.

Regards,
Robert Zupko

On Wed, Jan 16, 2019 at 4:34 PM Annetta Burger <[log in to unmask]> wrote:

> I checked and confirmed that my agents are not getting replaced by
> different agents on each timestep.
>
> I don’t think my geomPortrayal is causing this, but I’m including the code
> here:
>     public class agentGeomPortrayal extends GeomPortrayal {
>
>                 public Paint determineColor(Object object) {
>                         // determines color by healthstatus of the agent
>
>                         int hColor = (int)
> (((MasonGeometry)object).getUserData());
>                         //
> System.out.println("determineColor>healthstatus: " + hColor);
>                         if (hColor < 2)                 { return healthy;
> } // assume healthy first...to reduce computation
>                         else if (hColor >= 10)  {return dead; }
>                         else if (hColor >= 8)   { return lethal; }
>                         else if (hColor >= 6)   { return sickHigh; }
>                         else if (hColor >= 4)   { return sickMed; }
>                         else if (hColor >= 2)   { return sickLow; }
>                         else return healthy; // default to healthy
>                 }
>
>                 public void draw (Object object, Graphics2D graphics,
> DrawInfo2D info) {
>                         scale = 0.0003; // set scale of the portrayal
>                         paint = determineColor(object);
>                         super.draw(object, graphics, info);
>                 }
>     }
>
> I've also now tested different versions of the
> getSimulationInspectedObject() method, and it doesn't appear to be called
> when I doubleclick on an agent object in the GUI window. The Inspectors
> window remains blank.
>
> Any suggestions for why the method may be failing?
>
> Thanks,
> Annetta
>