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

📄 tscsequentialim.java~

📁 Java遗传算法库
💻 JAVA~
📖 第 1 页 / 共 2 页
字号:
/*
 * BISTIM.java
 *
 * Created on 19 May 2002, 18:56
 */

package jaga.pj.circuits.control;

import jaga.evolve.Evolver;
import jaga.deploy.Deployment;
import jaga.experiment.*;
import jaga.control.StandardInteractionModel;
import jaga.*;
import jaga.pj.circuits.CircuitState;
import jaga.pj.circuits.CircuitsLib;
import jaga.pj.circuits.fpgaft.*;
import jaga.pj.circuits.SimulatorLogicElement;
import jaga.pj.circuits.experiment.ConfigurableSequentialCircuitExperiment;
import jaga.pj.circuits.experiment.MealyFSMEdge;
import jaga.pj.circuits.experiment.MealyFSMNode;

import java.util.Random;
import java.util.Vector;
import java.util.Hashtable;
import java.awt.Point;

import islandev.SnapshotPainter;
import islandev.EmptySnapshotPainter;


/** Like BISTPIM but:
 * <ul><li>Only On-Line BIST evaluated (must report first fault affecting outputs)</li>
 * <li>Optimization in SimulatorFaultyCircuitOpt used for sequenial circuits</li>
 * <li>For combinational circuits use BISTPIM</li>
 * <li>Overdetecting always good.
 * </ul>
 *
 * Could cache generated TPS per generation for use with NoisyIM
 */
public class TSCSequentialIM extends StandardInteractionModel
{
    // Constants
    protected final int nrZs = 2;
    protected final int ST_MODE_ANY_STATE = 0;
    protected final int ST_MODE_ALL_STATES = 1;
    
    // Config Vars
    protected int STMode = ST_MODE_ANY_STATE;
    
    // Variables for finding E
    protected int EStartAt = 0; // For each input cycle, start at ...
    protected int inputResetLength = 0;
    protected int eSize;
    protected int DQTol;
    
    protected double threshold = 0.1;
    
    //Working Vars
    protected double currMaxF_e = -1;
    protected SingleFaultModel faultModel;
    protected SingleRandomFaultModel srfm = null; // If its randomness, its randomness will need to be controlled
    protected ConfigurableSequentialCircuitExperiment scexp;
    protected SimulatorFaultyCircuit circuit;
    protected Hashtable TPS = new Hashtable();
    
    /** Evaluate a sequential circuit's BIST behaviour under all State, Fault, Input combinations
     * @param evo Evolver
     * @param dep Deployment
     * @param cir A SimulatorFaultyCircuit which must allow running a section of a test pattern
     * @param exp A Configurable Sequential Circuit Experiment to know at what point in the test pattern new states are entered
     * @param iss Input Sample Separation
     * @param fm Fault Model
     * @param es Number of consecutve highs at the error line E to trigger a "fault detected" event
     * @param painter Circuit painter
     * @param startAt Position within test cycle of length input sample separation until which we can ignore behaviour
     * @param inputResetLength How many input cycles it takes to bring this sequential circuit to its reset state
     */
    public TSCSequentialIM(Evolver evo, Deployment dep, SimulatorFaultyCircuit cir, ConfigurableSequentialCircuitExperiment exp, int iss, SingleFaultModel fm, int es, int DQTol, SnapshotPainter painter, int EStartAt, int inputResetLength) {
        this( evo, dep, cir, exp, iss, fm, es, DQTol );
        this.painter = painter;
        this.EStartAt = EStartAt;
        this.inputResetLength = inputResetLength;
    }
    
    public TSCSequentialIM(Evolver evo, Deployment dep, SimulatorFaultyCircuit cir, ConfigurableSequentialCircuitExperiment exp, int iss, SingleFaultModel fm, int es, int DQTol) {
        super( evo, dep, exp, iss );
        BISTLib.setGetEMode( BISTLib.E_MODE_DUAL );
        scexp = exp;
        circuit = cir;
        faultModel = fm;
        if( faultModel instanceof SingleRandomFaultModel )
        {
            srfm = ( SingleRandomFaultModel ) fm;
        }        
        eSize = es;
        this.DQTol = DQTol;
        
        // Build TPS: Test Patterns to apply at each state s such that all leaving arrows are tested.
        MealyFSMNode[] allStates = exp.getStateGraphNodes();
        int nrStates = allStates.length;
        int nrIns = exp.getNumOfInputs();
        int nrNoCkIns = nrIns - 1;
        int nrNoCkVectors = 1 << nrNoCkIns;
        
        for( int sl = 0; sl < nrStates; sl++ )
        {
            // 1. Create TP BitSets
            MealyFSMNode currState = allStates[ sl ];
            BitSet[] testBits = new BitSet[ nrIns ];
            int nrEdges = currState.getNumOfEdges();
            for( int bl = 0; bl < nrIns; bl++ )
            {
                testBits[ bl ] = new BitSet( nrEdges );
            }
            
            // 2. Fill up TP BitSets
            int TPPos = 0;
            for( int el = 0; el < nrNoCkVectors; el++ )
            {
                if( currState.nextStates[ el ] != null )
                {
                    ESLib.setLine( testBits, TPPos++, el * 2 ); // * 2 because last line (clock) = 0
                }
            }
            
            // 3. Generate SampleData TP from BitSets
            //SampleData[] currTPS = ExperimentLib.generateInputFromTest( testBits, 1, nrEdges, inputSampleSeparation );
            
            // 4. Store TP in TPS Hashset
            TPS.put( currState, testBits );
        }
    }
        
    public void evolve()
    {
        super.evolve();
        if( srfm != null )
        {
            srfm.nextRandomSeries(); // Same for all per generation, but != 'tween generations.
        }
        currMaxF_e = -1;
    }
    
    /** Evaluates these individuals using the deployment and experiments and
     * procedure of this model.
     */
    synchronized public double[] evaluate(Genotype[] inds)
    {
        Genotype ind = inds[ 0 ];

        // 1) Evaluate Ind with no faults.
        deployment.program( ind );
        SampleData[] input = experiment.generateInput( inputSampleSeparation );
        int[] stateEnterPos = scexp.getStateEnterPos();
        MealyFSMNode[] stateEnterNodes = scexp.getStateGraphNodes();
        int nrStates = stateEnterPos.length;
        int prevStateTPPos = 0;
        CircuitState currentState;
                
        //TI//if( !stateNoise ) {
        //TI//circuit.reset();
        //TI//}else{
        //circuit.randomReset();
        //TI//}
        
        SampleData[] noFQWithE = deployment.run( input );
        int nrOuts = noFQWithE.length - 1;
        SampleData[] noFQNoE = ESLib.getLines( noFQWithE, 0, nrOuts );
        double f_e = experiment.getFitness( input, noFQNoE );
        double f_st = 0, f_fs = 0, f_t = 0;
        boolean mainTaskOK = f_e > currMaxF_e - threshold;

        
        // 2) Compute f_b now for all combinations of inputs under every fault at each state
        if( mainTaskOK && !BISTLib.getE( inputResetLength, noFQWithE, eSize, nrZs, inputSampleSeparation, EStartAt ) ) // Check that E low for no faults! If it isn't, then discard.
        {
            Hashtable shuffledTPS = new Hashtable();
            Hashtable TPQS = new Hashtable();
            Hashtable circuitStates = new Hashtable();
            Hashtable EBehaviour = new Hashtable();
            
            currMaxF_e = Math.max( f_e, currMaxF_e );
            
            // 2.1) Init variables.
            //boolean[] usedForY = CircuitsLib.getUsed( circuit, nrYs ); // Skipping faults in unused elements.
            boolean[] usedForYZ = CircuitsLib.getUsed( circuit );

            int nrInstances = 0; // how many faults tested for  // 07-05-04 was 1 changed to 0
            int diagInstances = 0; // how many correctly diagnosed, including no faults. // 07-05-04 was 1 changed to 0
                        
            // 2.2) Move to every state in turn
            for( int sl = 0; sl < nrStates; sl++ )
            {
                circuit.run( input, prevStateTPPos, stateEnterPos[ sl ] + 1 ); // **
                prevStateTPPos = stateEnterPos[ sl ];
                MealyFSMNode currNode = stateEnterNodes[ sl ];
                //TI//longStory += "\nMoving to state " + sl + "(" + currNode + ") at " + stateEnterPos[ sl ] ;
                
                // 2.2.1) Save state
                currentState = circuit.getState();
                circuitStates.put( currNode, currentState );
                
                // 2.2.2) Save no faults behaviour in current state for all inputs
                BitSet[] TPSBits = ( BitSet[] ) TPS.get( currNode );
                BitSet[] shuffledTPSBits = ExperimentLib.shuffleTest( TPSBits );
                shuffledTPS.put( currNode, shuffledTPSBits );
                SampleData[] currTPS = ExperimentLib.generateInputFromTest( shuffledTPSBits, 1, shuffledTPSBits[ 0 ].length(), inputSampleSeparation );
                int nrInputCombinations = currTPS[ 0 ].length();
                SampleData[] currStateQs = circuit.run( currTPS );
                TPQS.put( currNode, currStateQs );
                //TI//longStory += "\nBehaviour " + ESLib.sampleDatasToString( currTPS, currStateQs );
                
                // 2.3) Iterate through faults
                faultModel.reset();
                while( faultModel.hasMoreElements() )
                {
                    Point currFault = ( Point ) faultModel.nextElement();                    

⌨️ 快捷键说明

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