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

📄 bistpimseqonlinefull.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.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 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 BISTPIMSeqOnlineFull extends StandardInteractionModel
{
    // Constants
    final int E_HIGH = 1;
    final int E_LOW_OK = 0;
    final int E_LOW_ERROR = -1;
    
    final int nrEs = 1;
    
    // Config Vars
    
    // Variables for finding E
    protected int EStartAt = 0; // For each input cycle, start at ...
    protected int inputResetLength = 0;
    protected int eSize;
    protected int DQTol;
    
    // Variable for extracting value of output (kind of inverse of t_setup)
    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 EStartAt 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 BISTPIMSeqOnlineFull(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 BISTPIMSeqOnlineFull(Evolver evo, Deployment dep, SimulatorFaultyCircuit cir, ConfigurableSequentialCircuitExperiment exp, int iss, SingleFaultModel fm, int es, int DQTol) {
        super( evo, dep, exp, iss );
        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_b = 0, f_b_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, nrEs, 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[] used = getUsed( nrOuts ); // Skipping faults in unused elements.

            int nrInstances = 1; // how many faults tested for 
            int diagInstances = 1; // how many correctly diagnosed, including no faults.
            
            // 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 ];

⌨️ 快捷键说明

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