All Downloads are FREE. Search and download functionalities are using the official Maven repository.

aima.core.search.local.Individual Maven / Gradle / Ivy

Go to download

AIMA-Java Core Algorithms from the book Artificial Intelligence a Modern Approach 3rd Ed.

The newest version!
package aima.core.search.local;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * Artificial Intelligence A Modern Approach (3rd Edition): page 127.
*
* A state in a genetic algorithm is represented as an individual from the * population. * * @author Ciaran O'Reilly * * @param * the type of the alphabet used in the representation of the * individuals in the population (this is to provide flexibility in * terms of how a problem can be encoded). */ public class Individual { private List representation = new ArrayList(); private int descendants; // for debugging! /** * Construct an individual using the provided representation. * * @param representation * the individual's representation. */ public Individual(List representation) { this.representation = Collections.unmodifiableList(representation); } /** * * @return the individual's representation. */ public List getRepresentation() { return representation; } /** * * @return the length of the individual's representation. */ public int length() { return representation.size(); } /** * Should be called by the genetic algorithm whenever the individual is * selected to produce a descendant. */ public void incDescendants() { descendants++; } /** Returns the number of descendants for this individual. */ public int getDescendants() { return descendants; } @Override public String toString() { return representation.toString() + descendants; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy