public class Simulator {// ========================== static constants ========================== // ======================================================================/** {@link CDSimulator} */ public static final int CDSIM = 0;/** {@link EDSimulator} */ public static final int EDSIM = 1;/** Unknown simulator */ public static final int UNKNOWN = -1;/** the class names of simulators used */ protected static final String[] simName = { "peersim.cdsim.CDSimulator", "peersim.edsim.EDSimulator", };/** * Parameter representing the number of times the experiment is run. * Defaults to 1. * @config */ public static final String PAR_EXPS = "simulation.experiments";
/** * If present, this parameter activates the redirection of the standard * output to a given PrintStream. * This comes useful for processing the output of the simulation from * within the simulator. * @config */ public static final String PAR_REDIRECT = "simulation.stdout";// ==================== static fields =================================== // ======================================================================/** */ private static int simID = UNKNOWN;//========================== methods =================================== //======================================================================/** * Returns the numeric id of the simulator to invoke. At the moment this can * be {@link #CDSIM}, {@link #EDSIM} or {@link #UNKNOWN}. */ public static int getSimID() {
if (simID == UNKNOWN) { if( CDSimulator.isConfigurationCycleDriven()){ simID = CDSIM; } else if( EDSimulator.isConfigurationEventDriven() ) { simID = EDSIM; } } return simID; }// ----------------------------------------------------------------------/** * Loads the configuration and executes the experiments. * The number of independent experiments is given by config parameter * {@value #PAR_EXPS}. In all experiments the configuration is the same, * only the random seed is not re-initialized between experiments. * <p> * Loading the configuration is currently done with the help of constructing * an instance of {@link ParsedProperties} using the constructor * {@link ParsedProperties#ParsedProperties(String[])}. * The parameter * <code>args</code> is simply passed to this class. This class is then used * to initialize the configuration. * <p> * After loading the configuration, the experiments are run by invoking the * appropriate engine, which is identified as follows: * <ul> * <li>{@link CDSimulator}: * if {@link CDSimulator#isConfigurationCycleDriven} returns * true</li> * <li>{@link EDSimulator}: * if {@link EDSimulator#isConfigurationEventDriven} returns * true * </li> * </ul> * <p> * This list represents the order in which these alternatives are checked. * That is, if more than one return true, then the first will be taken. * Note that this class checks only for these clues and does not check if the * configuration is consistent or valid. * @param args passed on to * {@link ParsedProperties#ParsedProperties(String[])} * @see ParsedProperties * @see Configuration * @see CDSimulator * @see EDSimulator */ public static void main(String[] args) { long time = System.currentTimeMillis();
// XXX could be done through reflection, but // this is easier to read. switch(SIMID) { case CDSIM: CDSimulator.nextExperiment(); break; case EDSIM: EDSimulator.nextExperiment(); break; } }
你是怎么执行的,用命令的话要设置好环境变量
java -cp "peersim-1.0.3.jar:jep-2.3.0.jar:djep-1.0.0.jar" peersim.Simulator example/config-example1.txt
// ======================================================================/** {@link CDSimulator} */
public static final int CDSIM = 0;/** {@link EDSimulator} */
public static final int EDSIM = 1;/** Unknown simulator */
public static final int UNKNOWN = -1;/** the class names of simulators used */
protected static final String[] simName = {
"peersim.cdsim.CDSimulator",
"peersim.edsim.EDSimulator",
};/**
* Parameter representing the number of times the experiment is run.
* Defaults to 1.
* @config
*/
public static final String PAR_EXPS = "simulation.experiments";
/**
* If present, this parameter activates the redirection of the standard
* output to a given PrintStream.
* This comes useful for processing the output of the simulation from
* within the simulator.
* @config
*/
public static final String PAR_REDIRECT = "simulation.stdout";// ==================== static fields ===================================
// ======================================================================/** */
private static int simID = UNKNOWN;//========================== methods ===================================
//======================================================================/**
* Returns the numeric id of the simulator to invoke. At the moment this can
* be {@link #CDSIM}, {@link #EDSIM} or {@link #UNKNOWN}.
*/
public static int getSimID() {
if (simID == UNKNOWN) {
if( CDSimulator.isConfigurationCycleDriven()){
simID = CDSIM;
}
else if( EDSimulator.isConfigurationEventDriven() ) {
simID = EDSIM;
}
}
return simID;
}// ----------------------------------------------------------------------/**
* Loads the configuration and executes the experiments.
* The number of independent experiments is given by config parameter
* {@value #PAR_EXPS}. In all experiments the configuration is the same,
* only the random seed is not re-initialized between experiments.
* <p>
* Loading the configuration is currently done with the help of constructing
* an instance of {@link ParsedProperties} using the constructor
* {@link ParsedProperties#ParsedProperties(String[])}.
* The parameter
* <code>args</code> is simply passed to this class. This class is then used
* to initialize the configuration.
* <p>
* After loading the configuration, the experiments are run by invoking the
* appropriate engine, which is identified as follows:
* <ul>
* <li>{@link CDSimulator}:
* if {@link CDSimulator#isConfigurationCycleDriven} returns
* true</li>
* <li>{@link EDSimulator}:
* if {@link EDSimulator#isConfigurationEventDriven} returns
* true
* </li>
* </ul>
* <p>
* This list represents the order in which these alternatives are checked.
* That is, if more than one return true, then the first will be taken.
* Note that this class checks only for these clues and does not check if the
* configuration is consistent or valid.
* @param args passed on to
* {@link ParsedProperties#ParsedProperties(String[])}
* @see ParsedProperties
* @see Configuration
* @see CDSimulator
* @see EDSimulator
*/
public static void main(String[] args)
{
long time = System.currentTimeMillis();
System.err.println("Simulator: loading configuration");
Configuration.setConfig( new ParsedProperties(args) ); PrintStream newout =
(PrintStream)Configuration.getInstance(PAR_REDIRECT,System.out);
if(newout!=System.out) System.setOut(newout);
int exps = Configuration.getInt(PAR_EXPS,1); final int SIMID = getSimID();
if( SIMID == UNKNOWN )
{
System.err.println(
"Simulator: unable to identify configuration, exiting.");
return;
}
try { for(int k=0; k<exps; ++k)
{
if( k>0 )
{
long seed = CommonState.r.nextLong();
CommonState.initializeRandom(seed);
}
System.err.print("Simulator: starting experiment "+k);
System.err.println(" invoking "+simName[SIMID]);
System.err.println("Random seed: "+
CommonState.r.getLastSeed());
System.out.println("\n\n");
// XXX could be done through reflection, but
// this is easier to read.
switch(SIMID)
{
case CDSIM:
CDSimulator.nextExperiment();
break;
case EDSIM:
EDSimulator.nextExperiment();
break;
}
}
} catch (MissingParameterException e) {
System.err.println(e+"");
System.exit(1);
} catch (IllegalParameterException e) {
System.err.println(e+"");
System.exit(1);
} // undocumented testing capabilities
if(Configuration.contains("__t"))
System.out.println(System.currentTimeMillis()-time);
if(Configuration.contains("__x")) Network.test();
}}
这是主程序的入口
javahome=.;C:\Program Files\Java\jdk 1.5.0_05
classpath=.;C:\Program Files\Java\jdk 1.5.0_05 \bin