Compare commits
2 commits
6c365cfbbc
...
b0997231dc
Author | SHA1 | Date | |
---|---|---|---|
b0997231dc | |||
8d78540c2d |
6 changed files with 39 additions and 48 deletions
5
surete/tp_ltl/.gitignore
vendored
5
surete/tp_ltl/.gitignore
vendored
|
@ -1,2 +1,5 @@
|
||||||
|
/.toolchain
|
||||||
/venv
|
/venv
|
||||||
__pycache__
|
|
||||||
|
__pycache__
|
||||||
|
*.zip
|
||||||
|
|
|
@ -1,12 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
set -e
|
|
||||||
cd "$(dirname "$(realpath "$0")")"
|
|
||||||
|
|
||||||
|
|
||||||
if ! [ -d venv ]
|
|
||||||
then ./setup.sh
|
|
||||||
fi
|
|
||||||
. venv/bin/activate
|
|
||||||
|
|
||||||
|
|
||||||
python src/product.py
|
|
|
@ -3,6 +3,32 @@ set -e
|
||||||
cd "$(dirname "$(realpath "$0")")"
|
cd "$(dirname "$(realpath "$0")")"
|
||||||
|
|
||||||
|
|
||||||
|
py_ver="3.12.4"
|
||||||
|
|
||||||
|
|
||||||
|
mkdir -p ".toolchain"
|
||||||
|
export PYENV_ROOT="$PWD/.toolchain/pyenv"
|
||||||
|
|
||||||
|
|
||||||
|
if ! [ -f "$PYENV_ROOT/versions/$py_ver/bin/python" ]
|
||||||
|
then
|
||||||
|
echo ""
|
||||||
|
echo "[setup.sh] Installing pyenv."
|
||||||
|
curl https://pyenv.run | bash > /dev/null
|
||||||
|
alias pyenv="$PYENV_ROOT/bin/pyenv"
|
||||||
|
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "[setup.sh] Installing python $py_ver."
|
||||||
|
echo " This takes a few minutes. ☕"
|
||||||
|
echo ""
|
||||||
|
pyenv install "$py_ver"
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
alias python="$PYENV_ROOT/versions/$py_ver/bin/python"
|
||||||
|
|
||||||
|
|
||||||
python -m venv venv
|
python -m venv venv
|
||||||
. venv/bin/activate
|
. venv/bin/activate
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ class GBA[T]:
|
||||||
self.accepting_states.append(set(final).intersection(self.all_states))
|
self.accepting_states.append(set(final).intersection(self.all_states))
|
||||||
self.ap = set(propositions)
|
self.ap = set(propositions)
|
||||||
self.formulas = {frozenset(formula) for (_,formula,_) in edges}
|
self.formulas = {frozenset(formula) for (_,formula,_) in edges}
|
||||||
self.next_states = {(state, formula): set()
|
self.next_states: dict[tuple[state[T], frozenset[str]], set[state[T]]] = {(state, formula): set()
|
||||||
for state in self.all_states
|
for state in self.all_states
|
||||||
for formula in self.formulas}
|
for formula in self.formulas}
|
||||||
for edge in edges:
|
for edge in edges:
|
||||||
|
|
|
@ -1,22 +1,5 @@
|
||||||
from GBA import GBA
|
from GBA import GBA
|
||||||
|
|
||||||
|
|
||||||
def dfs(gba : GBA, s1, s2, sets, eactuel, index, past):
|
|
||||||
if index == len(sets):
|
|
||||||
return eactuel == s2
|
|
||||||
past.add((eactuel, index))
|
|
||||||
for ns in gba.transitions[eactuel]:
|
|
||||||
if ns in sets[index] and (ns, index + 1) not in past:
|
|
||||||
return dfs(gba, s1, s2, ns, index + 1, past)
|
|
||||||
if (ns, index) not in past:
|
|
||||||
return dfs(gba, s1, s2, ns, index, past)
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
def path(gba: GBA, s1, s2, sets):
|
|
||||||
past = set()
|
|
||||||
return dfs(gba, s1,s2, s1, 0, past)
|
|
||||||
|
|
||||||
#Entrée : une formule sous forme de liste de littéraux (ie une variable ou sa négation)
|
#Entrée : une formule sous forme de liste de littéraux (ie une variable ou sa négation)
|
||||||
#Vérifie que cette formule est consistente cad qu'elle ne contient pas à la fois une variable et sa négation
|
#Vérifie que cette formule est consistente cad qu'elle ne contient pas à la fois une variable et sa négation
|
||||||
def is_consistent(formula):
|
def is_consistent(formula):
|
||||||
|
@ -35,11 +18,4 @@ def is_Buchi_empty(buchi):
|
||||||
#Sortie : renvoie True si cet automate n'admet aucune exécution et false sinon
|
#Sortie : renvoie True si cet automate n'admet aucune exécution et false sinon
|
||||||
def is_GBA_empty(gba):
|
def is_GBA_empty(gba):
|
||||||
#à compléter
|
#à compléter
|
||||||
for init in gba.initial_state:
|
return False
|
||||||
for accept in gba.accepting_sets:
|
|
||||||
for acc in accept:
|
|
||||||
if path(gba, init, acc, gba.accepting_sets):
|
|
||||||
return False
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -17,11 +17,9 @@ def product[T, U](gba1: GBA[T], gba2: GBA[U]):
|
||||||
ap = gba1.ap.union(gba2.ap)
|
ap = gba1.ap.union(gba2.ap)
|
||||||
edges = list[edge]()
|
edges = list[edge]()
|
||||||
|
|
||||||
|
|
||||||
#à compléter
|
#à compléter
|
||||||
product_impl(gba1, gba2, edges)
|
product_impl(gba1, gba2, edges)
|
||||||
|
|
||||||
|
|
||||||
accepting = list[frozenset[tuple[state[T], state[U]]]]()
|
accepting = list[frozenset[tuple[state[T], state[U]]]]()
|
||||||
for acc in gba1.accepting_states:
|
for acc in gba1.accepting_states:
|
||||||
accepting.append(frozenset({(state1, state2) for state1 in acc for state2 in gba2.all_states}))
|
accepting.append(frozenset({(state1, state2) for state1 in acc for state2 in gba2.all_states}))
|
||||||
|
@ -31,13 +29,13 @@ def product[T, U](gba1: GBA[T], gba2: GBA[U]):
|
||||||
|
|
||||||
|
|
||||||
def product_impl[T, U](gpa_left: GBA[T], gba_right: GBA[U], edges: list[edge[tuple[state[T], state[U]]]]):
|
def product_impl[T, U](gpa_left: GBA[T], gba_right: GBA[U], edges: list[edge[tuple[state[T], state[U]]]]):
|
||||||
for (d1, f1), dest1 in gpa_left.next_states.items():
|
for (state_l, form_l), nexts_l in gpa_left.next_states.items():
|
||||||
for (d2, f2), dest2 in gba_right.next_states.items():
|
for (state_r, form_r), nexts_r in gba_right.next_states.items():
|
||||||
for item1 in dest1:
|
for next_l in nexts_l:
|
||||||
for item2 in dest2:
|
for next_r in nexts_r:
|
||||||
vari = f1.union(f2)
|
formula = form_l.union(form_r)
|
||||||
if is_consistent(vari):
|
if is_consistent(formula):
|
||||||
edges.append(((d1, d2), vari, (item1, item2)))
|
edges.append(((state_l, state_r), formula, (next_l, next_r)))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue