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

📄 evorepair.java

📁 Java遗传算法库
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package jaga.pj.circuits.control;

import jaga.control.*;import jaga.deploy.*;import jaga.evolve.*;import jaga.experiment.*;import jaga.*;
import jaga.pj.circuits.*;import jaga.pj.circuits.experiment.*;import jaga.pj.circuits.fpgaft.*;
import jaga.pj.gral.*;import islandev.IslandsEvolutionServer;import debug.DebugLib;
import java.util.Vector;import java.util.Random;import java.rmi.*;import java.io.*;import java.awt.Point;
import java.util.ArrayList;
import distrit.*;

public class EvoRepair implements InteractiveTaskServer
{
    // Simulation Config Constants
    protected final int CLOCK_SPEED_MHZ = 10;
    protected final int HOUSEWORK_CYCLES = 20;
    protected final int AVG_TP_LENGTH = 50; // This is for CM42 N1
    protected final int EVALS_PER_SEC = CLOCK_SPEED_MHZ * 1000000 / ( HOUSEWORK_CYCLES + AVG_TP_LENGTH );
    protected final int GENS_PER_SEC = EVALS_PER_SEC / 2;
    protected final int EVALS_PER_MIN = EVALS_PER_SEC * 60, GENS_PER_MIN = EVALS_PER_MIN / 2;
    protected final int EVALS_PER_HOUR = EVALS_PER_MIN * 60, GENS_PER_HOUR = EVALS_PER_HOUR / 2;
    
    //Other Constants
    protected final int SEQUENCE_LENGTH_S_MULT = 3;
    
    // Defaults Config Constants
    protected final int IX_FIT_FUN = 0;
    protected final int IX_SAMPLE = 1;
    protected final int IX_TPG = 2;
    protected final int IX_TIMEOUT = 3;
    protected final int IX_DELAY_MIN = 4;
    protected final int IX_DELAY_MAX = 5;
    protected final int IX_DELAY_VAR = 6;
    protected final int IX_H = 7;
    protected final int IX_EXTRA_BPV = 8;
    protected final int IX_EXTRA_DESCR = 9;
    protected final int IX_MUT_RATE = 10;
    
    // Configuration
    protected String[] config = new String[ 11 ];
    protected String[] configOption = new String[ 11 ];
    
    // Default setup configuration
    protected void setupConfig()
    {
        config[ IX_FIT_FUN ] = "C";     configOption[ IX_FIT_FUN ] = "ff";
        config[ IX_SAMPLE ] = "15";     configOption[ IX_SAMPLE ] = "s";
        config[ IX_TPG ] = "TP";        configOption[ IX_TPG ] = "tpg";
        config[ IX_TIMEOUT ] = "1";     configOption[ IX_TIMEOUT ] = "t";
        config[ IX_DELAY_MIN ] = "0";   configOption[ IX_DELAY_MIN ] = "dm";
        config[ IX_DELAY_MAX ] = "1";   configOption[ IX_DELAY_MAX ] = "dM";
        config[ IX_DELAY_VAR ] = "0.4"; configOption[ IX_DELAY_VAR ] = "dv";
        config[ IX_H ] = "32";          configOption[ IX_H ] = "h";
        config[ IX_EXTRA_BPV ] = "0";   configOption[ IX_EXTRA_BPV ] = "ebpv";
        config[ IX_EXTRA_DESCR ] = "";  configOption[ IX_EXTRA_DESCR ] = "edescr";
        config[ IX_MUT_RATE ] = "1";    configOption[ IX_MUT_RATE ] = "m";
    }
    
    protected void updateConfig( ArrayList args )
    {   for( int alp = 0; alp < args.size(); alp++ )
        {   
            String withoutFirst = ( ( String ) args.get( alp ) ).substring( 1 );
            int ix = ESLib.equalsIndexOf( withoutFirst, configOption );
            if( ix >= 0 ) config[ ix ] = args.get( ++alp ) + "";
    }   }
    
    protected int getIntConfig( int ix ){   return Integer.parseInt( config[ ix ] );    }
    protected double getDoubleConfig( int ix ){   return Double.parseDouble( config[ ix ] );    }
    
