Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Correct differents bugs.
Browse files Browse the repository at this point in the history
One of theme : plot2 and plot3 of BetaAdicMonoid was freeing the data but they should'nt when a FastAutomaton is given in argument.
  • Loading branch information
mercatp committed Aug 17, 2014
1 parent eaf6401 commit 350054a
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/sage/combinat/words/automataC.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Automaton Determinise (Automaton a, Dict d, bool noempty, bool onlyfinals, bool
Automaton Duplicate (Automaton a, InvertDict id, int na2, bool verb);

//retire tous les états à partir desquels il n'y a pas de chemin infini
Automaton emonde_inf (Automaton a);
Automaton emonde_inf (Automaton a, bool verb);

//Compute the transposition, assuming it is deterministic
Automaton Transpose (Automaton a);
Expand Down
2 changes: 1 addition & 1 deletion src/sage/combinat/words/automata_tools.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ void TikZ (const char *data, const char *graph_name, double sx, double sy)
fclose(f);
if (verb)
printf("draw...\n");
sprintf(tamp, "dot %s -Gname -Tsvg > output.svg", name);
sprintf(tamp, "dot %s -Gname -Tsvg > output%s%s.svg", name, time(NULL), clock());
system(tamp);
}
51 changes: 27 additions & 24 deletions src/sage/combinat/words/cautomata.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ AUTHORS:
from libc.stdlib cimport malloc, free

cimport sage.combinat.words.cautomata
include "sage/ext/interrupt.pxi"

#ctypedef Automate Automaton

Expand All @@ -44,7 +45,7 @@ cdef extern from "automataC.h":
void plotTikZ (Automaton a, const char **labels, const char *graph_name, double sx, double sy)
Automaton Product(Automaton a1, Automaton a2, Dict d)
Automaton Determinise (Automaton a, Dict d, bool noempty, bool onlyfinals, bool nof, bool verb)
Automaton emonde_inf (Automaton a)
Automaton emonde_inf (Automaton a, bool verb)
Automaton emonde (Automaton a, bool verb)
Automaton emondeI (Automaton a, bool verb)
bool equalsAutomaton (Automaton a1, Automaton a2)
Expand Down Expand Up @@ -214,7 +215,7 @@ def TestEmonde (a, noempty=True, verb=True):
if verb:
print "Avant émondation :"
printAutomaton(au)
cdef Automaton r = emonde_inf(au)
cdef Automaton r = emonde_inf(au, verb)
if verb:
print "Après émondation :"
printAutomaton(r)
Expand Down Expand Up @@ -325,8 +326,10 @@ cdef class FastAutomaton:

def __dealloc__ (self):
#print "free"
sig_on()
FreeAutomaton(self.a[0])
free(self.a)
sig_off()

def __repr__ (self):
return "FastAutomaton with %d states and an alphabet of %d letters"%(self.a.n, self.a.na)
Expand All @@ -335,6 +338,7 @@ cdef class FastAutomaton:
return AutomatonGet(self.a[0], self.A)

def plot (self, int sx=10, int sy=8):
sig_on()
cdef char** ll
ll = <char **>malloc(sizeof(char*)*self.a.na)
cdef int i
Expand All @@ -344,7 +348,7 @@ cdef class FastAutomaton:
ll[i] = strA[i]
plotTikZ(self.a[0], ll, "Automaton", sx, sy)
free(ll);

sig_off()
#self.Automaton().plot2()

def Alphabet (self):
Expand All @@ -360,43 +364,42 @@ cdef class FastAutomaton:
l.append(i)
return l

def emonde_inf (self):
#sig_on()
def emonde_inf (self, verb=False):
sig_on()
cdef Automaton a
r = FastAutomaton(None)
a = emonde_inf(self.a[0])
#FreeAutomaton(self.a[0])
a = emonde_inf(self.a[0], verb)
r.a[0] = a
r.A = self.A
#sig_off()
sig_off()
return r

def emonde_i (self, verb=False):
#sig_on()
sig_on()
cdef Automaton a
r = FastAutomaton(None)
a = emondeI(self.a[0], verb)
r.a[0] = a
r.A = self.A
#sig_off()
sig_off()
return r

