示例#1
0
 /** @param args */
 public static void main(String[] args) throws Exception {
   File file = new File("input.txt");
   if (file.exists()) {
     System.setIn(new BufferedInputStream(new FileInputStream("input.txt")));
   }
   out = System.out;
   bw = new BufferedWriter(new PrintWriter(out));
   // sc =  new Scanner(System.in);
   br = new BufferedReader(new InputStreamReader(System.in));
   C231 t = new C231();
   t.solve();
   bw.close();
 }
示例#2
0
    @Override
    public boolean accept(File file) {
      if (file.isDirectory()) {
        return true;
      }

      String name = file.getName().toLowerCase();
      for (int i = 0; i < extensions.length; ++i) {
        if (name.endsWith(extensions[i])) {
          return true;
        }
      }

      return false;
    }
示例#3
0
  public void saveAs() {
    Vector<RopeFileFilter> filters = new Vector<RopeFileFilter>();

    if (fileExt.equals("m") || fileExt.equals("mac")) {
      filters.add(new RopeFileFilter(new String[] {".m", ".mac"}, "Macro files (*.m *.mac)"));
      filters.add(
          new RopeFileFilter(
              new String[] {".a", ".asm", ".aut", ".s"}, "Assembly files (*.a *.asm *.aut *.s)"));
    } else {
      filters.add(
          new RopeFileFilter(
              new String[] {".a", ".asm", ".aut", ".s"}, "Assembly files (*.a *.asm *.aut *.s)"));
      filters.add(new RopeFileFilter(new String[] {".m", ".mac"}, "Macro files (*.m *.mac)"));
    }
    filters.add(new RopeFileFilter(new String[] {".txt"}, "Text files (*.txt)"));

    RopeFileChooser chooser = new RopeFileChooser(selectedPath, null, filters);
    chooser.setDialogTitle("Save Source File");
    String fileName = String.format("%s.%s", baseName, fileExt);
    chooser.setSelectedFile(new File(selectedPath, fileName));
    JTextField field = chooser.getTextField();
    field.setSelectionStart(0);
    field.setSelectionEnd(baseName.length());
    File file = chooser.save(ROPE.mainFrame);
    if (file != null) {
      selectedPath = file.getParent();

      BufferedWriter writer = null;
      try {
        writer = new BufferedWriter(new FileWriter(file));
        writer.write(sourceArea.getText());
      } catch (IOException ex) {
        ex.printStackTrace();
      } finally {
        try {
          if (writer != null) {
            writer.close();
          }
        } catch (IOException ex) {
          ex.printStackTrace();
        }
      }
    }
  }
示例#4
0
  public static void main(String[] args) {

    double[] sigma = {3E-4, 1E-6, 2.4E-2, 6.67E-5, 1E-6, 6E-3, 4.4E-4, 1E-2, 1E-6};
    double[] mu = {0.42E9, 2.27};
    double alpha = 0.0;
    Sampler sampler = new Sampler(mu, sigma, alpha);
    double[][] M = sampler.getCovMat();
    System.out.println("The Covirance Matrix is:");
    sampler.printMatrix(M);

    double[][] A = sampler.getCholDecompA();
    System.out.println("The decomposed Matrix A is");
    sampler.printMatrix(A);

    try {

      File file = new File("/Users/Weizheng/Documents/JavaWorkPlace/CLS_MCIntegrator/output.txt");
      // if file doesnt exists, then create it
      if (!file.exists()) {
        file.createNewFile();
      } else {
        file.delete();
        file.createNewFile();
      }

      PrintWriter fw = new PrintWriter(file);

      long startTime = System.currentTimeMillis();

      for (int i = 0; i < 1E3; i++) {
        double[] MultiNormalVector = sampler.nextMultiNormalVector();
        //				for(double a:MultiNormalVector ){
        //					fw.printf("%4.2e ", a);
        //				}
        //				fw.println("");
      }
      fw.close();
      long endTime = System.currentTimeMillis();
      System.out.println("That took " + (endTime - startTime) + " milliseconds");

    } catch (IOException e) {
      e.printStackTrace();
    }
  }
