Ejemplo n.º 1
0
 public CostGenerator(MatrixGenerator m, ComponentInstance ci, int type) {
   mainComponent = ci;
   matrix = m;
   dsmGenerator = new DsmGenerator(matrix, mainComponent, type);
   depth = dsmGenerator.getDepth();
   cost = 0;
   total = 0;
   impactReports = new HashMap<String, CostImpactReport>();
 }
Ejemplo n.º 2
0
  public void compute() {
    int[][][] dsms;
    int[][] dsm;
    CostImpactReport impactReport;
    String componentName;
    dsms = new int[depth][depth][depth];

    if (depth == 0) {
      System.out.println("[COSTGENERATOR] ERROR depth==0");
      return;
    }

    /*
     * Compute all DSM matrixes
     */
    for (int i = 0; i < depth; i++) {
      dsms[i] = dsmGenerator.getDsm(i);
    }

    /*
     * Compute the final cost impact
     */
    for (int i = 0; i < depth; i++) {
      for (int j = 0; j < depth; j++) {
        for (int k = 0; k < depth; k++) {
          total += (double) dsms[i][j][k];
        }
      }
    }

    /*
     * Compute the slocs impact for each component
     */
    for (int c = 0; c < dsmGenerator.getComponents().size(); c++) {
      long slocs;
      int crit;
      String depName;
      ComponentInstance depInstance;
      ComponentInstance component;

      component = dsmGenerator.getComponents().get(c);
      componentName = Utils.getComponentName(component);

      impactReport = new CostImpactReport(componentName);
      System.out.println("Cost analysis for: " + componentName);
      for (int d = 0; d < depth; d++) {
        System.out.println("DEPTH=" + d);
        dsm = dsmGenerator.getDsm(d);

        for (int dep = 0; dep < dsmGenerator.getComponents().size(); dep++) {
          depInstance = dsmGenerator.getComponents().get(dep);
          depName = Utils.getComponentName(depInstance);

          slocs = SlocProperty.getSloc(depInstance);
          crit = CriticalityProperty.getCriticality(depInstance);
          System.out.println(
              "   Looking for dep (depth="
                  + d
                  + "): "
                  + depName
                  + "(crit="
                  + crit
                  + ";slocs="
                  + slocs
                  + ";coeff="
                  + dsm[c][dep]
                  + ")");

          if (dsm[dep][c] > 0) {
            System.out.println(
                "   Looking for dep (depth="
                    + d
                    + "): "
                    + depName
                    + "(crit="
                    + crit
                    + ";slocs="
                    + slocs
                    + ";coeff="
                    + dsm[c][dep]
                    + ")");
            impactReport.addSlocs(slocs * dsm[dep][c], crit);
          }
        }
      }
      impactReports.put(componentName, impactReport);
    }

    cost = total / (double) ((depth * depth));
    System.out.println(
        "[COSTGENERATOR] Cost=" + cost + "(total = " + total + " depth=" + depth + ")");
  }