コード例 #1
0
  @SuppressWarnings({"rawtypes", "unchecked"})
  private void greedy()
      throws MOutofNException, ExceedLongMaxException, ArraysNotSameLengthException,
          InterruptedException {
    Graph<Integer, String> gOriginal = AlgorithmUtil.prepareGenericGraph(adjacencyMatrix);
    Graph<Integer, String> g = gOriginal;
    /* apply poly-rr */
    // Graph<Integer, String> g =		 GreedyDSUtil.applyPolyReductionRules(gOriginal,
    // this.runningTimeMap,GreedyDSUtil.POLY_RR_2_VALVE);
    /* apply degree-rr */
    DegreeRRReturn drrr = GreedyDSUtil.applyDegreeReductionRules(g, this.runningTimeMap);

    Map<Integer, Boolean> gDominatedMap = drrr.getDominatedMap();
    List<Integer> dI = drrr.getDsAfterDegreeRR();
    /*
     * it is possible that a graph has been dominated at this point, so a if
     * branch is needed here
     */

    // sort a list of vertex from lowest degree to highest
    List<Integer> vList = OrderPackageUtil.getVertexListDegreeAsc(g);

    Graph<Integer, String> gI = new SparseMultigraph<Integer, String>();
    // AlgorithmUtil.prepareGenericGraph(this.adjacencyMatrix, gI, dI);
    GreedyDSUtil.addCloseNeighborToSubgraph(g, gI, dI);
    List<Integer> undominatedVertices = null;
    Integer v;
    Integer u;
    do {

      gDominatedMap = GreedyDSUtil.getDominatedMap(g, dI);
      if (AlgorithmUtil.isAllDominated(gDominatedMap)) {
        break;
      }
      undominatedVertices = GreedyDSUtil.getUndominatedVertices(gDominatedMap);
      v = GreedyDSUtil.getTheFirstItemInOrderedListAndInAnotherList(vList, undominatedVertices);
      /*
       * if vi is not dominated, i) get its highest utility neighbor
       * vi;ii) put ui in DI; and iii) construct a GI with N[ui]; and iv)
       * if it is a moment of regret (in michael's original idea, it
       * always true),
       *
       * divide gI into V and DI, divide V into Vk (the k highest degree
       * vertices in V) and Vl (vertices not in Vk), divide DI into
       * Dk(Vk's neigbors which do not have neighbors in Vl), and Dl(the
       * neighbors of Vl)
       *
       * take Dk, GI, r as parameters to invoke dds fpt to get a solution
       * DDSI; v) set the smaller solution (of DI and DDSI ) to be
       * solution for GI
       */

      // i)
      u = AlgorithmUtil.getHighestUtilityNeighborOfAVertex(v, g, gDominatedMap);
      // ii)
      AlgorithmUtil.addElementToList(dI, u);
      // iii)
      GreedyDSUtil.addCloseNeighborToSubgraph(g, gI, u);

      MomentRegretReturn<Integer, String> mrr = null;
      if (isMomentOfRegret()) {
        mrr =
            GreedyDSUtil.applyAtMomentOfRegret(
                vList, dI, gI, this.indicator, k, this.rUpperBoundary, this.runningTimeMap, true);
      }

      if ((mrr.getDds() != null && mrr.getDds().size() > 0) && mrr.getDds().size() < dI.size()) {
        dI = mrr.getDds();
        Graph<Integer, String> gICopyNextRound = mrr.getGraph();
        GreedyDSUtil.addCloseNeighborToSubgraph(g, gICopyNextRound, dI);
        gI = gICopyNextRound;
      }

      // viii)
      gDominatedMap = GreedyDSUtil.getDominatedMap(g, dI);

    } while (!AlgorithmUtil.isAllDominated(gDominatedMap));

    // do guarantee, minimal, ls at the last step;
    List<Integer> gDI = GreedyDSUtil.useGreedyToCalcDS(g, this.runningTimeMap);
    if (dI.size() < gDI.size()) {
      this.dominatingSet = dI;
    } else {
      this.dominatingSet = gDI;
    }

    GreedyDSUtil.applyMinimal(g, this.dominatingSet, this.runningTimeMap);
    GreedyDSUtil.applyLS(g, this.dominatingSet, this.runningTimeMap);
  }
コード例 #2
0
 public Result getResult() {
   return GreedyDSUtil.getResult(
       this.k, this.rUpperBoundary, this.dominatingSet, this.runningTimeMap);
 }
コード例 #3
0
  private void initialization() {
    dominatingSet = new ArrayList<Integer>();

    this.runningTimeMap = new HashMap<String, Long>();
    GreedyDSUtil.initRunningTimeMap(this.runningTimeMap);
  }