コード例 #1
0
ファイル: Main.java プロジェクト: kplogo/komiwojager
 private static void printResult(List<Point> pointList, List<Algorithm> algorithms) {
   for (Algorithm algorithm : algorithms) {
     Result r = algorithm.run(pointList);
     r.stop();
     System.err.println(algorithm.toString());
     System.err.println("Time: " + r.getTime());
     System.err.println("Iterations: " + r.getIterationCount());
     for (RoundResult rr : r.getResultsToReport()) {
       System.err.println(rr.printResult());
     }
     //            System.out.println(r.getBestResult().print(true));
     System.err.println();
   }
 }
コード例 #2
0
ファイル: Main.java プロジェクト: kplogo/komiwojager
 private static void writeToFile(Algorithm a, RoundResult[] resultsToReport) {
   try {
     PrintWriter pw =
         new PrintWriter(
             "resources/results_"
                 + a.getClass().getSimpleName()
                 + "_"
                 + new SimpleDateFormat("yyyyMMdd_kkmm")
                     .format(new Date(System.currentTimeMillis())));
     for (RoundResult r : resultsToReport) {
       pw.println(r.toString());
     }
     pw.flush();
     pw.close();
   } catch (FileNotFoundException e) {
     System.err.println("File not found: " + e.getMessage());
     for (RoundResult r : resultsToReport) {
       System.out.println(r.toString());
     }
   }
 }
