/*
  Copyright 2006 by Sean Luke
  Licensed under the Academic Free License version 3.0
  See the file "LICENSE" for more information
*/


package ec.app.parity;
import ec.util.*;
import ec.*;
import ec.gp.*;
import ec.gp.koza.*;
import ec.simple.*;

/* 
 * Parity.java
 * 
 * Created: Mon Nov  1 15:46:19 1999
 * By: Sean Luke
 */

/**
 * Parity implements the family of n-[even|odd]-Parity problems up 
 * to 32-parity.  Read the README file in this package for information on
 * how to set up the parameter files to your liking -- it's a big family.
 *
 * 

The Parity family evolves a boolean function on n sets of bits, * which returns true if the number of 1's is even (for even-parity) or odd * (for odd-parity), false otherwise. *

Parameters

base.data
classname, inherits or == ec.app.parity.ParityData
(the class for the prototypical GPData object for the Parity problem)
base.even
bool = true (default) or false
(is this even-parity (as opposed to odd-parity)?)
base.bits
2 >= int <= 31
(The number of data bits)

Parameter bases

base.data species (the GPData object)
* * @author Sean Luke * @version 1.0 */ public class Parity extends GPProblem implements SimpleProblemForm { private static final long serialVersionUID = 1; public static final String P_NUMBITS = "bits"; public static final String P_EVEN = "even"; public boolean doEven; public int numBits; public int totalSize; public int bits; // data bits public void setup(final EvolutionState state, final Parameter base) { // very important, remember this super.setup(state,base); // not using a default base here // verify our input is the right class (or subclasses from it) if (!(input instanceof ParityData)) state.output.fatal("GPData class must subclass from " + ParityData.class, base.push(P_DATA), null); // can't use all 32 bits -- Java is signed. Must use 31 bits. numBits = state.parameters.getIntWithMax(base.push(P_NUMBITS),null,2,31); if (numBits<2) state.output.fatal("The number of bits for Parity must be between 2 and 31 inclusive",base.push(P_NUMBITS)); totalSize = 1; for(int x=0;x>> b) & 1; tb &= 1; // now tb is 1 if we're odd, 0 if we're even ((GPIndividual)ind).trees[0].child.eval( state,threadnum,input,stack,((GPIndividual)ind),this); if ((doEven && ((input.x & 1) != tb)) || ((!doEven) && ((input.x & 1) == tb))) sum++; } // the fitness better be KozaFitness! KozaFitness f = ((KozaFitness)ind.fitness); f.setStandardizedFitness(state, (totalSize - sum)); f.hits = sum; ind.evaluated = true; } } }

Ads help maintain this website.