def var2proved(self, node, var): # list of all attackers of 'var' within 'node' that is labeled in conditionsd = [ var2tab_col(node, v, False) + " = 0" for (v, w) in self.subframework_edges(node) if w == var ] # list of all attackers of 'var' within 'node' that is labeled out conditionso = [ var2tab_col(node, v, False) + " = 2" for (v, w) in self.subframework_edges(node) if w == var ] if not node.needs_introduce(var): # if var is not introduced (has appeared before in some child), check if it hasn't already been proved conditionsd += [ "{}.{}".format(node2tab_alias(child_node), var2col_proved(var)) for child_node in node.vertex_children(var) ] conditionso += [ "{}.{}".format(node2tab_alias(child_node), var2col_proved(var)) for child_node in node.vertex_children(var) ] # var is in proved as def when it is in def and one of its attackers labeled in # var is in proved as out when it is in out and one of its attackers labeled out # otherwise, is not proved (FALSE) q = '(' q += ('(' + var2tab_col(node, var, False) + " = 1 AND (" + ' OR '.join(conditionsd) + '))') if conditionsd else 'FALSE' q += ' OR ' q += ('(' + var2tab_col(node, var, False) + " = 2 AND (" + ' OR '.join(conditionso) + ')))') if conditionso else 'FALSE)' return q
def var2extra(self, node, var): """Specifies a value to be selected for the extra (w) column of variable (argument) var. :param node: Node of the tree decomposition var is in. :param var: Id of variable (argument) :return: Value for the 'extra' column. """ # list of all attackers of 'var' within 'node' (as table columns) attacking_var = [ var2tab_col(node, v, False) for (v, w) in self.subframework_edges(node) if w == var ] # list of all arguments attacked by 'var' within 'node' (as table columns) attacked_by_var = [ var2tab_col(node, w, False) for (v, w) in self.subframework_edges(node) if v == var ] # if any of attackers of var is labelled IN, then var has to be labelled DEF def_conditions = [v for v in attacking_var] att_conditions_att_already = [] if not node.needs_introduce(var): # if var is not introduced (has appeared before in some child), check if it hasn't already been # labelled DEF def_conditions += [ "({}.{})".format(node2tab_alias(child_node), var2extra_col(var)) for child_node in node.vertex_children(var) ] # if var has been labelled ATT before (in some child) then var has to be labelled ATT # (unless it is defeated in the current node) att_conditions_att_already = [ "(NOT {}.{})".format(node2tab_alias(child_node), var2extra_col(var)) for child_node in node.vertex_children(var) ] # var must be remain as ATT if no attacker of var is labelled IN att_conditions_not_defeated = [f'NOT {v}' for v in attacking_var] return f'CASE ' \ f'WHEN {" OR ".join(def_conditions) if def_conditions else "FALSE"} THEN true ' \ f'WHEN ({" OR ".join(attacked_by_var) if attacked_by_var else "FALSE"}) ' \ f'AND ({" AND ".join(att_conditions_not_defeated) if att_conditions_not_defeated else "TRUE"}) ' \ f'OR ({" OR ".join(att_conditions_att_already) if att_conditions_att_already else "FALSE"}) THEN false ' \ f'ELSE null::{EXTRA_COL_DATATYPE} '\ f'END'
def var2defeat(self, node, var): """Specifies a value to be selected for the 'defeat' column of variable (argument) var. :param node: Node of the tree decomposition var is in. :param var: Id of variable (argument) :return: Value for the 'defeat' column. """ # list of all attackers of 'var' within 'node' conditions = [var2tab_col(node, v, False) for (v, w) in self.subframework_edges(node) if w == var] if not node.needs_introduce(var): # if var is not introduced (has appeared before in some child), check if it hasn't already been defeated conditions += ["{}.{}".format(node2tab_alias(child_node), var2col_defeated(var)) for child_node in node.vertex_children(var)] # var is defeated either when some of its attackers is labeled in or it has already been defeated before # otherwise, is not defeated (FALSE) return '({})'.format(' OR '.join(conditions)) if conditions else 'FALSE'
def node2cnt(node): return "{}.model_count".format(node2tab_alias(node))