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

📄 evokingkongbist.java~

📁 Java遗传算法库
💻 JAVA~
📖 第 1 页 / 共 4 页
字号:
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.*;

public class EvoKingKongBIST extends IslandsEvolutionServer
{
    static Vector taskQ = new Vector();         static Vector taskQNames = new Vector();
    static Vector taskQDescr = new Vector();    static Vector taskQBestIndID = new Vector();
    static Vector taskQEffort = new Vector();    
    static String logDir;               static final String logFileName = "kk-ms-log.txt";
    static final double migrationRate = 0.5;    static final boolean log2dbase = true;
    
    static
    {
        try
        {
            DebugLib.trcLogger.isLogging = true;
            DebugLib.logFileName = logFileName;
            addTTC17();
        }catch( IOException e )
        {
            e.printStackTrace();
        }
    }
    
    public EvoKingKongBIST( Vector extraArgs )
    {
        super( taskQ, taskQNames, ( String ) extraArgs.get( 0 ), migrationRate, log2dbase, taskQDescr, taskQBestIndID, taskQEffort );        
    }
    
    protected static void addTTC17() throws IOException
    {
        String blifFN = "/home/mmg20/eh/benchmarks/C17.blif";
        String sisQFN = "/home/mmg20/eh/benchmarks/C17.sout";
        String dirName = "TTC17L4O";
        String descr = "Benchmark C17 (2 four-input LUTs) under multiple faults (Osc.)";
        int bestHD = 1530;
        addCombBLIFBenchmarkNoLockingTT( blifFN, sisQFN, dirName, descr, bestHD );
    }

