ajout des graphs

This commit is contained in:
gdamms 2021-11-27 16:33:20 +01:00
parent 75e9c40e9f
commit 1a74253aaa
2 changed files with 124 additions and 352 deletions

File diff suppressed because one or more lines are too long

View file

@ -29,13 +29,13 @@
"\u001b[32m\u001b[1m No Changes\u001b[22m\u001b[39m to `~/.julia/environments/v1.6/Manifest.toml`\n", "\u001b[32m\u001b[1m No Changes\u001b[22m\u001b[39m to `~/.julia/environments/v1.6/Manifest.toml`\n",
"\u001b[32m\u001b[1mPrecompiling\u001b[22m\u001b[39m project...\n", "\u001b[32m\u001b[1mPrecompiling\u001b[22m\u001b[39m project...\n",
"\u001b[32m ✓ \u001b[39mTestOptinum\n", "\u001b[32m ✓ \u001b[39mTestOptinum\n",
" 1 dependency successfully precompiled in 6 seconds (158 already precompiled)\n", " 1 dependency successfully precompiled in 6 seconds (167 already precompiled)\n",
"\u001b[32m\u001b[1m Resolving\u001b[22m\u001b[39m package versions...\n", "\u001b[32m\u001b[1m Resolving\u001b[22m\u001b[39m package versions...\n",
"\u001b[32m\u001b[1m No Changes\u001b[22m\u001b[39m to `~/.julia/environments/v1.6/Project.toml`\n", "\u001b[32m\u001b[1m No Changes\u001b[22m\u001b[39m to `~/.julia/environments/v1.6/Project.toml`\n",
"\u001b[32m\u001b[1m No Changes\u001b[22m\u001b[39m to `~/.julia/environments/v1.6/Manifest.toml`\n", "\u001b[32m\u001b[1m No Changes\u001b[22m\u001b[39m to `~/.julia/environments/v1.6/Manifest.toml`\n",
"\u001b[32m\u001b[1mPrecompiling\u001b[22m\u001b[39m project...\n", "\u001b[32m\u001b[1mPrecompiling\u001b[22m\u001b[39m project...\n",
"\u001b[32m ✓ \u001b[39mTestOptinum\n", "\u001b[32m ✓ \u001b[39mTestOptinum\n",
" 1 dependency successfully precompiled in 3 seconds (158 already precompiled)\n" " 1 dependency successfully precompiled in 3 seconds (167 already precompiled)\n"
] ]
} }
], ],
@ -54,7 +54,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 1, "execution_count": 2,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -63,7 +63,7 @@
"readKnapInstance (generic function with 1 method)" "readKnapInstance (generic function with 1 method)"
] ]
}, },
"execution_count": 1, "execution_count": 2,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -108,7 +108,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 2, "execution_count": 3,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -117,7 +117,7 @@
"TestsSondabilite_relaxlin (generic function with 1 method)" "TestsSondabilite_relaxlin (generic function with 1 method)"
] ]
}, },
"execution_count": 2, "execution_count": 3,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -160,6 +160,7 @@
" if affich\n", " if affich\n",
" println(\"\\n\")\n", " println(\"\\n\")\n",
" end\n", " end\n",
" \n",
" TA, TO, TR, Bestsol, BestProfit\n", " TA, TO, TR, Bestsol, BestProfit\n",
"end" "end"
] ]
@ -173,7 +174,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 3, "execution_count": 4,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -182,7 +183,7 @@
"ExplorerAutreNoeud_relaxlin (generic function with 1 method)" "ExplorerAutreNoeud_relaxlin (generic function with 1 method)"
] ]
}, },
"execution_count": 3, "execution_count": 4,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -218,13 +219,14 @@
" break\n", " break\n",
" end\n", " end\n",
" end\n", " end\n",
" \n",
" # On ajoute les sous-noeuds a la pile des noeuds a explorer\n", " # On ajoute les sous-noeuds a la pile des noeuds a explorer\n",
" push!(listvars, nextX1)\n",
" push!(listvars, nextX0)\n", " push!(listvars, nextX0)\n",
" push!(listvars, nextX1)\n",
"\n", "\n",
" # On ajoute aussi leurs valeurs\n", " # On ajoute aussi leurs valeurs\n",
" push!(listvals, val1)\n",
" push!(listvals, val0)\n", " push!(listvals, val0)\n",
" push!(listvals, val1)\n",
"\n", "\n",
" listvars, listvals\n", " listvars, listvals\n",
"end\n", "end\n",
@ -250,7 +252,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 4, "execution_count": 5,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@ -259,7 +261,7 @@
"AllDef (generic function with 1 method)" "AllDef (generic function with 1 method)"
] ]
}, },
"execution_count": 4, "execution_count": 5,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -300,48 +302,41 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 5, "execution_count": 6,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stdout", "data": {
"output_type": "stream", "text/plain": [
"text": [ "SolveKnapInstance (generic function with 1 method)"
"Capacity : 994 | Number of objects : 50\n",
"\n",
"----------\n",
"Node n°1001 : \n",
"\n",
"Previous Solution memorized with bestprofit 994\n",
"\n",
"non sondable\n",
"\n",
"\n",
"\n",
"FINISHED\n",
"\n",
"******\n",
"\n",
"Optimal value = 994\n",
"\n",
"Optimal x=[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n"
] ]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
} }
], ],
"source": [ "source": [
"function SolveKnapInstance(filename)\n", "function SolveKnapInstance(filename)\n",
"\n", "\n",
" # Extraction des données\n",
" price, weight, capacity = readKnapInstance(filename)\n", " price, weight, capacity = readKnapInstance(filename)\n",
"\n", "\n",
" println(\"Capacity : \", capacity, \" | Number of objects : \", length(price), \"\\n\")\n", " println(\"Capacity : \", capacity, \" | Number of objects : \", length(price), \"\\n\")\n",
"\n", "\n",
" # Pour dessiner le graph\n",
" trParentnodes = Int64[]\n",
" trChildnodes = Int64[]\n",
" trNamenodes = []\n",
"\n",
" # Liste des variable pour naviguer de noeuds en noeuds\n", " # Liste des variable pour naviguer de noeuds en noeuds\n",
" listvars=[]\n", " listvars = []\n",
" listvals=[]\n", " listvals = []\n",
" listnodes = []\n",
"\n", "\n",
" # La meilleur solution et sa valeur\n", " # La meilleur solution et sa valeur\n",
" BestProfit=-1\n", " BestProfit = -1\n",
" Bestsol=[]\n", " Bestsol = []\n",
"\n", "\n",
" # Compter le nombre de noeud explorés\n", " # Compter le nombre de noeud explorés\n",
" current_node_number = 0\n", " current_node_number = 0\n",
@ -352,8 +347,12 @@
" # On ajoute le premier noeud à explorer (la racine)\n", " # On ajoute le premier noeud à explorer (la racine)\n",
" push!(listvars, [-1 for p in price])\n", " push!(listvars, [-1 for p in price])\n",
" push!(listvals, Objective(last(listvars), price))\n", " push!(listvals, Objective(last(listvars), price))\n",
" push!(listnodes, 1)\n",
" push!(trNamenodes, 0)\n",
" newnodeid = 2\n",
"\n", "\n",
" while (!stop)\n", " while (!stop)\n",
"\n",
" # Le noeud actuel\n", " # Le noeud actuel\n",
" x = last(listvars)\n", " x = last(listvars)\n",
"\n", "\n",
@ -371,9 +370,28 @@
" if (!is_node_sondable)\n", " if (!is_node_sondable)\n",
" # Le noeud n'est pas sondable, on le sépare en 2 sous-noeuds\n", " # Le noeud n'est pas sondable, on le sépare en 2 sous-noeuds\n",
" listvars, listvals = SeparerNoeud_relaxlin(price, listvars, listvals)\n", " listvars, listvals = SeparerNoeud_relaxlin(price, listvars, listvals)\n",
"\n",
" curnode = pop!(listnodes)\n",
"\n",
" push!(trParentnodes, curnode)\n",
" push!(trParentnodes, curnode)\n",
"\n",
" push!(listnodes, newnodeid+1)\n",
" push!(listnodes, newnodeid)\n",
"\n",
" push!(trChildnodes, newnodeid)\n",
" push!(trChildnodes, newnodeid+1)\n",
"\n",
" push!(trNamenodes, newnodeid-1)\n",
" push!(trNamenodes, newnodeid)\n",
"\n",
" newnodeid += 2\n",
"\n",
" else\n", " else\n",
" # Le noeud est sondable, on passe au noeud suivant\n", " # Le noeud est sondable, on passe au noeud suivant\n",
" listvars, listvals, stop = ExplorerAutreNoeud_relaxlin(listvars, listvals)\n", " listvars, listvals, stop = ExplorerAutreNoeud_relaxlin(listvars, listvals)\n",
"\n",
" pop!(listnodes)\n",
" end\n", " end\n",
"\n", "\n",
" # On évite de spammer l'output donc on n'affiche pas tout les résultats\n", " # On évite de spammer l'output donc on n'affiche pas tout les résultats\n",
@ -386,11 +404,21 @@
" current_node_number += 1\n", " current_node_number += 1\n",
" end\n", " end\n",
"\n", "\n",
" println(\"\\n******\\n\\nOptimal value = \", BestProfit, \"\\n\\nOptimal x=\", Bestsol)\n", " println(\"\\n******\\n\\nOptimal value = \", BestProfit, \"\\n\\nOptimal x = \", Bestsol)\n",
"\n", "\n",
"end\n", " trParentnodes, trChildnodes, trNamenodes\n",
"end"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
"trParentnodes, trChildnodes, trNamenodes = SolveKnapInstance(\"data/circle/knapPI_16_8_1000_1_-2291.opb\")\n",
"\n", "\n",
"SolveKnapInstance(\"data/subset_sum/knapPI_6_50_1000_1_-994.opb\")" "graphplot(trParentnodes, trChildnodes, names=trNamenodes, method=:tree)"
] ]
}, },
{ {