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

📄 testingtesterbistpimseq.java

📁 Java遗传算法库
💻 JAVA
字号:
/* * TestingTesterBISTPIMSeq.java * * Created on 13 June 2003, 11:16 */package jaga.pj.circuits.control;import jaga.Genotype;import jaga.SampleData;import jaga.evolve.Evolver;import jaga.deploy.Deployment;import jaga.experiment.Experiment;import jaga.pj.circuits.CircuitState;import jaga.pj.circuits.experiment.ConfigurableSequentialCircuitExperiment;import jaga.pj.circuits.fpgaft.SimulatorFaultyCircuitOpt;import islandev.SnapshotPainter;import java.util.Collection;import java.util.Iterator;import java.util.Hashtable;import java.util.HashSet;import java.util.Vector;import java.awt.Point;/** * * @author  mmg20 */public class TestingTesterBISTPIMSeq extends TestingTesterBISTPIM {        // Const    protected static final int STATE = 0;    protected static final int DESQ = 1;        // Config    protected ConfigurableSequentialCircuitExperiment scexp;    protected SimulatorFaultyCircuitOpt circuit;        protected int startAt = 3; // how much to wait until check e! **!! Check this!        // Working    protected Hashtable noFStates;    protected Hashtable singleFStates;        /** Creates a new instance of TestingTesterBISTPIMSeq */    public TestingTesterBISTPIMSeq( Evolver theEvolver, Deployment deployment, ConfigurableSequentialCircuitExperiment experiment, SimulatorFaultyCircuitOpt faultyCircuit, double[] thresholds, int sizeOfEHigh, int numOfELines, int roundForAverage, int howManySimultFaults, SnapshotPainter painter)    {        super( theEvolver, deployment, experiment, thresholds, sizeOfEHigh, numOfELines, roundForAverage, howManySimultFaults, painter );        scexp = experiment;        circuit = faultyCircuit;        defFitFunK = 990d;    }        protected double evalTask( Genotype ind, SampleData[] ins )    {        double rv;        circuit.randomReset();        SampleData[] outs = deploy.run( ins );        SampleData[] outsNoE = jaga.ESLib.getLines( outs, 0, outs.length - nrEs );        rv = exp.getFitness( ins, outsNoE );        // Check that E not high during no faults.  If it is high, somehow signal next round        // to not be evaluated.        boolean eHighNoF = BISTLib.getE( outs, eSize, nrEs, iss, startAt );        if( eHighNoF )        {            thisRoundIndsI[ 0 ].remove();        }else        {            CircuitState cs = circuit.getState();            Vector stateAndDesQ = new Vector( 2 );            stateAndDesQ.add( STATE, cs );            stateAndDesQ.add( DESQ, outs );            Hashtable secondLev = ( Hashtable ) noFStates.get( ind );            if( secondLev == null )            {                secondLev = new Hashtable();                noFStates.put( ind, secondLev );            }            secondLev.put( exp.get( null ), stateAndDesQ );        }        return rv;    }        protected int evalAllFaultCombs(int maxDepth, Genotype ind, SampleData[] ins) {        //System.out.println("" + ind ); //debug        int insFAt = scexp.rndStatePos();        Collection allF = BISTLib.buildAllFaultsColl( circuit );        Vector stateAndDesQ = ( Vector )( ( Hashtable ) noFStates.get( ind ) ).get( exp.get( null ) );        CircuitState noFState = ( CircuitState ) stateAndDesQ.get( STATE );        SampleData[] desQ = ( SampleData[] ) stateAndDesQ.get( DESQ );        int nrEls = allF.size() / 2; // !! Hardcoded nr of types of faults = 2        return testAllFaults( Math.min( maxDepth, nrEls ), 1, nrEls, ins, desQ, allF, insFAt, noFState, new HashSet(), new Vector() );    }    /** Depths (of recursion) start counting at 1     */    protected int testAllFaults( int maxDepth, int currentDepth, int nrEls, SampleData[] ins, SampleData[] desQ, Collection remF, int insFAt, CircuitState prevCircuitState, Collection A, Vector prevSeq )    {        int rv = 0;        if( currentDepth > maxDepth )        {            return 0; // neutral when adding        }                //Debug        //System.out.println("Depth:" + currentDepth + "RemF" + remF);                Iterator remFI = remF.iterator();        while( remFI.hasNext() )        {            Point currF = ( Point ) remFI.next();            int[] rv2 = { -1 };                        Vector currSeq = new Vector( prevSeq );            currSeq.add( currF );            boolean optimize = false;            Iterator ait = A.iterator();            while( ait.hasNext() && !optimize )            {                Vector ai = ( Vector ) ait.next();                if( subSequence( ai, currSeq ) )                {                    optimize = true;                }            }            if( optimize )            {                rv2[ 0 ] = SimulatorFaultyCircuitOpt.OUTPUT_DIFFERENT;            }else            {                circuit.setState( prevCircuitState ); // Includes state of faults                //circuit.randomReset();                circuit.setFault( currF );                //System.out.println("Adding F " + currF );//debug                SampleData[] q; //d                q=circuit.run( ins, desQ, rv2, currF, insFAt );                //System.out.println("First run " + rv2[ 0 ]);//debug                                if( rv2[ 0 ] == SimulatorFaultyCircuitOpt.NORMAL )                {                    q=circuit.run( ins, desQ, rv2 );//d                    //System.out.println("Second run " + rv2[ 0 ]);//debug                }                /*                if( rv2[ 0 ] == SimulatorFaultyCircuitOpt.OUTPUT_DIFFERENT )//d                {                    SampleData[] allQ = { q[ 0 ],q[ 1 ], desQ[ 0 ], desQ[ 1 ] };                    //System.out.println(es.ESLib.sampleDatasToString( ins, allQ));//d                }                 */            }                                    switch( rv2[ 0 ] )            {                case SimulatorFaultyCircuitOpt.NORMAL:                    CircuitState currState = circuit.getState();                    Collection nextRemainingFaults = BISTLib.removeFaultAtPos( currF, new HashSet( remF ) );                    rv += testAllFaults( maxDepth, currentDepth + 1, nrEls, ins, desQ, nextRemainingFaults, insFAt, currState, A, currSeq );                    break;                case SimulatorFaultyCircuitOpt.LINE_HIGH:                     break;                case SimulatorFaultyCircuitOpt.OUTPUT_DIFFERENT:                    //rv += jaga.ESLib.fact( nrEls - currentDepth ) * 1 << ( nrEls - currentDepth ); // Not taking maxDepth into account.                    rv += productOfRange( nrEls - maxDepth + 1, nrEls - currentDepth ) * 1 << ( maxDepth - currentDepth );                    if( !optimize )                    {                        A.add( currSeq );                    }            }            //System.out.println("Removing F " + currF );//debug            circuit.removeFault( currF );        }        return rv;    }    protected void resetForNewGeneration()    {        super.resetForNewGeneration();        noFStates = new Hashtable();        singleFStates = new Hashtable();    }        /** Given that b >= a returns product of all numbers between and including them      * @return a * (a+1) * (a+2) * ... * (b - 1) * b     */    protected int productOfRange( int a, int b )    {        int rv = 1;        for( int i=a; i <= b; i++ )        {            rv *= i;        }        return rv;    }        /** Returns true if vector b contains all elements of vector a and they appear in the same order     */    protected boolean subSequence( Vector a, Vector b )    {        boolean rv = true;        int aSize = a.size();        for( int al = 0; rv && al < aSize; al++ )        {            rv &= a.get( al ).equals( b.get( al ) );        }        return rv;    }    }

⌨️ 快捷键说明

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