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.cable_activities, self.n_bundles, self.agglomeration_energy, self.agglomeration_mask, ) max_energy, i_bundle, i_cable = nb.max_2d(self.agglomeration_energy) # Add a new bundle if appropriate if max_energy > self.agglomeration_threshold: # Add the new bundle to the end of the list. i_new_bundle = self.n_bundles self.increment_n_bundles() # Make a copy of the growing bundle. self.mapping[:, i_new_bundle] = self.mapping[:, i_bundle] # self.bundle_to_cable_mapping.append( # self.bundle_to_cable_mapping[i_bundle]) # Add in the new cable. # self.bundle_to_cable_mapping[i_new_bundle].append(i_cable) self.mapping[i_cable, i_bundle] = 1 # Update the contributing cables. # for i_cable in self.bundle_to_cable_mapping[i_new_bundle]: # self.cable_to_bundle_mapping[i_cable].append(i_new_bundle) # Reset the accumulated nucleation and agglomeration energy # for the two cables involved. self.nucleation_energy[i_cable, :] = 0 self.nucleation_energy[i_cable, :] = 0 self.nucleation_energy[:, i_cable] = 0 self.nucleation_energy[:, i_cable] = 0 self.agglomeration_energy[:, i_cable] = 0 self.agglomeration_energy[i_bundle, :] = 0 # Update agglomeration_mask to account for the new bundle. # The new bundle should not accumulate agglomeration energy with # 1) the cables that its constituent cable # are blocked from nucleating with or # 2) the cables that its constituent bundle # are blocked from agglomerating with. blocked_cable = np.where(self.nucleation_mask[i_cable, :] == 0) blocked_bundle = np.where( self.agglomeration_mask[i_bundle, :] == 0) blocked = np.union1d(blocked_cable[0], blocked_bundle[0]) self.agglomeration_mask[i_new_bundle, blocked] = 0 # if self.debug: if False: logger.debug(' '.join([ ' ', self.name, 'bundle', str(i_new_bundle), 'added: bundle', str(i_bundle), 'and cable', str(i_cable) ]))
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) ]))