Reproduction

The method we use for reproduction of the agents is very simple and straightforward. It is broken down into two steps: finding a mate and mating with the mate that is found. Right now the agents look for a mate every timestep, but that will get changed so reproduction only happens when certain conditions are met. We do not use a particular genetic algorithm, we use one that we created on our own. Here is a description of the methods used for reproduction.

Finding a Mate

The agent looks around itself to see if any agent is around it. If it encounters an agent, it automatically mates with it. The findMate() method implements the getFirstNeighbor() method which searches the list of neighbors of the agent and returns the first one that it encounters as long as it is not the agent itself and that it is alive. The findMate() method then passes this potential mate to the mateWith() method. This is an example of the methods mentioned above:

public Agent getFirstNeighbor(){
        for(Agent n : neighborList){
            if(n != this && n.isAlive())
                return n;
        }
        return null;
    }

    /**
     * The agent would look around itself to see if any agent is around it. If it encounters an agent,
     * it automatically mates with it.
     * @return
     */
    public void findMate(){
        vision = this.getVision();
        potMate = this.getFirstNeighbor();
        if(potMate == null)
            return;
        else 
            mateWith(potMate);
    }

+Mating With the Potential Mate

This method will create the new child agent and place it in the environment to be incorporated as another agent. It starts off by getting the ID's of the agents who are going to mate so they can be used later to contribute to the characteristics of the child. It then makes the child an instant of an agent and gives it characteristics such as a sugar metabolism, a spice metabolism, vision, sugar stores, and spice stores. These characteristics are determined by averaging the parents characteristics and giving the result to the child. It then adds the child to the neighbor list and to the list of agents that is kept by the controller for updating. An example of this method is given below:

private void mateWith(Agent potMate2) {
        potMateName = potMate2.getID();
        mateName = this.getID();

        child = new Agent();

        //Want to average parents' metabolism, vision, and sugar/spice stores so the child can inherit it.

        //Want to average parents' metabolism, vision, and sugar stores so the child can inherit it.
        //need to fix for unique sugar and spice metabolisms, and food (spiceFood and sugarFood).

        cVis = (potMate2.getVision() + this.getVision())/2;
        cSugMet = (potMate2.getSugarMetabolism() + this.getSugarMetabolism())/2;
        cSpiMet = (potMate2.getSpiceMetabolism() + this.getSpiceMetabolism())/2;
        cSug = (potMate2.getSugar() + this.getSugar())/2;
        cSpi = (potMate2.getSpice() + this.getSpice())/2;
        if(child == null)
            System.out.println("No child was born");
        System.out.println("Child was born!!!" + " Parents are :" + potMateName + "and" + mateName + ".");
        neighborList.add(child);
        numChildren++;
        //agents.add(child);
    }
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License