示例#5
0
  private void browseAction() {
    if (selectedPath == null) {
      selectedPath = System.getenv("ROPE_SOURCES_DIR");
      if (selectedPath != null) {
        File dir = new File(selectedPath);
        if (!dir.exists() || !dir.isDirectory()) {
          String message =
              String.format(
                  "The sources path set in environment variable ROPE_SOURCES_DIR is not avaliable.\n%s",
                  selectedPath);
          JOptionPane.showMessageDialog(null, message, "ROPE", JOptionPane.WARNING_MESSAGE);
          selectedPath = null;
        } else {
          System.out.println("Source folder path set from ROPE_SOURCES_DIR: " + selectedPath);
        }
      }
      if (selectedPath == null) {
        selectedPath = System.getProperty("user.dir");

        System.out.println("Source folder path set to current directory: " + selectedPath);
      }
    }

    Vector<RopeFileFilter> filters = new Vector<RopeFileFilter>();
    filters.add(
        new RopeFileFilter(
            new String[] {".a", ".asm", ".aut", ".s"}, "Assembly files (*.a *.asm *.aut *.s)"));
    filters.add(new RopeFileFilter(new String[] {".m", ".mac"}, "Macro files (*.m *.mac)"));
    filters.add(new RopeFileFilter(new String[] {".lst"}, "List files (*.lst)"));
    filters.add(new RopeFileFilter(new String[] {".txt"}, "Text files (*.txt)"));

    RopeFileChooser chooser = new RopeFileChooser(selectedPath, null, filters);
    chooser.setDialogTitle("Source document selection");
    chooser.setFileFilter(filters.firstElement());
    chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);

    File file = chooser.open(this, fileText);
    if (file != null) {
      if (loadSourceFile(file)) {
        mainFrame.showExecWindow(baseName);
      }
    }
  }
示例#6
0
  /** @param args */
  public static void main(String[] args) throws Exception {
    File file = new File("B-small-practice.in");
    if (file.exists()) {
      System.setIn(new BufferedInputStream(new FileInputStream(file)));
    }
    sc = new Scanner(System.in);
    FileWriter fw = new FileWriter(new File("output.txt"));
    out = new PrintWriter(fw);

    Bsmall b = new Bsmall();
    int T = sc.nextInt();
    int t = 1;
    while (t <= T) {
      out.print("Case #" + t + ": ");
      b.solve();
      t++;
    }
    out.close();
    fw.close();
  }
示例#7
0
  /** @param args */
  public static void main(String[] args) throws Exception {
    out = System.out;
    File file = new File("input.txt");
    if (file.exists()) {
      System.setIn(new BufferedInputStream(new FileInputStream("input.txt")));
    }
    sc = new Scanner(System.in);
    POJ3109 p = new POJ3109();

    while (true) {
      try {
        N = sc.nextInt();
        if (N == 0) {
          break;
        }
      } catch (Exception ex) {
        break;
      }
      p.solve();
    }
  }
