List of usage examples for java.lang Double parseDouble
public static double parseDouble(String s) throws NumberFormatException
From source file:net.forkwait.imageautomator.ImageAutomator.java
public static void main(String[] args) throws IOException { String inputImage = ""; Options options = new Options(); options.addOption("o", true, "output file name (e.g. thumb.jpg), default thumbnail.filename.ext"); options.addOption("q", true, "jpeg quality (e.g. 0.9, max 1.0), default 0.97"); options.addOption("s", true, "output max side length in px (e.g. 800), default 1200"); options.addOption("w", true, "watermark image file"); options.addOption("wt", true, "watermark transparency (e.g. 0.5, max 1.0), default 1.0"); options.addOption("wp", true, "watermark position (e.g. 0.9, max 1.0), default BOTTOM_RIGHT"); /*//www. jav a 2s . c om TOP_LEFT TOP_CENTER TOP_RIGHT CENTER_LEFT CENTER CENTER_RIGHT BOTTOM_LEFT BOTTOM_CENTER BOTTOM_RIGHT */ CommandLineParser parser = new BasicParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); if (cmd.getArgs().length < 1) { throw new ParseException("Too few arguments"); } else if (cmd.getArgs().length > 1) { throw new ParseException("Too many arguments"); } inputImage = cmd.getArgs()[0]; } catch (ParseException e) { showHelp(options, e.getLocalizedMessage()); System.exit(-1); } Thumbnails.Builder<File> st = Thumbnails.of(inputImage); if (cmd.hasOption("q")) { st.outputQuality(Double.parseDouble(cmd.getOptionValue("q"))); } else { st.outputQuality(0.97f); } if (cmd.hasOption("s")) { st.size(Integer.parseInt(cmd.getOptionValue("s")), Integer.parseInt(cmd.getOptionValue("s"))); } else { st.size(1200, 1200); } if (cmd.hasOption("w")) { Positions position = Positions.BOTTOM_RIGHT; float trans = 0.5f; if (cmd.hasOption("wp")) { position = Positions.valueOf(cmd.getOptionValue("wp")); } if (cmd.hasOption("wt")) { trans = Float.parseFloat(cmd.getOptionValue("wt")); } st.watermark(position, ImageIO.read(new File(cmd.getOptionValue("w"))), trans); } if (cmd.hasOption("o")) { st.toFile(new File(cmd.getOptionValue("o"))); } else { st.toFiles(Rename.PREFIX_DOT_THUMBNAIL); } //.outputFormat("jpg") System.exit(0); }
From source file:com.nubits.nubot.testsmanual.TestRPCLiquidityInfo.java
public static void main(String[] args) { InitTests.setLoggingFilename(TestRPCLiquidityInfo.class.getSimpleName()); InitTests.loadConfig(TEST_OPTIONS_PATH); //Load settings //Default values String custodian = CUSTODIAN_PUBLIC_ADDRESS; String user = NUD_RPC_USER;//w w w . j a v a 2 s .c om String pass = NUD_RPC_PASS; double sell = 0; double buy = 0; //java -jar testRPC user pass custodian sell buy if (args.length == 5) { LOG.info("Reading input parameters"); user = args[0]; pass = args[1]; custodian = args[2]; sell = Double.parseDouble(args[3]); buy = Double.parseDouble(args[4]); } Global.rpcClient = new NuRPCClient("127.0.0.1", 9091, user, pass, true, custodian, CurrencyList.NBT_BTC, ""); TestRPCLiquidityInfo test = new TestRPCLiquidityInfo(); test.testCheckNudTask(); Utils.installKeystore(true); //test.testGetInfo(); //test.testIsConnected(); test.testSendLiquidityInfo(buy, sell, 1); //test.testGetLiquidityInfo(); //test.testGetLiquidityInfo(Constant.SELL, Passwords.CUSTODIA_PUBLIC_ADDRESS); //test.testGetLiquidityInfo(Constant.BUY, Passwords.CUSTODIA_PUBLIC_ADDRESS); }
From source file:ca.mcgill.networkdynamics.geoinference.evaluation.CrossValidationScorer.java
public static void main(String[] args) throws Exception { if (args.length != 4) { System.out.println("java CVS predictions-dir/ " + "cv-gold-dir/ results.txt error-sample.tsv"); return;/* ww w .j a v a 2 s . c o m*/ } File predDir = new File(args[0]); File cvDir = new File(args[1]); TDoubleList errors = new TDoubleArrayList(10_000_000); TLongSet locatedUsers = new TLongHashSet(10_000_000); TLongSet allUsers = new TLongHashSet(10_000_000); TLongObjectMap<TDoubleList> userToErrors = new TLongObjectHashMap<TDoubleList>(); TLongDoubleMap tweetIdToError = new TLongDoubleHashMap(10_000_000); TLongObjectMap<double[]> idToPredLoc = new TLongObjectHashMap<double[]>(); int tweetsSeen = 0; int tweetsLocated = 0; BufferedReader cvBr = new BufferedReader(new FileReader(new File(cvDir, "folds.info.tsv"))); for (String foldLine = null; (foldLine = cvBr.readLine()) != null;) { String[] cols = foldLine.split("\t"); String foldName = cols[0]; System.out.printf("Scoring results for fold %s%n", foldName); File foldPredictionsFile = new File(predDir, foldName + ".results.tsv.gz"); File goldLocFile = new File(cvDir, foldName + ".gold-locations.tsv"); if (foldPredictionsFile.exists()) { BufferedReader br = Files.openGz(foldPredictionsFile); for (String line = null; (line = br.readLine()) != null;) { String[] arr = line.split("\t"); long id = Long.parseLong(arr[0]); idToPredLoc.put(id, new double[] { Double.parseDouble(arr[1]), Double.parseDouble(arr[2]) }); } br.close(); } System.out.printf("loaded predictions for %d tweets; " + "scoring predictions%n", idToPredLoc.size()); BufferedReader br = new BufferedReader(new FileReader(goldLocFile)); for (String line = null; (line = br.readLine()) != null;) { String[] arr = line.split("\t"); long id = Long.parseLong(arr[0]); long userId = Long.parseLong(arr[1]); allUsers.add(userId); tweetsSeen++; double[] predLoc = idToPredLoc.get(id); if (predLoc == null) continue; tweetsLocated++; locatedUsers.add(userId); double[] goldLoc = new double[] { Double.parseDouble(arr[2]), Double.parseDouble(arr[3]) }; double dist = Geometry.getDistance(predLoc, goldLoc); errors.add(dist); tweetIdToError.put(id, dist); TDoubleList userErrors = userToErrors.get(userId); if (userErrors == null) { userErrors = new TDoubleArrayList(); userToErrors.put(userId, userErrors); } userErrors.add(dist); } br.close(); } errors.sort(); System.out.println("Num errors to score: " + errors.size()); double auc = 0; double userCoverage = 0; double tweetCoverage = tweetsLocated / (double) tweetsSeen; double medianMaxUserError = Double.NaN; double medianMedianUserError = Double.NaN; if (errors.size() > 0) { auc = computeAuc(errors); userCoverage = locatedUsers.size() / ((double) allUsers.size()); TDoubleList maxUserErrors = new TDoubleArrayList(locatedUsers.size()); TDoubleList medianUserErrors = new TDoubleArrayList(locatedUsers.size()); for (TDoubleList userErrors : userToErrors.valueCollection()) { userErrors.sort(); maxUserErrors.add(userErrors.get(userErrors.size() - 1)); medianUserErrors.add(userErrors.get(userErrors.size() / 2)); } maxUserErrors.sort(); medianMaxUserError = maxUserErrors.get(maxUserErrors.size() / 2); medianUserErrors.sort(); medianMedianUserError = medianUserErrors.get(medianUserErrors.size() / 2); // Compute CDF int[] errorsPerKm = new int[MAX_KM]; for (int i = 0; i < errors.size(); ++i) { int error = (int) (Math.round(errors.get(i))); errorsPerKm[error]++; } // The accumulated sum of errors per km int[] errorsBelowEachKm = new int[errorsPerKm.length]; for (int i = 0; i < errorsBelowEachKm.length; ++i) { errorsBelowEachKm[i] = errorsPerKm[i]; if (i > 0) errorsBelowEachKm[i] += errorsBelowEachKm[i - 1]; } final double[] cdf = new double[errorsBelowEachKm.length]; double dSize = errors.size(); // to avoid casting all the time for (int i = 0; i < cdf.length; ++i) cdf[i] = errorsBelowEachKm[i] / dSize; } PrintWriter pw = new PrintWriter(new File(args[2])); pw.println("AUC\t" + auc); pw.println("user coverage\t" + userCoverage); pw.println("tweet coverage\t" + tweetCoverage); pw.println("median-max error\t" + medianMaxUserError); pw.close(); // Choose a random sampling of 10K tweets to pass on to the authors // here. PrintWriter errorsPw = new PrintWriter(args[3]); TLongList idsWithErrors = new TLongArrayList(tweetIdToError.keySet()); idsWithErrors.shuffle(new Random()); // Choose the first 10K for (int i = 0, chosen = 0; i < idsWithErrors.size() && chosen < 10_000; ++i) { long id = idsWithErrors.get(i); double[] prediction = idToPredLoc.get(id); double error = tweetIdToError.get(id); errorsPw.println(id + "\t" + error + "\t" + prediction[0] + "\t" + prediction[1]); ++chosen; } errorsPw.close(); }
From source file:com.aestel.chemistry.openEye.fp.FPDictionarySorter.java
public static void main(String... args) throws IOException { long start = System.currentTimeMillis(); int iCounter = 0; int fpCounter = 0; // create command line Options object Options options = new Options(); Option opt = new Option("i", true, "input file [.ism,.sdf,...]"); opt.setRequired(true);/*from w ww .j av a2s . c o m*/ options.addOption(opt); opt = new Option("fpType", true, "fingerPrintType: maccs|linear7|linear7*4"); opt.setRequired(true); options.addOption(opt); opt = new Option("sampleFract", true, "fraction of input molecules to use (Default=1)"); opt.setRequired(false); options.addOption(opt); CommandLineParser parser = new PosixParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (Exception e) { System.err.println(e.getMessage()); exitWithHelp(options); } args = cmd.getArgs(); if (cmd.hasOption("d")) { System.err.println("Start debugger and press return:"); new BufferedReader(new InputStreamReader(System.in)).readLine(); } if (args.length != 0) { exitWithHelp(options); } String type = cmd.getOptionValue("fpType"); boolean updateDictionaryFile = false; boolean hashUnknownFrag = false; Fingerprinter fprinter = Fingerprinter.createFingerprinter(type, updateDictionaryFile, hashUnknownFrag); OEMolBase mol = new OEGraphMol(); String inFile = cmd.getOptionValue("i"); oemolistream ifs = new oemolistream(inFile); double fract = 2D; String tmp = cmd.getOptionValue("sampleFract"); if (tmp != null) fract = Double.parseDouble(tmp); Random rnd = new Random(); LearningStrcutureCodeMapper mapper = (LearningStrcutureCodeMapper) fprinter.getMapper(); int dictSize = mapper.getMaxIdx() + 1; int[] freq = new int[dictSize]; while (oechem.OEReadMolecule(ifs, mol)) { iCounter++; if (rnd.nextDouble() < fract) { fpCounter++; Fingerprint fp = fprinter.getFingerprint(mol); for (int bit : fp.getBits()) freq[bit]++; } if (iCounter % 100 == 0) System.err.print("."); if (iCounter % 4000 == 0) { System.err.printf(" %d %d %dsec\n", iCounter, fpCounter, (System.currentTimeMillis() - start) / 1000); } } System.err.printf("FPDictionarySorter: Read %d structures calculated %d fprints in %d sec\n", iCounter, fpCounter, (System.currentTimeMillis() - start) / 1000); mapper.reSortDictionary(freq); mapper.writeDictionary(); fprinter.close(); }
From source file:edu.cmu.lti.oaqa.knn4qa.apps.CollectionSplitter.java
public static void main(String[] args) { Options options = new Options(); options.addOption("i", null, true, "Input file"); options.addOption("o", null, true, "Output file prefix"); options.addOption("p", null, true, "Comma separated probabilities e.g., 0.1,0.2,0.7."); options.addOption("n", null, true, "Comma separated part names, e.g., dev,test,train"); CommandLineParser parser = new org.apache.commons.cli.GnuParser(); try {/*from w ww . j ava 2 s .c o m*/ CommandLine cmd = parser.parse(options, args); InputStream input = null; if (cmd.hasOption("i")) { input = CompressUtils.createInputStream(cmd.getOptionValue("i")); } else { Usage("Specify Input file"); } ArrayList<Double> probs = new ArrayList<Double>(); String[] partNames = null; if (cmd.hasOption("p")) { String parts[] = cmd.getOptionValue("p").split(","); try { double sum = 0; for (String s : parts) { double p = Double.parseDouble(s); if (p <= 0 || p > 1) Usage("All probabilities must be in the range (0,1)"); sum += p; probs.add(p); } if (Math.abs(sum - 1.0) > Float.MIN_NORMAL) { Usage("The sum of probabilities should be equal to 1, but it's: " + sum); } } catch (NumberFormatException e) { Usage("Can't convert some of the probabilities to a floating-point number."); } } else { Usage("Specify part probabilities."); } if (cmd.hasOption("n")) { partNames = cmd.getOptionValue("n").split(","); if (partNames.length != probs.size()) Usage("The number of probabilities is not equal to the number of parts!"); } else { Usage("Specify part names"); } BufferedWriter[] outFiles = new BufferedWriter[partNames.length]; if (cmd.hasOption("o")) { String outPrefix = cmd.getOptionValue("o"); for (int partId = 0; partId < partNames.length; ++partId) { outFiles[partId] = new BufferedWriter(new OutputStreamWriter( CompressUtils.createOutputStream(outPrefix + "_" + partNames[partId] + ".gz"))); } } else { Usage("Specify Output file prefix"); } System.out.println("Using probabilities:"); for (int partId = 0; partId < partNames.length; ++partId) System.out.println(partNames[partId] + " : " + probs.get(partId)); System.out.println("================================================="); XmlIterator inpIter = new XmlIterator(input, YahooAnswersReader.DOCUMENT_TAG); String oneRec = inpIter.readNext(); int docNum = 1; for (; !oneRec.isEmpty(); ++docNum, oneRec = inpIter.readNext()) { double p = Math.random(); if (docNum % 1000 == 0) { System.out.println(String.format("Processed %d documents", docNum)); } BufferedWriter out = null; for (int partId = 0; partId < partNames.length; ++partId) { double pp = probs.get(partId); if (p <= pp || partId + 1 == partNames.length) { out = outFiles[partId]; break; } p -= pp; } oneRec = oneRec.trim() + System.getProperty("line.separator"); out.write(oneRec); } System.out.println(String.format("Processed %d documents", docNum - 1)); // It's important to close all the streams here! for (BufferedWriter f : outFiles) f.close(); } catch (ParseException e) { Usage("Cannot parse arguments"); } catch (Exception e) { System.err.println("Terminating due to an exception: " + e); System.exit(1); } }
From source file:net.openbyte.Launch.java
/** * This is the main method that allows Java to initiate the program. * * @param args the arguments to the Java program, which are ignored */// ww w .jav a 2s . c om public static void main(String[] args) { logger.info("Checking for a new version..."); try { GitHub gitHub = new GitHubBuilder().withOAuthToken("e5b60cea047a3e44d4fc83adb86ea35bda131744 ").build(); GHRepository repository = gitHub.getUser("PizzaCrust").getRepository("OpenByte"); for (GHRelease release : repository.listReleases()) { double releaseTag = Double.parseDouble(release.getTagName()); if (CURRENT_VERSION < releaseTag) { logger.info("Version " + releaseTag + " has been released."); JOptionPane.showMessageDialog(null, "Please update OpenByte to " + releaseTag + " at https://github.com/PizzaCrust/OpenByte.", "Update", JOptionPane.WARNING_MESSAGE); } else { logger.info("OpenByte is at the latest version."); } } } catch (Exception e) { logger.error("Failed to connect to GitHub."); e.printStackTrace(); } logger.info("Checking for a workspace folder..."); if (!Files.WORKSPACE_DIRECTORY.exists()) { logger.info("Workspace directory not found, creating one."); Files.WORKSPACE_DIRECTORY.mkdir(); } logger.info("Checking for a plugins folder..."); if (!Files.PLUGINS_DIRECTORY.exists()) { logger.info("Plugins directory not found, creating one."); Files.PLUGINS_DIRECTORY.mkdir(); } try { logger.info("Grabbing and applying system look and feel..."); UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) { logger.info("Something went wrong when applying the look and feel, using the default one..."); e.printStackTrace(); } logger.info("Starting event manager..."); EventManager.init(); logger.info("Detecting plugin files..."); File[] pluginFiles = PluginManager.getPluginFiles(Files.PLUGINS_DIRECTORY); logger.info("Detected " + pluginFiles.length + " plugin files in the plugins directory!"); logger.info("Beginning load/register plugin process..."); for (File pluginFile : pluginFiles) { logger.info("Loading file " + FilenameUtils.removeExtension(pluginFile.getName()) + "..."); try { PluginManager.registerAndLoadPlugin(pluginFile); } catch (Exception e) { logger.error("Failed to load file " + FilenameUtils.removeExtension(pluginFile.getName()) + "!"); e.printStackTrace(); } } logger.info("All plugin files were loaded/registered to OpenByte."); logger.info("Showing graphical interface to user..."); WelcomeFrame welcomeFrame = new WelcomeFrame(); welcomeFrame.setVisible(true); }
From source file:main.ParseManager.java
/** * @param args the command line arguments * @throws java.io.FileNotFoundException * @throws org.json.simple.parser.ParseException *//*from www. j a v a 2 s . co m*/ public static void main(String[] args) throws FileNotFoundException, IOException, ParseException { // TODO code application logic here // MADRID /*String path_to_map = "test/madrid_spain-roads.geojson"; //String roadClass = "highway";// or railway String roadClass = "railway";// or railway //X range [3.536570133,3.914573235] //X range [3.662571167,3.788572201] double minX = -3.7509727478027344; double maxX = -3.65518569946289; // Y range [40.29201553,40.537983518] // Y range in [40.390402726,40.439596324] //-3.7509727478027344,40.398529177904926,-3.65518569946289,40.43936977302504 double minY = 40.378529177904926; double maxY = 40.45936977302504; ParseJsonMaps pjm = new ParseJsonMaps(path_to_map,minX,maxX,minY,maxY); pjm.readJSONMap(); pjm.generateGraph(roadClass); pjm.printGraph(roadClass);*/ // BOSTON!! //-71.16497039794922,42.33050426119193,-71.03347778320312,42.40976960320691 /*String path_to_map = "test/boston_massachusetts-roads.geojson"; String roadClass = "highway";// or railway double minX = -71.16497039794922; double maxX = -71.03347778320312; double minY = 42.33050426119193; double maxY = 42.40976960320691; ParseJsonMaps pjm = new ParseJsonMaps(path_to_map,minX,maxX,minY,maxY); pjm.readJSONMap(); pjm.generateGraph(roadClass); pjm.printGraph(roadClass);*/ // NEW YORK!! //-74.0969467163086,40.70016219564594,-73.8339614868164,40.85147526676901 //String path_to_map = "test/new-york_new-york-roads.geojson"; //String roadClass = "highway";// or railway //String roadClass = "railway";// or railway //double minX = -74.0969467163086; //double maxX = -73.8339614868164; //double minY = 40.70016219564594; //double maxY = 40.85147526676901; if (args.length == 6) { String path_to_map = args[0]; String roadClass = args[1]; double minX = Double.parseDouble(args[2]); double maxX = Double.parseDouble(args[3]); double minY = Double.parseDouble(args[4]); double maxY = Double.parseDouble(args[5]); ParseJsonMaps pjm = new ParseJsonMaps(path_to_map, minX, maxX, minY, maxY); pjm.readJSONMap(); pjm.generateGraph(roadClass); pjm.printGraph(roadClass); } else { System.err.println("ERROR: Wrong number of arguments"); System.err.println(); System.err.println("USAGE:"); System.err.println(); System.err.println("java -jar graphFromGeoJson.jar path_to_map road_class minX maxX minY maxY"); System.err.println(); } }
From source file:com.yarsquidy.x12.example.exampleSpringParseX12FileOne.java
public static void main(String[] args) { X12 x12 = null;//w w w. j av a 2 s . com Resource xmlResource = new FileSystemResource("./target/classes/cf/appContext_835_004010X091.xml"); BeanFactory factory = new XmlBeanFactory(xmlResource); Cf cf = (Cf) factory.getBean("bean_X12"); Double totalChargeAmount = 0.0; URL url = exampleSpringParseX12FileOne.class.getClass() .getResource("/org/pb/x12/example/example835One.txt"); File f1 = new File(url.getFile()); Parser parser = new X12Parser(cf); try { x12 = (X12) parser.parse(f1); // calculate the total charge amount List<Loop> loops = x12.findLoop("2100"); for (Loop loop : loops) { for (Segment s : loop) { if (s.getElement(0).equals("CLP")) { totalChargeAmount = totalChargeAmount + Double.parseDouble(s.getElement(3)); } } } System.out.println("Total Charged Amount = " + totalChargeAmount.toString()); // calculate the total charge amount - alternate method totalChargeAmount = 0.0; List<Segment> segments = x12.findSegment("CLP"); for (Segment s : segments) { totalChargeAmount = totalChargeAmount + Double.parseDouble(s.getElement(3)); } System.out.println("Total Charged Amount = " + totalChargeAmount.toString()); } catch (Exception e1) { e1.printStackTrace(); } }
From source file:ca.uwaterloo.cpami.mahout.matrix.utils.GramSchmidt.java
public static void main(String[] args) throws IOException { //final Configuration conf = new Configuration(); //final FileSystem fs = FileSystem.get(conf); //final SequenceFile.Reader reader = new SequenceFile.Reader(fs, // new Path("R1.dat"), conf); //IntWritable key = new IntWritable(); //VectorWritable vec = new VectorWritable(); Matrix mat = new SparseMatrix(1500, 100); //SparseRealMatrix mat2 = new OpenMapRealMatrix(12419,1500 ); BufferedReader reader = new BufferedReader(new FileReader("R.3.csv")); String line = null;//from ww w . j a v a 2s . c om while ((line = reader.readLine()) != null) { String[] parts = line.split(","); mat.set(Integer.parseInt(parts[0]), Integer.parseInt(parts[1]), Double.parseDouble(parts[2])); /* Vector v = vec.get(); int i=0; Iterator<Vector.Element> itr = v.iterateNonZero(); while(itr.hasNext()){ double elem = itr.next().get(); if(elem !=0) mat2.setEntry(i, key.get(), elem); i++; } */ } //mat = mat.transpose(); System.out.println(mat.viewColumn(0).isDense()); System.out.println(mat.viewRow(0).isDense()); mat = mat.transpose(); GramSchmidt.orthonormalizeColumns(mat); /* System.out.println("started QR"); System.out.println(Runtime.getRuntime().maxMemory()); System.out.println(Runtime.getRuntime().maxMemory()-Runtime.getRuntime().freeMemory()); QRDecomposition qr = new QRDecomposition(mat2); System.out.println(qr.getQ().getColumnDimension()); System.out.println(qr.getQ().getRowDimension()); */ //mat = mat.transpose(); //storeSparseColumns(mat); //for (int i = 0; i < 10; i++) { // System.out.println(mat.viewRow(i).getNumNondefaultElements()); //} }
From source file:fr.tpt.s3.mcdag.generator.MainGenerator.java
/** * Main method for the generator: it launches a given number of threads with the parameters * given/* www . j av a2 s . c om*/ * @param args */ public static void main(String[] args) { /* ============================ Command line ================= */ Options options = new Options(); Option o_hi = new Option("mu", "max_utilization", true, "Upper bound utilization"); o_hi.setRequired(true); options.addOption(o_hi); Option o_tasks = new Option("nt", "nb_tasks", true, "Number of tasks for the system"); o_tasks.setRequired(true); options.addOption(o_tasks); Option o_eprob = new Option("e", "eprobability", true, "Probability of edges"); o_eprob.setRequired(true); options.addOption(o_eprob); Option o_levels = new Option("l", "levels", true, "Number of criticality levels"); o_levels.setRequired(true); options.addOption(o_levels); Option o_para = new Option("p", "parallelism", true, "Max parallelism for the DAGs"); o_para.setRequired(true); options.addOption(o_para); Option o_nbdags = new Option("nd", "num_dags", true, "Number of DAGs"); o_nbdags.setRequired(true); options.addOption(o_nbdags); Option o_nbfiles = new Option("nf", "num_files", true, "Number of files"); o_nbfiles.setRequired(true); options.addOption(o_nbfiles); Option o_rfactor = new Option("rf", "reduc_factor", true, "Reduction factor for criticality modes"); o_rfactor.setRequired(false); options.addOption(o_rfactor); Option o_out = new Option("o", "output", true, "Output file for the DAG"); o_out.setRequired(true); options.addOption(o_out); Option graphOpt = new Option("g", "graphviz", false, "Generate a graphviz DOT file"); graphOpt.setRequired(false); options.addOption(graphOpt); Option debugOpt = new Option("d", "debug", false, "Enabling debug"); debugOpt.setRequired(false); options.addOption(debugOpt); Option jobsOpt = new Option("j", "jobs", true, "Number of jobs"); jobsOpt.setRequired(false); options.addOption(jobsOpt); CommandLineParser parser = new DefaultParser(); HelpFormatter formatter = new HelpFormatter(); CommandLine cmd; try { cmd = parser.parse(options, args); } catch (ParseException e) { System.out.println(e.getMessage()); formatter.printHelp("DAG Generator", options); System.exit(1); return; } double maxU = Double.parseDouble(cmd.getOptionValue("max_utilization")); int edgeProb = Integer.parseInt(cmd.getOptionValue("eprobability")); int levels = Integer.parseInt(cmd.getOptionValue("levels")); int nbDags = Integer.parseInt(cmd.getOptionValue("num_dags")); int nbFiles = Integer.parseInt(cmd.getOptionValue("num_files")); int para = Integer.parseInt(cmd.getOptionValue("parallelism")); int nbTasks = Integer.parseInt(cmd.getOptionValue("nb_tasks")); boolean graph = cmd.hasOption("graphviz"); boolean debug = cmd.hasOption("debug"); String output = cmd.getOptionValue("output"); int nbJobs = 1; if (cmd.hasOption("jobs")) nbJobs = Integer.parseInt(cmd.getOptionValue("jobs")); double rfactor = 2.0; if (cmd.hasOption("reduc_factor")) rfactor = Double.parseDouble(cmd.getOptionValue("reduc_factor")); /* ============================= Generator parameters ============================= */ if (nbFiles < 0 || nbDags < 0 || nbJobs < 0) { System.err.println("[ERROR] Generator: Number of files & DAGs need to be positive."); formatter.printHelp("DAG Generator", options); System.exit(1); return; } Thread threads[] = new Thread[nbJobs]; int nbFilesCreated = 0; int count = 0; while (nbFilesCreated != nbFiles) { int launched = 0; for (int i = 0; i < nbJobs && count < nbFiles; i++) { String outFile = output.substring(0, output.lastIndexOf('.')).concat("-" + count + ".xml"); GeneratorThread gt = new GeneratorThread(maxU, nbTasks, edgeProb, levels, para, nbDags, rfactor, outFile, graph, debug); threads[i] = new Thread(gt); threads[i].setName("GeneratorThread-" + i); launched++; count++; threads[i].start(); } for (int i = 0; i < launched; i++) { try { threads[i].join(); nbFilesCreated++; } catch (InterruptedException e) { e.printStackTrace(); } } } }