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

📄 simulatorfaultycircuitopt.java~

📁 Java遗传算法库
💻 JAVA~
字号:
/* * SimulatorFaultyCircuit.java * * Created on 24 November 2001, 15:40 */package jaga.pj.circuits.fpgaft;import jaga.*;import jaga.pj.circuits.*;import debug.DebugLib;import java.io.Serializable;import java.awt.Point;/** A circuit to be simulated.  Includes faults, currently only single stuck at * faults are simulated.  Must be extended to provide the reconfigure method * which will take a BitSet and build a network of SimulatorFaultyDelayLE logic * elements of whichever type. <p> *  * @author  Michael Garvie * @version  */public class SimulatorFaultyCircuitOpt extends SimulatorFaultyCircuit{    public final static int NORMAL = 0, OUTPUT_DIFFERENT = 1, LINE_HIGH = 2;        protected int time2Reset = 1; // Number of input samples to ignore while synchronyzing circuits to reset state.    protected boolean scanMode = false;    protected int DQTolerance, lineHighSize, nrLines, ignoreAtStart = 0, groupEvery = 1;    public SimulatorFaultyCircuitOpt(CircuitMapping mapping)    {        super( mapping );    }        public SimulatorFaultyCircuitOpt(CircuitMapping mapping, int DQTol, int lineHighSize)    {        this( mapping, DQTol, lineHighSize, 1 );    }        public SimulatorFaultyCircuitOpt(CircuitMapping mapping, int DQTol, int lineHighSize, int nrLinesToScan)    {        this( mapping );        DQTolerance = DQTol;        this.lineHighSize = lineHighSize;        nrLines = nrLinesToScan;    }        public SimulatorFaultyCircuitOpt(CircuitMapping mapping, int DQTol, int lineHighSize, int nrLinesToScan, int time2Rst )    {        this( mapping, DQTol, lineHighSize, nrLinesToScan );        time2Reset = time2Rst;    }        public SimulatorFaultyCircuitOpt(CircuitMapping mapping, int DQTol, int lineHighSize, int nrLinesToScan, int time2Rst, int ignoreAtStart )    {        this( mapping, DQTol, lineHighSize, nrLinesToScan, time2Rst );        this.ignoreAtStart = ignoreAtStart;    }        public SimulatorFaultyCircuitOpt(CircuitMapping mapping, int DQTol, int lineHighSize, int nrLinesToScan, int time2Rst, int ignoreAtStart, int groupEvery )    {        this( mapping, DQTol, lineHighSize, nrLinesToScan, time2Rst, ignoreAtStart );        this.groupEvery = groupEvery;    }            public SampleData[] run( SampleData[] inputData )    {        scanMode = false;        int[] rv = { 0 };        return this.run( inputData, null, rv );    }        /** Omitted fault, insFautlAt, stopAt */    public SampleData[] run( SampleData[] inputData, SampleData[] desQ, int[] retVal2 )    {        return run( inputData, desQ, retVal2, null, -1, Integer.MAX_VALUE );    }        /** Omitted fault, insFaultAt */    public SampleData[] run( SampleData[] inputData, SampleData[] desQ, int[] retVal2, int stopAt )    {        return run( inputData, desQ, retVal2, null, -1, stopAt );    }        /** Omitted stopAt */    public SampleData[] run( SampleData[] inputData, SampleData[] desQ, int[] retVal2, Point fault, int insFAt )    {        return run( inputData, desQ, retVal2, fault, insFAt, Integer.MAX_VALUE );    }        /** <p>Sends these inputs to the circuit and returns the outputs.     * The input sample separation is taken into account to sample the outputs     * at the appropriate frequency. </p>     *      * <p> If faults are sent with inptus, the first ( ( bitsPerVar + 1 ) * nrSSAFaults ) SampleDatas define stuck      * at faults to be simualted at each point in the input test.  For each of     * the bitsPerVar + 1 sections, the bitsPerVar encode which element is faulty and the      * extra bit what value it's stuck at. </p>     *     * <p> The retVal2 hack is used so that the state of termination of the method can be sent back     * to the caller.  The more proper way of doing this would be to throw Exceptions containing the     * output data so far, but this would be adding inefficiency to an optimization... </p>     *     * @param inputData Inputs fed into circuit, usually their input sample separation > 1.     * @param desQ Desired outputs, if these are different to the current ones for more than DQTolerance we abort with retVal2 flagging OUTPUT_DIFFERENT.     * @param retVal2 int array that must be passed with one element.  It is actually used to return an extra value.     * @param fault Point defining fault to insert during run. (<0 = never )     * @param infFAt Position in input test pattern to insert the fault at.     * @param stopAt Position in input test pattern to halt and exit with retval2[ 0 ] = NORMAL    */    public SampleData[] run( SampleData[] inputData, SampleData[] desQ, int[] retVal2, Point fault, int insFAt, int stopAt )    {        if( desQ != null )        {            scanMode = true;        }        // 1. Set up stuff        int nrOuts = outputs.length;        SampleData[] rv = new SampleData[ nrOuts ];        int inputSampleSeparation = inputData[ 0 ].getSampleSeparation();        int inputDataLength = inputData[ 0 ].length();                // 1.b Scan stuff        int currDQs = 0;        int currLineHighs = 0;                // 2. Init output sample data        for( int odl = 0; odl < nrOuts; odl++ )        {            rv[ odl ] = new SampleData( 1, inputDataLength * inputSampleSeparation );        }                int dlMax = Math.min( stopAt, inputData[ 0 ].length() );                int blockDL = 0;        // 3. Run the circuit!        for( int dl = 0; dl < dlMax; dl++ )        {            // 3.1 Set Fault?            if( dl == insFAt )            {                setFault( fault );            }            // 3.2 Set Inputs            for( int ivl = 0; ivl < inputs.length; ivl++ )            {                inputs[ ivl ].setNow( inputData[ ivl ].get( dl ) );            }                        // So that lineHigh and DQ counting can cross input blocks            if( ( dl % groupEvery ) == 0 )            {                currDQs = 0;                blockDL = 0;            }                        // Let it run for inputSampleSeparation            for( int sdl = 0; sdl < inputSampleSeparation; sdl++, blockDL++ )            {                // Critical Path - We are in this block 75% of total processing time                // Update state                for( int vl = 0; vl < elements.length; vl++ ) // opt for loop in blocks of four?                {                    elements[ vl ].sampleInputs();                }                for( int vl = 0; vl < elements.length; vl++ )                {                    elements[ vl ].refreshOutput();                }                // End Critical Path                // Sample outputs                boolean currQSame = scanMode;                int currQPos = dl * inputSampleSeparation + sdl;                for( int ovl = 0; ovl < nrOuts; ovl++ )                {                    boolean currQovl = outputs[ ovl ].getNow();                    rv[ ovl ].setTo( currQPos, currQovl );                    // Check DQ Scan                    //System.out.println(currQSame);//debug                    if( ovl < nrOuts - nrLines )                    {                        currQSame = currQSame && ( currQovl == desQ[ ovl ].get( currQPos ) );                    }                }                // Update DQScan                if( ( dl >= time2Reset * groupEvery ) && ( blockDL >= ignoreAtStart ) && !currQSame ) // could be more in circuits with long reset time **                {                    currDQs++;                    //System.out.println(currDQs); /debug                }                // Update Line Scan                if(  ( dl >= time2Reset * groupEvery ) && ( blockDL >= ignoreAtStart ) ) // **                {                    // Scan all lines                    boolean lineHighNow = false;                    for( int sl = 0; sl < nrLines; sl++ )                     {                        lineHighNow = lineHighNow || rv[ nrOuts - 1 - sl ].get( currQPos );                    }                    if( lineHighNow )                    {                        currLineHighs++;                        //System.out.println( currLineHighs);                        if( scanMode && ( currLineHighs >= lineHighSize ) )                        {                            //EXIT NOW with LINE_HIGH                            //System.out.println("LineHigh with " + currLineHighs); // debug                            retVal2[ 0 ] = LINE_HIGH;			    rv[ 0 ].setLength( currQPos + 1 ); // to know when aborted for checking equality                            return  rv;                        }                    }else		    {		    	currLineHighs = 0;		    }                }else                {                    currLineHighs = 0;                }                // DEBUG/*                String qstr = "a,b,q,desq" + inputData[0].get(dl)+inputData[1].get(dl)+rv[0].get(currQPos);                if( desQ != null )                {                    qstr += desQ[0].get(currQPos);                }                System.out.println(qstr+currDQs);                //DEBUG   */                                         }//next input            if( scanMode && currDQs >= DQTolerance )            {                // EXIT NOW with OUTPUT_DIFFERENT                //System.out.println("OUTDiff" + currDQs); // debug                retVal2[ 0 ] = OUTPUT_DIFFERENT;		rv[ 0 ].setLength( ( dl + 1 ) * inputSampleSeparation );                return rv;            }        }        retVal2[ 0 ] = NORMAL;        return rv;    }    public String toString()    {        String rv = "Optimized Faulty Simulator Circuit with:";        rv += "\n    # Lines = " + nrLines;        rv += "\n    Line High Size = " + lineHighSize;        rv += "\n    Output Error Tolerance = " + DQTolerance;        rv += "\n    Genotype to Phenotype Mapping: " + circuitMapping;        return rv;    }        }

⌨️ 快捷键说明

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