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

📄 singlerandomfaultmodel.java

📁 Java遗传算法库
💻 JAVA
字号:
/*
 * SingleStaticFaultModel.java
 *
 * Created on 18 May 2002, 17:00
 */

package jaga.pj.circuits.fpgaft;

import java.util.Random;

/** A fault model where a single element will fail at any time, but this element
 * will be chosen randomly from a range of values.  The number of elements chose
 * in this series of fautls is also random. <p>
 * To have different random series the randomizer seed must be changed by
 * calling nextRandomSeries().
 *
 * @author  Michael Garvie
 * @version 
 */
public class SingleRandomFaultModel implements SingleFaultModel {

    protected long rndSeed = System.currentTimeMillis();
    protected int floorPos = 0;
    protected int roofPos;
    protected int howMany = 1;
    protected int faultTypes = 2;
    protected int currFaultType = 0;
    protected int howManySoFar = -1;
    protected int currFaultPos = -1;
    
    protected Random rnd = new Random( rndSeed );
    protected Random srnd = new Random();
    
    /** Creates new SingleRandomFaultModel.
     * @param proofPos position of (EXCLUSIVE) highest element number to 
     * randomly pick from.  Note this value will never be picked.
    */
    public SingleRandomFaultModel( int proofPos ) {
        roofPos = proofPos;
    }

    /** Creates new SingleRandomFaultModel
     * @param proofPos position of highest element number to randomly pick from.
     * @param phowMany how many random elements to pick to make sequence.
    */
    public SingleRandomFaultModel( int proofPos, int phowMany ) {
        roofPos = proofPos;
        howMany = phowMany;
    }

    /** Creates new SingleRandomFaultModel
     * @param proofPos position of lowest element number to randomly pick from.
     * @param proofPos position of highest element number to randomly pick from.
     * @param phowMany how many random elements to pick to make sequence.
     * @param ftypes number of fault types to generate.  These are as defined in FTLib.
    */
    public SingleRandomFaultModel( int pfloorPos, int proofPos, int phowMany, int ftypes ) {
        this( proofPos, phowMany );
        faultTypes = ftypes;
        floorPos = pfloorPos;
    }
    
    /** Resets the sequence of faults
     */
    public void reset() {
        howManySoFar = currFaultType = 0;
        currFaultPos = -1;
        rnd = new Random( rndSeed );
    }
    public boolean hasMoreElements() {
        return ( howManySoFar < howMany  );
    }
    public java.lang.Object nextElement() {
        if( currFaultPos < 0 )
        {
            currFaultPos = floorPos + rnd.nextInt( roofPos );
        }
        java.awt.Point rv = new java.awt.Point( currFaultPos, currFaultType++ );
        if( currFaultType == faultTypes )
        {
            howManySoFar++;
            currFaultType = 0;
            currFaultPos = -1;            
        }
        return rv;
    }
    public String toString()
    {
        String rv = "Single Random Fault Model with:";
        rv += "\n  Floor Pos = " + floorPos;
        rv += "\n  Roof Pos = " + roofPos;
        rv += "\n  # of Faults = " + howMany;
        rv += "\n  Fault Types = " + faultTypes;
        return rv;
    }
    public void nextRandomSeries()
    {
        this.rndSeed = srnd.nextLong();
    }
}

⌨️ 快捷键说明

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