def emonde (self, verb=False):
#sig_on()
sig_on()
cdef Automaton a
r = FastAutomaton(None)
a = emonde(self.a[0], verb)
r.a[0] = a
r.A = self.A
#sig_off()
sig_off()
return r

def equals (self, FastAutomaton b):
return Bool(equalsAutomaton(self.a[0], b.a[0]))

#assume that the dictionnary d is injective !!!
def product (self, FastAutomaton b, dict d, verb=False):
#sig_on()
sig_on()
cdef Automaton a
cdef Dict dC
r = FastAutomaton(None)
Expand All @@ -413,7 +416,7 @@ cdef class FastAutomaton:
FreeDict(dC)
r.a[0] = a
r.A = Av
#sig_off()
sig_off()
return r

def intersection (self, FastAutomaton a, verb=False):
Expand All @@ -426,7 +429,7 @@ cdef class FastAutomaton:
return self.product(a, d, verb=verb)

def determinise_proj (self, dict d, noempty=True, onlyfinals=False, nof=False, verb=False):
#sig_on()
sig_on()
cdef Automaton a
cdef Dict dC
r = FastAutomaton(None)
Expand All @@ -440,13 +443,13 @@ cdef class FastAutomaton:
#FreeAutomaton(self.a[0])
r.a[0] = a
r.A = A2
#sig_off()
sig_off()
return r

#change les lettres selon d, en dupliquant les arêtes si nécessaire
#the result is assumed deterministic !!!
def duplicate (self, dict d, verb=False):
#sig_on()
sig_on()
cdef Automaton a
cdef InvertDict dC
r = FastAutomaton(None)
Expand All @@ -463,19 +466,19 @@ cdef class FastAutomaton:
FreeInvertDict(dC)
r.a[0] = a
r.A = A2
#sig_off()
sig_off()
return r

def transpose (self):
#sig_on()
sig_on()
r = FastAutomaton(None)
r.a[0] = Transpose(self.a[0])
r.A = self.A
#sig_off()
sig_off()
return r

def strongly_connected_components (self):
#sig_on()
sig_on()
cdef int* l = <int*>malloc(sizeof(int)*self.a.n)
cdef int ncc = StronglyConnectedComponents(self.a[0], l)
#inverse la liste
Expand All @@ -486,14 +489,14 @@ cdef class FastAutomaton:
l2[l[i]] = []
l2[l[i]].append(i)
free(l)
#sig_off()
sig_off()
return l2.values()

def sub_automaton (self, l, verb=False):
#sig_on()
sig_on()
r = FastAutomaton(None)
r.a[0] = SubAutomaton(self.a[0], list_to_Dict(l), verb)
r.A = self.A
#sig_off()
sig_off()
return r

12 changes: 10 additions & 2 deletions src/sage/monoids/beta_adic_monoid.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,8 @@ class BetaAdicMonoid(Monoid_class):
if verb:
print "Free..."
FreeSurface(s)
FreeAutomate(b.a)
if not isinstance(tss, FastAutomaton):
FreeAutomate(b.a)
FreeBetaAdic(b)

def plot3 (self, n=None, la=None, ss=None, tss=None, sx=800, sy=600, ajust=True, prec=53, colormap = 'hsv', backcolor=None, opacity = 1., add_letters=True, verb=False):
Expand Down Expand Up @@ -824,7 +825,12 @@ class BetaAdicMonoid(Monoid_class):
if verb:
print "Free..."
FreeSurface(s)
FreeAutomates(b.a, b.na)
if la is None:
FreeAutomates(b.a, b.na)
else:
for i,a in enumerate(la):
if not isinstance(a, FastAutomaton):
FreeAutomate(b.a[i])
FreeBetaAdic2(b)
FreeColorList(cl)

Expand Down Expand Up @@ -1692,6 +1698,8 @@ class BetaAdicMonoid(Monoid_class):
a.delete_edge(f, d, l)

if step == 2:
a.I = ['O']
a.F = Set([K.zero()])
return ("automate des relations ordonnées", a)

a.emondeI(I=['O'])
Expand Down

0 comments on commit 350054a

Please sign in to comment.