Example #1
0
  /** It launches the algorithm */
  public void execute() {
    if (somethingWrong) { // We do not execute the program
      System.err.println("An error was found");
      System.err.println("Aborting the program");
      // We should not use the statement: System.exit(-1);
    } else {
      this.proc =
          new AlcalaetalProcess(
              this.trans,
              this.nEvaluations,
              this.popSize,
              this.nBitsGene,
              this.phi,
              this.d,
              this.nFuzzyRegionsForNumericAttributes,
              this.useMaxForOneFrequentItemsets,
              this.minSupport,
              this.minConfidence);
      this.proc.run();
      this.associationRulesSet = this.proc.getRulesSet();
      this.proc.printReport(this.associationRulesSet);

      /*for (int i=0; i < this.associationRulesSet.size(); i++) {
      	System.out.println(this.associationRulesSet.get(i));
      }*/

      try {
        int r, i;
        AssociationRule ar;
        Itemset itemset;

        this.saveFuzzyAttributes(
            this.uniformFuzzyAttributesFilename, this.proc.getUniformFuzzyAttributes());
        this.saveFuzzyAttributes(
            this.adjustedFuzzyAttributesFilename, this.proc.getAdjustedFuzzyAttributes());
        this.saveGeneticLearningLog(
            this.geneticLearningLogFilename, this.proc.getGeneticLearningLog());

        PrintWriter rules_writer = new PrintWriter(this.rulesFilename);
        PrintWriter values_writer = new PrintWriter(this.valuesFilename);

        rules_writer.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
        rules_writer.println("<rules>");

        values_writer.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
        values_writer.print("<values ");
        values_writer.println(
            "n_one_frequent_itemsets=\""
                + this.proc.getNumberOfOneFrequentItemsets()
                + "\" n_rules=\""
                + this.associationRulesSet.size()
                + "\">");

        for (r = 0; r < this.associationRulesSet.size(); r++) {
          ar = this.associationRulesSet.get(r);

          rules_writer.println("<rule id = \"" + r + "\" />");
          values_writer.println(
              "<rule id=\""
                  + r
                  + "\" rule_support=\""
                  + ar.getRuleSupport()
                  + "\" antecedent_support=\""
                  + ar.getAntecedentSupport()
                  + "\" confidence=\""
                  + ar.getConfidence()
                  + "\"/>");
          rules_writer.println("<antecedents>");
          itemset = ar.getAntecedent();

          for (i = 0; i < itemset.size(); i++)
            this.createRule(itemset.get(i), this.proc.getAdjustedFuzzyAttributes(), rules_writer);

          rules_writer.println("</antecedents>");

          rules_writer.println("<consequents>");
          itemset = ar.getConsequent();

          for (i = 0; i < itemset.size(); i++)
            this.createRule(itemset.get(i), this.proc.getAdjustedFuzzyAttributes(), rules_writer);

          rules_writer.println("</consequents>");

          rules_writer.println("</rule>");
        }

        rules_writer.println("</rules>");
        values_writer.println("</values>");

        rules_writer.close();
        values_writer.close();

        System.out.println("\nAlgorithm Finished");
      } catch (FileNotFoundException e) {
        e.printStackTrace();
      }
    }
  }