June 2012


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, 20 Jun 2012 13:34:34 -0500
text/plain (61 lines)
On Jun 20, 2012, at 12:41 PM, Joaquin Zabalo wrote:

> The idea is that while the predator (small disk) is inside the school (large
> disk), the number of fish in the school will decrease due to predation. In
> the visualization, I can represent this decrease in the number of fish
> either by making the large disk more transparent or by making the large disk
> shrink. However, the predator (small disk) needs to determine if it is
> inside one or more schools of prey (large disks) so that it can choose one
> at random and feed while inside the school. I am accomplishing this by
> obtaining a bag of all the schools in which the predator is closer to the
> center of the school than the radius of the school. For instance, if the
> school has diameter 6 (and hence radius 3), then the predator would have to
> be within 3 units from the center of the school in order to be inside the
> school. In the predatorís code I have:
> Bag bag = baysim.fishSpace.getObjectsExactlyWithinDistance(myNewLoc, 3);
> where myNewLoc  is the location of the predator and 3 is the radius of the
> school OvalPortrayal2D(6).


One other thing to note: you're using a grid space of 1.0.  This means that in the worst case your example above will search a 7x7 box of grid cells (49 in all) for fish.  That's 49 hash lookups.  If your school is bigger, say, a radius of 10, then you're looking at 441 hash lookups.

A hash lookup is expensive.  But on the other hand if your grid space is too big, you'll do one single hash lookup but it'll give you lots and lots of fish which aren't of interest to you.  So you may want to play with your grid spacing to find the magic optimal number.

> How can I display a disk whose size (width) represents the actual size of
> the school? Does a scale value of S=6 of the OvalPortrayal2D(6) mean that
> the displayed disk will have a width of 6 times the default width of
> OvalPortrayal2D()? If so, what is the default width if no scale value is
> set, as in OvalPortrayal2D()? Also, what is the additional offset in pixels O?

Let's assume that the you want a disk whose *area* is proportional to the size of the school.  Then since A = pi r^2,  the *radius* should be proportional to the sqrt(A/pi).  Since pi is a constant, you can take it out like this:

final double sqrt_pi = Math.sqrt(Math.PI);
public double radius(int numFish) { return Math.sqrt(numFish) * sqrt_pi; }

So that means you can do something like this:

final double sqrt_pi = Math.sqrt(Math.PI);
SimplePortrayal2D myPortrayal = new OvalPortrayal2D()
	double radius(int numFish) { return Math.sqrt(numFish) * sqrt_pi; }
	public void draw(Object object, Graphics2D graphics, DrawInfo2D info)
		School school = (School) object;
		scale = radius(school.getNumFish());
		super.draw(object, graphics, info);
	public boolean hitObject(Object object, DrawInfo2D range) 
		School school = (School) object;
		scale = radius(school.getNumFish());
		return hitObject(object, range);