Example #1
0
    def _create_new_bundles(self):
        """
        If the right conditions have been reached, create a new bundle.
        """
        # Incrementally accumulate nucleation energy.
        nb.nucleation_energy_gather(self.nonbundle_activities,
                                    self.nucleation_energy)

        # Don't accumulate nucleation energy between a cable and itself
        ind = np.arange(self.cable_activities.size).astype(int)
        self.nucleation_energy[ind, ind] = 0.

        # Don't accumulate nucleation energy between cables already
        # in the same bundle
        for i in range(self.n_map_entries):
            i_bundle = self.bundle_map_rows[i]
            i_cable = self.bundle_map_cols[i]
            j = 1
            j_bundle = self.bundle_map_rows[i + j]
            j_cable = self.bundle_map_cols[i + j]
            while j_bundle == i_bundle:
                self.nucleation_energy[i_cable, j_cable] = 0.
                self.nucleation_energy[j_cable, i_cable] = 0.
                j += 1
                j_bundle = self.bundle_map_rows[i + j]
                j_cable = self.bundle_map_cols[i + j]

        results = -np.ones(3)
        nb.max_dense(self.nucleation_energy, results)
        max_energy = results[0]
        cable_index_a = int(results[1])
        cable_index_b = int(results[2])

        # Add a new bundle if appropriate
        if max_energy > self.nucleation_threshold:
            self.bundle_map_rows[self.n_map_entries] = self.num_bundles
            self.bundle_map_cols[self.n_map_entries] = cable_index_a
            self.increment_n_map_entries()
            self.bundle_map_rows[self.n_map_entries] = self.num_bundles
            self.bundle_map_cols[self.n_map_entries] = cable_index_b
            self.increment_n_map_entries()
            self.num_bundles += 1

            print(' '.join(['    ', self.name,
                            'bundle', str(self.num_bundles),
                            'added with cables', str(cable_index_a),
                            str(cable_index_b)]))

            # Check whether the ``ZipTie``'s capacity has been reached.
            if self.num_bundles == self.max_num_bundles:
                self.bundles_full = True

            # Reset the accumulated nucleation and agglomeration energy
            # for the two cables involved.
            self.nucleation_energy[cable_index_a, :] = 0.
            self.nucleation_energy[cable_index_b, :] = 0.
            self.nucleation_energy[:, cable_index_a] = 0.
            self.nucleation_energy[:, cable_index_b] = 0.
            self.agglomeration_energy[:, cable_index_a] = 0.
            self.agglomeration_energy[:, cable_index_b] = 0.
Example #2
0
    def _grow_bundles(self, masked_cable_activities):
        """
        Update an estimate of co-activity between all cables.
        """
        # Incrementally accumulate agglomeration energy.
        #nb.agglomeration_energy_gather(self.bundle_activities,
        #                               self.nonbundle_activities,
        #                               self.num_bundles,
        #                               self.agglomeration_energy)
        #nb.agglomeration_energy_gather(self.bundle_activities,
        #                               self.cable_activities,
        #                               self.num_bundles,
        #                               self.agglomeration_energy)
        nb.agglomeration_energy_gather(self.bundle_activities,
                                       masked_cable_activities,
                                       self.num_bundles,
                                       self.agglomeration_energy)

        # Don't accumulate agglomeration energy between cables already
        # in the same bundle
        val = 0.
        if self.n_map_entries > 0:
            nb.set_dense_val(self.agglomeration_energy,
                             self.bundle_map_rows[:self.n_map_entries],
                             self.bundle_map_cols[:self.n_map_entries], val)

        results = -np.ones(3)
        nb.max_dense(self.agglomeration_energy, results)
        max_energy = results[0]
        cable_index = int(results[2])
        bundle_index = int(results[1])

        # Add a new bundle if appropriate
        if max_energy > self.agglomeration_threshold:
            # Find which cables are in the new bundle.
            cables = [cable_index]
            for i in range(self.n_map_entries):
                if self.bundle_map_rows[i] == bundle_index:
                    cables.append(self.bundle_map_cols[i])
            # Check whether the agglomeration is already in the bundle map.
            candidate_bundles = np.arange(self.num_bundles)
            for cable in cables:
                matches = np.where(self.bundle_map_cols == cable)[0]
                candidate_bundles = np.intersect1d(
                    candidate_bundles,
                    self.bundle_map_rows[matches],
                    assume_unique=True)
            if candidate_bundles.size != 0:
                # The agglomeration has already been used to create a
                # bundle. Ignore and reset they count. This can happen
                # under normal circumstances, because of how nonbundle
                # activities are calculated.
                self.agglomeration_energy[bundle_index, cable_index] = 0.
                return

            # Make a copy of the growing bundle.
            for i in range(self.n_map_entries):
                if self.bundle_map_rows[i] == bundle_index:
                    self.bundle_map_rows[self.n_map_entries] = self.num_bundles
                    self.bundle_map_cols[self.n_map_entries] = (
                        self.bundle_map_cols[i])
                    self.increment_n_map_entries()
            # Add in the new cable.
            self.bundle_map_rows[self.n_map_entries] = self.num_bundles
            self.bundle_map_cols[self.n_map_entries] = cable_index
            self.increment_n_map_entries()
            self.num_bundles += 1

            if self.debug:
                print(' '.join([
                    '    ', self.name, 'bundle',
                    str(self.num_bundles), 'added: bundle',
                    str(bundle_index), 'and cable',
                    str(cable_index)
                ]))

            # Check whether the Ziptie's capacity has been reached.
            if self.num_bundles == self.max_num_bundles:
                self.bundles_full = True

            # Reset the accumulated nucleation and agglomeration energy
            # for the two cables involved.
            self.nucleation_energy[cable_index, :] = 0.
            self.nucleation_energy[cable_index, :] = 0.
            self.nucleation_energy[:, cable_index] = 0.
            self.nucleation_energy[:, cable_index] = 0.
            self.agglomeration_energy[:, cable_index] = 0.
            self.agglomeration_energy[bundle_index, :] = 0.
