nettoyage du code et ajout dans le cours
This commit is contained in:
parent
ab695aadcc
commit
e66bdb987f
3 changed files with 11 additions and 28 deletions
|
@ -1,16 +1,19 @@
|
||||||
\documentclass[main.tex]{subfiles}
|
\documentclass[main.tex]{subfiles}
|
||||||
\begin{document}
|
\begin{document}
|
||||||
\section{Codage d'Huffman}
|
\section{Codage d'Huffman}
|
||||||
|
\subsection{version objet}
|
||||||
|
|
||||||
|
\inputminted{python}{../algo_code/huffman.py}
|
||||||
|
\subsection{version simple}
|
||||||
|
|
||||||
|
\inputminted{python}{../algo_code/huffman2.py}
|
||||||
\section{Codage arithétique}
|
\section{Codage arithétique}
|
||||||
\section{Codage LZW}
|
\section{Codage LZW}
|
||||||
|
\inputminted{python}{../algo_code/LZW.py}
|
||||||
|
|
||||||
|
|
||||||
\end{document}
|
\end{document}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
%%% Local Variables:
|
%%% Local Variables:
|
||||||
%%% mode: latex
|
%%% mode: latex
|
||||||
%%% TeX-master: t
|
%%% TeX-master: main.tex
|
||||||
%%% End:
|
%%% End:
|
||||||
|
|
|
@ -37,10 +37,6 @@ def decode_LZW(code,univers):
|
||||||
print(dictionnaire)
|
print(dictionnaire)
|
||||||
return ''.join(msg)
|
return ''.join(msg)
|
||||||
|
|
||||||
|
|
||||||
code,dictionnaire = code_LZW(message,univers)
|
code,dictionnaire = code_LZW(message,univers)
|
||||||
print(code)
|
|
||||||
print(dictionnaire)
|
|
||||||
msg = decode_LZW(code, univers)
|
msg = decode_LZW(code, univers)
|
||||||
print(message)
|
print(code, dictionnaire, msg)
|
||||||
print(msg)
|
|
||||||
|
|
|
@ -28,7 +28,6 @@ def create_tree(table_noeud):
|
||||||
root= Noeud(left=queue[0],right=queue[1])
|
root= Noeud(left=queue[0],right=queue[1])
|
||||||
return root
|
return root
|
||||||
|
|
||||||
|
|
||||||
def gen_code(node,prefix=''):
|
def gen_code(node,prefix=''):
|
||||||
def gen_code_rec(node,prefix=''):
|
def gen_code_rec(node,prefix=''):
|
||||||
if node.left != None:
|
if node.left != None:
|
||||||
|
@ -63,8 +62,6 @@ def make_tree():
|
||||||
f.write('{rank =same; N' + '; N'.join([n.code for n in table_noeud]) +';}\n')
|
f.write('{rank =same; N' + '; N'.join([n.code for n in table_noeud]) +';}\n')
|
||||||
f.write('}')
|
f.write('}')
|
||||||
subprocess.call('dot -Tpng graph.dot -o graph.png', shell=True)
|
subprocess.call('dot -Tpng graph.dot -o graph.png', shell=True)
|
||||||
print('done')
|
|
||||||
|
|
||||||
|
|
||||||
def decode_huffman(reverse, code):
|
def decode_huffman(reverse, code):
|
||||||
res =""
|
res =""
|
||||||
|
@ -75,23 +72,10 @@ def decode_huffman(reverse, code):
|
||||||
text = text[len(k):]
|
text = text[len(k):]
|
||||||
return res
|
return res
|
||||||
|
|
||||||
table = [
|
table = [('A', 25),('B', 20),('C', 15),('D', 12),
|
||||||
('A', 25),
|
('E', 10),('F', 8),('G', 5),('H', 5)]
|
||||||
('B', 20),
|
|
||||||
('C', 15),
|
|
||||||
('D', 12),
|
|
||||||
('E', 10),
|
|
||||||
('F', 8),
|
|
||||||
('G', 5),
|
|
||||||
('H', 5)]
|
|
||||||
|
|
||||||
table_noeud = [Noeud(name=x[0],p=x[1]) for x in table]
|
table_noeud = [Noeud(name=x[0],p=x[1]) for x in table]
|
||||||
|
|
||||||
print(table_noeud)
|
|
||||||
root_node= create_tree(table_noeud)
|
root_node= create_tree(table_noeud)
|
||||||
print(root_node)
|
|
||||||
|
|
||||||
x= gen_code(root_node)
|
x= gen_code(root_node)
|
||||||
reverse_huffman = {x[i+1]:x[i] for i in range(0,len(x)-1,2)}
|
reverse_huffman = {x[i+1]:x[i] for i in range(0,len(x)-1,2)}
|
||||||
|
|
||||||
print(table_huffman)
|
print(table_huffman)
|
||||||
|
|
Loading…
Reference in a new issue