bsh% for (i=0; i<14; i++) { |
||
Before |
After |
By definition, any expanded neighborhood of depth greater than 1 contains the original agent.
It is marginally more efficient to get the neighborhood of an agent by calling agent.getNeighborhood() instead of ExpandedNeighborhood(agent,1);
The following code sets all members of the 3-expanded neighborhood (using the Moore 8 neighborhood) of the agent at (50,50) to 5.
bsh% SetStrategies( ExpandedNeighborhood( GetAgent(50,50), 3), 5);
Before | After |
When combined with RandomSubset, this allows one to
introduce "blocks" of mutants at random locations in the network or lattice.
For
example, in a two-dimensional lattice where all individuals use the Moore
8 neighborhood, the following command selects 4 individuals at
random from the population and changes them, plus the squares surrounding
them in the lattice, to the strategy Demand 5.
bsh% SetStrategies( ExpandedNeighborhood( RandomSubset(population, 4), 2), 5);This could also be written (for greater clarity) as:
bsh% subset = RandomSubset(population, 4);
bsh% expanded_subset = ExpandedNeighborhood(subset, 2);
bsh% SetStrategies( expanded_subset, 5 );
Before | After |
This can be used to introduce a number of "mutations" into the population.
For example, suppose we have a 4--6 polymorphism of
divide-the-dollar. Then the following command introduces 3 mutants following
Demand 5 into the population:
bsh% SetStrategies( RandomSubset( population, 3 ), 5 );
bsh% SaveBitmap("/Users/jalex/bitmaps/foo.png");
The values of Array need not sum to 1, as the sum is normalized
before being used. This makes it convenient to specify
frequencies in terms of one strategy being twice as common as another and
six times as common as yet another.
The length of array must equal the number of strategies in the current model, otherwise an error occurs.
bsh% double[] array = {0.0, 0.0, 1.0, 0.5, 0.25, 4.0}
bsh% SetInitialConditions(array);
bsh% SetStrategy( GetAgent( 50 ), 5);
bsh% p = Partition(population, 3);
bsh% SetStrategies(p[0], 4);
bsh% SetStrategies(p[1], 5);
bsh% SetStrategues(p[2], 6);
bsh% FrontierCompetition( 3, 6 ); |
bsh% FrontierCompetition(3, 5, 0.25, 6); |
bsh% FrontierCompetition(3, 5, 6, 0.25); |
bsh% FrontierCompetition(4, 6, 0.2, 3, 7, 0.2); |