    protected static void addTTCM42() throws IOException
    {
        String blifFN = "/home/mmg20/eh/benchmarks/cm42a.blif";
        String sisQFN = "/home/mmg20/eh/benchmarks/cm42a.sout";
        String dirName = "TTCM42AD";
        String descr = "Benchmark CM42A (22 gates) under multiple faults (Ass. A, Dual Rail)";
        int bestHD = 1661;
        addCombBLIFBenchmarkNoLockingTT( blifFN, sisQFN, dirName, descr, bestHD );
    }
    
    
    protected static void addCombBLIFBenchmarkNoLockingTT( String blifFileName, String sisOutputFileName, String dirName, String descr, int bestIndID ) throws IOException
    {
        final double T_SETUP = 0.45;
        final int INPUT_SAMPLE_SEP = 30;
        // D -  Circuit Structure Properties
         final int LUT_INPUTS = 4;
        
        // B - BENCHMARK STUFF
        CombinationalBLIFExperiment experiment = new CombinationalBLIFExperiment( blifFileName, T_SETUP );
        final int E_LINES = 1;
        final boolean FPGA = false;
        final boolean VOTER = true;
        SisOutputReader sor = new SisOutputReader( new File( sisOutputFileName ), E_LINES, LUT_INPUTS, FPGA, VOTER );
        FullOrderGenotype seed = new FullOrderGenotype ( sor.getGenotype() );
        int bitsPerVar = sor.getBitsPerVar();   
        int usedEls = sor.getTotalEls();        
        // A - Genetic Algorithms Properties
        // Standard
        final int POP_SIZE = 32;
        final int GENOTYPE_MUT = 1;
        final int NUM_OF_ELITES = 2;
        // M - Log Properties
        int DUMP_POP_EVERY = 200;
        // D - DEPLOYMENT set up
        ElementDelayModel delayModel = new CoinDelayModel( );
        //ElementDelayModel delayModel = new GaussianDelayModel( 0.3, 0.3 );
        CircuitMapping circuitMapping = new LUTAbsoluteMapping( experiment.getNumOfInputs(), experiment.getNumOfOutputs() + E_LINES, bitsPerVar, LUT_INPUTS, delayModel );
        SimulatorFaultyCircuit circuit = new SimulatorFaultyCircuitAsynchronous( circuitMapping );
        boolean randomResetBeforeEveryEval = true;  SimulatorDeployment deployment = new SimulatorDeployment( circuit, randomResetBeforeEveryEval );
        SingleFaultModel faultModel = new SingleUsedFaultModel( circuit, experiment.getNumOfOutputs() );
        
        // A - Genetic Operators Set up
        int nrAddUnits = ( 1 << bitsPerVar ) - experiment.getNumOfInputs();
        int lutSize = 1 << LUT_INPUTS;
        int blockSize = lutSize + LUT_INPUTS * bitsPerVar;
        int genotypeLength = nrAddUnits * blockSize;

        Genotype[] seeds = new Genotype[ POP_SIZE ];
        seeds[ 0 ] = seed;
        for( int pl = 1; pl < POP_SIZE; pl++ )
        {
            seeds[ pl ] = ( FullOrderGenotype ) seed.clone();
            for( int bl = 0; bl < seeds[ pl ].length(); bl++ )
            {
                if( Math.random() < 0.5 )
                {
                    seeds[ pl ].set( bl );
                }
            }
        }
        int howManyBunches = 1;
        //GeneticOperator m = new SAGAMutator( 1, genotypeLength / 100, 0 );
        ExactGenotypeMutator m = new ExactGenotypeMutator( GENOTYPE_MUT );
        GeneticOperator spxo = new SinglePointXOver();
        GeneticOperator bmin0 = new BunchMutator( bitsPerVar, howManyBunches, blockSize, lutSize );
        GeneticOperator bmin1 = new BunchMutator( bitsPerVar, howManyBunches, blockSize, lutSize + bitsPerVar );
        GeneticOperator bc = new BlockCopy ( blockSize, blockSize, 0 );        
        GeneticOperator[] geneticOps = { m, spxo, bmin0, bmin1, bc };
        double[] opsProbs = { 0.2, 0.2, 0.2, 0.2, 0.2 };
        Selector selector = new RankSelector(  );
        Evolver evolver = new StandardEvolver( POP_SIZE, genotypeLength, geneticOps, opsProbs, selector, NUM_OF_ELITES, seeds );
        
        PopulationLogReader.fullOrderGenotypes = true;
        int nrEvals = 7;    int eSize = 3;  int startAt = 10;
        CircuitPainterObject painter = new CircuitPainterObject( new CircuitPainter(), new LUTAbsoluteMapping( experiment.getNumOfInputs(), experiment.getNumOfOutputs() + E_LINES, bitsPerVar, LUT_INPUTS, new ConstantDelayModel( 0 ) ) ); 
        double[] thresholds = { 0.1, 0.1, 0.1 };    int avgRound = 1;   int faultDepth = 2;
        boolean assumptionA = false;  int getEMode = BISTLib.E_OSCILLATING;
        TestingTesterBISTPIMComb inIm = new TestingTesterBISTPIMComb( evolver, deployment, experiment, circuit, thresholds, eSize, E_LINES, avgRound, faultDepth, startAt, getEMode, INPUT_SAMPLE_SEP, assumptionA, painter );
        int[] numProps = { 2 }; // Warning, if raise nrEvals will give incorrect value for p0d
        InteractionModel noisyIM = new NoisyPIM( inIm, deployment, experiment, numProps, nrEvals );
        double maxSize = nrAddUnits;        
        InteractionModel interactionModel = new CircuitParsimonyPIM( noisyIM, circuit, maxSize );
        int windowSize = 10;
        //InteractionModel interactionModel = new HistoryWindowIM( windowSize, parsIM );
        Monica monica = new Monica( interactionModel, DUMP_POP_EVERY, java.lang.Integer.MAX_VALUE );
        painter.setEvoTask( monica );
        monica.setName( dirName );
        taskQ.add( monica );
        taskQNames.add( dirName );
        taskQDescr.add( descr );
        taskQBestIndID.add( new Integer( bestIndID ) );
        ControlLib.writeGNUPlotScript( dirName, logDir, logFileName, 3, false );
        ControlLib.writeWebGraphDaemon( dirName, logDir, logFileName, 3, false, new File(".").getCanonicalPath() + File.separator );
        int avgCirSize = ( int ) ( 1.5 * usedEls );
        int tpLen = 1 << experiment.getNumOfInputs();  int effort = tpLen * nrEvals * avgCirSize * INPUT_SAMPLE_SEP * sumBinCo( avgCirSize, faultDepth ) / 1000000;
        taskQEffort.add( new Integer( effort ) );        
    }        
    
