def prims_NodeLandmark(pr, measure, kind, order_val, timer, algo): """ Jees New code the nodeLandmark """ import math global full_mat, count k_list = [ math.ceil(math.log(order_val)) - 2, math.ceil(math.log(order_val)), math.ceil(math.log(order_val)) + 2, math.ceil(math.log(order_val)) + 4 ] for k in k_list: # g_prime = copy.copy(g) g_prime = {} timer.start() oracle_plugin = NodeLandMarkRandom(g_prime, k, oracle, order_val) p = prims_plugin(order_val, oracle, oracle_plugin) p.mst(0) timer.end() print( "Node Landmark:\nActual(Vanila) Prims Path Length: {}\nNode Lankmark(our plugin) Prims Path Length: {}\nmeasure: {}, kind: {}, order_val: {}" .format(pr.mst_path_length, p.mst_path_length, measure, kind, order_val)) print("COUNT node Landmark {}\nk:{}\nTime: {}\n\n".format( count, k, timer.time_elapsed))
def prims_TSS(pr, measure, kind, order_val, timer, algo): """ Jees added this part to test the naive code for intersection-TriSearch(This) This accepts a graph(graph with edge and distance format) and converts it into adjacency list representation and stores it. This updates a new edge the moment its gets a new resolution This computes the value of lower-bound only when needed by a query Q(a, b) This find the Triangles through intersection of adjacency list of both end points of the query edge (a & b) The class IntersectTriSearch: is initialized with the graph and it takes care of everything else including conversion to adjacency list. """ global full_mat, count timer.start() oracle_plugin = IntersectTriSearch({}, order_val) p = prims_plugin(order_val, oracle, oracle_plugin) p.mst(0) timer.end() print( "IntersctionTriSearch Experiments:\nActual(Vanila) Prims Path Length: {}\nIntersctionTriSearch(our plugin) Prims Path Length: {}\nmeasure: {}, kind: {}, order_val: {}" .format(pr.mst_path_length, p.mst_path_length, measure, kind, order_val)) print( "COUNT intersct Trisearch: {}\nLB Time(Tri): {}\nUB Time(Tri): {}\n\n". format(count, timer.time_elapsed - oracle_plugin.sp_time, oracle_plugin.sp_time))
def prims_DSS(g, pr, measure, kind, order_val, timer, algo): """ DSS Solution Scheme """ print("Experiment Starting DSS (Prims)\n") global full_mat, count # g = {} oracle = flicker_oracle() timer.start() obj_dss = DSS(g, order_val) oracle_plugin = obj_dss p = prims_plugin(order_val, oracle, oracle_plugin) p.mst(0) timer.end() assert abs(p.mst_path_length - pr.mst_path_length) < 0.000001 print( "Plugin with DSS\nActual(SW) {} Path Length: {}\nDSS Path Length: {}\n" "measure: {}, kind: {}, order_val: {}".format(algo, p.mst_path_length, pr.mst_path_length, measure, kind, order_val)) print("DSS COUNT {}\nTime: {}\n\n".format( count, timer.time_elapsed, ))
def prims_SW(g, pr, measure, kind, order_val, timer): # Sasha Wang algorithm print("Experiment Starting Sasha Wang (Prims)\n") global full_mat, count # g = {} timer.start() obj_sw = SashaWang() obj_sw.store(g, order_val) oracle_plugin = obj_sw p = prims_plugin(order_val, oracle, oracle_plugin) p.mst(0) timer.end() assert abs(p.mst_path_length - pr.mst_path_length) < 0.000001 print( "Plugin with Sasha Wang Experiments\nActual(SW) Prims Path Length: {}\nSasha Wang Prims Path Length: {}\n" "measure: {}, kind: {}, order_val: {}".format(p.mst_path_length, pr.mst_path_length, measure, kind, order_val)) sasha_wang_results = "COUNT Sasha Wang " + str(count) + " Time " + str( timer.time_elapsed - obj_sw.update_time) + "\n" print("COUNT Sasha Wang: {}, Time(total): {}, Time(SP): {}\n\n".format( count, timer.time_elapsed, obj_sw.update_time))
def prims_LSS(pr, measure, kind, order_val, timer, algo): """ code to test the landmarkbased methods """ global full_mat, count timer.start() oracle_plugin = LSS({}, order_val, 6, oracle) p = prims_plugin(order_val, oracle, oracle_plugin) p.mst(0) timer.end() print("{} COUNT LSS: {}\nTime(LSS): {}\n\n".format(algo, count, timer.time_elapsed))
def helper_prims_plugin(): global g, g_mat, order_val, full_mat, count count = 0 obj_sw = SashaWang() obj_sw.store(g, order_val) obj = unified_graph_lb_ub() obj.store(g, order_val) assert not np.any( np.abs(np.array(obj_sw.lb_matrix) - np.array(obj.lb_matrix)) < -0.0000001) start = time.time() obj_sw = SashaWang() obj_sw.store(g, order_val) oracle_plugin = obj_sw p = prims_plugin(order_val, oracle, oracle_plugin) p.mst(0) end = time.time() print("COUNT Sasha Wang", count, end - start, "\n\n") count = 0 start = time.time() obj = unified_graph_lb_ub() obj.store(g, order_val) oracle_plugin = obj p = prims_plugin(order_val, oracle, oracle_plugin) p.mst(0) end = time.time() print("COUNT LBTree enabled", count, end - start, "\n\n") start = time.time() count = 0 obj = ParamTriSearch(2, obj_sw.ub_matrix) obj.store(g, order_val) oracle_plugin = obj p = prims_plugin(order_val, oracle, oracle_plugin) p.mst(0) end = time.time() print("PARA", count, end - start, "\n\n")
def prims_SW(g, pr, order_val, timer, oracle, bounder=False): # Sasha Wang algorithm print("Experiment Starting Sasha Wang (Prims)\n") global full_mat, count # g = {} timer.start() obj_sw = SashaWang() obj_sw.store(g, order_val) oracle_plugin = obj_sw # oracle = flicker_oracle() p = prims_plugin(order_val, oracle, oracle_plugin) p.mst(0) timer.end() print("value from SW: {}".format(p.mst_path_length)) assert abs(p.mst_path_length - pr.mst_path_length) < 0.000001 print( "Plugin with Sasha Wang Experiments\nActual(SW) Prims Path Length: {}\nSasha Wang Prims Path Length: {}\n" "order_val: {}".format(p.mst_path_length, pr.mst_path_length, order_val)) sasha_wang_results = "COUNT Sasha Wang " + str(count) + " Time " + str( timer.time_elapsed - obj_sw.update_time) + "\n" print("COUNT Sasha Wang: {}, Time(total): {}, Time(SP): {}\n\n".format( count, timer.time_elapsed, obj_sw.update_time)) if bounder: lb = [] ub = [] lb_name = 'lower_bounds_{}_sw.lb'.format(order_val) ub_name = 'upper_bounds_{}_sw.ub'.format(order_val) for i in range(order_val): for j in range(i + 1, order_val): a, b = p.plug_in_oracle.lookup(i, j) lb.append(a) ub.append(b) path_out = os.path.join(os.getcwd(), "bounds_compare_results", "bounds_{}_sw".format(order_val)) if not os.path.exists(path_out): os.makedirs(path_out) with open(os.path.join(path_out, lb_name), 'w') as f: f.write('\n'.join([str(b) for b in lb])) with open(os.path.join(path_out, ub_name), 'w') as f: f.write('\n'.join([str(b) for b in ub])) with open("dft_scale.res", 'a+') as f: f.write("Order Val: {}\n".format(order_val)) f.write( "COUNT Sasha Wang: {}, Time(total): {}, Time(SP): {}\n\n".format( count, timer.time_elapsed, obj_sw.update_time))
def prims_LBUB(g, pr, measure, kind, order_val, timer, algo): timer.start() obj = unified_graph_lb_ub() # obj = SW_and_LBUB_Oracle() obj.store(g, order_val) oracle_plugin = obj p = prims_plugin(order_val, oracle, oracle_plugin) p.mst(0) timer.end() print( "LB Tree - Original Length: {}, our length: {}, measure: {}, kind: {}, order_val: {}" .format(p.mst_path_length, pr.mst_path_length, measure, kind, order_val)) # average_lbt = np.average(np.array(obj_sw.lb_matrix) - np.array(obj.lb_matrix)) # average_original = np.average(full_mat - np.array(obj_sw.lb_matrix)) print("COUNT LBTree enabled {}\nTotal Time: {}\n\n\n".format( count, timer.time_elapsed))
def prims_LSS(g, pr, measure, kind, order_val, timer, algo): """ code to test the landmarkbased methods """ print("Experiment Starting LSS (Prims)\n") global full_mat, count # g = {} k_ = math.ceil(math.log(order_val, 2)) timer.start() oracle_plugin = LSS(g, order_val, k_, oracle) p = prims_plugin(order_val, oracle, oracle_plugin) p.mst(0) timer.end() print("{} COUNT LSS: {}\nTime(LSS): {}\n\n".format(algo, count, timer.time_elapsed)) print("Total Lookups: {}\nUpper Beats: {}\nLower Beats: {}".format( oracle_plugin.lookup_ctr, oracle_plugin.ub_better_ctr, oracle_plugin.lb_better_ctr))