Example #3
0
    def _create_new_bundles(self, masked_cable_activities):
        """
        If the right conditions have been reached, create a new bundle.
        """
        # Incrementally accumulate nucleation energy.
        #nb.nucleation_energy_gather(self.nonbundle_activities,
        #                            self.nucleation_energy)
        nb.nucleation_energy_gather(masked_cable_activities,
                                    self.nucleation_energy)

        # Don't accumulate nucleation energy between a cable and itself
        ind = np.arange(self.cable_activities.size).astype(int)
        self.nucleation_energy[ind, ind] = 0.

        # Don't accumulate nucleation energy between cables already
        # in the same bundle
        for i in range(self.n_map_entries):
            i_bundle = self.bundle_map_rows[i]
            i_cable = self.bundle_map_cols[i]
            j = 1
            j_bundle = self.bundle_map_rows[i + j]
            j_cable = self.bundle_map_cols[i + j]
            while j_bundle == i_bundle:
                self.nucleation_energy[i_cable, j_cable] = 0.
                self.nucleation_energy[j_cable, i_cable] = 0.
                j += 1
                j_bundle = self.bundle_map_rows[i + j]
                j_cable = self.bundle_map_cols[i + j]

        results = -np.ones(3)
        nb.max_dense(self.nucleation_energy, results)
        max_energy = results[0]
        cable_index_a = int(results[1])
        cable_index_b = int(results[2])

        # Add a new bundle if appropriate
        if max_energy > self.nucleation_threshold:
            self.bundle_map_rows[self.n_map_entries] = self.num_bundles
            self.bundle_map_cols[self.n_map_entries] = cable_index_a
            self.increment_n_map_entries()
            self.bundle_map_rows[self.n_map_entries] = self.num_bundles
            self.bundle_map_cols[self.n_map_entries] = cable_index_b
            self.increment_n_map_entries()
            self.num_bundles += 1

            print(' '.join([
                '    ', self.name, 'bundle',
                str(self.num_bundles), 'added with cables',
                str(cable_index_a),
                str(cable_index_b)
            ]))

            # Check whether the Ziptie's capacity has been reached.
            if self.num_bundles == self.max_num_bundles:
                self.bundles_full = True

            # Reset the accumulated nucleation and agglomeration energy
            # for the two cables involved.
            self.nucleation_energy[cable_index_a, :] = 0.
            self.nucleation_energy[cable_index_b, :] = 0.
            self.nucleation_energy[:, cable_index_a] = 0.
            self.nucleation_energy[:, cable_index_b] = 0.
            self.agglomeration_energy[:, cable_index_a] = 0.
            self.agglomeration_energy[:, cable_index_b] = 0.
