geopro:pedro:mason
Essa é uma revisão anterior do documento!
Mason
MASON (Multi-Agent Simulator Of Neighborhoods… or Networks… or something…) is a fast discrete-event multiagent simulation library core in Java, designed to be the foundation for large custom-purpose Java simulations, and also to provide more than enough functionality for many lightweight simulation needs.
| Homepage | http://cs.gmu.edu/%7Eeclab/projects/mason/ |
|---|---|
| Origin | George Mason University |
| Year | 2003 |
| Version | 11 |
| License | Academic Free License |
| Language | Java |
It has an example of Schelling's model in /home/pedro/codigo/mason/sim/app/schelling/Agent.java. The model is composed by reds, blues, empty sites where the players can move, and non-available sites. Following there is an example of calculating the unsatisfaction and moving to another site:
// get all the places I can go. This will be slow as we have to rely on grabbing neighbors.
sch.neighbors.getNeighborsMaxDistance(loc.x,loc.y,sch.neighborhood,false,neighborsX,neighborsY);
// compute value
double val = 0;
int threshold = sch.threshold; // locals a little faster
int numObjs = neighborsX.numObjs;
int[] objsX = neighborsX.objs;
int[] objsY = neighborsY.objs;
int myVal = locs[x][y];
for(int i=0;i<numObjs;i++)
{
if (locs[objsX[i]][objsY[i]] == myVal // just like me
&& !(objsX[i] == x && objsY[i] == y)) // but it's NOT me
{
val += 1.0/Math.sqrt((x-objsX[i])*(x-objsX[i]) + (y-objsY[i])*(y-objsY[i]));
if (val >= threshold) return; // we're not moving
}
}
// find a new spot to live -- a random jump? Move to a nearby location? Websites differ
int newLocIndex = state.random.nextInt(sch.emptySpaces.numObjs);
Int2D newLoc = (Int2D)(sch.emptySpaces.objs[newLocIndex]);
sch.emptySpaces.objs[newLocIndex] = loc;
// swap colors
int swap = locs[newLoc.x][newLoc.y];
locs[newLoc.x][newLoc.y] = locs[loc.x][loc.y];
locs[loc.x][loc.y] = swap;
// adopt new position
loc = newLoc;
geopro/pedro/mason.1184030762.txt.gz · Última modificação: 2007/07/10 01:26 por pedro
