/** Initializes an experiment run from an xml file */ void readExperimentRunFromNode(Node root) { try { Run run = new Run(); run.readFromNode((Element) root); expRunner = run.getExperimentRunner(); model = run.getModel(); expRunnerClass = expRunner.getClass(); modelClass = model.getClass(); expAccessPoints = new AccessPointTableModel(expRunner.getExperimentSettings()); modelAccessPoints = new AccessPointTableModel(expRunner.getModelParameters()); } catch (Exception e) { e.printStackTrace(); } }
public static void main(String[] args) throws Exception { if (args.length < 1) System.out.println("Usage: java desmoj.util.Run <parameterfile>.xml"); else { System.out.println("*** DESMO-J Simulation Runner ***"); System.out.println("* Reading experiment specification from " + args[0]); Document d = DocumentReader.getInstance().readDoc(args[0]); Run run = new Run(); run.readFromNode(d.getDocumentElement()); ExperimentRunner runner = run.getExperimentRunner(); long startMillis = System.currentTimeMillis(); runner.start(); long stopMillis = System.currentTimeMillis(); System.out.println( "* Simulation took " + (stopMillis - startMillis) / 1000.0 + " seconds.\n"); } }
/** * Runs batch specified in the given DOM node * * @param a DOM node representing an xml batch file */ void runBatch(final Node batch) { final Map defaultExpSettings = new HashMap(); final Map defaultModelParams = new HashMap(); Node settings = DOMUtil.getFirstChildElement(batch, "exp"); Node params = DOMUtil.getFirstChildElement(batch, "model"); if (settings != null) Run.readParamList(settings, defaultExpSettings); if (params != null) Run.readParamList(params, defaultModelParams); // Getting default model factory from node <modelfactory class=.../> String defaultModelN = DOMUtil.getAttrValue((Element) batch, "model"); if (defaultModelN.equals("")) defaultModelN = null; String defaultExpRunnerN = DOMUtil.getAttrValue((Element) batch, "expRunner"); if (defaultExpRunnerN == null || defaultExpRunnerN.equals("")) defaultExpRunnerN = "desmoj.extensions.experimentation.util.ExperimentRunner"; final String defaultModelName = defaultModelN; final String defaultExpRunnerName = defaultExpRunnerN; // Create the default model System.out.println("* Processing batch...\n"); Runnable r = new Runnable() { public void run() { // Read list of runs int count = 0; NodeList runs = batch.getChildNodes(); for (int i = 0; i < runs.getLength(); i++) { HashMap expSettings = new HashMap(defaultExpSettings); HashMap modelParams = new HashMap(defaultModelParams); Node nextDesc = runs.item(i); if (nextDesc.getNodeName().equals("run")) { count++; System.out.println("* Initializing run no " + count); try { if (defaultModelName != null) modelClass = Class.forName(defaultModelName); if (defaultExpRunnerName != null) expRunnerClass = Class.forName(defaultExpRunnerName); model = (Model) modelClass.newInstance(); expRunner = (ExperimentRunner) expRunnerClass.newInstance(); } catch (Exception e) { e.printStackTrace(); } Run run = new Run(model, expRunner, expSettings, modelParams, count); run.readFromNode((Element) nextDesc); expRunner = run.getExperimentRunner(); model = run.getModel(); expRunnerClass = expRunner.getClass(); modelClass = model.getClass(); expAccessPoints = new AccessPointTableModel(expRunner.getExperimentSettings()); modelAccessPoints = new AccessPointTableModel(expRunner.getModelParameters()); startExperiment(); try { expRunner.getThread().join(); } catch (InterruptedException ex) { ex.printStackTrace(); } if (i < runs.getLength() - 1) experimentGUI.resetGUI( filename, runsBatch, modelAccessPoints, expAccessPoints, model.getName()); } } System.out.println("* Batch completed."); } }; new Thread(r).start(); }