Example #4
0
    def _grow_bundles(self):
        """
        Update an estimate of co-activity between all cables.
        """
        # Incrementally accumulate agglomeration energy.
        nb.agglomeration_energy_gather(self.bundle_activities,
                                       self.nonbundle_activities,
                                       self.num_bundles,
                                       self.agglomeration_energy)

        # Don't accumulate agglomeration energy between cables already
        # in the same bundle
        val = 0.
        if self.n_map_entries > 0:
            nb.set_dense_val(self.agglomeration_energy,
                             self.bundle_map_rows[:self.n_map_entries],
                             self.bundle_map_cols[:self.n_map_entries],
                             val)

        results = -np.ones(3)
        nb.max_dense(self.agglomeration_energy, results)
        max_energy = results[0]
        cable_index = int(results[2])
        bundle_index = int(results[1])

        # Add a new bundle if appropriate
        if max_energy > self.agglomeration_threshold:
            # Find which cables are in the new bundle.
            cables = [cable_index]
            for i in range(self.n_map_entries):
                if self.bundle_map_rows[i] == bundle_index:
                    cables.append(self.bundle_map_cols[i])
            # Check whether the agglomeration is already in the bundle map.
            candidate_bundles = np.arange(self.num_bundles)
            for cable in cables:
                matches = np.where(self.bundle_map_cols == cable)[0]
                candidate_bundles = np.intersect1d(
                    candidate_bundles,
                    self.bundle_map_rows[matches],
                    assume_unique=True)
            if candidate_bundles.size != 0:
                # The agglomeration has already been used to create a
                # bundle. Ignore and reset they count. This can happen
                # under normal circumstances, because of how nonbundle
                # activities are calculated.
                self.agglomeration_energy[bundle_index, cable_index] = 0.
                return

            # Make a copy of the growing bundle.
            for i in range(self.n_map_entries):
                if self.bundle_map_rows[i] == bundle_index:
                    self.bundle_map_rows[self.n_map_entries] = self.num_bundles
                    self.bundle_map_cols[self.n_map_entries] = (
                        self.bundle_map_cols[i])
                    self.increment_n_map_entries()
            # Add in the new cable.
            self.bundle_map_rows[self.n_map_entries] = self.num_bundles
            self.bundle_map_cols[self.n_map_entries] = cable_index
            self.increment_n_map_entries()
            self.num_bundles += 1

            print(' '.join(['    ', self.name,
                            'bundle', str(self.num_bundles),
                            'added: bundle', str(bundle_index),
                            'and cable', str(cable_index)]))

            # Check whether the ``ZipTie``'s capacity has been reached.
            if self.num_bundles == self.max_num_bundles:
                self.bundles_full = True

            # Reset the accumulated nucleation and agglomeration energy
            # for the two cables involved.
            self.nucleation_energy[cable_index, :] = 0.
            self.nucleation_energy[cable_index, :] = 0.
            self.nucleation_energy[:, cable_index] = 0.
            self.nucleation_energy[:, cable_index] = 0.
            self.agglomeration_energy[:, cable_index] = 0.
            self.agglomeration_energy[bundle_index, :] = 0.
Example #5
0
    def _create_new_bundles(self, cable_activities):
        """
        If the right conditions have been reached, create a new bundle.
        """
        # Incrementally accumulate nucleation energy.
        nb.nucleation_energy_gather(cable_activities, self.nucleation_energy,
                                    self.nucleation_mask)

        # Don't accumulate nucleation energy between a cable and itself
        ind = np.arange(self.cable_activities.size).astype(int)
        self.nucleation_energy[ind, ind] = 0.

        results = -np.ones(3)
        nb.max_dense(self.nucleation_energy, results)
        max_energy = results[0]
        cable_index_a = int(results[1])
        cable_index_b = int(results[2])

        # Add a new bundle if appropriate
        if max_energy > self.nucleation_threshold:
            self.bundle_map_rows[self.n_map_entries] = self.n_bundles
            self.bundle_map_cols[self.n_map_entries] = cable_index_a
            self.increment_n_map_entries()
            self.bundle_map_rows[self.n_map_entries] = self.n_bundles
            self.bundle_map_cols[self.n_map_entries] = cable_index_b
            self.increment_n_map_entries()

            # Reset the accumulated nucleation and agglomeration energy
            # for the two cables involved.
            self.nucleation_energy[cable_index_a, :] = 0.
            self.nucleation_energy[cable_index_b, :] = 0.
            self.nucleation_energy[:, cable_index_a] = 0.
            self.nucleation_energy[:, cable_index_b] = 0.
            self.agglomeration_energy[:, cable_index_a] = 0.
            self.agglomeration_energy[:, cable_index_b] = 0.

            # Update nucleation_mask to prevent the two cables from
            # accumulating nucleation energy in the future.
            self.nucleation_mask[cable_index_a, cable_index_b] = 0.
            self.nucleation_mask[cable_index_b, cable_index_a] = 0.

            # Update agglomeration_mask to account for the new bundle.
            # The new bundle should not accumulate agglomeration energy
            # with any of the cables that any of its constituent cables
            # are blocked from nucleating with.
            blocked_a = np.where(self.nucleation_mask[cable_index_a, :] == 0.)
            blocked_b = np.where(self.nucleation_mask[cable_index_b, :] == 0.)
            blocked = np.union1d(blocked_a[0], blocked_b[0])
            self.agglomeration_mask[self.n_bundles, blocked] = 0.

            self.n_bundles += 1
            if self.debug:
                print(' '.join([
                    '    ', self.name, 'bundle',
                    str(self.n_bundles), 'added with cables',
                    str(cable_index_a),
                    str(cable_index_b)
                ]))

            # Check whether the Ziptie's capacity has been reached.
            if self.n_bundles == self.n_bundles:
                self.bundles_full = True