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

📄 repairtimes.java~

📁 Java遗传算法库
💻 JAVA~
📖 第 1 页 / 共 2 页
字号:
/*
 * MonicaServer.java
 *
 * Created on 16 April 2001, 17:12
 */

package es.pj.circuits.control;

import es.control.*;
import es.deploy.*;
import es.evolve.*;
import es.experiment.*;
import es.*;

import es.pj.circuits.*;
import es.pj.circuits.experiment.*;
import es.pj.circuits.fpgaft.*;
import es.pj.gral.*;

import islandev.IslandsEvolutionServer;

import debug.DebugLib;

import java.util.Vector;
import java.rmi.*;
import java.io.*;

/**
 *
 * @author  Michael Garvie
 * @version 
 */
public abstract class RepairTimes
{
     static Vector taskQ = new Vector();
     static Vector taskQNames = new Vector();
    
    static String logDir;
    static final String logFileName = "repair-log.txt";
    static final double migrationRate = 0.2;
    
    public static void main( String[] args )
    {
        logDir = args[ 0 ];
        DebugLib.trcLogger.isLogging = true;
        DebugLib.logFileName = logFileName;

        String bigRed = "00010010000101011101010010110001001100011100110110000000001111110000000001010000100101110110101110000101111100000011111010000000011111111100000110001100100001100011001100011111011100111011111111101110111011110000011010010101000110110101110011111110000000101110111110001011101111000111111101110001111111111101011111111111100111111011110000000000000000000000000000000000000000000000000000000000";
        String comp7v = "000101000101011000000110011001000101000111101100000111101101000111001111000111011111000000000000000000000000000000000000000000000000000000000000";
        final int R = 5;
       
        /*for( int el = 0; el < 20; el++ )
        {
            for( int rl = 0; rl < R; rl++ )
            {
                add2Mult( el, 0, 5, rl, bigRed );
                add2Mult( el, 1, 5, rl, bigRed );
            }
        }*/
        
        for( int el = 0; el < 7; el++ )
        {
            for( int rl = 0; rl < R; rl++ )
            {
                add2Mult( el, 0, 4, rl, comp7v );
                add2Mult( el, 1, 4, rl, comp7v );
            }
        }
        
        
        try
        {
            IslandsEvolutionServer ms = new IslandsEvolutionServer( "Spok", taskQ, taskQNames, logDir, migrationRate );
            ms.bindServer();
            //MonicaServer ms = new MonicaServer( "MonicaServer", taskQ, taskQNames, args[ 0 ], 0.5 );
        }catch( java.rmi.RemoteException e )
        {
            System.out.println( e );
        }
        
    }