示例#8
0
  public boolean loadSourceFile(File file) {
    boolean result = false;

    selectedPath = file.getParent();

    BufferedReader sourceFile = null;

    String directoryPath = file.getParent();
    String sourceName = file.getName();

    int idx = sourceName.lastIndexOf(".");
    fileExt = idx == -1 ? "" : sourceName.substring(idx + 1);
    baseName = idx == -1 ? sourceName.substring(0) : sourceName.substring(0, idx);
    String basePath = directoryPath + File.separator + baseName;

    DataOptions.directoryPath = directoryPath;

    sourcePath = file.getPath();

    AssemblerOptions.sourcePath = sourcePath;
    AssemblerOptions.listingPath = basePath + ".lst";
    AssemblerOptions.objectPath = basePath + ".cd";

    String var = System.getenv("ROPE_MACROS_DIR");
    if (var != null && !var.isEmpty()) {
      File dir = new File(var);
      if (dir.exists() && dir.isDirectory()) {
        AssemblerOptions.macroPath = var;
      } else {
        AssemblerOptions.macroPath = directoryPath;
      }
    } else {
      AssemblerOptions.macroPath = directoryPath;
    }

    DataOptions.inputPath = AssemblerOptions.objectPath;
    DataOptions.outputPath = basePath + ".out";
    DataOptions.readerPath = null;
    DataOptions.punchPath = basePath + ".pch";
    DataOptions.tape1Path = basePath + ".mt1";
    DataOptions.tape2Path = basePath + ".mt2";
    DataOptions.tape3Path = basePath + ".mt3";
    DataOptions.tape4Path = basePath + ".mt4";
    DataOptions.tape5Path = basePath + ".mt5";
    DataOptions.tape6Path = basePath + ".mt6";

    this.setTitle("EDIT: " + sourceName);
    fileText.setText(sourcePath);

    if (dialog == null) {
      dialog = new AssemblerDialog(mainFrame, "Assembler options");

      Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
      Dimension dialogSize = dialog.getSize();
      dialog.setLocation(
          (screenSize.width - dialogSize.width) / 2, (screenSize.height - dialogSize.height) / 2);
    }

    dialog.initialize();

    AssemblerOptions.command = dialog.buildCommand();

    sourceArea.setText(null);

    try {
      sourceFile = new BufferedReader(new FileReader(file));
      String line;

      while ((line = sourceFile.readLine()) != null) {
        sourceArea.append(line + "\n");
      }

      sourceArea.setCaretPosition(0);
      optionsButton.setEnabled(true);
      assembleButton.setEnabled(true);
      saveButton.setEnabled(true);

      setSourceChanged(false);
      undoMgr.discardAllEdits();

      result = true;
    } catch (IOException ex) {
      ex.printStackTrace();
    } finally {
      try {
        if (sourceFile != null) {
          sourceFile.close();
        }
      } catch (IOException ignore) {
      }
    }

    return result;
  }