    protected static int sumBinCo( int n, int maxR )
    {
        int rv = 0;
        for( int r = 1; r < maxR; r++ )
        {
            rv += ESLib.binomialCoefficient( n, r );
        }
        return rv;
    }
        
        
    protected static void addTTAdd1( String dirName ) throws IOException
    {
        final int INPUT_SAMPLE_SEP = 30;

        final double T_SETUP = 0.5;
        BooleanFunction functionC = new Add1bitCFun();  BooleanFunction functionQ = new Add1bitQFun();
        ArbitraryFunctionExperiment expC = new ArbitraryFunctionExperiment ( functionC, T_SETUP );  ArbitraryFunctionExperiment expQ = new ArbitraryFunctionExperiment ( functionQ, T_SETUP );
        ConfigurableRandomInputExperiment[] exps = { expQ, expC };  ConfigurableRandomInputMultiOutputExperiment experiment = new ConfigurableRandomInputMultiOutputExperiment( exps );
        final int LUT_INPUTS = 2;   final int E_LINES = 1;  int bitsPerVar = 4;
        final int POP_SIZE = 31;   final int NUM_OF_ELITES = 1;
        final int GENOTYPE_MUT = 1;      int DUMP_POP_EVERY = 20000;

        ElementDelayModel delayModel = new CoinDelayModel( );
        CircuitMapping circuitMapping = new LUTAbsoluteMapping( experiment.getNumOfInputs(), experiment.getNumOfOutputs() + E_LINES, bitsPerVar, LUT_INPUTS, delayModel );
        SimulatorFaultyCircuit circuit = new SimulatorFaultyCircuitAsynchronous( circuitMapping );        
        boolean randomResetBeforeEveryEval = true;  SimulatorDeployment deployment = new SimulatorDeployment( circuit, randomResetBeforeEveryEval );

        int nrAddUnits = ( 1 << bitsPerVar ) - experiment.getNumOfInputs(); int lutSize = 1 << LUT_INPUTS;  int blockSize = lutSize + LUT_INPUTS * bitsPerVar;
        int genotypeLength = nrAddUnits * blockSize;
        Genotype[] seeds = new Genotype[ POP_SIZE ]; 
        Genotype seed = new FullOrderGenotype( genotypeLength );
        //FullOrderGenotype seed = new FullOrderGenotype( "011011011011011010010011011001000001011111111110011010000010101001011110011101100101000010010000100110101100001000001101000111101111011011111110001011010000" );
        //FullOrderGenotype seed = new FullOrderGenotype( "RRQNQ1faOcALlfVu][8D7uRuBG", genotypeLength, 6 );
        seeds[ 0 ] = seed;
        for( int pl = 1; pl < POP_SIZE; pl++ )
        {
            seeds[ pl ] = ( FullOrderGenotype ) seed.clone();
            for( int bl = 0; bl < seeds[ pl ].length(); bl++ )  if( Math.random() < 0.5 )   seeds[ pl ].set( bl );
        }
        int howManyBunches = 1; int qDefSize = 0;   int fixedAlignments = 0;
        ExactGenotypeMutator m = new ExactGenotypeMutator( GENOTYPE_MUT );
        GeneticOperator spxo = new SinglePointXOver();
        GeneticOperator bmin0 = new BunchMutator( bitsPerVar, howManyBunches, blockSize, lutSize, fixedAlignments, qDefSize );
        GeneticOperator bmin1 = new BunchMutator( bitsPerVar, howManyBunches, blockSize, lutSize + bitsPerVar, fixedAlignments, qDefSize );
        GeneticOperator bmin2 = new BunchMutator( bitsPerVar, howManyBunches, blockSize, lutSize + 2 * bitsPerVar, fixedAlignments, qDefSize );

⌨️ 快捷键说明

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