📄 evotsca.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 EvoTSCA implements InteractiveTaskServer
{
// Configuration constants
protected final double MIGRATION_RATE = 1;
// 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;
public EvoTSCA(ArrayList extraArgs) throws IOException
{
logDir = ( String ) extraArgs.get( 0 ); logFileName = ( String ) extraArgs.get( 1 );
boolean logToDatabase = true, logTopology = true;
if( extraArgs.size() >= 3 )
{
if( ( ( String ) extraArgs.get( 2 ) ).equalsIgnoreCase( "-L" ) )
{
logToDatabase = false;
System.out.println("Server option: Not logging to SQL database.");
}else if( ( ( String ) extraArgs.get( 2 ) ).equalsIgnoreCase( "-T" ) )
{
logTopology = false;
System.out.println("Server option: Not logging topology data to SQL database.");
}
}
//addTTC17();
//addBWL4();
//addCM42();
addZ4ML();
ies = new IslandsEvolutionServer( taskQ, taskQNames, logDir, logFileName, MIGRATION_RATE, logToDatabase, taskQDescr, taskQBestIndID, taskQEffort, logTopology );
}
// -------------- FROM HERE ON METHODS TO ADD TASKS TO THE QUEUE --------------
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 = 7; final int SAMPLE_WINDOW_START = 5;
final int DUMP_POP_EVERY = 500; 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 FaultyOptimizedMapping( circuitMapping );
SimulatorFaultyCircuit circuit = new SimulatorFaultyCircuit( circuitMapping );
SimulatorDeployment deployment = new SimulatorDeployment( circuit );
SingleFaultModel faultModel = new SingleUsedFaultModel( circuit, experiment.getNumOfOutputs() );
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 = genotypeLength / 500 + 1; 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();
GeneticOperator bmin0 = new BunchMutator( bitsPerVar, howManyBunches, blockSize, lutSize, fixedAlignments, qDefSize );
GeneticOperator bmin1 = new BunchMutator( bitsPerVar, howManyBunches, blockSize, lutSize + bitsPerVar, fixedAlignments, qDefSize );
GeneticOperator bmin2 = new BunchMutator( bitsPerVar, howManyBunches, blockSize, lutSize + bitsPerVar * 2, fixedAlignments, qDefSize );
GeneticOperator bmin3 = new BunchMutator( bitsPerVar, howManyBunches, blockSize, lutSize + bitsPerVar * 3, fixedAlignments, qDefSize );
GeneticOperator bc = new BlockCopy ( blockSize, blockSize, 0, fixedAlignments, qDefSize );
GeneticOperator[] geneticOps = { m, spxo, bmin0, bmin1, bmin2, bmin3, bc };
double[] opsProbs = { 0.2, 0.3, 0.1, 0.1, 0.1, 0.1, 0.1 };
if( LUTInputs == 2 )
{
geneticOps[ 4 ] = bmin0;
geneticOps[ 5 ] = bmin1;
}
Selector selector = new RankSelector( );
Evolver evolver = new StandardEvolver( POP_SIZE, genotypeLength, geneticOps, opsProbs, selector, NUM_OF_ELITES, seeds );
PopulationLogReader.fullOrderGenotypes = true; int[] numProps = { 2 }; double maxSize = nrAddUnits;
CircuitPainterObject painter = new CircuitPainterObject( new CircuitPainter(), new LUTAbsoluteMapping( experiment.getNumOfInputs(), experiment.getNumOfOutputs() + E_LINES, bitsPerVar, LUTInputs, new ConstantDelayModel( 0 ) ) );
TSCCombinationalAlgebraicIM inIm = new TSCCombinationalAlgebraicIM( evolver, deployment, circuit, experiment, faultModel, E_SIZE, E_START_AT, INPUT_SAMPLE_SEP, painter);
InteractionModel noisyIM = new NoisyPIM( inIm, deployment, experiment, numProps, NO_EVALS );
InteractionModel interactionModel = new CircuitParsimonyPIM( noisyIM, circuit, maxSize );
Monica monica = new Monica( interactionModel, DUMP_POP_EVERY, java.lang.Integer.MAX_VALUE );
painter.setEvoTask( monica ); monica.setName( dirName );
taskQ.add( monica ); taskQNames.add( dirName ); taskQDescr.add( descr ); taskQBestIndID.add( new Integer( bestIndID ) );
int avgSize = ( int )( usedEls * 1.45 );
int effort = NO_EVALS * INPUT_SAMPLE_SEP * avgSize * avgSize * ( 1 << experiment.getNumOfInputs() );
taskQEffort.add( new Integer( effort ) );
ControlLib.writeGNUPlotScript( dirName, logDir, logFileName, 3, false );
ControlLib.writeWebGraphDaemon( dirName, logDir, logFileName, 3, false, new File(".").getCanonicalPath() + File.separator, 60 * 12 );
}
protected void addZ4ML() throws IOException
{
String blifFN = "/home/mmg20/eh/benchmarks/z4ml.blif";
String sisQFN = "/home/mmg20/eh/benchmarks/z4ml.sout";
String dirName = "Z4MLTSCA";
String descr = "";
int bestHD = -1;
int LUTInputs = 2;
boolean spaceForVoter = true;
boolean locking = false;
addCombBLIFBenchmark( blifFN, sisQFN, dirName, descr, bestHD, LUTInputs, spaceForVoter, locking );
}
protected void addCM42() throws IOException
{
String blifFN = "/home/mmg20/eh/benchmarks/cm42a.blif";
String sisQFN = "/home/mmg20/eh/benchmarks/cm42a.sout";
String dirName = "CM42TSCA";
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 );
}
/** Called by clients the first time they connect.
* @param initialParameters Initial parameters from client local configuration.
* The current client implementation, see
* InteractiveTaskClient, provides the ip address of
* the client and the command line paramaters used to
* launch the client. These are packaged in a Vector.
* @return The ID of this client will from now on used for
* interaction with the server.
*/
public Object getID(Object initialParameters) throws RemoteException {
return ies.getID( initialParameters );
}
/** This will provide the client with the InteractiveTask
* it should run.
* @param id The ID provided by the getID method by which the
* client will always refer to itself.
* @return The task this client should run. This could be
* exactly the same as the one all other clients are
* running or tailored to this particular client.
*/
public InteractiveTask getTask(Object id) throws RemoteException {
return ies.getTask( id );
}
/** Called by clients when they wish to interact.
* @param ID the client's ID
* @param clientTaskOutput the outputs of the client obtained by task.get( null ) on the client task
* @return whatever should be sent into the client through task.set( )
*/
public Object interact(Object ID, Object clientTaskOutput) throws RemoteException {
return ies.interact( ID, clientTaskOutput );
}
public String toString()
{
String rv = "EvoTSCA with IES: " + ies;
return rv;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -