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

📄 testingtesterbistpimcomb.java~

📁 Java遗传算法库
💻 JAVA~
字号:
/* * TesterTestingBISTPIMComb.java * * Created on 12 June 2003, 16:21 */package jaga.pj.circuits.control;import jaga.SampleData;import jaga.Genotype;import jaga.evolve.Evolver;import jaga.deploy.Deployment;import jaga.experiment.ConfigurableExperiment;import jaga.pj.circuits.fpgaft.SimulatorFaultyCircuit;import jaga.pj.circuits.fpgaft.FTLib;import islandev.SnapshotPainter;import java.util.Iterator;import java.util.Set;import java.util.HashSet;import java.util.Hashtable;import java.util.Collection;//import java.util.Vector;import java.awt.Point;/** Interaction Model for evolving circuits whose E line(s) go high before a number of faults * affect the output, no matter in what order or what inputs are fed into the circuit.  The simple * mode evolves circuits for which all input vectors are assumed to be fed into the circuit between  * faults arriving. * * @author  mmg20 */public class TestingTesterBISTPIMComb extends TestingTesterBISTPIM {        // Config    protected boolean simpleMode = false;        // Working    protected SimulatorFaultyCircuit circuit;    protected Hashtable noFaultQs;        protected double validChunkProp = 0.2; // Proportion at end of output data used to measure its value.            public TestingTesterBISTPIMComb(Evolver evo, Deployment deployment, ConfigurableExperiment experiment, SimulatorFaultyCircuit faultyCircuit, double[] thresholds, int sizeOfEHigh, int numOfELines, int roundForAverage, int howManySimultFaults, int startAt, int getEMode, int iss, boolean simpleMode, SnapshotPainter painter )    {        this( evo, deployment, experiment, faultyCircuit, thresholds, sizeOfEHigh, numOfELines, roundForAverage, howManySimultFaults, startAt, getEMode, iss, painter );        this.simpleMode = simpleMode;    }        /** Creates a new instance of TesterTestingBISTPIMComb */    public TestingTesterBISTPIMComb(Evolver evo, Deployment deployment, ConfigurableExperiment experiment, SimulatorFaultyCircuit faultyCircuit, double[] thresholds, int sizeOfEHigh, int numOfELines, int roundForAverage, int howManySimultFaults, int startAt, int getEMode, int iss, SnapshotPainter painter ) {        super( evo, deployment, experiment, thresholds, sizeOfEHigh, numOfELines, roundForAverage, howManySimultFaults, startAt, getEMode, iss, painter );        circuit = faultyCircuit;        defFitFunK = 990; // So that with 10 undetected faults, will have .99 fitness.  General formula is        // k=f*n/(1-f) where n is undetected faults and f is fitness for this n    }            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 )        {            //System.out.println("E High during eval, Removing from list" + thisRoundInds[ 0 ] );//D            try            {                thisRoundIndsI[ 0 ].remove();                ind.setProperty( 0, new Double( 0 ) );                ind.setProperty( 1, new Double( 0 ) );            }catch( IllegalStateException e )            {                //System.out.println("Trying to remove twice...");            }                    }else        {            int inVLen = ins[ 0 ].length();            int[] compactOuts = new int[ inVLen ];            for( int idl = 0; idl < inVLen; idl++ )            {                compactOuts[ idl ] = BISTLib.getOutAt( outs, idl, nrEs, iss, validChunkProp );            }            Hashtable ixByIns = ( Hashtable ) noFaultQs.get( ind );            if( ixByIns == null )            {                ixByIns = new Hashtable();                noFaultQs.put( ind, ixByIns );            }            ixByIns.put( exp.get( null ), compactOuts );            //System.out.println("Ind " + ind + " table just added and retrieved as " + noFaultQs.get( ind ) ); //D        }        return rv;    }        protected int[] evalAllFaultCombs( int maxDepth, Genotype ind, SampleData[] ins )    {        Object expNoiseKey = exp.get( null );        Hashtable individualTable = ( Hashtable ) noFaultQs.get( ind );        //System.out.println("individual " + ind + " table is " + individualTable);//D        int[] noFQ = ( int[] ) individualTable.get( expNoiseKey );                if( noFQ == null )        {            int[] uf = new int[ maxDepth ];            uf[ 0 ] = Integer.MAX_VALUE;            System.out.println("HEEEEEEEEEEEELPPPPPPPPPPPP SHOULDN@T HAPPENNNNNNNNN!!");            System.out.println("HEEEEEEEEEEEELPPPPPPPPPPPP SHOULDN@T HAPPENNNNNNNNN!!");            System.out.println("HEEEEEEEEEEEELPPPPPPPPPPPP SHOULDN@T HAPPENNNNNNNNN!!");            System.out.println("HEEEEEEEEEEEELPPPPPPPPPPPP SHOULDN@T HAPPENNNNNNNNN!!");            return uf;        }                // 1. Initialize        Collection F = BISTLib.buildAllFaultsColl( circuit );                Set A = new HashSet();        Set C = new HashSet();      C.add( new HashSet() );        Set D = null;        Hashtable CE = new Hashtable();        Hashtable DE = null;                int[] uf = new int[ maxDepth ];        int inpCombs = 1 << ins.length;        int nrEls = F.size() / 2; // !! hardcoded two fault types                // 2.        for( int currDepth = 0; currDepth < maxDepth; currDepth++ )        {            // Debug            /*            System.out.println("Depth: " + currDepth );            System.out.println("uf = " + uf);            System.out.println("A,C,D,CE,DE:" + A );            System.out.println(C);            System.out.println(D);            */            D = C;            DE = CE;            C = new HashSet();            CE = new Hashtable();            Iterator dit = D.iterator();            while( dit.hasNext() )            {                Set di = ( Set ) dit.next();                Iterator fit = F.iterator();                while( fit.hasNext() )                {                    Point fault = ( Point ) fit.next();                    if( !posClash( fault, di ) )                    {                        Set cij = new HashSet( di );                        cij.add( fault );                        Iterator ait = A.iterator();                        boolean aclash = false;                        while( ait.hasNext() && !aclash )                        {                            Set ar = ( Set ) ait.next();                            if( cij.containsAll( ar ) )                            {                                aclash = true;                            }                        }                        if( !aclash )                        {                            C.add( cij );                        }// !! else could add score, but could be incomplete                    }                }            }            if( C.isEmpty() )            {                break;            }                        // Debug            /*if( maxDepth > 1 )            {                System.out.println("Step 2 Over, now C,D = " + C + ", \n" + D);            }*/                        // 3.            // 3.1 Evaluate            Iterator cit = C.iterator();            while( cit.hasNext() )            {                Set ci = ( Set ) cit.next();                setFaults( ci );                circuit.randomReset(); // Random Reset inserted 22/1/04                SampleData[] outs = deploy.run( ins );                removeFaults( ci );                boolean[] es = getEs( outs );                                boolean commonZero = false;                if( !simpleMode )                {                    Iterator djt = D.iterator();                    while( djt.hasNext() && !commonZero )                    {                        Set dj = ( Set ) djt.next();                        if( dj.isEmpty() )                        {                            commonZero = true;                            //System.out.println("Common Zero between empty dj, ci " + ci );                        }else if( ci.containsAll( dj ) )                        {                            boolean[] djes = ( boolean[] ) DE.get( dj );                            if( commonZero( es, djes ) )                            {                                commonZero = true;                                //System.out.println("Common Zero between dj ci " + dj + ", " + ci );                            }                        }                    }                }                if( simpleMode || commonZero )                {                                        int undetectedFails = 0;                    boolean someEHigh = false;                    boolean allEHigh = true;                    for( int il = 0; il < inpCombs; il++ )                    {                        if( ( getQ( outs, il ) != noFQ[ il ] ) && !es[ il ] )                        {                            undetectedFails++;                        }                        someEHigh |= es[ il ];                        allEHigh &= es[ il ];                    }                                        if( undetectedFails > 0 )                    {                        //System.out.println("" + ci + " undetected " + undetectedFails );                        for( int dl = currDepth; dl < maxDepth; dl++ )                        {                            uf[ dl ] += undetectedFails;                            uf[ dl ] += sumCrx( nrEls, ci.size(), dl );                        }                        A.add( ci );                        cit.remove();                    }else if( simpleMode && someEHigh )                    {                        //System.out.println("Some E High so removing" + ci );                        cit.remove();                    }else if( !simpleMode && allEHigh )                    {                        //System.out.println("All E High so removing" + ci );                        cit.remove();                    }else                    {                        CE.put( ci, es );                    }                }else if( !simpleMode )                {                    cit.remove();                    //System.out.println("Removing from C " + ci);                }            } // Next ci        } // Back to step 2        return uf;    }        /** Returns true if there is in fs a Point whose x coord (fault pos) is equal to that of f     */    public static boolean posClash( Point f, Collection fs )    {        Iterator fit = fs.iterator();        while( fit.hasNext() )        {            Point fi = ( Point )fit.next();            if( f.x == fi.x )            {                return true;            }        }        return false;    }        /** Sets a number of faults inside the set fs     */    protected void setFaults( Set fs )    {        Iterator fit = fs.iterator();        while( fit.hasNext() )        {            Point fi = ( Point )fit.next();            circuit.setFault( fi );        }    }        /** Removes a number of faults inside the set fs     */    protected void removeFaults( Set fs )    {        Iterator fit = fs.iterator();        while( fit.hasNext() )        {            Point fi = ( Point )fit.next();            circuit.removeFault( fi );        }    }        /** Extracts the values of E during each input loop and puts it in an array.  If nrEs > 1     * then an oring of all of them is made.     */    public boolean[] getEs( SampleData[] outs )    {        int itplen = outs[ 0 ].length() / iss;        boolean[] rv = new boolean[ itplen ];        for( int il = 0; il < itplen; il++ )        {            rv[ il ] = BISTLib.getE( outs, il, eSize, nrEs, iss, startAt );        }        return rv;    }        /** Returns true if there exists an index n st. a[n]==false==b[n].     * Length of b must be >= length of a.     */    public static boolean commonZero( boolean[] a, boolean[] b )    {        for( int al = 0; al < a.length; al++ )        {            if( !a[ al ] && !b[ al ] )            {                return true;            }        }        return false;    }        /** GetQ is a forwarder for BISTLib.getOutAt to make code cleaner     */    protected int getQ( SampleData[] outs, int ix )    {        return BISTLib.getOutAt( outs, ix, nrEs, iss, validChunkProp );    }        /** SumCrx is a special summation to calculate how many nodes are cut off from the      * tree when a node is added to A.  This is equal to: SUM(r=1,maxDepth-1){ C(nrEls-ciSize,r) * 2^r }     * If maxDepth > nrEls then it was probably set to infinity so it should be = nrEls     */    public static int sumCrx( int nrEls, int ciSize, int maxDepth )    {        int rv = 0;        maxDepth = Math.min( nrEls, maxDepth );        for( int r = 1; r < maxDepth - 1; r++ )        {            rv += jaga.ESLib.binomialCoefficient( nrEls - ciSize, r ) * ( 1 << r );        }        return rv;    }        protected void resetForNewGeneration()    {        super.resetForNewGeneration();        noFaultQs = new Hashtable();    }        public String toString()    {        String rv = "Testing the Tester BIST PIM for Combinational Circuits with Superclass: " + super.toString();        return rv;    }    }

⌨️ 快捷键说明

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