Exemplo n.º 1
0
 def my_proc(m):
     i = int(m.group(1))
     j = int(m.group(3)) if m.group(3) is not None else None
     k = int(m.group(5)) if m.group(5) is not None else None
     val = float(m.group(7))
     if j is not None:
         util.ensure_has_capacity(result, i + 1, lambda: [])
         if k is not None:
             util.ensure_has_capacity(result[i], j + 1, lambda: [])
             util.ensure_has_capacity(result[i][j], k + 1)
             result[i][j][k] = val
         else:
             util.ensure_has_capacity(result[i], j + 1)
             result[i][j] = val
     else:
         util.ensure_has_capacity(result, i + 1)
         result[i] = val
Exemplo n.º 2
0
    def break_active_vbuckets_into_colors(self):
        """
        Returns a 2-d array representing the different colors of active
        vbuckets in this problem.
        E.g. if the solution the problem has the active vbuckets as
                [ 3, 0, 5 ]
        this method would return 2 arrays of:
                [ 3, 0, 0 ]
                [ 0, 0, 5 ]
        where the first array represents the active vbuckets of color 0
        and the second array the active vbuckets of color 1.

        This method is related to the similarly named method for replica
        vbuckets. To extend the previous example, let's imagine that
        2 of the 3 active vbuckets of color 1 are replicated to node 1
        and the remainder to node 2. Breaking apart the replica vbuckets
        into colors would look like:
                [ 0, 2, 1 ]
                [ 3, 2, 0 ]
        assuming a reasonable divide of the replicas for the active
        vbuckets on node 2.
        """
        if not self.avb_with_colors:
            avb = self.get_active_vbuckets()
            map = self.get_replication_map()
            a = []
            r = []
            count = 0
            for i in range(len(avb)):
                if avb[i] > 0:
                    util.ensure_has_capacity(a, count + 1, lambda: [])
                    util.ensure_has_capacity(r, count + 1, lambda: [])
                    a[count] = [0 for _ in range(self.node_count)]
                    r[count] = [0 for _ in range(self.node_count)]
                    a[count][i] = avb[i]
                    for j in range(self.node_count):
                        r[count][j] = map[i][j]
                    count += 1
                    continue
            self.color_count = count
            self.avb_with_colors = a
            self.rvb_with_colors = r
        return self.avb_with_colors
Exemplo n.º 3
0
 def generate_replica_networks(self):
     """
     Generates the "replica networks" for this.
     :return:
     """
     actuals = None
     if self.previous:
         self.previous.generate_vbmap()
         actuals = self.previous.get_actual_replica_networks()
         for k in range(len(actuals)):
             util.ensure_has_capacity(actuals[k], self.node_count, lambda: [])
             for i in range(len(actuals[k])):
                 util.ensure_has_capacity(actuals[k][i], self.node_count)
     map = build_replica_networks(self.node_count,
                                  self.replica_count,
                                  self.slave_factor,
                                  actuals,
                                  self.working_dir,
                                  self._use_exising_solution)
     self._replica_networks = MultiDimArray(map, self.replica_count, self.node_count, self.node_count)
Exemplo n.º 4
0
 def generate_vbmap(self):
     if not self._replica_networks:
         self.generate_replica_networks()
     if self.previous:
         avb = list(self.previous.get_active_vbuckets())
         util.ensure_has_capacity(avb, self.node_count)
         rvb = list(self.previous.get_replica_vbuckets())
         util.ensure_has_capacity(rvb, self.node_count)
         rep_map = self.previous.get_replication_map()
         self.vbmap_model = generate_vbmap_with_prev(self.node_count,
                                                     self.replica_count,
                                                     self._replica_networks,
                                                     avb,
                                                     rvb,
                                                     rep_map,
                                                     self.working_dir,
                                                     self._use_exising_solution)
     else:
         self.vbmap_model = generate_vbmap(self.node_count,
                                           self.replica_count,
                                           self._replica_networks,
                                           self.working_dir,
                                           self._use_exising_solution)
Exemplo n.º 5
0
 def get_actual_replica_networks(self):
     rep_map = self.get_replication_map()
     result = []
     for k in range(self.replica_count):
         network = self._replica_networks[k]
         util.ensure_has_capacity(result, k + 1, lambda: [])
         for i in range(self.node_count):
             util.ensure_has_capacity(result[k], i + 1, lambda: [])
             for j in range(self.node_count):
                 util.ensure_has_capacity(result[k][i], j + 1)
                 if network[i][j] > 0 and rep_map[i][j] > 0:
                     result[k][i][j] = 1
     return result
Exemplo n.º 6
0
 def prev_rvb(self):
     prev_rvb = copy.deepcopy(self.previous.break_replica_vbuckets_into_colors())
     for val in prev_rvb:
         util.ensure_has_capacity(val, self.node_count)
     return prev_rvb