def bubbleSort(data): for i in range(len(data)): for j in range(len(data) - i - 1): if data[j] > data[j + 1]: data[j], data[j + 1] = data[j + 1], data[j] Plot(j + 1, data) return data
def insertionSort(data): for i in range(len(data)): current = data[i] index = i while index > 0 and data[index - 1] > current: data[index] = data[index - 1] index -= 1 Plot(index, data) data[index] = current return data
def selectionSort(data): for i in range(len(data)): index = i for j in range(i + 1, len(data)): if data[index] > data[j]: index = j Plot(j, data) data[i], data[index] = data[index], data[i] return data
def partition(array, low, high): i = (low - 1) pivot = array[high] for j in range(low, high): if array[j] < pivot: i += 1 array[i], array[j] = array[j], array[i] Plot(i + 1, array) array[i + 1], array[high] = array[high], array[i + 1] return i + 1
def countingSort(array, digit): size = len(array) output = [0] * size count = [0] * 10 for i in range(0, size): index = array[i] // digit count[index % 10] += 1 for i in range(1, 10): count[i] += count[i - 1] i = size - 1 while i >= 0: index = array[i] // digit output[count[index % 10] - 1] = array[i] count[index % 10] -= 1 Plot(i, array) i -= 1 for i in range(0, size): array[i] = output[i] Plot(i, array)
def createHeap(data, heapSize, index): largest = index left = 2 * index + 1 right = 2 * index + 2 if left < heapSize and data[largest] < data[left]: largest = left if right < heapSize and data[largest] < data[right]: largest = right if largest != index: data[index], data[largest] = data[largest], data[index] createHeap(data, heapSize, largest) Plot(index, data)
def init_plot_contents(self): """ Decide plot contents for every plot.""" colorbar_dict = {'pred': 'occupancy_axes', 'obser': 'map_axes', 'corr': 'occupancy_axes'} for i in range(self.num_models): for j in range(self.num_col): if not self.show_colorbar: colorbar_on = None else: if self.dynamically: colorbar_on = colorbar_dict[self.show_elements[j]] else: colorbar_on = "occupancy_axes" if not self.tracking else None self.plots[i, j] = Plot(self.axes[i ,j], self.map, self.res, colorbar_on=colorbar_on, plot_map=self.show_map, plot_seen=self.show_seen, title='') if self.tracking and not self.dynamically: self.add_custom_elements_to_plot(self.plots[i, j]) if j == 0: self.plots[i, j].set_ylabel(self.model_names[i]) if self.traj_overlay: # trajectory from scene can only be calculated for one target num_targets = self.num_targets if self.simulated_data else 1 self.plots[i, j].add_traj_line(num_targets=num_targets) # add title to figure if self.simulated_data and self.init_moves is not None: self.fig.suptitle("Initial movements = {}".format(str(self.init_moves))) # add legend if neccessary if self.tracking and not self.dynamically: self.add_legend()