    private static void add2Mult( int faultPos, int faultVal, int bpv, int n, String genome )
    {
        String dirName = "2MultRepair_" + faultPos + "-" + faultVal + "-" + bpv + "-" + n;
        
         final int POP_SIZE = 2;
         final int GENOTYPE_MUT = 1;
         final double MUTATION_PROB = 1;
         final int NUM_OF_ELITES = 1;
         final double[] RANK_PROBS = { 1d, 0d };

        // D -  Circuit Structure Properties
         final int BITS_PER_VARIABLE = bpv;
         final int LUT_INPUTS = 2;

        // D - Simulator Properties
         final int SIMULATOR_GATE_DELAY = 0;
         final double T_SETUP = 0.45;
        // final int INPUT_SAMPLE_SEPARATION = 1;

        // E - Experiment Properties
         final int TEST_LENGTH = 50;

        // M - Log Properties
         int DUMP_POP_EVERY = 60;

        // E - EXPERIMENT set up
        ConfigurableRandomInputExperiment experiment = new MultiplierExperiment( 2, T_SETUP );

        // D - DEPLOYMENT set up
        // SimulatorCircuit circuit = new SimulatorLUTCircuit( SIMULATOR_GATE_DELAY, BITS_PER_VARIABLE , LUT_INPUTS, experiment.getNumOfInputs(), experiment.getNumOfOutputs() );
         ElementDelayModel delayModel = new ConstantDelayModel( SIMULATOR_GATE_DELAY );
         //ElementDelayModel delayModel = new GaussianDelayModel( 0.5, 0.5 );
         CircuitMapping circuitMapping = new VassilevMapping( experiment.getNumOfInputs(), experiment.getNumOfOutputs(), BITS_PER_VARIABLE, LUT_INPUTS, delayModel );
         SimulatorFaultyCircuit circuit = new SimulatorFaultyCircuit( circuitMapping );
         SimulatorDeployment deployment = new SimulatorDeployment( circuit );
        int[] fps = { faultPos };   int[] fvs = { faultVal };
        circuit.setPersistentFaults( fps, fvs );

        // A - Genetic Operators Set up
         int genotypeLength = ( ( 1 << BITS_PER_VARIABLE ) - experiment.getNumOfInputs() ) * ( ( 1 << LUT_INPUTS ) + LUT_INPUTS * BITS_PER_VARIABLE );
        genotypeLength += experiment.getNumOfOutputs() * BITS_PER_VARIABLE;

        String outDef = ( bpv == 4 )? "0000000100100011": "00000000010001000011";
        
        final Genotype SEED0 = new Genotype( outDef + genome );
         final Genotype[] SEEDS = { SEED0 };
        // final Genotype[] SEEDS = { };

         GeneticOperator m = new ExactGenotypeMutator( GENOTYPE_MUT );
         GeneticOperator[] geneticOps = { m };
         double[] opsProbs = { MUTATION_PROB };

        Selector selector = new RankSelector( RANK_PROBS );

         Evolver evolver = new StandardEvolver( POP_SIZE, genotypeLength, geneticOps, opsProbs, selector, NUM_OF_ELITES, SEEDS );

        InteractionModel interactionModel = new StandardInteractionModel( evolver, deployment, experiment );
        //int nrEvals = 8;
        //InteractionModel interactionModel = new NoisyIM( inIm, deployment, experiment, nrEvals );
        Monica monica = new Monica( interactionModel, DUMP_POP_EVERY, java.lang.Integer.MAX_VALUE );
        
        monica.setName( dirName );
        taskQ.add( monica );
        taskQNames.add( dirName );
        ControlLib.writeGNUPlotScript( dirName, logDir, logFileName, 3 );
    }
    
   
    private static void addAdd1BIST( SingleFaultModel faultModel, String fName )
    {

        // A - Genetic Algorithms Properties
        // Standard
         final int POP_SIZE = 32;
         final int TP_POP_SIZE = 7;
         final double BIT_MUTATION_PROB = 0.05;
         final int GENOTYPE_MUT = 1;
         final double XOVER_PROB = 0.4;
         final double ALIEN_PROB = 0;
         final double WIRE_SWAP_PROB = 0.7;
         final double MUTATION_PROB = 0.6;
         final int NUM_OF_ELITES = 2;

         final double TP_XOVER_PROB = 0.5;
         final double TP_MUTATION_PROB = 0.5;
         final int TP_NUM_OF_ELITES = 2;

        final double[] TP_RANK_PROBS = { 8d, 4d, 2d, 1d };

        /* 1+1
         final int POP_SIZE = 2;
         final int TP_POP_SIZE = 2;
         final double BIT_MUTATION_PROB = 0.05;
         final int GENOTYPE_MUT = 2;
         final double XOVER_PROB = 0;
         final double MUTATION_PROB = 1;
         final int NUM_OF_ELITES = 1;

         final double TP_XOVER_PROB = 0;
         final double TP_MUTATION_PROB = 1;
         final int TP_NUM_OF_ELITES = 1;

         final double[] RANK_PROBS = { 1d, 0d };
         final double[] TP_RANK_PROBS = { 1d, 0d };
        */
        // D -  Circuit Structure Properties
         final int BITS_PER_VARIABLE = 4;
         final int LUT_INPUTS = 2;

        /* For NANDC
         final int BITS_PER_VARIABLE = 5;
         final int STABILIZERS = 1;
         final int GATE_INPUTS = 2;
        */

        // D - Simulator Properties
         final int SIMULATOR_GATE_DELAY = 1;
         final double T_SETUP = 0.45;
        // final int INPUT_SAMPLE_SEPARATION = 1;

        // E - Experiment Properties
         final int TEST_LENGTH = 50;

        // M - Log Properties
         int DUMP_POP_EVERY = 60;

        // E - EXPERIMENT set up
        BooleanFunction boolFunQ = new Add1bitQFun();
        BooleanFunction boolFunC = new Add1bitCFun();
        // BooleanFunction boolFun = new MUXFunction( 2 , 4 );
        // BooleanFunction boolFun = new VertorHorizFun();
        // BooleanFunction boolFun = new FLEXToneDetectFun();
         ConfigurableRandomInputExperiment experimentQ = new ArbitraryFunctionExperiment( boolFunQ, T_SETUP );
        ConfigurableRandomInputExperiment experimentC = new ArbitraryFunctionExperiment( boolFunC, T_SETUP );
        ConfigurableRandomInputExperiment[] exps = { experimentQ, experimentC };
        ConfigurableRandomInputExperiment experiment = new ConfigurableRandomInputMultiOutputExperiment( exps );
        
         Experiment tpexp = new TestPattern4EvolvingExperiment( experiment );

        // D - DEPLOYMENT set up
        // SimulatorCircuit circuit = new SimulatorLUTCircuit( SIMULATOR_GATE_DELAY, BITS_PER_VARIABLE , LUT_INPUTS, experiment.getNumOfInputs(), experiment.getNumOfOutputs() );
        //ElementDelayModel delayModel = new ConstantDelayModel( SIMULATOR_GATE_DELAY );
        ElementDelayModel delayModel = new GaussianDelayModel( 0.5, 0.5 );
         CircuitMapping circuitMapping = new LUTAbsoluteMapping( experiment.getNumOfInputs(), experiment.getNumOfOutputs() + 1, BITS_PER_VARIABLE, LUT_INPUTS, delayModel );
         SimulatorFaultyCircuit circuit = new SimulatorFaultyCircuit( circuitMapping );
         SimulatorDeployment deployment = new SimulatorDeployment( circuit );

        // FLEXDeployment deployment = new FLEXDeployment( vFileName,  path2Prog, path2MaxPlus, wrkDir, BITS_PER_VARIABLE, STABILIZERS, GATE_INPUTS, experiment.getNumOfInputs(), experiment.getNumOfOutputs(), PORT_ADD );

        // A - Genetic Operators Set up
        /* For CNAND
         int genotypeLength = GATE_INPUTS * STABILIZERS * ( ( 1 << BITS_PER_VARIABLE ) - experiment.getNumOfInputs() ) * ( BITS_PER_VARIABLE + 1 );        
        */
         int genotypeLength = ( ( 1 << BITS_PER_VARIABLE ) - experiment.getNumOfInputs() ) * ( ( 1 << LUT_INPUTS ) + LUT_INPUTS * BITS_PER_VARIABLE );
         int testPatLength = ( 1 << experiment.getNumOfInputs() ) * 2;
         int tpGenLength = testPatLength * experiment.getNumOfInputs();
         //final Genotype SEED0 = new FullOrderGenotype( "011011011011011010010011000100011000110101011110000000000000100100101111000000000000000000000000000100000101001000001101000000000000011011111110000000000000" ); // SF8 from log
        final Genotype SEED0 = new FullOrderGenotype( "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" ); // SF8 from log
        //GZOsPaRNQBol74^f^Umq81Fupo
         //final Genotype SEED1 = new Genotype( "REPpX8fsLbonVdSFmXG]PHK8^t", genotypeLength, 6 );
        // final Genotype SEED2 = new Genotype( "2GS_i17CiQY8ELA2eO6ZJ8eMnPDTC_jrLtUVdjDG8EEQS\\beNi9PKfu87Jjc3jRiaIqH[ALYJsE11WIqSMRIgj04oBe09jKAhLiLaMVU_08qdSQaImCtgaB4cc[3r3raARcfpAJli0jWiJ0kq4Nk0WPF64USqpH2gi3bBKu2]SRe`cCfknjBqEMKTO7Iu5ru1_THNb72V3n6rWD824uaHW0etY9[[Iv9KTBf`gtYM_AhAq6hNldYCEAdb1i0", genotypeLength, 6 );
        // final Genotype[] SEEDS = { SEED0, SEED1, SEED2 };
         //final Genotype[] SEEDS = { SEED0, SEED1 };
        // final Genotype[] SEEDS = { SEED0 };
        //final Genotype[] SEEDS = { };
        Genotype[] SEEDS = new Genotype[ POP_SIZE ];
        for( int pl = 0; pl < POP_SIZE; pl++ )
        {
            SEEDS[ pl ] = ( FullOrderGenotype ) SEED0.clone();
            for( int bl = 0; bl < SEEDS[ pl ].length(); bl++ )

⌨️ 快捷键说明

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