?? evotsc.java~
字號:
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 distrit.*;
import java.util.Vector;import java.rmi.*;import java.io.*;import java.util.ArrayList;
public class EvoTSC implements InteractiveTaskServer
{
// Configuration constants
protected final String BENCHMARK_DIR = "/home/mmg20/eh/benchmarks/";
// Working
protected Vector taskQ = new Vector(), taskQNames = new Vector(), taskQDescr = new Vector();
protected Vector taskQBestIndID = new Vector(), taskQEffort = new Vector();
protected String logDir, logFileName; protected IslandsEvolutionServer ies;
// Defaults Config Constants
protected final int IX_LOG_SQL = 0;
protected final int IX_LOG_TOP = 1;
protected final int IX_DESCR = 2;
protected final int IX_BEST_HD = 3;
protected final int IX_LUT_INS = 4;
protected final int IX_SPACE_FOR_VOTER = 5;
protected final int IX_LOCKED = 6;
protected final int IX_MIGRATION_RATE = 7;
protected final int IX_MODE = 8;
protected final int IX_GRAPH_REFRESH_MIN = 9;
protected final int IX_DUMP_POP_EVERY = 10;
// Configuration
protected String[] config = new String[ 11 ];
protected String[] configOption = new String[ 11 ];
// Default setup configuration
protected void setupConfig()
{
config[ IX_LOG_SQL ] = "false"; configOption[ IX_LOG_SQL ] = "logSQL";
config[ IX_LOG_TOP ] = "false"; configOption[ IX_LOG_TOP ] = "logTop";
config[ IX_DESCR ] = "Evolving_TSC";configOption[ IX_DESCR ] = "descr";
config[ IX_BEST_HD ] = "0"; configOption[ IX_BEST_HD ] = "bestHD";
config[ IX_LUT_INS ] = "2"; configOption[ IX_LUT_INS ] = "lutIns";
config[ IX_SPACE_FOR_VOTER ] = "true"; configOption[ IX_SPACE_FOR_VOTER ] = "v";
config[ IX_LOCKED ] = "false"; configOption[ IX_LOCKED ] = "l";
config[ IX_MIGRATION_RATE ] = "1"; configOption[ IX_MIGRATION_RATE ] = "m";
config[ IX_MODE ] = "ff"; configOption[ IX_MODE ] = "mode";
config[ IX_GRAPH_REFRESH_MIN ] = "720"; configOption[ IX_GRAPH_REFRESH_MIN ] = "grm";
config[ IX_DUMP_POP_EVERY ] = "2000"; configOption[ IX_DUMP_POP_EVERY ] = "popdump";
}
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 ] ); }
protected boolean getBooleanConfig( int ix ){ return config[ ix ].equals( "true" ); }
public EvoTSC(ArrayList extraArgs) throws IOException
{
logDir = ( String ) extraArgs.get( 0 );
logFileName = ( String ) extraArgs.get( 1 );
String benchmarkName = ( String ) extraArgs.get( 2 );
String dirName = ( String ) extraArgs.get( 3 );
setupConfig();
updateConfig( extraArgs );
int LUTInputs = getIntConfig( IX_LUT_INS );
String descr = config[ IX_DESCR ].replace( '_', ' ' );
boolean spaceForVoter = getBooleanConfig( IX_SPACE_FOR_VOTER );
boolean locking = getBooleanConfig( IX_LOCKED );
int bestHD = getIntConfig( IX_BEST_HD );
double migrationRate = getDoubleConfig( IX_MIGRATION_RATE );
String blifFN = BENCHMARK_DIR + benchmarkName + ".blif";
String sisQFN = BENCHMARK_DIR + benchmarkName;
if( LUTInputs == 4 )
{
sisQFN += "L4";
}
sisQFN += ".sout";
if( config[ IX_MODE ].equals( "recurrent" ) )
{
oldAddCombBLIFBenchmark( blifFN, sisQFN, dirName, descr, bestHD, LUTInputs, spaceForVoter, locking );
}else
{
addCombBLIFBenchmark( blifFN, sisQFN, dirName, descr, bestHD, LUTInputs, spaceForVoter, locking );
}
boolean logToDatabase = getBooleanConfig( IX_LOG_SQL );
boolean logTopology = getBooleanConfig( IX_LOG_TOP );
ies = new IslandsEvolutionServer( taskQ, taskQNames, logDir, logFileName, migrationRate, logToDatabase, taskQDescr, taskQBestIndID, taskQEffort, logTopology );
}
// -------------- FROM HERE ON METHODS TO ADD TASKS TO THE QUEUE --------------
protected void addCM42() throws IOException
{
String blifFN = "/home/mmg20/eh/benchmarks/cm42a.blif";
String sisQFN = "/home/mmg20/eh/benchmarks/cm42a.sout";
String dirName = "CM42TSC";
String descr = "Benchmark CM42 (18 gates)";
int bestHD = 549;
int LUTInputs = 2;
boolean spaceForVoter = true;
boolean locking = false;
addCombBLIFBenchmark( blifFN, sisQFN, dirName, descr, bestHD, LUTInputs, spaceForVoter, locking );
}
protected void addBWL4() throws IOException
{
String blifFN = "/home/mmg20/eh/benchmarks/bw.blif";
String sisQFN = "/home/mmg20/eh/benchmarks/bwL4.sout";
String dirName = "BWL4BPV8";
String descr = "Locked Benchmark: BW (144 four-input LUTs)";
int bestHD = 2370;
int LUTInputs = 4;
boolean voter = false;
boolean locking = false;
addCombBLIFBenchmark( blifFN, sisQFN, dirName, descr, bestHD, LUTInputs, voter, locking );
}
protected void addCombBLIFBenchmark( String blifFileName, String sisOutputFileName, String dirName, String descr, int bestIndID ) throws IOException
{
int defaultLUTInputs = 2;
boolean defaultVoter = true;
boolean defaultLocking = true;
addCombBLIFBenchmark( blifFileName, sisOutputFileName, dirName, descr, bestIndID, defaultLUTInputs,defaultVoter,defaultLocking );
}
protected void addCombBLIFBenchmark( String blifFileName, String sisOutputFileName, String dirName, String descr, int bestIndID, int LUTInputs, boolean spaceForVoter, boolean locking ) throws IOException
{
final int INPUT_SAMPLE_SEP = 1; final int SAMPLE_WINDOW_START = 0;
final int DUMP_POP_EVERY = 2000; final int E_LINES = 2;
final int NO_EVALS = 1;
final int E_SIZE = INPUT_SAMPLE_SEP - SAMPLE_WINDOW_START;
final int E_START_AT = SAMPLE_WINDOW_START;
FitnessFunction corrFF = new CorrelationFitnessFunction();
FitnessFunction tSetupFF = new SampleWindowFitnessFunction( corrFF, SAMPLE_WINDOW_START );
TestPatternGenerator tpg = new CompleteShuffledTPG();
CombinationalBLIFExperiment experiment = new CombinationalBLIFExperiment( blifFileName, tSetupFF, tpg );
final boolean FPGA = false;
SisOutputReader sor = new SisOutputReader( new File( sisOutputFileName ), E_LINES, LUTInputs, FPGA, spaceForVoter );
FullOrderGenotype seed = new FullOrderGenotype ( sor.getVassilevGenotype() );
int bitsPerVar = sor.getBitsPerVar(); int usedEls = sor.getTotalEls();
int nrAddUnits = ( 1 << bitsPerVar ) - experiment.getNumOfInputs();
int lutSize = 1 << LUTInputs;
int blockSize = lutSize + LUTInputs * bitsPerVar;
int qDefSize = ( experiment.getNumOfOutputs() + E_LINES ) * bitsPerVar;
int genotypeLength = qDefSize + nrAddUnits * blockSize;
//ElementDelayModel delayModel = new CoinDelayModel( );
ElementDelayModel delayModel = new ConstantDelayModel( 0 );
CircuitMapping inMapping = new LUTAbsoluteMapping( experiment.getNumOfInputs(), experiment.getNumOfOutputs() + E_LINES, bitsPerVar, LUTInputs, delayModel );
CircuitMapping circuitMapping = new VassilevMapping( inMapping, experiment.getNumOfOutputs() + E_LINES, bitsPerVar );
int[] inputDefWithinGene = new int[ LUTInputs ];
for( int il = 0; il < LUTInputs; il++ )
{
inputDefWithinGene[ il ] = lutSize + il * bitsPerVar;
}
//circuitMapping = new FeedForwardMapping( circuitMapping, bitsPerVar, blockSize, inputDefWithinGene, qDefSize, -1 );
circuitMapping = new DynamicFeedForwardMapping( circuitMapping, bitsPerVar, blockSize, inputDefWithinGene, qDefSize );
circuitMapping = new FaultyFeedForwardOptimizedMapping( circuitMapping );
SimulatorFaultyCircuit circuit = new SimulatorFaultyCircuitAsynchronous( circuitMapping );
//SimulatorFaultyCircuit circuit = new SimulatorFaultyCircuit( circuitMapping );
SimulatorDeployment deployment = new SimulatorDeployment( circuit );
SingleFaultModel faultModel = new SingleUsedFaultModel( circuit );
final int POP_SIZE = 32; final int NUM_OF_ELITES = 2;
Genotype[] seeds = new Genotype[ POP_SIZE ];
//seeds[ 0 ] = seed;
for( int pl = 0; pl < POP_SIZE; pl++ )
{
seeds[ pl ] = ( FullOrderGenotype ) seed.clone();
for( int bl = qDefSize + usedEls * blockSize; bl < seeds[ pl ].length(); bl++ )
if( Math.random() < 0.5 ) seeds[ pl ].set( bl );
}
int fixedAlignments = locking ? usedEls : 0;
int minMutationRate = Math.max( 1, genotypeLength / 500 );
int maxMutationRate = genotypeLength / 25 + 1;
// was 1000, 50
int SAGAFitnessIndex = 1; int howManyBunches = 1;
GeneticOperator m = new SAGAMutator( minMutationRate, maxMutationRate, SAGAFitnessIndex, fixedAlignments * blockSize, -1 );
//ExactGenotypeMutator m = new ExactGenotypeMutator( ( int ) ( genotypeLength / 500 ) + 1 ); // For real biggies
//m.setRange( fixedAlignments * blockSize, -1 );
GeneticOperator spxo = new SinglePointXOver();
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -