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

Commit

Permalink
Improve the completion of FastAutomaton and add complementaryOP() and…
Browse files Browse the repository at this point in the history
… test of inclusion : included().
  • Loading branch information
mercatp committed Nov 13, 2014
1 parent 8d1a1cb commit 4c59b96
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 8 deletions.
17 changes: 15 additions & 2 deletions src/sage/combinat/words/automataC.c
Original file line number Diff line number Diff line change
Expand Up @@ -333,25 +333,38 @@ bool IsCompleteAutomaton (Automaton a)
}

//complete the automaton (i.e. add a hole state if necessary)
void CompleteAutomaton (Automaton *a)
//return true iff a state was added
bool CompleteAutomaton (Automaton *a)
{
int ne = a->n; //nouvel état
AddEtat(a, false); //ajoute l'état puits
int i,j;
bool add_etat = false;
for (i=0;i<ne;i++)
{
for (j=0;j<a->na;j++)
{
if (a->e[i].f[j] == -1)
{
a->e[i].f[j] = ne;
add_etat = true;
}
}
}
if (a->i == -1)
{
a->i = ne;
add_etat = true;
}
if (!add_etat)
return false;
AddEtat(a, false); //ajoute l'état puits
for (j=0;j<a->na;j++)
{
a->e[ne].f[j] = ne;
}
if (a->i == -1)
a->i = ne;
return true;
}

//détermine si les automates sont les mêmes (différents si états permutés)
Expand Down
2 changes: 1 addition & 1 deletion src/sage/combinat/words/automataC.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ bool emptyLangage (Automaton a);
bool IsCompleteAutomaton (Automaton a);

//complete the automaton (i.e. add a hole state if necessary)
void CompleteAutomaton (Automaton *a);
bool CompleteAutomaton (Automaton *a);

//copy the automaton with a new bigger alphabet
Automaton BiggerAlphabet (Automaton a, Dict d, int nna);
Expand Down
37 changes: 32 additions & 5 deletions src/sage/combinat/words/cautomata.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ cdef extern from "automataC.h":
bool emptyLangage (Automaton a)
void AddEtat (Automaton *a, bool final)
bool IsCompleteAutomaton (Automaton a)
void CompleteAutomaton (Automaton *a)
bool CompleteAutomaton (Automaton *a)
Automaton BiggerAlphabet (Automaton a, Dict d, int nna) #copy the automaton with a new bigger alphabet
void Test ()

Expand Down Expand Up @@ -501,13 +501,14 @@ cdef class FastAutomaton:
sig_on()
res = IsCompleteAutomaton(self.a[0])
sig_off()
return res
return Bool(res)

#give a complete automaton (i.e. with his hole state)
def complete (self):
sig_on()
CompleteAutomaton(self.a)
res = CompleteAutomaton(self.a)
sig_off()
return Bool(res)

def union (self, FastAutomaton a, verb=False):
#complete the automata
Expand Down Expand Up @@ -837,8 +838,34 @@ cdef class FastAutomaton:
sig_off()
r.A = nA
return r



def complementaryOP (self):
self.complete()
cdef i
for i in range(self.a.n):
self.a.e[i].final = not self.a.e[i].final

def included (self, FastAutomaton a, bool verb=False, step=None):
d = {}
for l in self.A:
if l in a.A:
d[(l,l)] = l
if verb:
print "d=%s"%d
a.complete()
cdef FastAutomaton p = self.product(a, d, verb=verb)

#set final states
cdef int i,j
cdef n1 = self.a.n
for i in range(n1):
for j in range(a.a.n):
p.a.e[i+n1*j].final = self.a.e[i].final and not a.a.e[j].final

if step == 1:
return p;

return p.has_empty_langage()



Expand Down

0 comments on commit 4c59b96

Please sign in to comment.