Java Collections.min Examples

Java Collections.min - 30 examples found. These are the top rated real world Java examples of java.util.Collections.min extracted from open source projects. You can rate examples to help us improve the quality of examples.
  private GASolution<int[]> algorithmRun() {
    GASolution<int[]> best = null;
    for (int iter = 0; iter < maxiter; iter++) {
      gBestChanged = false;

      population = makeChildren();

      best = Collections.min(population.getSols());
      if (globalBest == null || best.compareTo(globalBest) < 0) {
        globalBest = best;
        gBestChanged = true;
      }
      if (Math.abs(globalBest.fitness) < minFit) {
        return globalBest;
      }
      if (gBestChanged) {
        //				System.out.println((iter + 1) + ": " + best.fitness + " -> " + best.toString());
        System.out.println((iter + 1) + ": " + best.fitness);
      }
    }
    best = Collections.min(population.getSols());
    if (best.compareTo(globalBest) < 0) {
      globalBest = best;
    }
    return globalBest;
  }
  private void getDataToPlot() {
    switch (position) {
      case 0: // Humidity
        dataToPlot = humidityData;
        min = Collections.min(humidityData);
        max = Collections.max(humidityData);
        break;

      case 1: // Light
        dataToPlot = lightData;
        min = Collections.min(lightData);
        max = Collections.max(lightData);
        break;

      case 2: // Moisture
        dataToPlot = moistureData;
        min = Collections.min(moistureData);
        max = Collections.max(moistureData);
        break;

      case 3: // Temperature
        dataToPlot = temperatureData;
        min = Collections.min(temperatureData);
        max = Collections.max(temperatureData);
        break;
    }
  }
  static void displayStats() {
    if (training_time_stats.size() > 0)
      // TODO format floating point
      System.out.println(
          "Iteration time: min="
              + Collections.min(training_time_stats)
              + ", max="
              + Collections.max(training_time_stats)
              + ", avg="
              + Utils.average(training_time_stats)
              + " seconds");

    if (eval_time_stats.size() > 0)
      System.out.println(
          "Evaluation time: min="
              + Collections.min(eval_time_stats)
              + ", max="
              + Collections.max(eval_time_stats)
              + ", avg="
              + Utils.average(eval_time_stats)
              + " seconds");

    if (compute_fit && fit_time_stats.size() > 0)
      System.out.println(
          "fit_time: min="
              + Collections.min(fit_time_stats)
              + ", max="
              + Collections.max(fit_time_stats)
              + ", avg="
              + Utils.average(fit_time_stats)
              + " seconds");

    System.out.println("Memory: " + Memory.getUsage() + " MB");
  }
Example #4
0
  /**
   * this is the core if the h2_OwnPreferences is not the first for CMP to call
   *
   * @param candidatesKB
   */
  public HashMap<Integer, RuleEngine> core(HashMap<Integer, rule_engine.RuleEngine> candidatesKB) {

    ArrayList<Integer> preference_count = new ArrayList<>();
    ArrayList<Integer> candidateID = new ArrayList<>();
    ArrayList<Integer> toberemoved = new ArrayList<>();
    for (int i : candidatesKB.keySet()) {
      if (!preference_count.isEmpty()) {
        if (countActiveOwnPreferences(candidatesKB.get(i)) < Collections.min(preference_count)) {
          preference_count.removeAll(preference_count);
          candidateID.removeAll(candidateID);
          preference_count.add(countActiveOwnPreferences(candidatesKB.get(i)));
          candidateID.add(i);
        } else if (countActiveOwnPreferences(candidatesKB.get(i))
            == Collections.min(preference_count)) {
          preference_count.add(countActiveOwnPreferences(candidatesKB.get(i)));
          candidateID.add(i);
        }
      } else {
        preference_count.add(countActiveOwnPreferences(candidatesKB.get(i)));
        candidateID.add(i);
      }
    }
    for (int i : candidatesKB.keySet()) {
      if (!candidateID.contains(i)) {

        toberemoved.add(i);
      }
    }
    for (int i : toberemoved) {
      candidatesKB.remove(i);
    }
    return candidatesKB;
  }
Example #5
0
  // NEED TO FIX LOGIC FROM LEFT
  private String getIncidenceDirection(Article a, Article b) {

    double pL = a.getX(); // left
    double pR = pL + a.getWidth(); // right
    double pT = a.getY(); // bottom
    double pB = pT + a.getHeight();
    double tL = b.getX(); // left
    double tR = tL + b.getWidth();
    double tT = b.getY();
    double tB = tT + b.getHeight();
    String[] directions = {"Left", "Right", "Bottom", "Top"};
    Double inf = Double.MAX_VALUE;
    List<Double> intersect_diffs = new ArrayList<Double>(Arrays.asList(inf, inf, inf, inf));
    if (pR > tL && pL < tL)
      // Player on left
      intersect_diffs.remove(0);
    intersect_diffs.add(0, Math.abs(pR - tL));
    if (pL < tR && pR > tR) // Player on Right
    intersect_diffs.remove(1);
    intersect_diffs.add(1, Math.abs(tR - pL));
    if (pT > tB && pB < tB) // Player on Bottom
    intersect_diffs.remove(2);
    intersect_diffs.add(2, Math.abs(pT - tB));
    if (pB < tT && pT > tT) // Player on Top
    intersect_diffs.remove(3);
    intersect_diffs.add(3, Math.abs(tT - pB));
    Collections.min(intersect_diffs);
    // return the closest intersection
    return directions[intersect_diffs.indexOf(Collections.min(intersect_diffs))];
  }
Example #6
0
  public static void evaluateCircuitSNR(LogicCircuit lc, Args options) {

    /*for(Gate g: lc.get_logic_gates()) {
        evaluateGateSNR(g, options);
    }
    for(Gate g: lc.get_output_gates()) {
        evaluateGateSNR(g, options);
    }*/

    ArrayList<Double> input_ons = new ArrayList<>();
    ArrayList<Double> input_offs = new ArrayList<>();

    for (Gate input : lc.get_input_gates()) {
      for (int i = 0; i < input.get_logics().size(); ++i) {
        if (input.get_logics().get(i) == 1) {
          input_ons.add(input.get_outreus().get(i));
        } else if (input.get_logics().get(i) == 0) {
          input_offs.add(input.get_outreus().get(i));
        }
      }
    }

    Double input_on_min = Collections.min(input_ons);
    Double input_off_max = Collections.max(input_offs);

    ArrayList<Double> output_ons = new ArrayList<>();
    ArrayList<Double> output_offs = new ArrayList<>();

    for (Gate output : lc.get_output_gates()) {
      for (int i = 0; i < output.get_logics().size(); ++i) {
        if (output.get_logics().get(i) == 1) {
          output_ons.add(output.get_outreus().get(i));
        } else if (output.get_logics().get(i) == 0) {
          output_offs.add(output.get_outreus().get(i));
        }
      }
    }

    Double output_on_min = Collections.min(output_ons);
    Double output_off_max = Collections.max(output_offs);

    Double out_snr =
        20 * Math.log10((Math.log10(output_on_min / output_off_max)) / (2 * Math.log10(3.2)));

    Double in_snr =
        20 * Math.log10((Math.log10(input_on_min / input_off_max)) / (2 * Math.log10(3.2)));

    Double dsnr = out_snr - in_snr;

    lc.get_scores().set_snr(out_snr);
    lc.get_scores().set_dsnr(dsnr);
  }