📄 evothreemults.java~
字号:
final int GENOTYPE_MUT = 1;
final double XOVER_PROB = 0;
final double MUTATION_PROB = 0.6;
final int NUM_OF_ELITES = 1;
final double CHOP_PROB = 0.2;
final double STRETCH_PROB = 0.2;
final double TP_XOVER_PROB = 0;
final double TP_MUTATION_PROB = 1;
final int TP_NUM_OF_ELITES = 1;
final double[] RANK_PROBS = { 1d, 0d };
final double[] TP_RANK_PROBS = { 1d, 0d };
//
// D - Circuit Structure Properties
final int BITS_PER_VARIABLE = 5;
final int LUT_INPUTS = 2;
// D - Simulator Properties
final int SIMULATOR_GATE_DELAY = 1;
final double T_SETUP = 0.45;
// final int INPUT_SAMPLE_SEPARATION = 1;
// E - Experiment Properties
final int TEST_LENGTH = 50;
// M - Log Properties
int DUMP_POP_EVERY = 1;
int GENERATIONS = 200000;
// E - EXPERIMENT set up
Experiment inExperiment = new MultiplierExperiment( 2, T_SETUP );
Experiment aonExperiment = new AllOrNothingExperiment( inExperiment );
Experiment tpexp = new TestPattern4EvolvingExperiment( inExperiment );
// D - DEPLOYMENT set up
// SimulatorCircuit circuit = new SimulatorLUTCircuit( SIMULATOR_GATE_DELAY, BITS_PER_VARIABLE , LUT_INPUTS, experiment.getNumOfInputs(), experiment.getNumOfOutputs() );
ElementDelayModel delayModel = new ConstantDelayModel( SIMULATOR_GATE_DELAY );
CircuitMapping circuitMapping = new LUTAbsoluteMapping( inExperiment.getNumOfInputs(), inExperiment.getNumOfOutputs(), BITS_PER_VARIABLE, LUT_INPUTS, delayModel );
SimulatorSimpleCircuit circuit = new SimulatorSimpleCircuit( circuitMapping );
SimulatorDeployment deployment = new SimulatorDeployment( circuit );
// E - For Parsimony Experiment
final int TARGET_GATES = 6;
Experiment experiment = new ElementParsimonyExperiment( inExperiment, circuit, TARGET_GATES );
// FLEXDeployment deployment = new FLEXDeployment( vFileName, path2Prog, path2MaxPlus, wrkDir, BITS_PER_VARIABLE, STABILIZERS, GATE_INPUTS, experiment.getNumOfInputs(), experiment.getNumOfOutputs(), PORT_ADD );
// A - Genetic Operators Set up
int lutSize = 1 << LUT_INPUTS;
int blockSize = lutSize + LUT_INPUTS * BITS_PER_VARIABLE;
int genotypeLength = ( ( 1 << BITS_PER_VARIABLE ) - experiment.getNumOfInputs() ) * blockSize;
int blockLength = BITS_PER_VARIABLE * LUT_INPUTS + 1 << LUT_INPUTS;
int testPatLength = ( 1 << experiment.getNumOfInputs() ) * 2;
int tpGenLength = testPatLength * experiment.getNumOfInputs();
final Genotype[] SEEDS = { };
final Genotype[] TP_SEEDS = { };
//GeneticOperator m = new SAGAMutator( 1, 10 );
GeneticOperator m = new ExactGenotypeMutator( GENOTYPE_MUT );
GeneticOperator bmin0 = new BunchMutator( BITS_PER_VARIABLE, 1, blockSize, lutSize );
GeneticOperator bmin1 = new BunchMutator( BITS_PER_VARIABLE, 1, blockSize, lutSize + BITS_PER_VARIABLE );
GeneticOperator bmf = new BunchMutator( lutSize, 1, blockSize );
GeneticOperator bc = new BlockCopy ( blockSize, blockSize );
GeneticOperator chop = new Chopper( 1 );
GeneticOperator stretch = new Stretcher( 1, 0 );
GeneticOperator tpm = new ExactGenotypeMutator( GENOTYPE_MUT );
GeneticOperator spxo = new TracingSinglePointXOver();
GeneticOperator tpspxo = new SinglePointXOver();
// 1+1
GeneticOperator[] geneticOps = { bmin0, bmin1, bmf, bc };
GeneticOperator[] tpGeneticOps = { tpm };
double[] opsProbs = { 0.2,0.3,0.3,0.2 };
double[] tpOpsProbs = { TP_MUTATION_PROB };
//
//
// Selector selector = new FitnessProportionateSelector();
Selector selector = new RankSelector( RANK_PROBS );
//Selector selector = new RankSelector( );
// Selector tpSelector = new FitnessProportionateSelector();
// Selector tpSelector = new RankSelector( TP_RANK_PROBS );
Selector tpSelector = new RankSelector( TP_RANK_PROBS );
Evolver evolver = new StandardEvolver( POP_SIZE, genotypeLength, geneticOps, opsProbs, selector, NUM_OF_ELITES, SEEDS );
Evolver tpEvolver = new StandardEvolver( TP_POP_SIZE, tpGenLength, tpGeneticOps, tpOpsProbs, tpSelector, TP_NUM_OF_ELITES, TP_SEEDS );
Evolver[] evolvers = { evolver, tpEvolver };
Experiment[] experiments = { experiment, tpexp };
InteractionModel interactionModel = new StandardInteractionModel( evolver, deployment, experiment );
int[] evolutionFrequency = { 1 , 4 };
// InteractionModel interactionModel = new CircuitTestPatternIM( evolvers, deployment, experiments, evolutionFrequency );
Monica monica = new Monica( interactionModel, DUMP_POP_EVERY, GENERATIONS );
String dirName = "2MultParsimony1Plus1-" + id;
monica.setName( dirName );
taskQ.add( monica );
taskQNames.add( dirName );
writeGNUPlotScript( dirName, 1 );
}
private static void add2MultPostParsimonyP100M50X50( int id, String[] finalPopGenes )
{
// A - Genetic Algorithms Properties
// Standard
final int POP_SIZE = 103;
final int TP_POP_SIZE = 7;
final double BIT_MUTATION_PROB = 0.05;
final int GENOTYPE_MUT = 1;
final double XOVER_PROB = 0.45;
final double ALIEN_PROB = 0;
final double WIRE_SWAP_PROB = 0.7;
final double MUTATION_PROB = 0.45;
final double CHOP_PROB = 0.05;
final double STRETCH_PROB = 0.05;
final int NUM_OF_ELITES = 3;
final double TP_XOVER_PROB = 0.5;
final double TP_MUTATION_PROB = 0.5;
final int TP_NUM_OF_ELITES = 2;
final double[] TP_RANK_PROBS = { 8d, 4d, 2d, 1d };
//
// D - Circuit Structure Properties
final int BITS_PER_VARIABLE = 5;
final int LUT_INPUTS = 2;
// D - Simulator Properties
final int SIMULATOR_GATE_DELAY = 1;
final double T_SETUP = 0.45;
// final int INPUT_SAMPLE_SEPARATION = 1;
// E - Experiment Properties
final int TEST_LENGTH = 50;
// M - Log Properties
int DUMP_POP_EVERY = 1;
int GENERATIONS = 5000;
// E - EXPERIMENT set up
Experiment inExperiment = new MultiplierExperiment( 2, T_SETUP );
Experiment tpexp = new TestPattern4EvolvingExperiment( inExperiment );
Experiment aonExperiment = new AllOrNothingExperiment( inExperiment );
// D - DEPLOYMENT set up
// SimulatorCircuit circuit = new SimulatorLUTCircuit( SIMULATOR_GATE_DELAY, BITS_PER_VARIABLE , LUT_INPUTS, experiment.getNumOfInputs(), experiment.getNumOfOutputs() );
ElementDelayModel delayModel = new ConstantDelayModel( SIMULATOR_GATE_DELAY );
CircuitMapping circuitMapping = new LUTAbsoluteMapping( inExperiment.getNumOfInputs(), inExperiment.getNumOfOutputs(), BITS_PER_VARIABLE, LUT_INPUTS, delayModel );
SimulatorSimpleCircuit circuit = new SimulatorSimpleCircuit( circuitMapping );
SimulatorDeployment deployment = new SimulatorDeployment( circuit );
// E - For Parsimony Experiment
final int TARGET_GATES = 6;
Experiment experiment = new ElementParsimonyExperiment( aonExperiment, circuit, TARGET_GATES );
// FLEXDeployment deployment = new FLEXDeployment( vFileName, path2Prog, path2MaxPlus, wrkDir, BITS_PER_VARIABLE, STABILIZERS, GATE_INPUTS, experiment.getNumOfInputs(), experiment.getNumOfOutputs(), PORT_ADD );
// A - Genetic Operators Set up
int lutSize = 1 << LUT_INPUTS;
int blockSize = lutSize + LUT_INPUTS * BITS_PER_VARIABLE;
int genotypeLength = ( ( 1 << BITS_PER_VARIABLE ) - experiment.getNumOfInputs() ) * blockSize;
int blockLength = BITS_PER_VARIABLE * LUT_INPUTS + 1 << LUT_INPUTS;
int testPatLength = ( 1 << experiment.getNumOfInputs() ) * 2;
int tpGenLength = testPatLength * experiment.getNumOfInputs();
// Doing pool of mud for traceable seeds
//TraceableGenotype[] SEEDS = new TraceableGenotype[ POP_SIZE ];
Genotype[] SEEDS = new Genotype[ POP_SIZE ];
for( int pl = 0; pl < POP_SIZE; pl++ )
{
//SEEDS[ pl ] = ( TraceableGenotype ) EvolveLib.randomize( new TraceableGenotype( genotypeLength ) );
SEEDS[ pl ] = new Genotype( finalPopGenes[ pl ], genotypeLength, 6 );
}
final Genotype[] TP_SEEDS = { };
// BitMutator bm = new BitMutator( BIT_MUTATION_PROB );
// GeneticOperator m = new ExactGenotypeMutator( GENOTYPE_MUT );
//GeneticOperator m = new TracingExactGenotypeMutator( GENOTYPE_MUT );
GeneticOperator m = new ExactGenotypeMutator( GENOTYPE_MUT );
GeneticOperator bmin0 = new BunchMutator( BITS_PER_VARIABLE, 1, blockSize, lutSize );
GeneticOperator bmin1 = new BunchMutator( BITS_PER_VARIABLE, 1, blockSize, lutSize + BITS_PER_VARIABLE );
GeneticOperator bmf = new BunchMutator( lutSize, 1, blockSize );
GeneticOperator bc = new BlockCopy ( blockSize, blockSize );
GeneticOperator chop = new Chopper( 1 );
GeneticOperator stretch = new Stretcher( 1, 0 );
GeneticOperator tpm = new ExactGenotypeMutator( GENOTYPE_MUT );
GeneticOperator spxo = new TracingSinglePointXOver();
GeneticOperator tpspxo = new SinglePointXOver();
// 1+1
GeneticOperator[] geneticOps = { bmin0, bmin1, bmf, bc, spxo };
GeneticOperator[] tpGeneticOps = { tpm };
double[] opsProbs = { 0.2,0.2,0.2,0.1,0.3 };
double[] tpOpsProbs = { TP_MUTATION_PROB };
//
//
// Selector selector = new FitnessProportionateSelector();
//Selector selector = new RankSelector( RANK_PROBS );
Selector selector = new RankSelector( );
// Selector tpSelector = new FitnessProportionateSelector();
// Selector tpSelector = new RankSelector( TP_RANK_PROBS );
Selector tpSelector = new RankSelector( TP_RANK_PROBS );
Evolver evolver = new StandardEvolver( POP_SIZE, genotypeLength, geneticOps, opsProbs, selector, NUM_OF_ELITES, SEEDS );
Evolver tpEvolver = new StandardEvolver( TP_POP_SIZE, tpGenLength, tpGeneticOps, tpOpsProbs, tpSelector, TP_NUM_OF_ELITES, TP_SEEDS );
Evolver[] evolvers = { evolver, tpEvolver };
Experiment[] experiments = { experiment, tpexp };
InteractionModel interactionModel = new StandardInteractionModel( evolver, deployment, experiment );
int[] evolutionFrequency = { 1 , 4 };
// InteractionModel interactionModel = new CircuitTestPatternIM( evolvers, deployment, experiments, evolutionFrequency );
Monica monica = new Monica( interactionModel, DUMP_POP_EVERY, GENERATIONS );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -