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

📄 faulttolerationim.java

📁 Java遗传算法库
💻 JAVA
字号:
/*
 * FaultTolerationIM.java
 *
 * Created on 09 June 2002, 18:08
 */

package jaga.pj.circuits.control;

import jaga.control.*;
import jaga.*;
import jaga.pj.circuits.fpgaft.*;

/**
 *
 * @author  Michael Garvie
 * @version 
 */
public class FaultTolerationIM extends StandardInteractionModel {

    protected SimulatorFaultyCircuit circuit;
    protected SingleFaultModel faultModel;
    
    protected final double w_e = 0.9;         protected final double w_ft = 1 - w_e;
    protected final double threshold = 0.1;
    
    /** Creates new FaultTolerationIM */
    public FaultTolerationIM ( jaga.evolve.Evolver evo, jaga.deploy.Deployment dep, SimulatorFaultyCircuit cir, jaga.experiment.Experiment exp, SingleFaultModel fm )
    {
        super( evo, dep, exp );
        circuit = cir;
        faultModel = fm;
    }
    
    public synchronized double[] evaluate( Genotype[] inds )
    {
        Genotype ind = inds[ 0 ];
        
        // 1. Evaluate Ind with no faults.
        deployment.program( ind );
        SampleData[] input = experiment.generateInput( inputSampleSeparation );
        SampleData[] output = deployment.run( input );
        double f_e = experiment.getFitness( input, output );
        
        // 2. Evaluate under all faults in used elements & Collect stats
        boolean[] usedEls = jaga.pj.circuits.CircuitsLib.getUsed( circuit );
        int nrTested = 0;
        int nrFaults = 0;   int faultsTolerated = 0;
        faultModel.reset();
        while( faultModel.hasMoreElements() )
        {
            // 2.1 Set Fault and run circuit
            java.awt.Point fPosVal = ( java.awt.Point ) faultModel.nextElement();
            if( usedEls[ fPosVal.x ] )
            {
                nrTested++;
                circuit.setFault( fPosVal.x, fPosVal.y );
                circuit.reset();
                output = deployment.run( input );

                // 2.2 Evaluate behaviour
                double f_f_i = experiment.getFitness( input, output );
                if( f_f_i > f_e - threshold )
                {
                    faultsTolerated++;
                }

                // 2.3 Clear fault
                circuit.setFault( fPosVal.x, FTLib.NOFAULT );
            }
            nrFaults++;
        }

        // 3. Calculate Fitness
        double f_ft = ( double ) faultsTolerated / ( double ) nrTested;
        double fitness = w_e * f_e * f_e + w_ft * f_ft;
        houseWork( ind, fitness );
        ind.setProperty( 0, new Double( f_e ) );
        ind.setProperty( 1, new Double( f_ft ) );
        double[] rv = { fitness };
        return rv;
    }
}

⌨️ 快捷键说明

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