diff --git a/approximations.py b/approximations.py index 2c5d6829fed141ed6933109f49ad25ae49a4b63d..1456a20d763a1619edf350ee42a370386df961e8 100644 --- a/approximations.py +++ b/approximations.py @@ -125,7 +125,7 @@ logging.basicConfig(filename='approximations_run.log', datefmt='%m/%d/%Y %I:%M:%S %p') # Choix du fichier test -filename = "eil101" +filename = "tsp225" probleme = read_tsp_file ("problemes/{}.tsp".format (filename)) graphe = probleme["GRAPH"] diff --git a/dual.py b/dual.py index 178a540486ee65e252cd0ddf32252e1bd214e782..b7c148eccd7b854224c192886f5b20c67cbb34af 100644 --- a/dual.py +++ b/dual.py @@ -16,6 +16,33 @@ import mincut import numpy as np import scipy.optimize as scopt +import cvxpy as cvx + +def minim(A_eq,b_eq, c, A_in = [], b_in = []): + + A_eq = np.array (A_eq) + b_eq = np.array (b_eq) + c = np.array (c) + + m,n = A_eq.shape + assert(n == len(c) and (m==len(b_eq))) + + x = cvx.Variable(n) + objective = cvx.Minimize(cvx.sum_entries(c*x)) + if(A_in == []): + constraints = [0 <= x, A_eq*x == b_eq] + else: + constraints = [0 <= x, A_eq*x == b_eq, A_in*x >= b_in] + + prob = cvx.Problem(objective, constraints) + opt = prob.solve() + s = prob.status + + valx = np.copy(x.value) + valx = np.array(np.transpose(valx)[0]) + + return({"status":s,"opt":opt,"x":valx}) + def subsets(l): """ Retourne l'ensemble de sous ensembles @@ -333,8 +360,13 @@ def algorithme_separation (graphe, filename="default_separation_dual", maxiter=1 # On se demande si on a une bonne solution ou non # logging.debug ("Solve dual problem") + # res2 = minim (A,b, [ - y for y in c ]) + res1 = vrai_simplexe (A1,b1,c1) res2 = vrai_simplexe (A,b, [ -y for y in c ]) logging.debug ("Dual value : {}".format (-1 * res2["fun"])) + + print ("{} - {}".format (res1["fun"], -1 * res2["fun"])) + logging.debug ("CHECK if good primal solution") edge_to_add = trouve_arete_a_ajouter (n,e_s,w,A,b,c,graphe, res2["x"]) logging.debug ("EDGE to add : {}".format (edge_to_add)) @@ -387,7 +419,7 @@ def algorithme_separation (graphe, filename="default_separation_dual", maxiter=1 if __name__ == '__main__': - filename = "burma14" + filename = "ch150" # initialisation du loggeur logging.basicConfig(filename='dual_run.log', level=logging.DEBUG, diff --git a/images/00_APPROX_tsp225_approx2.png b/images/00_APPROX_tsp225_approx2.png new file mode 100644 index 0000000000000000000000000000000000000000..a797dba4cc2e1494d5c9155578ca5c49a4d8750b Binary files /dev/null and b/images/00_APPROX_tsp225_approx2.png differ diff --git a/images/00_APPROX_tsp225_approx2_2opt.png b/images/00_APPROX_tsp225_approx2_2opt.png new file mode 100644 index 0000000000000000000000000000000000000000..2688f04dfa10f544f6b549e3dc91ee3727bdc915 Binary files /dev/null and b/images/00_APPROX_tsp225_approx2_2opt.png differ diff --git a/images/00_APPROX_tsp225_glouton.png b/images/00_APPROX_tsp225_glouton.png new file mode 100644 index 0000000000000000000000000000000000000000..c596fa985f37bbfa19177bc7c0ed2b44ebc1f8f0 Binary files /dev/null and b/images/00_APPROX_tsp225_glouton.png differ diff --git a/images/00_APPROX_tsp225_glouton_2opt.png b/images/00_APPROX_tsp225_glouton_2opt.png new file mode 100644 index 0000000000000000000000000000000000000000..5934af99de15f7534ce3e10778fabe185989909f Binary files /dev/null and b/images/00_APPROX_tsp225_glouton_2opt.png differ diff --git a/images/0CVX_tsp225_approxPL.png b/images/0CVX_tsp225_approxPL.png new file mode 100644 index 0000000000000000000000000000000000000000..f7671a6593111777e0fc195589c2041caba2a708 Binary files /dev/null and b/images/0CVX_tsp225_approxPL.png differ diff --git a/images/0CVX_tsp225_separationfinie.png b/images/0CVX_tsp225_separationfinie.png new file mode 100644 index 0000000000000000000000000000000000000000..c727351ecee0a9a0675d6eca6238a3c1305a945f Binary files /dev/null and b/images/0CVX_tsp225_separationfinie.png differ diff --git a/images/0CVX_tsp225_simple_1.png b/images/0CVX_tsp225_simple_1.png new file mode 100644 index 0000000000000000000000000000000000000000..684d0661b5406051f270e721df6b7eecd604e2e6 Binary files /dev/null and b/images/0CVX_tsp225_simple_1.png differ diff --git a/images/0CVX_tsp225_simple_11.png b/images/0CVX_tsp225_simple_11.png new file mode 100644 index 0000000000000000000000000000000000000000..63514e989c8a5a83505de8442f4be45460118cc9 Binary files /dev/null and b/images/0CVX_tsp225_simple_11.png differ diff --git a/images/0CVX_tsp225_simple_21.png b/images/0CVX_tsp225_simple_21.png new file mode 100644 index 0000000000000000000000000000000000000000..f0c676fc1687a0d7e704d5acf30e0bc1c07a7ed2 Binary files /dev/null and b/images/0CVX_tsp225_simple_21.png differ diff --git a/images/0CVX_tsp225_simple_31.png b/images/0CVX_tsp225_simple_31.png new file mode 100644 index 0000000000000000000000000000000000000000..3d49f447fb0c21236af829810f7662acb55f0257 Binary files /dev/null and b/images/0CVX_tsp225_simple_31.png differ diff --git a/images/0CVX_tsp225_simple_41.png b/images/0CVX_tsp225_simple_41.png new file mode 100644 index 0000000000000000000000000000000000000000..7f0184b8f1ab13fab0eb0d9eede33dc420c1a9e2 Binary files /dev/null and b/images/0CVX_tsp225_simple_41.png differ diff --git a/new_separation.py b/new_separation.py index baec8aa34da8b527cea298002ca987ef0370a3e0..025602c4b31a90abc5b0f4a1d10d9065215376f8 100644 --- a/new_separation.py +++ b/new_separation.py @@ -315,6 +315,10 @@ def algorithme_separation(graphe, filename="default_separation_output",epsilon = return value,convert_to_edges (graphe, sol) +def primal_dual (graphe, filename="primal_dual", epsilon=0.0001): + pass + + def test(filename): """ Un test de l'algorithme @@ -372,4 +376,4 @@ def test_separation_on_file (filename): -test_separation_on_file("hk48") +test_separation_on_file("tsp225") diff --git a/rapport/presentation.tex b/rapport/presentation.tex index d61cd103b225b15f5ae3ac2ae1f923e2a00f75c3..c78c1d1674196906273c79d03b0c9af9d131b822 100644 --- a/rapport/presentation.tex +++ b/rapport/presentation.tex @@ -523,6 +523,28 @@ Implémenté dans NetworkX. \end{frame} + +\begin{frame} + \frametitle{Exemple d'historique} + \begin{exampleblock}{Sur un problème avec 225 points} + \begin{figure} + \centering + \begin{overlayarea}{6cm}{4cm} + \only<1>{\includegraphics[width=7cm]{../images/0CVX_tsp225_simple_1.png}} + \only<2>{\includegraphics[width=7cm]{../images/0CVX_tsp225_simple_11.png}} + \only<3>{\includegraphics[width=7cm]{../images/0CVX_tsp225_simple_21.png}} + \only<4>{\includegraphics[width=7cm]{../images/0CVX_tsp225_simple_31.png}} + \only<5>{\includegraphics[width=7cm]{../images/0CVX_tsp225_simple_41.png}} + \only<6>{\includegraphics[width=7cm]{../images/0CVX_tsp225_separationfinie.png}} + \only<7>{\includegraphics[width=7cm]{../images/0CVX_tsp225_approxPL.png}} + \only<8>{\includegraphics[width=7cm]{../images/00_APPROX_tsp225_approx2_2opt.png}} + \only<9>{\includegraphics[width=7cm]{../images/00_APPROX_tsp225_glouton_2opt.png}} + \end{overlayarea} + \caption{Le problème tsp225 de valeur optimale $3919$} + \end{figure} + \end{exampleblock} +\end{frame} + \begin{frame} plus de résultats \end{frame} @@ -536,7 +558,7 @@ Implémenté dans NetworkX. \label{eqn:dual} \boxed{ \begin{array}{rll} - \textrm{Maximiser} & \displaystyle- \sum_{uv \in E'} \lambda_{1,uv} x_{uv} - 2 \sum_{u \in V} \nu_u + 2 \sum_{S \in W} \lambda_{3,S} \\ + \textrm{Maximiser} & \displaystyle- \sum_{uv \in E'} \lambda_{1,uv} - 2 \sum_{u \in V} \nu_u + 2 \sum_{S \in W} \lambda_{3,S} \\ \textrm{Avec} & \lambda_1 \geq 0 \\ & \lambda_2 \geq 0 \\ & \lambda_3 \geq 0 \\ @@ -564,14 +586,14 @@ Avec $D_{E'}$ la matirce d'incidence du graphe restreint à $E'$, et $G_{E'}$ la En pratique~: on ajoute toutes les arêtes. \begin{exampleblock}{Algorithme dual suivi de primal} - \begin{enumerate} - \item Calcul d'un sous ensemble $E'$ d'arête qui donne - une minoration avec la méthode du dual - - \item Calcul d'une borne inférieure de plus - en plus précise en utilisant le primal - sur l'ensemble $E'$ d'arêtes - \end{enumerate} + Boucle~: + \begin{enumerate} + \item Calcul d'un sous ensemble $E'$ d'arête qui donne + une minoration avec la méthode du dual + + \item Calcul d'une contrainte de \emph{sous-tour} + à ajouter via le calcul du primal + \end{enumerate} \end{exampleblock} \end{frame} diff --git a/rapport/rapport_projet_opti.tex b/rapport/rapport_projet_opti.tex index 6165d44c0234ae5f173000aee0232182a8df38f5..7aa706c32f28febe14daa1f82a2979b8b9c26464 100644 --- a/rapport/rapport_projet_opti.tex +++ b/rapport/rapport_projet_opti.tex @@ -512,7 +512,7 @@ L'expression du dual est alors simplement~: \label{eqn:dual} \boxed{ \begin{array}{rll} - \textrm{max} & \displaystyle- \sum_{uv \in E'} \lambda_{1,uv} x_{uv} - 2 \sum_{u \in V} \nu_u + 2 \sum_{S \in W} \lambda_{3,S} \\ + \textrm{max} & \displaystyle- \sum_{uv \in E'} \lambda_{1,uv} - 2 \sum_{u \in V} \nu_u + 2 \sum_{S \in W} \lambda_{3,S} \\ & \lambda_1 \geq 0 \\ & \lambda_2 \geq 0 \\ & \lambda_3 \geq 0 \\