コード例 #1
0
 private static Set<FormationSolution> _cartesianProduct(
     int index, List<Set<ComponentSolution>> sets) {
   Set<FormationSolution> ret = new HashSet<FormationSolution>();
   if (index == sets.size()) {
     ret.add(new FormationSolution());
   } else {
     for (ComponentSolution cs : sets.get(index)) {
       for (FormationSolution fs : _cartesianProduct(index + 1, sets)) {
         fs.getComponentSolutions().add(cs);
         ret.add(fs);
       }
     }
   }
   return ret;
 }
コード例 #2
0
  private static Double compareGAFull(
      FormationDecision fd, FormationValue bestGA, FormationValue bestFull) {

    if (bestGA == null || bestFull == null) return null;

    FormationSolution fsGA = new FormationSolution();
    fsGA.setComponentSolutions(bestGA.getComponentSolutions());
    FormationSolution fsFull = new FormationSolution();
    fsFull.setComponentSolutions(bestFull.getComponentSolutions());
    List<FormationSolution> fs = new ArrayList<FormationSolution>();
    fs.add(fsGA);
    fs.add(fsFull);
    System.out.println("Comparing following solutions: GA:" + fsGA + ", fsFull:" + fsFull);

    AnalyticHierarchyProcess ahp =
        new AnalyticHierarchyProcess(createFormationDecisionAlternatives(fd, fs));
    EvaluationResult formationEvalResult = null;
    try {
      formationEvalResult =
          ahp.evaluateFull(createFormationEvaluations(fd.getAlternatives()), 15, true);
    } catch (Exception e) {
      e.printStackTrace();
    }

    SortedSet<FormationValue> results = createSortedFormationResults(formationEvalResult);
    FormationValue previous = null;
    double bestGAValue = 1D;
    double bestFullValue = 1D;
    for (FormationValue fv : results) {
      if (previous != null)
        System.out.println(
            "Comparison prev: diff: "
                + (previous.getFormationValue() - fv.getFormationValue())
                + ", ratio: "
                + (previous.getFormationValue() / fv.getFormationValue()));
      previous = fv;
      if (fv.equals(bestGA)) bestGAValue = fv.getFormationValue();
      if (fv.equals(bestFull)) bestFullValue = fv.getFormationValue();
    }
    System.out.println(
        "Comparison best: diff: "
            + (bestGAValue - bestFullValue)
            + ", ratio: "
            + (bestGAValue / bestFullValue));

    return bestGAValue / bestFullValue;
  }