Skip to content

Commit

Permalink
index, notebook, canvas in notebooks...
Browse files Browse the repository at this point in the history
  • Loading branch information
sdpython committed Mar 24, 2015
1 parent 0852aeb commit 779c4cf
Show file tree
Hide file tree
Showing 29 changed files with 667 additions and 27 deletions.
199 changes: 199 additions & 0 deletions _doc/notebooks/algorithmes/voyageur_de_commerce.ipynb

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions _doc/sphinxdoc/source/donnees/correcteur_orthographe.rst
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@

.. issue.
.. index:: correcteur orthographique, orthographe, énoncé, sondage, vote

.. _l-donnes_orthographe:

Le correcteur orthographique moyen
==================================

.. index:: correcteur orthographique, orthographe, énoncé, sondage, vote

A partir de 9 ans (mais ce n'est qu'une indication).

Le texte est tiré des `dictées de Pivot <http://lecercledor.jimdo.com/dict%C3%A9es/france/les-dict%C3%A9es-de-bernard-pivot/>`_.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@

.. issue.
.. index:: correcteur orthographique, orthographe, solution, sondage, vote

.. _l-donnes_orthographe_sol:

Le correcteur orthographique moyen (solution)
=============================================

.. index:: correcteur orthographique, orthographe, solution, sondage, vote

**Q1 :**

Une solution simple est le vote, pour chaque mot dont il faut décider de l'orthographe,
Expand Down
4 changes: 2 additions & 2 deletions _doc/sphinxdoc/source/donnees/dessert_cantine.rst
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@

.. issue.
.. index:: cantine, like, facebook, smartphone, sondage, droit, énoncé

.. _l-donnes_cantine:

Le dessert de la cantine
========================

.. index:: cantine, like, facebook, smartphone, sondage, droit, énoncé

A partir de 7-8 ans (mais ce n'est qu'une indication).


Expand Down
4 changes: 2 additions & 2 deletions _doc/sphinxdoc/source/donnees/dessert_cantine_solution.rst
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@

.. issue.
.. index:: cantine, like, facebook, smartphone, sondage, droit, solution

.. _l-donnes_cantine_sol:

Le dessert de la cantine (solution)
===================================

.. index:: cantine, like, facebook, smartphone, sondage, droit, solution

A partir de 7-8 ans (mais ce n'est qu'une indication).


Expand Down
3 changes: 2 additions & 1 deletion _doc/sphinxdoc/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ Annexes
glossary
FAQ
index_et_autre

all_notebooks

Pour les plus chevronnés, certains bouts de codes en python
pourront être réutilisés via
`pypi <https://pypi.python.org/pypi/code_beatrix/>`_
Expand Down
4 changes: 2 additions & 2 deletions _doc/sphinxdoc/source/programmation/parcours_echiquier.rst
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

.. issue.
.. _l-prog_parcours_echiquier:

.. index:: énoncé, échiquier, parcours, variable

.. _l-prog_parcours_echiquier:

Parcours d'un échiquier
=======================

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

.. issue.
.. _l-prog_parcours_echiquier_sol:

.. index:: solution, échiquier, parcours, variable

.. _l-prog_parcours_echiquier_sol:

Parcours d'un échiquier (solution)
==================================

Expand Down
4 changes: 2 additions & 2 deletions _doc/sphinxdoc/source/sanso_algo/demineur.rst
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

.. issue.
.. _l-algo_demineur:

.. index:: démineur, énoncé, énigme

.. _l-algo_demineur:

Le démineur
===========

Expand Down
4 changes: 2 additions & 2 deletions _doc/sphinxdoc/source/sanso_algo/demineur_solution.rst
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@

.. issue.
.. _l-algo_demineur_sol:

.. index:: démineur, solution, énigme


.. _l-algo_demineur_sol:

Le démineur (solution)
======================

Expand Down
4 changes: 2 additions & 2 deletions _doc/sphinxdoc/source/sanso_algo/notions.rst
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@

.. issue.
.. _l-algo_sans_ordinateur_notions:
.. index:: notion, concept

.. _l-algo_sans_ordinateur_notions:

.. index:: notion, concept

Notions, Concepts
=================
Expand Down
4 changes: 2 additions & 2 deletions _doc/sphinxdoc/source/sanso_algo/sacados.rst
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

.. issue.
.. _l-algo_sacados:

.. index:: sac-à-dos, énoncé, poids, algorithme

.. _l-algo_sacados:

Sac-à-dos
=========

Expand Down
4 changes: 2 additions & 2 deletions _doc/sphinxdoc/source/sanso_algo/sacados_solution.rst
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

.. issue.
.. _l-algo_sacados_sol:

.. index:: sac-à-dos, solution, poids, algorithme, glouton

.. _l-algo_sacados_sol:

Sac-à-dos (solution)
====================

Expand Down
4 changes: 2 additions & 2 deletions _doc/sphinxdoc/source/sanso_algo/tsp.rst
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

.. issue.
.. _l-algo_tsp:
.. index:: voyageur de commerce, énoncé, distance, algorithme, parcours, circuit, tsp

.. index:: voyageur de commerce, énoncé, distance, algorithme, parcours, circuit
.. _l-algo_tsp:

Le voyageur de commerce
=======================
Expand Down
23 changes: 21 additions & 2 deletions _doc/sphinxdoc/source/sanso_algo/tsp_solution.rst
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

.. issue.
.. _l-algo_tsp_sol:
.. index:: voyageur de commerce, solution, distance, algorithme, parcours, circuit, tsp

.. index:: voyageur de commerce, solution, distance, algorithme, parcours, circuit
.. _l-algo_tsp_sol:


