/* Copyright 2006 by Sean Luke Licensed under the Academic Free License version 3.0 See the file "LICENSE" for more information */ package ec.rule; import ec.*; import ec.util.*; import java.io.*; /* * RuleIndividual.java * * Created: Tue May 29 18:20:20 EDT 2001 * By: Sean Luke */ /** * RuleIndividual is an Individual with an array of RuleSets, each of which * is a set of Rules. RuleIndividuals belong to some subclass of RuleSpecies * (or just RuleSpecies itself). * *

RuleIndividuals really have basically one parameter: the number * of RuleSets to use. This is determined by the num-rulesets * parameter. *

From ec.Individual: * *

In addition to serialization for checkpointing, Individuals may read and write themselves to streams in three ways. * *

*

In general, the various readers and writers do three things: they tell the Fitness to read/write itself, * they read/write the evaluated flag, and they read/write the Rulesets. If you add instance variables to * a RuleIndividual or subclass, you'll need to read/write those variables as well.

Parameters
base.num-rulesets
int >= 1
(number of rulesets used)
base.ruleset.n
Classname, subclass of or = ec.rule.RuleSet
(class of ruleset n)

Parameter bases
base.ruleset.n
RuleSet n

Default Base
rule.individual * @author Sean Luke * @version 1.0 */ public class RuleIndividual extends Individual { public static final String P_RULESET = "ruleset"; public static final String P_NUMRULESETS = "num-rulesets"; /** The individual's rulesets. */ public RuleSet[] rulesets; public Parameter defaultBase() { return RuleDefaults.base().push(P_INDIVIDUAL); } public Object clone() { RuleIndividual myobj = (RuleIndividual) (super.clone()); myobj.rulesets = new RuleSet[rulesets.length]; for(int x=0;x>> 31 ) ^ rulesets[x].hashCode(); return hash; } public void setup(final EvolutionState state, final Parameter base) { super.setup(state,base); // actually unnecessary (Individual.setup() is empty) // I'm the top-level setup, I guess int numrulesets = state.parameters.getInt( base.push(P_NUMRULESETS), defaultBase().push(P_NUMRULESETS), 1); // need at least 1 ruleset! if (numrulesets == 0) state.output.fatal("RuleIndividual needs at least one RuleSet!", base.push(P_NUMRULESETS), defaultBase().push(P_NUMRULESETS)); rulesets = new RuleSet[numrulesets]; for(int x=0;x