def show_network(self): """! @brief Shows connections in the network. It supports only 2-d and 3-d representation. """ if (self._ccore_network_pointer is not None) and (self._osc_conn is None): self._osc_conn = sync_connectivity_matrix(self._ccore_network_pointer) dimension = len(self._osc_loc[0]) if (dimension != 3) and (dimension != 2): raise NameError('Network that is located in different from 2-d and 3-d dimensions can not be represented'); from matplotlib.font_manager import FontProperties from matplotlib import rcParams rcParams['font.sans-serif'] = ['Arial'] rcParams['font.size'] = 12 fig = plt.figure() axes = None if dimension == 2: axes = fig.add_subplot(111) elif dimension == 3: axes = fig.gca(projection='3d') surface_font = FontProperties() surface_font.set_name('Arial') surface_font.set_size('12') for i in range(0, self._num_osc, 1): if dimension == 2: axes.plot(self._osc_loc[i][0], self._osc_loc[i][1], 'bo') if self._conn_represent == conn_represent.MATRIX: for j in range(i, self._num_osc, 1): # draw connection between two points only one time if self.has_connection(i, j) is True: axes.plot([self._osc_loc[i][0], self._osc_loc[j][0]], [self._osc_loc[i][1], self._osc_loc[j][1]], 'b-', linewidth = 0.5) else: for j in self.get_neighbors(i): if (self.has_connection(i, j) is True) and (i > j): # draw connection between two points only one time axes.plot([self._osc_loc[i][0], self._osc_loc[j][0]], [self._osc_loc[i][1], self._osc_loc[j][1]], 'b-', linewidth = 0.5) elif dimension == 3: axes.scatter(self._osc_loc[i][0], self._osc_loc[i][1], self._osc_loc[i][2], c = 'b', marker = 'o') if self._conn_represent == conn_represent.MATRIX: for j in range(i, self._num_osc, 1): # draw connection between two points only one time if self.has_connection(i, j) is True: axes.plot([self._osc_loc[i][0], self._osc_loc[j][0]], [self._osc_loc[i][1], self._osc_loc[j][1]], [self._osc_loc[i][2], self._osc_loc[j][2]], 'b-', linewidth = 0.5) else: for j in self.get_neighbors(i): if (self.has_connection(i, j) == True) and (i > j): # draw connection between two points only one time axes.plot([self._osc_loc[i][0], self._osc_loc[j][0]], [self._osc_loc[i][1], self._osc_loc[j][1]], [self._osc_loc[i][2], self._osc_loc[j][2]], 'b-', linewidth = 0.5) plt.grid() plt.show()
def has_connection(self, i, j): """! @brief Returns True if there is connection between i and j oscillators and False - if connection doesn't exist. @param[in] i (uint): index of an oscillator in the network. @param[in] j (uint): index of an oscillator in the network. """ if ( (self._ccore_network_pointer is not None) and (self._osc_conn is None) ): self._osc_conn = wrapper.sync_connectivity_matrix(self._ccore_network_pointer); return super().has_connection(i, j);
def get_neighbors(self, index): """! @brief Finds neighbors of the oscillator with specified index. @param[in] index (uint): index of oscillator for which neighbors should be found in the network. @return (list) Indexes of neighbors of the specified oscillator. """ if ( (self._ccore_network_pointer is not None) and (self._osc_conn is None) ): self._osc_conn = wrapper.sync_connectivity_matrix(self._ccore_network_pointer); return super().get_neighbors(index);