示例#9
0
  public void nextTimeStep() {
    births = 0;
    deaths = 0;
    //		for (int i=0;i<o2perTS;i++) iterateOxygen();  // oh dear
    iterateCells();
    radiotherapy = false;
    stem_cells_this_TS = 0; // counter to track population dynamics
    non_stem_cells_this_TS = 0; // counter to track population dynamics

    // NEW
    int totalCells = 0;
    int totalHealthy = 0;
    int totalStem = 0;
    int totalProgenitor = 0;
    int totalMature = 0;
    for (int i = 0; i < size; i++)
      for (int j = 0; j < size; j++)
        if (Cells[i][j] < 4) {
          totalCells++;
          if (Cells[i][j] == 0) totalHealthy++;
          else if (Cells[i][j] == 1) totalStem++;
          else if (Cells[i][j] == 2) totalProgenitor++;
          else if (Cells[i][j] == 3) totalMature++;
          else System.err.println("wrong cell type");
        }

    // Not so new
    if (timestep == 0)
      System.out.println(
          +size
              + ", "
              + mutfreq
              + ", "
              + lengthGenome
              + ", "
              + asymmetricRatio); // print (parent,child) pair

    // System.out.println ("% Timestep\t Cells\t Stem Cells \t Progenitor\t Mature");
    if (timestep % dataReportStep == 0) {
      // System.out.println(timestep+"\t"+totalCells+"\t"+totalStem+"\t"+totalProgenitor+"\t"+totalMature+"\t"+births+"\t"+deaths+"\t"+((float)births/deaths));
      // System.err.println(asymmetricRatio+" "+maxProDivisions+" "+totalCells+" "+totalStem);}
      // System.err.println(mutationNum+" "+totalStem);
    }
    timestep++;

    // Finally let's write down the data
    if ((timestep % dataWriteStep == 0) && (timestep > dataWriteStartTime)) {
      try {
        File dir = new File("./text");
        dir.mkdir();

        // cell matrix
        FileWriter outFile1 = new FileWriter("./text/cells" + timestep);
        PrintWriter outCells = new PrintWriter(outFile1);

        // attempt at hashtable
        // FileWriter outFileHm = new FileWriter("./text/pairs"+timestep); // new
        // PrintWriter outTable = new PrintWriter(outFileHm);  // new

        // carriedGenome
        // FileWriter outFilecG = new FileWriter("./text/genomes"+timestep); // new
        // PrintWriter outcG = new PrintWriter(outFilecG);  // new

        // attempt at hashtable
        // FileWriter outFileHm2 = new FileWriter("./text/timepairs"+timestep); // new
        // PrintWriter outTable2 = new PrintWriter(outFileHm2);  // new

        // oxygen matrix
        // FileWriter outFile2 = new FileWriter("./text/oxygen"+timestep);
        // PrintWriter outO2 = new PrintWriter(outFile2);

        // stem age matrix
        // FileWriter outFile3 = new FileWriter("./text/stemBirthCounter"+timestep);
        // PrintWriter outSBC = new PrintWriter(outFile3);

        // carried mutation matrix
        FileWriter outFile2 = new FileWriter("./text/carriedmutation" + timestep);
        PrintWriter outCM = new PrintWriter(outFile2);
        /*
        		// stem total birth matrix
                        //FileWriter outFile4 = new FileWriter("./text/stemBirthsTotal"+timestep);
                        //PrintWriter outSBM = new PrintWriter(outFile4);

        		// stem death matrix
                        //FileWriter outFile5 = new FileWriter("./text/stemDeathCounter"+timestep);
                        //PrintWriter outSD = new PrintWriter(outFile5);

        		// TAC birth matrix
                        //FileWriter outFile6 = new FileWriter("./text/TACBirthCounter"+timestep);
                        //PrintWriter outTB = new PrintWriter(outFile6);

        		// TAC death matrix
                        //FileWriter outFile7 = new FileWriter("./text/TACDeathCounter"+timestep);
                        //PrintWriter outTD = new PrintWriter(outFile7);

                		//write hashtable
              			for (Integer key : tree.keySet()) {
              			outTable.print(+key+", "+tree.get(key)+"\r\n");
              			} //new
                		outTable.println(""); //new
                		outTable.close(); //new

                		//write hashtable
              			for (Integer value : tree.valueSet()) {
              			outTableNew.print(+tree.get(value)+", "+value+"\r\n");
              			} //new
                		outTableNew.println(""); //new
                		outTableNew.close(); //new


                		//write hashtable
                		for (Integer key : timeTree.keySet()) {
              			outTable2.print(+key+", "+timeTree.get(key)+"\r\n");
              			} //new
                		outTable2.println(""); //new
                		outTable2.close(); //new
        */
        for (int i = 0; i < size; i++) {
          for (int j = 0; j < size; j++) {
            outCells.print(Cells[i][j] + ", ");
            // outcG.print(carriedGenome[i][j]+", ");
            // outO2.print(Oxygen[i][j]+", ");
            // outSBC.print(stemBirthCounter[i][j]+", ");
            outCM.print(carriedmutation[i][j] + ", ");
            // outSBM.print(stemBirthsTotal[i][j]+", ");
            // outSD.print(stemDeathCounter[i][j]+", ");
            // outTB.print(TACBirthCounter[i][j]+", ");
            // outTD.print(TACDeathCounter[i][j]+", ");

          }
          outCells.println("");
          // outcG.println("");
          outCM.println("");
          // outO2.println("");
          // outSBC.println("");
          // outSBM.println("");
          // outSD.println("");
          // outTB.println("");
          // outTD.println("");

        }
        outCells.close();
        // outcG.close();
        outCM.close();
        // outO2.close();
        // outSBC.close();
        // outSBM.close();
        // outSD.close();
        // outTB.close();
        // outTD.close();

      } catch (IOException e) {
        e.printStackTrace();
        System.exit(-1);
      }
    }
  }