Banner
Final Project


Mate Choice: Mobile Agents

Spring 2012

Psychology 120


We have all of the ingredients to create mobile agents that search for mates.  The only problem is how to do it.  Let’s verbally describe one possible scenario.  If you check a box labeled “mobileAgents”, then male and female agents search for each other by moving in the various ways we have already programmed (i.e., random movement, aggregation, or flocking).  They would have a mate search radius. So, at each time step, each agent in random order would get a bag of agents in its mate search radius and sort out either the males or females, which ever is its preferred sex. From the bag of agents, all of the same sex, it selects a possible mate. There are at least two ways this could be done that could lead to different results. First, it could choose one randomly from the bag. Second, it could choose the highest ranked or most similar. In either case it would then apply the same rules. A simple way to handle the two agents would be for each agent to have a handle to the Observer, which has a method for handling the rest.

Here are some hints (more hints may be added Thursday).

For the Agent, your new step method might look something like this with the new keyword synchronized added as a modifier.

	public synchronized void step(SimState state) {
		switch(simulationType){
		case SimulationEnvironment.AGGREGATION_FLOCK: aggregation_flock( state); break;
		case SimulationEnvironment.KH: KH_model(state); break;
		default: KH_model(state);
		}
	}

Also in Agents, your KH_model method might have the following code to start with.

public void KH_model(SimState state){
	if(!dated){
	    Bag neighbors =
                         se.particleSpace.getNeighborsMaxDistance(x, y,
                            mateSearchRadius, !boundaries, null, null, null);

                //add your code here
		}
		aggregation_flock(se);
	}

The next two methods are a start for the Observer.

public void handlePair(Agent a, Agent b){
	Agent f,m;
		if(a.sex==se.MALE){
			m = a;
			f = b;
		}
		else{
			m=b;
			f=a;
		}
          //add your code here
	}
     public void kh_model_mobile(){
		/*
		 * print the data
		 */
		printDataKH();
		/*
		 * Check to see if the simulations has ended
		 */
		testEndKHMobile();
		Bag b = se.particleSpace.getAllObjects();
		for(int i=0;i<b.numObjs;i++){
			Agent a = (Agent)b.objs[i];
			a.dated = false;
		}
	}

Additional Hints:

To test whether a simulation with mobile agents will end, you could use this method:

	public void testEndKHMobile(){
		int m = 0, f=0;
		Bag agents = se.particleSpace.allObjects;
		for(int i=0; i<agents.numObjs;i++){
			Agent a = (Agent)agents.objs[i];
			if(a.sex == se.MALE){
				m++;
			}
			else{
				f++;
			}
			if(f>0 && m>0){
				break;
			}
		}
		if(f==0 || m==0){
			for(int k=0; k<agents.numObjs;k++){
				Agent a = (Agent)agents.objs[k];
				a.event.stop();
			}
			event.stop();
		}
	}

One way to decide whether two agents pair up is to let each agent find a potential opposite sex agent and then let the observer handle the rest by giving the observer the potential pair.

	public void handlePair(Agent a, Agent b){
		Agent f,m;
		if(a.sex==se.MALE){
			m = a;
			f = b;
		}
		else{
			m=b;
			f=a;
		}
		if(se.chooseBest){
			if(se.random.nextBoolean(m.chooseBest(f))&&     
                             se.random.nextBoolean(f.chooseBest(m))){
				correlation.getData(f.attractiveness, m.attractiveness); 
                                 //get data
				paired++;
				removeAgent(m);
				removeAgent(f);
				if(replacement){
					this.newPair(); 
                                          //add back as many pairs as were removed
				}
			}
			else{
				m.update();
				f.update();
			}
		}
		else {
			if(se.random.nextBoolean(m.chooseSimilar(f))&& 
                                    se.random.nextBoolean(f.chooseSimilar(m))){
				correlation.getData(f.attractiveness, m.attractiveness); 
                                 //get data
				paired++;
				removeAgent(m);
				removeAgent(f);
				if(replacement){
					this.newPair(); 
                                         //add back as many pairs as were removed
				}
			}
			else{
				m.update();
				f.update();

			}
		}
	}

with

public void newPair(){
	double attractiveness = Math.floor(se.random.nextDouble()*se.maxAttractiveness)+1;
	Agent m =  new Agent(se).setsex(se.MALE).setattractivenss(attractiveness).setObserver(this);
	males.add(m);
	Color c = new Color((float)0,(float)0,(float)1,(float)(m.attractiveness/se.maxAttractiveness));
	OvalPortrayal2D o = new OvalPortrayal2D(c);
	se.particlesPortrayal.setPortrayalForObject(m, o);
	attractiveness = Math.floor(se.random.nextDouble()*se.maxAttractiveness)+1;
	Agent f =  new 
          Agent(se).setsex(se.FEMALE).setattractivenss(attractiveness).setObserver(this);
	females.add(f);
	c = new 
           Color((float)1,(float)0,(float)0,(float)(f.attractiveness/se.maxAttractiveness));
	o = new OvalPortrayal2D(c);
	e.particlesPortrayal.setPortrayalForObject(f, o);
}

Finally, in the kh_model() method in Agents, you could make things really interesting by allowing agents to choose the best or choose the most similar agent of the opposite sex in their local neighborhood. If they could do this, do you think it would increase or decrease correlations compared to making a random choice? If you want to try this out, you could add this code into the method after the potential mates are selected and added the appropriate Boolean variables in the SimulationEnvironment.

if(mates.numObjs == 1){
	o.handlePair(this,(Agent)mates.objs[0]) ;
}
else if(mates.numObjs > 1){
	if(se.randomlyChooseMate){
		Agent a = (Agent)(mates.objs[se.random.nextInt(mates.numObjs)]);
		o.handlePair(this,a) ;
	}
	else if(se.chooseBest){
		Agent a = (Agent)(mates.objs[se.random.nextInt(mates.numObjs)]);
		for(int i=0;i<mates.numObjs;i++){
			Agent b =(Agent)(mates.objs[i]);
			if(a.attractiveness < b.attractiveness){
				a = b;
			}
		}//end for
		o.handlePair(this,a) ;
	}
	else { //choose the most similar
		Agent a = (Agent)(mates.objs[se.random.nextInt(mates.numObjs)]);
		for(int i=0;i<mates.numObjs;i++){
			Agent b =(Agent)(mates.objs[i]);
			if(a.attractiveness > Math.abs(b.attractiveness-this.attractiveness)){
				a = b;
			}
		}//end for
		o.handlePair(this,a) ;
	}
}


Write a Report

Your report should include some interesting results you found and have the following form:

Introduction

Introduce the topic and the problems you are investigating. You can base this on the two Mate Choice papers you read for class.

Model and Methods

Describe the model and the methods of simulation you performed.

Results

Present the results.

Discussion

Discuss the result and especially why you think they are interesting.