コード例 #3
0
ファイル: Main.java プロジェクト: ai-se/SPL
  /** @param args the command line arguments -- modelname, alg_name, evaluation_times, [runid] */
  public static void main(String[] args) throws Exception {

    try {
      String name = args[0];
      URL location = Main.class.getProtectionDomain().getCodeSource().getLocation();
      String loc = location.toString();
      String project_path =
          loc.substring(5, loc.lastIndexOf("SPL/")) + "SPL/"; // with '/' at the end
      String fm = project_path + "dimacs_data/" + name + ".dimacs";
      String augment = fm + ".augment";
      String dead = fm + ".dead";
      String mandatory = fm + ".mandatory";
      String seed = fm + ".richseed";
      String opfile = fm + ".sipop";

      Problem p = new ProductLineProblem(fm, augment, mandatory, dead, seed);
      //            Problem p = new ProductLineProblemNovelPrep(fm, augment, mandatory, dead, seed,
      // opfile);
      //            GroupedProblem.grouping((ProductLineProblem) p, 100); System.exit(0);
      Algorithm a;
      int evaluation_times = Integer.parseInt(args[2]);
      String alg_name = args[1];
      String runid = "";
      if (args.length >= 4) {
        runid = args[3];
      }

      switch (alg_name) {
        case "IBEA":
          a = new SPL_SettingsIBEA(p).configureICSE2013(evaluation_times);
          break;
        case "SIPIBEA":
          a = new SPL_SettingsIBEA(p).configureSIPIBEA(evaluation_times);
          break;
        case "SPEA2":
          a = new SPL_SettingsEMOs(p).configureSPEA2(evaluation_times);
          break;
        case "NSGA2":
          a = new SPL_SettingsEMOs(p).configureNSGA2(evaluation_times);
          break;
        case "IBEASEED":
          a = new SPL_SettingsIBEA(p).configureIBEASEED(evaluation_times);
          break;
        case "SATIBEA":
          // a = new SPL_SettingsIBEA(p).configureICSE15(1000, fm, ((ProductLineProblem)
          // p).getNumFeatures(),
          // ((ProductLineProblem) p).getConstraints());
          a =
              new SPL_SettingsIBEA(p)
                  .configureSATIBEA(
                      evaluation_times,
                      fm,
                      ((ProductLineProblem) p).getNumFeatures(),
                      ((ProductLineProblem) p).getConstraints());
          break;
        default:
          a = new SPL_SettingsIBEA(p).configureICSE2013(evaluation_times);
      }

      long start = System.currentTimeMillis();
      SolutionSet pop = a.execute();
      float total_time = (System.currentTimeMillis() - start) / 1000.0f;

      String file_tag =
          name + "_" + alg_name + '_' + evaluation_times / 1000 + "k_" + runid + ".txt";
      String file_path = project_path + "j_res/" + file_tag;
      File file = new File(file_path);

      if (!file.exists()) {
        file.createNewFile();
      }

      FileWriter fw = new FileWriter(file.getAbsoluteFile());
      BufferedWriter bw = new BufferedWriter(fw);

      for (int i = 0; i < pop.size(); i++) {
        Variable v = pop.get(i).getDecisionVariables()[0];
        bw.write((Binary) v + "\n");
        System.out.println("Conf" + (i + 1) + ": " + (Binary) v + " ");
      }

      bw.write("~~~\n");

      for (int i = 0; i < pop.size(); i++) {
        Variable v = pop.get(i).getDecisionVariables()[0];
        for (int j = 0; j < pop.get(i).getNumberOfObjectives(); j++) {
          bw.write(pop.get(i).getObjective(j) + " ");
          System.out.print(pop.get(i).getObjective(j) + " ");
        }
        bw.write("\n");
        System.out.println("");
      }

      System.out.println(total_time);
      bw.write("~~~\n" + total_time + "\n");

      bw.close();
      fw.close();

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
コード例 #4
0
ファイル: MainOld.java プロジェクト: zchenyu/plusone
  public static void main(String[] args) throws Throwable {
    DATASET = System.getProperty("dataset", "movielens-pos.json");
    TRAINPERCENT = Double.parseDouble(System.getProperty("trainPercent", "0.8"));
    TESTPERCENT = Double.parseDouble(System.getProperty("testPercent", "0.5"));
    RUNS = Integer.parseInt(System.getProperty("runs", "1"));
    PREDICTIONS = Integer.parseInt(System.getProperty("predictions", "1"));
    // rand = new Random( Integer.parseInt( System.getProperty( "seed", "1" ) ) );
    rand = new Random();

    System.out.println("File: " + DATASET);
    System.out.println("Train Percent: " + TRAINPERCENT);
    System.out.println("Test Percent: " + TESTPERCENT);
    System.out.println("Runs: " + RUNS);
    System.out.println("Predictions: " + PREDICTIONS);
    docs = DatasetOld.loadDataset(DATASET);

    for (Algorithm alg : algs) {
      System.out.print(alg.name + "\t");
      double total = 0.0;

      long trainTime = 0;
      long predictTime = 0;

      for (int run = 0; run < RUNS; run++) {
        ArrayList<HashMap<Integer, Double>> traindocs = new ArrayList<HashMap<Integer, Double>>();
        ArrayList<HashMap<Integer, Double>> testdocs = new ArrayList<HashMap<Integer, Double>>();

        for (HashMap<Integer, Double> doc : docs) {
          if (rand.nextDouble() < TRAINPERCENT) traindocs.add(doc);
          else testdocs.add(doc);
        }

        long startTime = System.nanoTime();
        alg.train(traindocs);
        trainTime += System.nanoTime() - startTime;

        int successes = 0;

        for (HashMap<Integer, Double> testdoc : testdocs) {
          HashMap<Integer, Double> givenwords = new HashMap<Integer, Double>();
          HashSet<Integer> testwords = new HashSet<Integer>();

          for (int word : testdoc.keySet()) {
            if (rand.nextDouble() < TESTPERCENT) {
              testwords.add(word);
            } else {
              givenwords.put(word, testdoc.get(word));
            }
          }

          startTime = System.nanoTime();
          double[] scores = alg.predict(givenwords);
          predictTime += System.nanoTime() - startTime;
          // System.out.println(Arrays.toString( scores ));
          PriorityQueue<Pair> pq = new PriorityQueue<Pair>();

          for (int i = 0; i < scores.length; i++) {
            if (givenwords.containsKey(i)) {
              continue;
            }

            if (pq.size() < PREDICTIONS) {
              pq.add(new Pair(i, scores[i]));
            }
            if (scores[i] > pq.peek().score) {
              pq.poll();
              pq.add(new Pair(i, scores[i]));
            }
          }

          while (!pq.isEmpty()) {
            Pair pair = pq.poll();
            // System.out.println( WordIndex.get( pair.word ) + "\t" + pair.score + "\t" +
            // testwords.contains( pair.word ) );
            if (testwords.contains(pair.word)) {
              successes++;
            }
          }
        }

        total += (double) successes / PREDICTIONS / testdocs.size();
      }

      System.out.println(
          total / RUNS
              + "\t"
              + (trainTime / 1000000000.0 / RUNS)
              + "\t"
              + (predictTime / 1000000000.0 / RUNS));
    }
  }