    // Server Config Constants 
    protected final double MIGRATION_RATE = 0;
    
    // Other Constants
    protected final String FS = File.separator;
    
    // Working
    protected Vector taskQ = new Vector();
    protected Vector taskQNames = new Vector();
    protected IslandsEvolutionServer ies;
    protected String logFileName, logDir, benchmark;
    
    public EvoRepair( ArrayList extraArgs ) throws IOException
    {
        setupConfig();
        logFileName = ( String ) extraArgs.get( 1 );
        benchmark = ( String ) extraArgs.get( 2 );
        int M = Integer.parseInt( ( String ) extraArgs.get( 3 ) );
        int ixOffset = Integer.parseInt( ( String ) extraArgs.get( 4 ) );
        
        updateConfig( extraArgs );
                
        logDir = ( String ) extraArgs.get( 0 ) + "Repair" + FS + benchmark + FS + getDescription() + FS; new File( logDir ).mkdirs();
                
        addRepairComBenchMultipleNoLatch( M, ixOffset );

        ies = new IslandsEvolutionServer( taskQ, taskQNames, logDir, logFileName, MIGRATION_RATE );
    }
    
    
    public Object getID(Object initialParameters) throws RemoteException {
        return ies.getID( initialParameters );
    }    
    public InteractiveTask getTask(Object id) throws RemoteException {
        return ies.getTask( id );
    }    
    public Object interact(Object ID, Object clientTaskOutput) throws RemoteException {
        return ies.interact( ID, clientTaskOutput );
    }    
    
    public String getDescription()
    {
        String description = config[ IX_FIT_FUN ] + "_" + config[ IX_SAMPLE ] + "_" + config[ IX_TPG ];
        if( !config[ IX_EXTRA_DESCR ].equals( "" ) )
        {
            description += "_" + config[ IX_EXTRA_DESCR ];
        }
        return description;
    }
    
    public String toString()
    {
        String rv = "EvoRepair server description = " + getDescription();
        return rv;
    }
    
    
    // -------------- FROM HERE ON METHODS TO ADD TASKS TO THE QUEUE --------------
        
    private  int countBelow( Vector ints, int belowWhat )
    {
        int rv = 0;
        for( int el = 0; el < ints.size(); el++ )
        {
            int intVal = ( ( Integer ) ints.get( el ) ).intValue();
            if( intVal < belowWhat )
            {
                rv++;
            }
        }
        return rv;
    }    
        
    private void addRepairComBenchMultipleNoLatch( int M, int ixOffset ) throws IOException
    {
        String sisOutputFileName = "/home/mmg20/eh/benchmarks/" + benchmark + "L4.sout";
        int resQ = 0;    boolean fpga = false;    boolean voter = false;    int LUT_INPUTS = 4;  boolean varSized = false;
        
        SisOutputReader sor = new SisOutputReader( new File( sisOutputFileName ), resQ, LUT_INPUTS, fpga, voter, getIntConfig( IX_EXTRA_BPV ), varSized );
        int usedEls = sor.getTotalEls();
        int bitsPerVar = sor.getBitsPerVar();
        String blifFileName = "/home/mmg20/eh/benchmarks/" + benchmark + ".blif";
        ConfigurableRandomInputExperiment combexp = new CombinationalBLIFExperiment( blifFileName );
        int nrIns = combexp.getNumOfInputs();// no latch, no clock
        int totalCLBs = ( 1 << bitsPerVar ) - nrIns;
        int spareLUTs = totalCLBs - usedEls;
        int maxGens = GENS_PER_MIN * getIntConfig( IX_TIMEOUT );
        
        String narrator = "Repairing combinational benchmark: " + benchmark + " under multiple faults.";
        narrator += "\nBPV(CLB) = " + bitsPerVar + ".  Total CLBs = " + totalCLBs + ".  Used LUTs = " + usedEls;
        narrator += "\nSpares: " + spareLUTs + " LUTs. ";

⌨️ 快捷键说明

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