On Oct 19, 2006, at 5:42 PM, Christopher Roach wrote:
> I am currently working on some research where I am trying to
> optimize the
> individual ants in Ant Colony Optimization algorithms using
> evolutionary
> computation techniques and I am using MASON as my simulation
> engine. The
> problem I am using for testing my algorithm is dynamic TSP and I am
> using the
> Network facilities in MASON to represent the TSP graph. The only
> problem with
> this is that even in a small graph--e.g., eil51 with 1275 edges--
> the number of
> edges are quite large and displaying them all in the simulation
> just adds up to
> a huge amount of noise. What I would like to be able to do is make
> all edges in
> the graph invisible with the exception of the edges that fall on
> the best path
> found so far. So, my question is: does anyone happen to know how
> to set the
> visibilty of the individual edges in the network?
You'll need to make a SimpleEdgePortrayal2D subclass which draws
itself (or doesn't) based on whether or not the edge has a given
feature. Presuming that the edges in your best path all have info
elements which indicate this, the SimpleEdgePortrayal2D can just look
up this fact in the edge it's handed to draw. Something like:
public MyPortrayal extends SimpleEdgePortrayal2D
{
public void draw(Object obj, Graphics2D graphics, DrawInfo2D info)
{
Edge e = (Edge)obj;
if (isOnBestPath(e)) super.draw(obj,graphics,inf);
}
public boolean hitObject(Object object, DrawInfo2D range)
{
Edge e = (Edge) object;
if (isOnBestPath(e)) super.hitObject(object, range);
}
}
> Also, in the future, I would like to have the best paths (plural)
> displayed with
> differing levels of intensity based on the amount of pheromone on
> each edge.
> So, if anyone knows of a way to also add a color map to the edges
> in the
> network, that would be really helpful as well.
Hmmm, well SimpleEdgePortrayal2D could be rewritten or subclassed so
that instead of setting the graphics to the color provided, it does
this:
Edge e = (Edge)obj;
if (e.info != null)
{
if (e.info instanceof Valuable)
{
double val = ((Valuable)(e.info)).doubleValue();
graphics.setColor(myColorMap.getColor(val));
}
else if (e.info instanceof Number)
{
double val = ((Number)(e.info)).doubleValue();
graphics.setColor(myColorMap.getColor(val));
}
else graphics.setColor(someDefaultColor);
}
Sean
|