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


package ec.app.multiplexer;
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 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"); } public void evaluate(final EvolutionState state, final Individual ind, final int subpopulation, final int threadnum) { if (!ind.evaluated) // don't bother reevaluating { MultiplexerData input = (MultiplexerData)(this.input); input.status = (byte)bits; int sum = 0; ((GPIndividual)ind).trees[0].child.eval( state,threadnum,input,stack,((GPIndividual)ind),this); if (bits==1) { byte item1 = input.dat_3; byte item2 = Fast.M_3[Fast.M_3_OUTPUT]; for(int y=0;y>> 1); item2 = (byte)(item2 >>> 1); } } else if (bits==2) { long item1 = input.dat_6; long item2 = Fast.M_6[Fast.M_6_OUTPUT]; for(int y=0;y>> 1; item2 = item2 >>> 1; } } else // bits==3 { long item1, item2; for(int y=0;y>> 1; item2 = item2 >>> 1; } } } // the fitness better be KozaFitness! KozaFitness f = ((KozaFitness)ind.fitness); if (bits==1) f.setStandardizedFitness(state, (Fast.M_3_SIZE - sum)); else if (bits==2) f.setStandardizedFitness(state, (Fast.M_6_SIZE - sum)); else // (bits==3) f.setStandardizedFitness(state, (Fast.M_11_SIZE - sum)); f.hits = sum; ind.evaluated = true; } } }

Ads help maintain this website.