?? evorepair2.java~
字號(hào):
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 EvoRepair2 implements InteractiveTaskServer
{
// Simulation Config Constants
protected final int EVALS_PER_SEC = 50; protected final int HOUR = EVALS_PER_SEC * 60 * 60;
// Server Config Constants
protected final double MIGRATION_RATE = 0.5;
// 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;
public EvoRepair2(ArrayList extraArgs) throws IOException
{
logDir = ( String ) extraArgs.get( 0 );
logFileName = ( String ) extraArgs.get( 1 );
int extraBPV = 1; int hoursToRepair = 24;
addRepairComBenchMultipleNoLatch( "C17", 5, extraBPV, hoursToRepair );
ies = new IslandsEvolutionServer( taskQ, taskQNames, logDir, logFileName, MIGRATION_RATE );
}
/** 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 );
}
// -------------- 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( String fileName, int M, int extraBitsPerVar, int hoursToRepair ) throws IOException
{
String sisOutputFileName = "/home/mmg20/eh/benchmarks/" + fileName + "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, extraBitsPerVar, varSized );
int usedEls = sor.getTotalEls();
int bitsPerVar = sor.getBitsPerVar();
String blifFileName = "/home/mmg20/eh/benchmarks/" + fileName + ".blif";
ConfigurableRandomInputExperiment combexp = new CombinationalBLIFExperiment( blifFileName, 0 );
int nrIns = combexp.getNumOfInputs();// no latch, no clock
int totalCLBs = ( 1 << bitsPerVar ) - nrIns;
int spareLUTs = totalCLBs - usedEls;
int gensPerSec = EVALS_PER_SEC;
int gensPerHour = gensPerSec * 60 * 60;
int maxGens = gensPerHour * hoursToRepair;
String narrator = "Repairing combinational benchmark: " + fileName + " under multiple faults.";
narrator += "\nBPV(CLB) = " + bitsPerVar + ". Total CLBs = " + totalCLBs + ". Used LUTs = " + usedEls;
narrator += "\nSpares: " + spareLUTs + " LUTs. ";
narrator += "\nSequences totally random ending when only " + usedEls + " LUTs left (assume minimal design)";
narrator += "\nMax Gens per repair = (" + hoursToRepair + "h) = " + maxGens;
narrator += "\nOrderings:\n";
int[] faultPos = new int[ totalCLBs ]; // in FPGALUTAbsMapping it skips inputs
for( int flp = 0; flp < totalCLBs; flp++ )
{
faultPos[ flp ] = flp;
}
Vector[] orders = new Vector[ M ];
Random rnd = new Random();
for( int ml = 0; ml < M; ml++ )
{
orders[ ml ] = new Vector();
Vector allFaults = new Vector();
for( int flp = 0; flp < faultPos.length; flp++ )
{
allFaults.add( new Integer( faultPos[ flp ] ) ); // Extra level of inderection maintained just in case mapping changes
}
while( orders[ ml ].size() < spareLUTs )
{
int ix = rnd.nextInt( allFaults.size() );
Integer currFPos = ( Integer ) allFaults.remove( ix );
int currFVal = rnd.nextInt( 2 ); // SSA0 or 1
orders[ ml ].add( new Point( currFPos.intValue(), currFVal ) );
}
narrator += ml+": " + orders[ ml ] + "\n";
}
String dirName = logDir + "Repair" + FS + fileName + FS + "Multiple" + FS;
new File( dirName ).mkdirs();
File orderFile = new File( dirName + "orders.txt" );
BufferedWriter multipleBW = new BufferedWriter( new FileWriter( orderFile ) );
multipleBW.write( narrator );
multipleBW.flush();
multipleBW.close();
for( int ml = 0; ml < M; ml++ )
{
addRepairComBlifSequenceNoLatch( fileName, ml, orders[ ml ], extraBitsPerVar, maxGens );
}
}
private void addRepairComBlifSequenceNoLatch( String fileName, int ix, Vector seq, int extraBitsPerVar, int maxGensPerFault ) throws IOException
{
Point[] faultSequence = new Point[ seq.size() ];
for( int flp = 0; flp < faultSequence.length; flp++ )
{
faultSequence[ flp ] = ( Point ) seq.get( flp );
}
int ISS = 30; double T_SETUP = 0.84;
//int[] samLen = { 5 }; int[] samPos = { 45 };
double MIN_MU = 2; double SIGMA = 0.1; double MAX_MU = 6;
boolean sameRndPerGen = false; boolean alwaysResetBeforeRun = false; // Noise 2, 3
FitnessFunction inFF = new SimpleCorrelationFitnessFunction();
//FitnessFunction inFF = new SumFitnessFunction();
FitnessFunction pFF = new PessimisticFitnessFunction( inFF );
//FitnessFunction rFF = new PerRowFitnessFunction( pFF );
FitnessFunction fitnessFunction = new SingleSampleAvgFitnessFunction( pFF );
//FitnessFunction fitnessFunction = new SingleNoisySizeSampleAvgFitnessFunction( pFF, 0.7 );
//FitnessFunction fitnessFunction = new MultipleSampleAvgFitnessFunction( pff, samLen, samPos );
//int repeats = 1; TestPatternGenerator tpg = new NRepeatsTPG( repeats );
//FitnessFunction fitnessFunction = inFF;
TestPatternGenerator tpg = new CompleteShuffledTPG(); // NORMAL
int nrTrials = 16;
String blifFileName = "/home/mmg20/eh/benchmarks/" + fileName + ".blif";
ConfigurableRandomInputExperiment experiment = new CombinationalBLIFExperiment( blifFileName, T_SETUP, fitnessFunction, tpg );
String sisOutputFileName = "/home/mmg20/eh/benchmarks/" + fileName + "L4.sout";
int resQ = 0; boolean fpga = false; boolean voter = false; boolean varSized = false;
int LUT_INPUTS = 4; int DUMP_POP_EVERY = 10000;
SisOutputReader sor = new SisOutputReader( new File( sisOutputFileName ), resQ, LUT_INPUTS, fpga, voter, extraBitsPerVar, varSized );
Genotype seed = new Genotype( sor.getVassilevGenotype() );
int bitsPerVar = sor.getBitsPerVar(); int usedEls = sor.getTotalEls();
int addEls = ( 1 << bitsPerVar ) - experiment.getNumOfInputs();
int HOUR = EVALS_PER_SEC * 60 * 60; int MU_D = 3 * HOUR; int MU_S = 1 * HOUR;
MU_D *= 2 * addEls; MU_S *= 2 * addEls;// must multiply these by number of elements in circuit and popsize
ElementDelayModel delayModel = new DriftingGaussianDelayModel( MIN_MU,MAX_MU,SIGMA,MU_D,MU_S ); // Noise 1
//ElementDelayModel delayModel = new GaussianDelayModel( MIN_MU, SIGMA ); // mu,s
CircuitMapping inMap = new LUTAbsoluteMapping( experiment.getNumOfInputs(), experiment.getNumOfOutputs(), bitsPerVar, LUT_INPUTS, delayModel );
CircuitMapping circuitMapping = new VassilevMapping( inMap, experiment.getNumOfOutputs(), bitsPerVar );
SimulatorFaultyCircuit circuit = new SimulatorFaultyCircuit( circuitMapping );
SimulatorDeployment deployment = new SimulatorDeployment( circuit, alwaysResetBeforeRun );
int GENOTYPE_MUT = 1; // *** Set to 3 for DECOD, normal is 1.
int POP_SIZE = 2; int NUM_OF_ELITES = 1; double[] RANK_PROBS = { 1,0 };
int genotypeLength = seed.length(); final Genotype[] SEEDS = { seed };
GeneticOperator m = new ExactGenotypeMutator( GENOTYPE_MUT ); GeneticOperator[] geneticOps = { m }; double[] opsProbs = { 1 };
Selector selector = new RankSelector( RANK_PROBS );
Evolver evolver = new StandardEvolver( POP_SIZE, genotypeLength, geneticOps, opsProbs, selector, NUM_OF_ELITES, SEEDS );
InteractionModel inIM = new StandardInteractionModel( evolver, deployment, experiment,ISS );
InteractionModel nIM = new NoisyIM( inIM, deployment, experiment, 1, NoisyIM.MINIMUM, sameRndPerGen );
InteractionModel hIM = new HistoryWindowIM( nrTrials, nIM );
String dirName = "Repair" + FS + fileName + FS + "Multiple" + FS + ix;
new File( logDir + dirName ).mkdirs();
InteractionModel interactionModel = new RepairFaultSequenceIM( hIM, circuit, faultSequence, maxGensPerFault, nrTrials + 1 ); // to fill up history window with solutions
Monica monica = new Monica( interactionModel, DUMP_POP_EVERY, java.lang.Integer.MAX_VALUE );
monica.setName( dirName );
taskQ.add( monica );
taskQNames.add( dirName );
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -