def generate_pws(euler_asp_rules, num_solutions=0): euler_asp_soln, meta_data = run_clingo(clingo_rules=euler_asp_rules, num_solutions=num_solutions) # TODO Add meta data, such as column names # TODO Add missing dataframes eg. if po_2 doesn't exist, then add an empty df pw_rel_dfs, rel_schemas, pw_objs = load_worlds( asp_output=euler_asp_soln, meta_data=meta_data, reasoner='clingo') return pw_rel_dfs, rel_schemas, pw_objs
def are_equivalent_patterns(pw1, pw2, eq_check_encoding): pw1_edge_facts = get_edge_facts(pw1, 1) pw2_edge_facts = get_edge_facts(pw2, 2) pw1_head_facts = get_query_head_facts(pw1, idx=1) pw2_head_facts = get_query_head_facts(pw2, idx=2) #print(pw1_edge_facts, pw2_edge_facts, pw1_head_facts, pw2_head_facts) asp_out, _ = run_clingo(eq_check_encoding.split('\n')+pw1_edge_facts+pw2_edge_facts+pw1_head_facts+pw2_head_facts, num_solutions=1) #print(asp_out) _,_,eq_check_pws = load_worlds(asp_out, silent=True) return len(eq_check_pws) >= 1
def get_unexplored(self): map_soln, _ = run_clingo(self.encoding, num_solutions=1) pw_rel_dfs, rel_schemas, pws = load_worlds(map_soln, silent=True) if len(pws) == 0: return None if 'comp_1' not in pw_rel_dfs: return {} comp_1_dfs = pw_rel_dfs['comp_1'] comp_1_dfs = comp_1_dfs[comp_1_dfs['pw'] == 1] comps = set(list(comp_1_dfs['x1'])) return comps
def get_unexplored_max(self): map_soln, _ = run_clingo(self.encoding + '\n' + self.COMP_COUNT_RULE + '\n' + self.COMP_MAXIMIZE_RULE, num_solutions=0) pw_rel_dfs, rel_schemas, pws = load_worlds(map_soln, silent=True) if len(pws) == 0: return None if 'comp_1' not in pw_rel_dfs: return {} max_pw = max(pws, key=lambda pw: -pw.pw_soln) max_pw_id = max_pw.pw_id comp_1_dfs = pw_rel_dfs['comp_1'] comp_1_dfs = comp_1_dfs[comp_1_dfs['pw'] == max_pw_id] comps = set(list(comp_1_dfs['x1'])) return comps
def remove_redundant_edges(orig_pw_obj, edges_rel_name: str='pp_2'): _,_, sliced_orig_pw_obj = rel_slicer(None, None, [orig_pw_obj], [edges_rel_name]) orig_pp_facts = PWEExport.export_as_asp_facts(sliced_orig_pw_obj, include_pw_ids=False) rel_name = edges_rel_name.rsplit('_', maxsplit=1)[0] # Without arity output_rel_name = 'useful_e' redundancy_removal_rules = ['% define child(CHILD, PARENT)', 'child(X,Y) :- {}(X,Y).'.format(rel_name), 'child(X,Y) :- {}(X,Z), child(Z,Y).'.format(rel_name), 'redundant_child(X,Y) :- child(X,Y), child(X,Z), child(Z,Y), X!=Y, Y!=Z, X!=Y.', '{}(X,Y) :- child(X,Y), not redundant_child(X,Y).'.format(output_rel_name), '#show {}/2.'.format(output_rel_name), ] useful_pp_clingo_soln, _ = run_clingo(orig_pp_facts+redundancy_removal_rules) useful_pp_dfs, _, _ = load_worlds(useful_pp_clingo_soln, silent=True, reasoner='clingo') useful_pp_dfs, _ = pw_slicer(useful_pp_dfs, None, [1]) return useful_pp_dfs['{}_2'.format(output_rel_name)]
def visualize_figure_from_asp_rules(db_asp_rules, db_rel_name='propDB', db_rel_arity=3, property_name_column='property_name', property_value_column='property_value', figID_column='figure_ID', figIDs_to_visualize=None): asp_output, md = run_clingo(db_asp_rules) pws_rels_dfs, rel_schemas, pw_objects = load_worlds(asp_output, meta_data=md, silent=True) propDB_df_rel_name = "{}_{}".format(db_rel_name, str(db_rel_arity)) propDB_df = pws_rels_dfs[propDB_df_rel_name] # Assumes that running the reasoner will only produce one PW (or that atleast all of them have the same DB) propDB_df = propDB_df[propDB_df['pw'] == 1] return WODBVizLib.visualize_figures( propDB_df, property_name_column=property_name_column, property_value_column=property_value_column, figID_column=figID_column, figIDs_to_visualize=figIDs_to_visualize)