def test_fully_connected_graph(self): node_connections = np.array([[0,1,1,0], [1,0,1,0], [1,1,0,1], [0,0,1,0]]) node_connections = sps.csc_matrix(node_connections) G = graph.Graph(node_connections) G.color_nodes() assert np.all(G.color==0) assert G.regions == 1
def test_two_region_graph(self): node_connections = np.array([[0,1,1,0], [1,0,1,0], [1,1,0,0], [0,0,0,0]]) node_connections = sps.csc_matrix(node_connections) G = graph.Graph(node_connections) G.color_nodes() assert np.all(G.color[:2]==0) assert G.color[3]==1 assert G.regions == 2
def test_nodes_connected_to_self(self): node_connections = np.array([[1,1,1,0], [1,1,1,0], [1,1,1,0], [0,0,0,1]]) node_connections = sps.csc_matrix(node_connections) G = graph.Graph(node_connections) G.color_nodes() print(G.color) assert np.all(G.color[:2]==0) assert G.color[3]==1 assert G.regions == 2
def regen(): json_data = request.json nodes = json_data["nodes"] edges = json_data["edges"] removed = json_data["removed"] nodes[-1]['color'] = { 'background': '#d9abff', 'highlight': { 'background': '#ead1ff' } } nodes[-1]['shape'] = 'box' nodes[-2]['color'] = { 'background': '#b3f6ff', 'highlight': { 'background': '#ccf9ff' } } nodes[-2]['shape'] = 'box' new_graph = graph.Graph(nodes, edges) ntables, rtables, dtables = [], [], [] for i in [vert['id'] for vert in new_graph.vertices]: dijkstra, mins = graph.dijkstra_route(new_graph, i) dijkstra_table = graph.dijkstra_format(new_graph, dijkstra, mins) routing_table = graph.routing_table(new_graph, mins) neighbor_table = graph.neighbor_table(new_graph, i) ntables.append(neighbor_table) rtables.append(routing_table) dtables.append(dijkstra_table) for rem_id in sorted(removed): ntables.insert(rem_id, "Error in retrieving new table") rtables.insert(rem_id, "Error in retrieving new table") dtables.insert(rem_id, "Error in retrieving new table") res = make_response({ "neighbor_tables": ntables, "routing_tables": rtables, "dtables": dtables }) res.mimetype = "application/json" return res
def find_median(g): arr = [len(g.adjList[v]) for v in g.adjList] arr = sorted(arr) half, odd = divmod(len(arr), 2) if odd: return arr[half] median = (arr[half - 1] + arr[half]) / 2.00 return median if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('input_file', help='Path to input file') parser.add_argument('output_file', help='Path to output file') args = parser.parse_args() g = graph.Graph() with open(args.input_file, 'r') as f: lines = f.readlines() for line in lines: line = json.loads(line) process_transaction(g, line['created_time'], line['actor'], line['target']) median = find_median(g) with open(args.output_file, 'a') as out: out.write("{:0.2f}\n".format(median))
''' Created on Sep 19, 2019 @author: mania ''' import utils.graph as gr from utils.inputs import * graphs = [] graphs_dict = {} q3ds = gr.Graph(6, type=gr.Type.sequential) q3ds.add_edge(0, 1, 0) q3ds.add_edge(1, 2, 0) q3ds.add_edge(2, 3, 0) q3ds.add_edge(3, 4, 0) q3ds.add_edge(4, 5, 0) q3ds.add_edge(5, 6, 0) q3ds.config_inputs(0, {'d': 0}) graphs.append(q3ds) graphs_dict['DSQ3'] = q3ds q1h = gr.Graph(3, type=gr.Type.broadcast) q1h.add_edge(0, 1, 0) q1h.add_edge(0, 2, 0) q1h.add_edge(1, 2, 0) q1h.config_inputs(0, {'lineitem': 0}) graphs.append(q1h) graphs_dict['HQ1'] = q1h