if (!model.isFile()) {
System.err.print("Invalid model file: " + model.getAbsolutePath());
System.exit(1);
}
SolverDispatcher dispatcher = new SolverDispatcher();
// Starts the solution
dispatcher.solve(model);
copyFile(model, result);
} else if(args[0].equals("sim")){
Map<String,String> options = parseParameters(args, 2);
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
File model = new File(args[1]);
if (!model.isFile()) {
System.err.print("Model file not found: " + model.getAbsolutePath());
System.exit(1);
}
System.out.println(model.getName());
File temp = File.createTempFile("tempfileSim",".jsim");
temp.deleteOnExit();
Document doc = db.parse(model);
Element sim = XMLArchiver.getSimFromArchiveDocument(doc);
Document doc2 = db.newDocument();
Node dup = doc2.importNode(sim, true);
NamedNodeMap attributes = dup.getAttributes();
attributes.removeNamedItem("xsi:noNamespaceSchemaLocation");
doc2.appendChild(dup);
/*
* save to a temp file
*/
TransformerFactory tranFactory = TransformerFactory.newInstance();
Transformer aTransformer = tranFactory.newTransformer();
Source src = new DOMSource(doc2);
Result dest = new StreamResult(temp);
aTransformer.transform(src, dest);
Dispatcher_jSIMschema dispatcher = new Dispatcher_jSIMschema(temp);
// Sets simulation seed if required
if (options.containsKey(OPTION_SEED)) {
try {
dispatcher.setSimulationSeed(Long.parseLong(options.get(OPTION_SEED)));
} catch (NumberFormatException ex) {
System.err.println("Invalid simulation seed. Should be a number.");
System.exit(1);
}
}
if (options.containsKey(OPTION_MAXTIME)) {
try {
dispatcher.setSimulationMaxDuration(Long.parseLong(options.get(OPTION_MAXTIME)) * 1000);
} catch (NumberFormatException ex) {
System.err.println("Invalid maximum simulation time. Should be a number.");
System.exit(1);
}
}
// Starts the simulation
dispatcher.solveModel();
File output = dispatcher.getOutputFile();
File result = new File(args[1]+"-result.jsim");
copyFile(output, result);
output.delete();