Le voyageur de commerce (solution)
Expand All @@ -15,12 +15,16 @@ Le voyageur de commerce (solution)
Le bouteille de départ n'est pas importante puisqu'il s'agit de faire le tour.
On peut donc démarrer de n'importe quelle bouteille, ce sera toujours le même tour.

.. image:: tsp_tour.png
:width: 600 px


**Q2 :**

Regardons sur la figure suivante :

.. image:: tsp_croix.png
:width: 600 px

Avec le chemin rouge qui se croise, on parcourt : Lyon, Paris, Strasbourg, Nantes.
Avec le chemin bleu qui ne se croise pas, on parcourt : Lyon, Strasbourg, Paris, Nantes.
Expand All @@ -35,12 +39,17 @@ Sauf que aller de Lyon à Strasbourg en passant **C** est plus long que d'y alle
directement : c'est un détour. Donc, il suffit de ne pas passer par C. C'est plus court.


.. image:: tsp_tour1.png
:width: 600 px


**Q3 :**

Quel est le chemin de plus court, le rouge ou le bleu ? Vaut-il mieux
faire ``ABC`` ou ``BAC`` ?

.. image:: tsp_croix2.png
:width: 600 px

La différence entre les deux parcours ? On a permuté les villes ``A`` et ``B``.
Peut-on faire pareil avec les points ``IJK`` ? La réponse est oui.
Expand All @@ -51,6 +60,16 @@ quelle autre. On peut imaginer à peu près n'importe quelle transformation à
partir de là.


.. image:: tsp_tour2.png
:width: 600 px


.. image:: tsp_tour3.png
:width: 600 px


Le notebook :ref:`voyageurdecommercerst` permet d'avoir un cadre dans lequel
ses propres algorithmes.


Pour aller plus loin
Expand Down
Binary file added _doc/sphinxdoc/source/sanso_algo/tsp_tour.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added _doc/sphinxdoc/source/sanso_algo/tsp_tour1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added _doc/sphinxdoc/source/sanso_algo/tsp_tour2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added _doc/sphinxdoc/source/sanso_algo/tsp_tour3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
80 changes: 80 additions & 0 deletions _unittests/ut_algorithm/test_tsp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#-*- coding: utf-8 -*-
"""
@brief test log(time=4s)
"""

import sys
import os
import unittest
import re

try:
import src
except ImportError:
path = os.path.normpath(
os.path.abspath(
os.path.join(
os.path.split(__file__)[0],
"..",
"..")))
if path not in sys.path:
sys.path.append(path)
import src

try:
import pyquickhelper
except ImportError:
path = os.path.normpath(
os.path.abspath(
os.path.join(
os.path.split(__file__)[0],
"..",
"..",
"..",
"pyquickhelper",
"src")))
if path not in sys.path:
sys.path.append(path)
import pyquickhelper

from pyquickhelper import fLOG, get_temp_folder
from src.code_beatrix.algorithm import voyageur_commerce_simple, distance_circuit, plot_circuit


class TestTsp (unittest.TestCase):

def test_voyageur_commerce_simple(self):
fLOG(
__file__,
self._testMethodName,
OutputPrint=__name__ == "__main__")

points = [(105.61666870117188, 69.01666259765625),
(192.61666870117188, 92.01666259765625),
(372.6166687011719, 123.01666259765625),
(360.6166687011719, 249.01666259765625),
(190.61666870117188, 213.01666259765625),
(102.61666870117188, 166.01666259765625),
(104.61666870117188, 271.01666259765625),
(209.61666870117188, 278.01666259765625),
(321.6166687011719, 198.01666259765625),
(261.6166687011719, 153.01666259765625),
(196.61666870117188, 162.01666259765625),
(317.6166687011719, 306.01666259765625)]

d0 = distance_circuit(points)

newp = voyageur_commerce_simple(points)

d1 = distance_circuit(newp)

fLOG(d0, d1)
assert d1 < d0

if __name__ == "__main__":
import matplotlib.pyplot as plt
ax = plot_circuit(newp)
plt.show()

if __name__ == "__main__":
unittest.main()
67 changes: 67 additions & 0 deletions _unittests/ut_documentation/test_notebook_algorithm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#-*- coding: utf-8 -*-
"""
@brief test log(time=60s)
"""

import sys
import os
import unittest
import re

try:
import src
except ImportError:
path = os.path.normpath(
os.path.abspath(
os.path.join(
os.path.split(__file__)[0],
"..",
"..")))
if path not in sys.path:
sys.path.append(path)
import src

try:
import pyquickhelper
except ImportError:
path = os.path.normpath(
os.path.abspath(
os.path.join(
os.path.split(__file__)[0],
"..",
"..",
"..",
"pyquickhelper",
"src")))
if path not in sys.path:
sys.path.append(path)
import pyquickhelper

from pyquickhelper import fLOG, get_temp_folder
from src.code_beatrix.automation.notebook_test_helper import ls_notebooks, execute_notebooks, clean_function_notebook


class TestNotebookAlgorithm (unittest.TestCase):

def test_notebook_algorithm(self):
fLOG(
__file__,
self._testMethodName,
OutputPrint=__name__ == "__main__")
temp = get_temp_folder(__file__, "temp_algorithm")
keepnote = ls_notebooks("algorithmes")
assert len(keepnote) > 0
res = execute_notebooks(temp, keepnote,
lambda i, n: "deviner" not in n,
fLOG=fLOG,
clean_function=clean_function_notebook)
assert len(res) > 0
fails = [(os.path.split(k)[-1], v)
for k, v in sorted(res.items()) if not v[0]]
for f in fails:
fLOG(f)
if len(fails) > 0:
raise fails[0][1][1]

if __name__ == "__main__":
unittest.main()
Loading

0 comments on commit 779c4cf

Please sign in to comment.