def animate_all_pair_shortest_path(n=15, frames=None): # make node nodes = list(APSPNode(id=i) for i in range(n)) # make graph and set node graph = UndirectedGraph(nodes=nodes) # compute node position pos = antigravity_node_layout(nodes) # make and set edge for u, v, dist in degree_base_edge_layout(pos): graph.connect_undirected_edge(u, v, weight=min(10, 300/(1+np.exp(-(3*dist-5))))) ### this information use only for animation ### for node in nodes: node.make_aveilable_color(graph.n()) # initialize node for node in nodes: if node.identifier() == n-1: node.initialize(root=True) else: node.initialize(root=False) # make daemon and set graph daemon = FairDaemon(graph) # start animation return daemon.animation(pos, weight=False, label=False, interval=100, frames=frames or n*10), nodes
def animate_minimum_dominating_set_approx(n=15, frames=None): # make node nodes = list(MDSAprproxNode(id=i, k=5) for i in range(n)) # make graph and set node graph = UndirectedGraph(nodes=nodes) # compute node position pos = antigravity_node_layout(nodes) # make and set edge for u, v, dist in degree_base_edge_layout(pos): graph.connect_undirected_edge(u, v, weight=min( 20, 300 / (1 + np.exp(-(3 * dist - 5))))) # set max degree as initial knowledge for node in nodes: node.max_degree = graph.max_degree() # initialize give node n for node in nodes: node.initialize(graph.max_degree()) # make daemon and set graph daemon = FairDaemon(graph, conflict=False) # start animation return daemon.animation(pos, weight=False, label=False, interval=100, frames=frames or n * 10)
def animate_color_reduce(n=15, frames=None): # make node nodes = list(ColorReduceNode(id=i + 1, color=i + 1) for i in range(n)) # make graph and set node graph = UndirectedGraph(nodes=nodes) # compute node position pos = antigravity_node_layout(nodes) # make and set edge for u, v, dist in degree_base_edge_layout(pos): graph.connect_undirected_edge(u, v, weight=min( 20, 300 / (1 + np.exp(-(3 * dist - 5))))) ### this information use only for animation ### for node in nodes: node.make_aveilable_color(graph.n(), graph.max_degree()) # make daemon and set graph daemon = FairDaemon(graph) # start animation return daemon.animation(pos, weight=False, label=False, interval=100, frames=frames or n * 10)
def animate_breadth_first_tree(n=15, frames=None): # make node nodes = list(BFSTreeNode(id=i) for i in range(n - 1)) nodes.append(BFSTreeNode(id=n - 1, root=True)) # make graph and set node graph = UndirectedGraph(nodes=nodes) # compute node position pos = antigravity_node_layout(nodes) # make and set edge for u, v, dist in degree_base_edge_layout(pos): graph.connect_undirected_edge(u, v, weight=min( 20, 300 / (1 + np.exp(-(3 * dist - 5))))) # make daemon and set graph daemon = FairDaemon(graph) # start animation return daemon.animation(pos, weight=False, label=False, interval=100, frames=frames or n * 10)