Skip to content

Commit 236a123

Browse files
committed
PNF algorithm updated. First contact between beta-graphs and clingo.
1 parent c23b36c commit 236a123

File tree

3 files changed

+167
-83
lines changed

3 files changed

+167
-83
lines changed

src/asp_graph.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -959,7 +959,7 @@ def get_all_line_variables(self):
959959

960960
def get_variables(self):
961961
if self.line:
962-
return ['x' + str(self.line.line_id) + '_' + str(v)
962+
return ['X' + str(self.line.line_id) + '_' + str(v)
963963
for v in self.line.get_variables(self)]
964964
else:
965965
return []
@@ -1188,7 +1188,7 @@ def get_as_text(self):
11881188
txt += var
11891189
has_variables = True
11901190
else:
1191-
txt += ', '
1191+
txt += ','
11921192
txt += var
11931193
if has_variables:
11941194
txt += ')'

src/main.py

+28-11
Original file line numberDiff line numberDiff line change
@@ -105,16 +105,18 @@ def on_leave(self):
105105

106106
class CustomPopup(pup.Popup):
107107

108-
def __init__(self, root, **kwargs):
108+
def __init__(self, root, catch_keyboard=True, **kwargs):
109109
self.root = root
110+
self.catch_keyboard = catch_keyboard
110111
self.bind(on_open=self.open_callback)
111112
self.bind(on_dismiss=self.dismiss_callback)
112113
super(CustomPopup, self).__init__(**kwargs)
113114

114115
def open_callback(self, instance):
115116
print 'exec'
116117
#self.root._keyboard.unbind(on_key_down=self.root._on_keyboard_down)
117-
self.root._keyboard_release()
118+
if self.catch_keyboard:
119+
self.root._keyboard_release()
118120
#print('User focused', instance)
119121

120122
def dismiss_callback(self, instance):
@@ -126,7 +128,8 @@ def dismiss_callback(self, instance):
126128
# super(TextWidget, self).hide_keyboard()
127129

128130
#self.root._keyboard.bind(on_key_down=self.root._on_keyboard_down)
129-
self.root._keyboard_catch()
131+
if self.catch_keyboard:
132+
self.root._keyboard_catch()
130133
#print('User defocused', instance)
131134

132135
class LoadDialog(fl.FloatLayout):
@@ -599,8 +602,8 @@ def show_export(self):
599602

600603
def show_error(self, err_str):
601604
content = ErrorDialog(err_str, cancel=self.dismiss_popup)
602-
self._popup = CustomPopup(self, title="Error", content=content,
603-
size_hint=(0.4, 0.3))
605+
self._popup = CustomPopup(self, catch_keyboard=False, title="Error",
606+
content=content, size_hint=(0.4, 0.3))
604607
self._popup.open()
605608

606609
def show_about(self):
@@ -658,7 +661,7 @@ def load(self, path, filename):
658661
self.dismiss_popup()
659662
self.close_graph()
660663
self.new_graph()
661-
self.show_error('ERROR: Corrupted file.')
664+
self.show_error('Corrupted file.')
662665

663666
def save(self, path, filename):
664667
self.working_dir = path
@@ -686,7 +689,10 @@ def export(self, path, filename):
686689
s = norm.to_asp(i)
687690
stream.write(s)
688691
else:
689-
print 'File extension not supported.'
692+
error_str = 'File extension not supported.'
693+
print error_str
694+
self.show_error(error_str)
695+
return
690696
self.dismiss_popup()
691697

692698
def highlight_variables(self):
@@ -697,11 +703,21 @@ def view_symbolic_formula(self):
697703

698704
def gringo_query(self):
699705
rpn = self.active_graph.get_formula_RPN()
700-
print 'RPN formula: ', rpn
701-
f = norm.Formula(rpn)
702-
n = f.root
706+
print 80 * '-'
707+
print 'RPN formula:\n', rpn
708+
try:
709+
f = norm.Formula(rpn)
710+
n = f.root
711+
n = norm.pnf(n)
712+
print 80 * '-'
713+
print 'Prenex RPN formula:\n', n
714+
except Exception:
715+
self.show_error('Malformed formula.')
716+
return
717+
print 80 * '-'
703718
self.solver = gringo.Control()
704-
for i in norm.normalization(n):
719+
m = norm.get_matrix(n)
720+
for i in norm.normalization(m):
705721
#print i
706722
s = norm.to_asp(i)
707723
print 'ASP RULE: ', s
@@ -719,6 +735,7 @@ def gringo_query(self):
719735
print e
720736

721737
def on_model(self, m):
738+
print 80 * '-'
722739
print 'Stable models:'
723740
print m
724741

0 commit comments

Comments
 (0)