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


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

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

/**
 * Multiplexer implements the family of n-Multiplexer problems.
 *
 

Parameters

base.data
classname, inherits or == ec.app.multiplexer.MultiplexerData
(the class for the prototypical GPData object for the Multiplexer problem)
base.bits
1, 2, or 3
(The number of address bits (1 == 3-multiplexer, 2 == 6-multiplexer, 3==11-multiplexer)

Parameter bases

base.data species (the GPData object)
* * @author Sean Luke * @version 1.0 */ public class Multiplexer extends GPProblem implements SimpleProblemForm { private static final long serialVersionUID = 1; public static final int NUMINPUTS = 20; public static final String P_NUMBITS = "bits"; public int bits; // number of bits in the data public int amax; // maximum address value public int dmax; // maximum data value public int addressPart; // the current address part public int dataPart; // the current data part public void setup(final EvolutionState state, final Parameter base) { // very important, remember this super.setup(state,base); // not using any default base -- it's not safe // verify our input is the right class (or subclasses from it) if (!(input instanceof MultiplexerData)) state.output.fatal("GPData class must subclass from " + MultiplexerData.class, base.push(P_DATA), null); // I figure 3 bits is plenty -- otherwise we'd be dealing with // REALLY big arrays! bits = state.parameters.getIntWithMax(base.push(P_NUMBITS),null,1,3); if (bits<1) state.output.fatal("The number of bits for Multiplexer must be between 1 and 3 inclusive"); amax=1; for(int x=0;x>> addressPart) & 1) /* extracts the address-th bit in data and moves it to position 0, clearing out all other bits */ ^ /* "Is Different from" */ (input.x & 1)); /* A 1 if input.x is non-zero, else 0. */ } // the fitness better be KozaFitness! KozaFitness f = ((KozaFitness)ind.fitness); f.setStandardizedFitness(state, (amax*dmax - sum)); f.hits = sum; ind.evaluated = true; } } }

Ads help maintain this website.