parser.add_argument('-data_graph_path', metavar='N',help='path to data file') parser.add_argument('-pattern_path', metavar='N',help='path to data file') parser.add_argument('-output_path', metavar='N',help='path to data file') parser.add_argument('-exhaustive_approach_results_path', metavar='N',help='path to data file') parser.add_argument('-redo', default=False,action='store_true',help='flag for denoting redoing of experiment for this pattern. By default False') parser.add_argument('-runs', metavar='N',type=int,help='path to data file') parser.add_argument('-ignore', default=False,action='store_true',help='Ignore the fact that the patterns was not selected by short furer') parser.add_argument('-time_interval', metavar='N',type=int,help='time interval in seconds') parser.add_argument('-max_time', metavar='N',type=int,help='path to data file') parser.add_argument('-selected',default=False,action='store_true',help='do approximate approach only if the pattern is selected by the exhaustive approach') parser.add_argument('-s',default=False,action='store_true',help='use a fixed seed') parser.add_argument('-write', default=True,action='store_false',help='') args = parser.parse_args() experiments.globals.same_seed=args.s monitoring_marks=utils.generate_monitoring_marks(args.time_interval,args.max_time) print "Performing false furer...." all_falsefurer_times = [] falsefudicts = [] pathname = os.path.dirname(sys.argv[0]) command=su.make_command_string(sys.argv) data_graph=None try: data_graph=nx.read_gpickle(args.data_graph_path) except: data_graph=nx.read_gml(args.data_graph_path) pattern=nx.read_gml(args.pattern_path) analyzer.add_values_in_pattern_for_graph_if_missing(pattern) output_path=os.path.join(args.output_path,"results_false_furer_order_random") pattern_file_name=os.path.basename(args.pattern_path)[0:-4]
def get_nr_emb_within_time(data_graph_path, pattern_path, output_path, time_seconds): print "Exhaustive checkup ...." nr_emb = None monitoring_marks = utils.generate_monitoring_marks(time_seconds, time_seconds) data_graph = None try: data_graph = nx.read_gpickle(data_graph_path) except: data_graph = nx.read_gml(data_graph_path) number_of_nodes_in_data = len(data_graph) pattern = nx.read_gml(pattern_path) #vis.visualize_graph(pattern, "sat") #analyzer.add_values_in_pattern_for_graph_if_missing(pattern) output_path = os.path.join(output_path) if not os.path.exists(output_path): os.makedirs(output_path) root_node_predicate_name = None #well, not predefined. Let the algorithm find it and denote it (its id in the pattern) pattern_name = os.path.basename(pattern_path)[:-4] # logging.basicConfig( # level=logging.DEBUG, # filename=os.path.join(output_path,'error_exhaustive.log'), # filemode='w') # sys.excepthook = my_excepthook root_node = None #first check if the root node is determined by some other algorithm if not os.path.exists(os.path.join(output_path, 'root_node.dec')): hist = analyzer.get_sorted_labels_by_occurence_frequency_in_graph( data_graph_path) root_node, root_node_predicate_name = ut.choose_root_node( pattern, root_node_predicate_name, hist) with open(os.path.join(output_path, 'root_node.dec'), 'w') as f: f.write(str(root_node) + " ") f.write(str(root_node_predicate_name) + "\n") f.write("Determined by exhaustive approach") else: #read root node from the file with open(os.path.join(output_path, 'root_node.dec'), 'r') as f: for line in f.readlines(): root_node = int(line.split(" ")[0]) root_node_predicate_name = str( line.split(" ")[1].rstrip().lstrip()) break print "root node predicate name: ", root_node_predicate_name #get root nodes root_nodes = [ x for x in data_graph.nodes() if data_graph.node[x]['predicate'] == root_node_predicate_name ] print "Number of root nodes: ", len(root_nodes) #get OBD print "Root node,", pattern.node[root_node] OBdecomp = OBDsearch.get_heuristic4_OBD(pattern, startNode=root_node) if OBdecomp == None: print "No ombdecomp!" no_obd_decomp = True with open(os.path.join(output_path, 'no_obdecomp.info'), 'w') as f: f.write("No OBDecomp!") OBdecomp = OBDsearch.get_flatList(pattern, startNode=root_node) #get ordered list from OBD Plist = [item for sublist in OBdecomp for item in sublist] print "Using OBD: %s" % str(OBdecomp) print "and Plist: %s" % str(Plist) print "monitoring marks: ", monitoring_marks start = timeit.default_timer() try: lock = threading.Lock() print "starting scheduler" s = sched.scheduler(time.time, time.sleep) e1 = s.enter( 0, 4, exhaustive.find_nr_emb, (data_graph, pattern, Plist, root_nodes, output_path, lock)) t = threading.Thread(target=s.run) t.daemon = True t.start() time.sleep(time_seconds) end = timeit.default_timer() print "Main finished after ", end - start, "seconds" freq_dict = experiments.globals.fdict_exhaustive_limited if len(freq_dict) == 0: nr_emb = None else: nr_emb = 0 for k in freq_dict.keys(): nr_emb = nr_emb + freq_dict[k] except Wrong_root_node as e: print "Exception for the node occurred!" return nr_emb