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

📄 evorepair.java

📁 Java遗传算法库
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        narrator += "\nSequences totally random ending when only " + usedEls + " LUTs left (assume minimal design)";
        narrator += "\nMax Gens per repair = (" + getIntConfig( IX_TIMEOUT ) + "m) = " + maxGens;
        narrator += "\nOrderings:\n";
        
        int[] faultPos = new int[ totalCLBs ]; // in FPGALUTAbsMapping it skips inputs
        for( int flp = 0; flp < totalCLBs; flp++ )
        {
            faultPos[ flp ] = flp;
        }
        Vector[] orders = new Vector[ M ];
        Random rnd = new Random();
        for( int ml = 0; ml < M; ml++ )
        {
            orders[ ml ] = new Vector();
            Vector allFaults = new Vector();
            for( int flp = 0; flp < faultPos.length; flp++ )
            {
                allFaults.add( new Integer( faultPos[ flp ] ) ); // Extra level of inderection maintained just in case mapping changes
            }
            while( orders[ ml ].size() < ( spareLUTs * SEQUENCE_LENGTH_S_MULT ) )
            {
                int ix = rnd.nextInt( allFaults.size() );
                //Integer currFPos = ( Integer ) allFaults.remove( ix ); // Remove comment for unique fault positions each time
                Integer currFPos = ( Integer ) allFaults.get( ix );
                int currFVal = rnd.nextInt( 2 ); // SSA0 or 1
                orders[ ml ].add( new Point( currFPos.intValue(), currFVal ) );
            }
            narrator += ml+": " + orders[ ml ] + "\n";
        }
        
        File orderFile = new File( logDir + "orders" + ixOffset + ".txt" );
        BufferedWriter multipleBW = new BufferedWriter( new FileWriter( orderFile ) );
        multipleBW.write( narrator );
        multipleBW.flush();        
        multipleBW.close();
        
        for( int ml = 0; ml < M; ml++ )
        {
            addRepairComBlifSequenceNoLatch( ml + ixOffset * M, orders[ ml ] );
        }
    }    
    
    private void addRepairComBlifSequenceNoLatch( int ix, Vector seq ) throws IOException
    {
        Point[] faultSequence = new Point[ seq.size() ];
        for( int flp = 0; flp < faultSequence.length; flp++ )
        {
            faultSequence[ flp ] = ( Point ) seq.get( flp );
        }
        
        int ISS = 30; double tSetup = 0.84;
        //int[] samLen = { 5 }; int[] samPos = { 45 };
        boolean sameRndPerGen = false; boolean alwaysResetBeforeRun = false; // Noise 2, 3
        
        FitnessFunction inFF;
        if( config[ IX_FIT_FUN ].indexOf( 'C' ) >= 0  )
        {
            inFF = new SimpleCorrelationFitnessFunction();
        }else
        {
            // Assume is sum
            inFF = new SumFitnessFunction();
        }
        inFF = new PessimisticFitnessFunction( inFF );
        if( config[ IX_FIT_FUN ].indexOf( 'L' ) >= 0 )
        {
            inFF = new PerRowFitnessFunction( inFF );
        }
        
        FitnessFunction samFF = inFF;
        if( config[ IX_SAMPLE ].indexOf( "Avg" ) >= 0 )
        {
            samFF = new AverageSampleFitnessFunction( inFF );
        }
        
        FitnessFunction fitnessFunction;
        if( config[ IX_SAMPLE ].indexOf( "NoisyAvg5" ) >= 0  )
        {
            fitnessFunction = new NoisySampleWindowFitnessFunction( inFF, 25, 30, 0.7, 0 );
        }else
        {
            int start = 25;
            if( !config[ IX_SAMPLE ].equals( "Avg" ) )
            {
                start = Integer.parseInt( config[ IX_SAMPLE ] );
            }
            fitnessFunction = new SampleWindowFitnessFunction( samFF, start );
        }

        TestPatternGenerator tpg;
        if( config[ IX_TPG ].indexOf( "TP" ) >=0 )
        {
            tpg = new CompleteShuffledTPG();
        }else
        {
            // Assume N1
            int repeats = 1;    
            tpg = new NRepeatsTPG( repeats );
        }
        
        String blifFileName = "/home/mmg20/eh/benchmarks/" + benchmark + ".blif";
        ConfigurableRandomInputExperiment experiment = new CombinationalBLIFExperiment( blifFileName, fitnessFunction, tpg );
        String sisOutputFileName = "/home/mmg20/eh/benchmarks/" + benchmark + "L4.sout";
        int resQ = 0;        boolean fpga = false;        boolean voter = false;     boolean varSized = false;
        int LUT_INPUTS = 4;    int DUMP_POP_EVERY = Integer.MAX_VALUE;
        SisOutputReader sor = new SisOutputReader( new File( sisOutputFileName ), resQ, LUT_INPUTS, fpga, voter, getIntConfig( IX_EXTRA_BPV ), varSized );
        Genotype seed;
        if( config[ IX_FIT_FUN ].indexOf( "SSC" ) >= 0 )
        {
            seed = new FlagAbsoluteOrderGenotype( sor.getVassilevGenotype(), RepairFaultSequenceIM.ELITE_FLAG, RepairFaultSequenceIM.ELITE_FLAG_PROPERTY_INDEX );
            seed.setProperty( RepairFaultSequenceIM.ELITE_FLAG_PROPERTY_INDEX, RepairFaultSequenceIM.ELITE_FLAG );
        }else
        {
            seed = new Genotype( sor.getVassilevGenotype() );
        }
        int bitsPerVar = sor.getBitsPerVar();        int usedEls = sor.getTotalEls();
        int addEls = ( 1 << bitsPerVar ) - experiment.getNumOfInputs();
        int MU_D = 3 * GENS_PER_MIN;   int MU_S = 1 * GENS_PER_MIN;
        MU_D *= 2 * addEls; MU_S *= 2 * addEls;// must multiply these by number of elements in circuit and popsize
        ElementDelayModel delayModel = new DriftingGaussianDelayModel( getIntConfig( IX_DELAY_MIN ),getIntConfig( IX_DELAY_MAX ),getDoubleConfig( IX_DELAY_VAR ),MU_D,MU_S ); // Noise 1
        //ElementDelayModel delayModel = new GaussianDelayModel( MIN_MU, SIGMA ); // mu,s        
        CircuitMapping inMap = new LUTAbsoluteMapping( experiment.getNumOfInputs(), experiment.getNumOfOutputs(), bitsPerVar, LUT_INPUTS, delayModel );
        CircuitMapping circuitMapping = new VassilevMapping( inMap, experiment.getNumOfOutputs(), bitsPerVar );
        circuitMapping = new FaultyOptimizedMapping( circuitMapping );
        SimulatorFaultyCircuit circuit = new SimulatorFaultyCircuit( circuitMapping );
        SimulatorDeployment deployment = new SimulatorDeployment( circuit, alwaysResetBeforeRun );
        int POP_SIZE = 2;  int NUM_OF_ELITES = 1;  double[] RANK_PROBS = { 1,0 };
        int genotypeLength = seed.length(); final Genotype[] SEEDS = { seed };
        GeneticOperator m = new ExactGenotypeMutator( getIntConfig( IX_MUT_RATE ) );   GeneticOperator[] geneticOps = { m };  double[] opsProbs = { 1 };        
        Selector selector = new RankSelector( RANK_PROBS );
        Evolver evolver = new StandardEvolver( POP_SIZE, genotypeLength, geneticOps, opsProbs, selector, NUM_OF_ELITES, SEEDS );
        InteractionModel inIM;
        if( config[ IX_FIT_FUN ].indexOf( "SSC" ) >= 0 )
        {
            FitnessFunction inFF1 = new SimpleCorrelationFitnessFunction();
            FitnessFunction inFF2 = new SumFitnessFunction();
            int start = Integer.parseInt( config[ IX_SAMPLE ] );
            FitnessFunction FF1 = new SampleWindowFitnessFunction( inFF1, start );
            FitnessFunction FF2 = new SampleWindowFitnessFunction( inFF2, start );
            ConfigurableRandomInputExperiment experiment1 = new CombinationalBLIFExperiment( blifFileName, FF1, tpg );
            ConfigurableRandomInputExperiment experiment2 = new CombinationalBLIFExperiment( blifFileName, FF2, tpg );
            ConfigurableRandomInputExperiment[] exps = { experiment1, experiment2 };
            inIM = new MultipleExperimentIM( evolver, deployment, exps, ISS );
        }else
        {
            inIM = new StandardInteractionModel( evolver, deployment, experiment,ISS );
        }
        InteractionModel nIM = new NoisyIM( inIM, deployment, experiment, 1, NoisyIM.MINIMUM, sameRndPerGen );
        InteractionModel hIM = new HistoryWindowIM( getIntConfig( IX_H ), nIM );        
        String subDirName = "" + ix;  new File( logDir + subDirName ).mkdirs();
        int maxGensPerFault = GENS_PER_MIN * getIntConfig( IX_TIMEOUT );
        InteractionModel interactionModel = new RepairFaultSequenceIM( hIM, circuit, faultSequence, maxGensPerFault, getIntConfig( IX_H ) + 1 ); // to fill up history window with solutions
        Monica monica = new Monica( interactionModel, DUMP_POP_EVERY, java.lang.Integer.MAX_VALUE );
        monica.setName( "R" );
        taskQ.add( monica );
        taskQNames.add( subDirName );
    }
}

⌨️ 快捷键说明

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