⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 evoft.java~

📁 Java遗传算法库
💻 JAVA~
📖 第 1 页 / 共 2 页
字号:
/*
 * MonicaServer.java
 *
 * Created on 16 April 2001, 17:12
 */

package jaga.pj.circuits.control;

import jaga.control.*;
import jaga.deploy.*;
import jaga.evolve.*;
import jaga.experiment.*;
import jaga.*;

import jaga.pj.circuits.*;
import jaga.pj.circuits.experiment.*;
import jaga.pj.circuits.fpgaft.*;
import jaga.pj.gral.*;

import islandev.IslandsEvolutionServer;

import debug.DebugLib;

import java.util.Vector;
import java.rmi.*;
import java.io.*;

/**
 *
 * @author  Michael Garvie
 * @version 
 */
public abstract class EvoFT
{
     static Vector taskQ = new Vector();
     static Vector taskQNames = new Vector();
    
    static String logDir;
    static final String logFileName = "ft-ms-log.txt";
    static final double migrationRate = 0.5;
    
    public static void main( String[] args )
    {
        logDir = args[ 0 ];
        DebugLib.trcLogger.isLogging = true;
        DebugLib.logFileName = logFileName;
        
        /*addAdd1BIST( new SingleRandomFaultModel( 8, 6 ), "SR8" );
        addAdd1BIST( new SingleRandomFaultModel( 12, 6 ), "SR12" );
        addAdd1BIST( new SingleFullFaultModel( 8 ), "SF8" );*/
        //addAdd1BIST( new SingleFullFaultModel( 12 ), "S12" );
        //addAdd1FT( 0 );
        //add2MultSimpleMalteada( 0 );
        addAdd1FT( 0 );
        //addAdd1FT( 1 );
        //addAdd1FT( 3 );
        /*addAdd1Malt( 0 );
        addAdd1Malt( 1 );
        */
        /*addAdd1Malt( 2 );
        addAdd1Malt( 3 );
        addAdd1Malt( 4 );*/
        
        try
        {
            IslandsEvolutionServer ms = new IslandsEvolutionServer( "Krishna", taskQ, taskQNames, logDir, migrationRate );
            ms.bindServer();
            //MonicaServer ms = new MonicaServer( "MonicaServer", taskQ, taskQNames, args[ 0 ], 0.5 );
        }catch( java.rmi.RemoteException e )
        {
            System.out.println( e );
        }
        
    }
    
