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

📄 evotsc.java

📁 Java遗传算法库
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
        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 = 2;    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 = 4;
        boolean assumptionA = false;  int getEMode = BISTLib.E_MODE_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, faultDepth );
        //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 ) );
        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 ) );        
        ControlLib.writeGNUPlotScript( dirName, logDir, logFileName, 3, false );
        ControlLib.writeWebGraphDaemon( dirName, logDir, logFileName, 3, false, new File(".").getCanonicalPath() + File.separator );
    }        
    
    protected  int sumBinCo( int n, int maxR )
    {
        int rv = 0;
        for( int r = 1; r < maxR; r++ )
        {
            rv += ESLib.binomialCoefficient( n, r );
        }
        return rv;
    }
        
        
    protected  void addTTAdd1( String dirName ) throws IOException
    {
        final int INPUT_SAMPLE_SEP = 30;

        BooleanFunction functionC = new Add1bitCFun();  BooleanFunction functionQ = new Add1bitQFun();
         FitnessFunction corrFF = new CorrelationFitnessFunction();
         FitnessFunction tSetupFF = new SampleWindowFitnessFunction( corrFF, 15 );
        ArbitraryFunctionExperiment expC = new ArbitraryFunctionExperiment ( functionC, tSetupFF );
        ArbitraryFunctionExperiment expQ = new ArbitraryFunctionExperiment ( functionQ, tSetupFF );
        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 );
        GeneticOperator bmin3 = new BunchMutator( bitsPerVar, howManyBunches, blockSize, lutSize + 3 * bitsPerVar, fixedAlignments, qDefSize );
        GeneticOperator bc = new BlockCopy ( blockSize, blockSize, 0, fixedAlignments, qDefSize );
        GeneticOperator[] geneticOps ={ m,      spxo,   bmin0,  bmin1,  bmin2,  bmin3,  bc      };
        double[] opsProbs =          {  0.3,    0.2,    0.1,    0.1  ,  0.1  ,  0.1  ,  0.1     };
        Selector selector = new RankSelector(  );
        Evolver evolver = new StandardEvolver( POP_SIZE, genotypeLength, geneticOps, opsProbs, selector, NUM_OF_ELITES, seeds );
        PopulationLogReader.fullOrderGenotypes = true;
        int nrEvals = 1;    int eSize = 3;  int startAt = 3;
        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 = 4;
        boolean simpleMode = true;  int getEMode = BISTLib.E_MODE_OSCILLATING;
        TestingTesterBISTPIMComb inIm = new TestingTesterBISTPIMComb( evolver, deployment, experiment, circuit, thresholds, eSize, E_LINES, avgRound, faultDepth, startAt, getEMode, INPUT_SAMPLE_SEP, simpleMode, 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 = ( 1 << bitsPerVar ) - experiment.getNumOfInputs();
        InteractionModel parsIM = 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( "Full adder (5 gates) under multiple faults (Ass. A)" );
        taskQBestIndID.add( new Integer( 1574 ) );
        int avgTPLen = 8;   int usedEls = 7;
        int effort = 3;
        taskQEffort.add( new Integer( effort ) );
            ControlLib.writeGNUPlotScript( dirName, logDir, logFileName, 3, false );
            ControlLib.writeWebGraphDaemon( dirName, logDir, logFileName, 3, false, new File(".").getCanonicalPath() + File.separator );            
    }
    
    
    protected  void addDK27() throws IOException
    {
        String[][] inputs4ResetState = { { "0","1","0","0" } }; // for dk27
        int[] permanentEdges = { 9,11,12,14,16,17,18 }; // for dk27
        String resetStateName = "START"; // for dk27
        String kissFileName = "dk27";
        int bestID = 1985; // 23 * 2 + 1 = 47.  1 - 47/(64-1) = 0.25397
        int avgTPLen = 35; // avtTP
        addKISSL2BenchmarkLockedFull
        (
            "/home/mmg20/eh/benchmarks/dk27.kiss2",
            "/home/mmg20/eh/benchmarks/dk27.sout", 
            resetStateName, inputs4ResetState, permanentEdges, "DK27L2",
            "Locked Sequential Benchmark: DK27 (20 gates, 3 latches).  <strong>Largest Sequential Circuit Evolution ever undertaken!</strong>",
            bestID, avgTPLen
         );
    }            
    
    protected  void addMC() throws IOException
    {
        int[] permEdges = { 8,10,12,15 }; // for mc
        String[][] resetIns = { {"001","001","001" },{"011", "011", "011" } }; // for mc
        int bestID = 1338; // L2 => 8 ?? This may be BEECOUNT
        String resetStateName = "HG"; // for mc
        int avgTPLen = 155; // avtTP
        addKISSL4BenchmarkUnlockedFull
        (
            "/home/mmg20/eh/benchmarks/mc.kiss2",
            "/home/mmg20/eh/benchmarks/mcL4.sout", 
            resetStateName, resetIns, permEdges, "MCF32",
            "Sequential Benchmark: MC (8 four-input LUTs, 2 D-latches)",
            bestID, avgTPLen
         );
    }
    
    protected  void addBeecount() throws IOException
    {
        String[][] resetIns = { {"001"},{"011"},{"101"},{"111"} }; // for beecount
        int[] permEdges = { 10,14,17,19,21 }; // for beecount        
        int bestID = 1869;
        int avgTPLen = 220; // avtTP
        addKISSL4BenchmarkUnlockedFull
        (
            "/home/mmg20/eh/benchmarks/beecountSimp.kiss2",
            "/home/mmg20/eh/benchmarks/beecountL4.sout", 
            "S2", resetIns, permEdges, "BeecountL4",
            "Locked Sequential Benchmark BEECOUNT (9 four-input LUTs, 2 latches)",
            bestID, avgTPLen
         );
    }
    

    protected  void addKISSL4BenchmarkUnlockedFull( String kissFileName, String sisOutputFileName, String resetStateName, String[][] inputs4ResetState, int[] permanentEdges, String dirName, String descr, int bestIndID, int avgTPLen ) throws IOException
    {
        int time2Reset = -1;
        for( int pl = 0; pl < inputs4ResetState.length; pl++ )
        {
            time2Reset = Math.max( time2Reset, inputs4ResetState[ pl ].length );
        }
        final int INPUT_SAMPLE_SEP = 40;    final int LUT_INPUTS = 4;
        boolean generateClock = false;      int cyclesPerSample = 1;
        int nrELines = 1;        boolean fpga = true;        boolean voter = true;
         FitnessFunction corrFF = new CorrelationFitnessFunction();
         FitnessFunction tSetupFF = new SampleWindowFitnessFunction( corrFF, 20 );
        KISSFSMExperiment inExp = new KISSFSMExperiment( new File( kissFileName ), resetStateName, inputs4ResetState, permanentEdges, generateClock, tSetupFF );
        AddClockCSRIExperiment experiment = new AddClockCSRIExperiment( inExp, cyclesPerSample );
        SisOutputReader sor = new SisOutputReader( new File( sisOutputFileName ), nrELines, LUT_INPUTS, fpga, voter );
        FullOrderGenotype seed = new FullOrderGenotype ( sor.getGenotype() );
        int bitsPerVar = sor.getBitsPerVar();        int usedEls = sor.getTotalEls();
        int bitsPerAdd = bitsPerVar + 1;
        final int POP_SIZE = 21;    final int GENOTYPE_MUT = 1; final int NUM_OF_ELITES = 1;
        int DUMP_POP_EVERY = 2000;
        ElementDelayModel delayModel = new CoinDelayModel( );
        CircuitMapping circuitMapping = new FaultyOptimizedMapping( new FPGALUTAbsoluteMapping( experiment.getNumOfInputs(), experiment.getNumOfOutputs() + nrELines, bitsPerVar, LUT_INPUTS, delayModel ) );
        int DQTol = 3;        int eSize = 19;     int startAt = 20;
        SimulatorFaultyCircuit circuit = new SimulatorFaultyCircuit( circuitMapping );
        boolean alwaysResetBeforeRun = true;
        SimulatorDeployment deployment = new SimulatorDeployment( circuit, alwaysResetBeforeRun );
        SingleFaultModel faultModel = new SingleUsedFaultModel( circuit ); // Should take in whole circuit every time??
        int nrAddCLBs = ( 1 << bitsPerVar ) - experiment.getNumOfInputs();
        int lutSize = 1 << LUT_INPUTS;
        int blockSize = lutSize + ( LUT_INPUTS + 1 ) * bitsPerAdd;
        int qDefSize = ( experiment.getNumOfOutputs() + nrELines ) * bitsPerAdd;
        int genotypeLength = qDefSize + nrAddCLBs * blockSize;
        Genotype[] seeds = new Genotype[ POP_SIZE ];
        seeds[ 0 ] = seed;
        for( int pl = 0; pl < POP_SIZE; pl++ )
        {   seeds[ pl ] = ( FullOrderGenotype ) seed.clone();
            for( int bl = qDefSize + usedEls * blockSize; bl < seeds[ pl ].length(); bl++ )
                if( Math.random() < 0.5 ) seeds[ pl ].set( bl );
        }
        int fixedAlignments = 0;        int howManyBunches = 1;
        //GeneticOperator m = new SAGAMutator( 1, genotypeLength / 50, 0, fixedAlignments * blockSize, -1 );
        ExactGenotypeMutator m = new ExactGenotypeMutator( GENOTYPE_MUT );

⌨️ 快捷键说明

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