July 2015


Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Sean Luke <[log in to unmask]>
Reply To:
MASON Multiagent Simulation Toolkit <[log in to unmask]>
Wed, 22 Jul 2015 10:16:59 +0200
text/plain (30 lines)
On Jul 21, 2015, at 3:44 PM, Tschanen Miriam <[log in to unmask]> wrote:

> While digging through the NetwortPortrayal2D code I noticed something strange. I found this line in the hitOrDraw method:
> if (edgemap.containsKey(edge)) continue;
> edgemap.put(edge, edge);
> I cannot for the live of me imagine why anyone would add an object to a HashMap as both key and value. Why not just use a set? Is this an oversight, or am I missing something crucial here?

Nope, it's just being used as a set.

> Also, my graph is static and does not change at all during the simulation, so there would be no reason to redraw it at every time step. I found a flag called immutableField in the FieldPortrayal class, is setting this value to true enough to prevent redrawing? Or is there something else I need to do?

No. immutableField just informs the FieldPortrayal that the field will never be changing (as is the case for you), and so the FieldPortrayal can *cache* its drawing and just re-draw the cache rather than rebuild it, if that's useful.

What you're looking for is some kind of flag that tells a FieldPortrayal to only redraw itself when (say) the window is resized or scrolled or scaled, but NOT when the timestep is updated. Unfortunately this isn't feasible, but not for the reason you think. It's because the display doesn't know if there are *multiple* FieldPortrayals stacked on top of one another, so perhaps the window has been wiped and the FieldPortrayal *must* redraw.

If you'd like to be fast, I suggest that you cache your drawing into an image an re-draw that unless the FieldPortrayal has been declared dirty, at which time you redraw into the image again.

If you absolutely know that you'll only have *one* FieldPortrayal in the display, maybe I can suggest an approach to hack something up in the Display2D to not redraw on a step().

> And finally, I would like to highlight certain edges during the simulation, e.g. the shortest path between two nodes for any pair of nodes selected by the user. What would be the easiest way to implement the highlighting? I'm not looking for a complete example, just some pointers to get me started. Can this be done without redrawing the entire graph?

You'll probably have to redraw the whole graph unless you hack something. Highlighting is probably most easily done by making a custom subclass of EdgePortrayal2D which checks to see if the underlying edge is one which you want highlighted.

Another approach is to create a SECOND NetworkPortrayal2D, overlaid on top of the first one, which has a custom subclass of EdgePortrayal2D that either draws (in a custom color) or doesn't draw at all, depending on whether the underlying edge is the one you want highlighted. The advantage of this method is that you can use your immutableField flag to cache the underlying EdgePortrayal2D and it might be faster that way.