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.
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.cable_activities, self.nucleation_energy, self.nucleation_mask, ) max_energy, i_cable_a, i_cable_b = nb.max_2d(self.nucleation_energy) # Add a new bundle if appropriate if max_energy > self.nucleation_threshold: i_bundle = self.n_bundles self.increment_n_bundles() self.mapping[i_cable_a, i_bundle] = 1 self.mapping[i_cable_b, i_bundle] = 1 # if len(self.bundle_to_cable_mapping) > i_bundle: # self.bundle_to_cable_mapping[i_bundle] =[i_cable_a, i_cable_b] # else: # self.bundle_to_cable_mapping.append( # [i_cable_a, i_cable_b]) # self.cable_to_bundle_mapping[i_cable_a].append(i_bundle) # self.cable_to_bundle_mapping[i_cable_b].append(i_bundle) # Reset the accumulated nucleation and agglomeration energy # for the two cables involved. self.nucleation_energy[i_cable_a, :] = 0 self.nucleation_energy[i_cable_b, :] = 0 self.nucleation_energy[:, i_cable_a] = 0 self.nucleation_energy[:, i_cable_b] = 0 self.agglomeration_energy[:, i_cable_a] = 0 self.agglomeration_energy[:, i_cable_b] = 0 # Update nucleation_mask to prevent the two cables from # accumulating nucleation energy in the future. self.nucleation_mask[i_cable_a, i_cable_b] = 0 self.nucleation_mask[i_cable_b, i_cable_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[i_cable_a, :] == 0)[0] blocked_b = np.where(self.nucleation_mask[i_cable_b, :] == 0)[0] blocked = np.union1d(blocked_a, blocked_b) self.agglomeration_mask[i_bundle, blocked] = 0 # if self.debug: if False: logger.debug(' '.join([ ' ', self.name, 'bundle', str(i_bundle), 'added with cables', str(i_cable_a), str(i_cable_b) ]))
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.
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