    private static void addAdd1FT( int id )
    {

        // A - Genetic Algorithms Properties
        // Standard
         final int POP_SIZE = 32;
         final int GENOTYPE_MUT = 1;
         final double XOVER_PROB = 0.4;
         final double MUTATION_PROB = 0.6;
         final int NUM_OF_ELITES = 2;

        /* 1+1
         final int POP_SIZE = 2;
         final int GENOTYPE_MUT = 2;
         final double XOVER_PROB = 0;
         final double MUTATION_PROB = 1;
         final int NUM_OF_ELITES = 1;

         final double[] 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;

        // M - Log Properties
         int DUMP_POP_EVERY = 100;

        // E - EXPERIMENT set up
        BooleanFunction boolFunQ = new Add1bitQFun();
        BooleanFunction boolFunC = new Add1bitCFun();
         Experiment experimentQ = new ArbitraryFunctionExperiment( boolFunQ, T_SETUP );
        Experiment experimentC = new ArbitraryFunctionExperiment( boolFunC, T_SETUP );
        Experiment[] exps = { experimentQ, experimentC };
        Experiment experiment = new MultiOutputExperiment( exps );

        // 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 );
        ElementDelayModel delayModel = new GaussianDelayModel( 0.5, 0.5 );
         CircuitMapping circuitMapping = new LUTAbsoluteMapping( experiment.getNumOfInputs(), experiment.getNumOfOutputs() + 1, BITS_PER_VARIABLE, LUT_INPUTS, delayModel );
         SimulatorFaultyCircuit circuit = new SimulatorFaultyCircuit( circuitMapping );
         SimulatorDeployment deployment = new SimulatorDeployment( circuit );

        // A - Genetic Operators Set up
        int nrEls = ( 1 << BITS_PER_VARIABLE ) - experiment.getNumOfInputs();
        int lutSize = 1 << LUT_INPUTS;
        int blockSize = lutSize + LUT_INPUTS * BITS_PER_VARIABLE;
        int genotypeLength = nrEls * blockSize;
        

         //final Genotype SEED0 = new Genotype( "5X6e7R]nn^OmeHUYjQZ9", genotypeLength, 6 );
        // final Genotype SEED1 = new Genotype( "6WS_iRZCj6Y8ELA2eO6ZJ8eMnPDTCdlHHtQFdj95jMhqg7bcFi9PGfu86JVoIpWkQjmvWSX6S[shXWjEjlRQiieI9QV95HvQD6iK\\EHNY\\RKa\\hB5^aF\\3OL9cl3r7r07rdbpQJkrOYaivRCqCK5IWPFM4USapH2mi3_RR2BX[5i^cCfnLZRR]N5t94Ms0iiLfmLuh72feoUuHWV6CHTh[0etY9[[Iv9KTBf`iZZojZteMsirncWvonRShJ0", genotypeLength, 6 );
        // final Genotype SEED2 = new Genotype( "2GS_i17CiQY8ELA2eO6ZJ8eMnPDTC_jrLtUVdjDG8EEQS\\beNi9PKfu87Jjc3jRiaIqH[ALYJsE11WIqSMRIgj04oBe09jKAhLiLaMVU_08qdSQaImCtgaB4cc[3r3raARcfpAJli0jWiJ0kq4Nk0WPF64USqpH2gi3bBKu2]SRe`cCfknjBqEMKTO7Iu5ru1_THNb72V3n6rWD824uaHW0etY9[[Iv9KTBf`gtYM_AhAq6hNldYCEAdb1i0", genotypeLength, 6 );
        // final Genotype[] SEEDS = { SEED0, SEED1, SEED2 };
        // final Genotype[] SEEDS = { SEED0, SEED1 };
        // final Genotype[] SEEDS = { SEED0 };
         final Genotype[] SEEDS = { };

        // BitMutator bm = new BitMutator( BIT_MUTATION_PROB );
        // GeneticOperator m = new ExactGenotypeMutator( GENOTYPE_MUT );
        GeneticOperator m = new SAGAMutator( 1, 10 );
        GeneticOperator spxo = new SinglePointXOver();        
        GeneticOperator bmin0 = new BunchMutator( BITS_PER_VARIABLE, 1, blockSize, lutSize );
        GeneticOperator bmin1 = new BunchMutator( BITS_PER_VARIABLE, 1, blockSize, lutSize + BITS_PER_VARIABLE );
        GeneticOperator bc = new BlockCopy ( blockSize, blockSize );
        
        GeneticOperator[] geneticOps = { m, spxo, bmin0, bmin1, bc };
        double[] opsProbs = { 0.3, 0.1, 0.2, 0.2, 0.2 };
        
         /* 1+1
         GeneticOperator[] geneticOps = { m };

         double[] opsProbs = { MUTATION_PROB };
         */
        // Selector selector = new FitnessProportionateSelector();
         Selector selector = new RankSelector(  );

         Evolver evolver = new StandardEvolver( POP_SIZE, genotypeLength, geneticOps, opsProbs, selector, NUM_OF_ELITES, SEEDS );

        SingleFaultModel faultModel = new SingleFullFaultModel( nrEls );
        
        //InteractionModel interactionModel = new StandardInteractionModel( evolver, deployment, experiment );
        //InteractionModel interactionModel = new BISTIM( evolver, deployment, circuit, experiment, faultModel );
        //InteractionModel interactionModel = new MalteadaIM( evolver, deployment, circuit, experiment, nrEls );
        InteractionModel interactionModel = new FaultTolerationIM( evolver, deployment, circuit, experiment, faultModel );

        Monica monica = new Monica( interactionModel, DUMP_POP_EVERY, java.lang.Integer.MAX_VALUE );

        String dirName = "Add1FullFT-" + id;
        monica.setName( dirName );
        taskQ.add( monica );
        taskQNames.add( dirName );
        ControlLib.writeGNUPlotScript( dirName, logDir, logFileName, 2 );
    }

    private static void add2MultSimpleMalteada( int id )
    {
        // A - Genetic Algorithms Properties
        // Standard
         final int POP_SIZE = 32;
         final int TP_POP_SIZE = 7;
         final double BIT_MUTATION_PROB = 0.05;
         final int GENOTYPE_MUT = 1;
         final double XOVER_PROB = 0.4;
         final double ALIEN_PROB = 0;
         final double WIRE_SWAP_PROB = 0.7;
         final double MUTATION_PROB = 0.6;
         final int NUM_OF_ELITES = 2;

         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 };

        /* 1+1
         final int POP_SIZE = 2;
         final int TP_POP_SIZE = 2;
         final double BIT_MUTATION_PROB = 0.05;
         final int GENOTYPE_MUT = 2;
         final double XOVER_PROB = 0;
         final double MUTATION_PROB = 1;
         final int NUM_OF_ELITES = 1;

         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 = 4;
         final int LUT_INPUTS = 2;

        /* For NANDC
         final int BITS_PER_VARIABLE = 5;
         final int STABILIZERS = 1;
         final int GATE_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 = 60;

        // E - EXPERIMENT set up

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -