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[1mPrecompiling\u001b[22m\u001b[39m project...\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 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[1mPrecompiling\u001b[22m\u001b[39m project...\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",
"execution_count": 1,
"execution_count": 2,
"metadata": {},
"outputs": [
{
@ -63,7 +63,7 @@
"readKnapInstance (generic function with 1 method)"
]
},
"execution_count": 1,
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
@ -108,7 +108,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 3,
"metadata": {},
"outputs": [
{
@ -117,7 +117,7 @@
"TestsSondabilite_relaxlin (generic function with 1 method)"
]
},
"execution_count": 2,
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
@ -160,6 +160,7 @@
" if affich\n",
" println(\"\\n\")\n",
" end\n",
" \n",
" TA, TO, TR, Bestsol, BestProfit\n",
"end"
]
@ -173,7 +174,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 4,
"metadata": {},
"outputs": [
{
@ -182,7 +183,7 @@
"ExplorerAutreNoeud_relaxlin (generic function with 1 method)"
]
},
"execution_count": 3,
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
@ -218,13 +219,14 @@
" break\n",
" end\n",
" end\n",
" \n",
" # On ajoute les sous-noeuds a la pile des noeuds a explorer\n",
" push!(listvars, nextX1)\n",
" push!(listvars, nextX0)\n",
" push!(listvars, nextX1)\n",
"\n",
" # On ajoute aussi leurs valeurs\n",
" push!(listvals, val1)\n",
" push!(listvals, val0)\n",
" push!(listvals, val1)\n",
"\n",
" listvars, listvals\n",
"end\n",
@ -250,7 +252,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 5,
"metadata": {},
"outputs": [
{
@ -259,7 +261,7 @@
"AllDef (generic function with 1 method)"
]
},
"execution_count": 4,
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
@ -300,44 +302,37 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"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"
"data": {
"text/plain": [
"SolveKnapInstance (generic function with 1 method)"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"function SolveKnapInstance(filename)\n",
"\n",
" # Extraction des données\n",
" price, weight, capacity = readKnapInstance(filename)\n",
"\n",
" println(\"Capacity : \", capacity, \" | Number of objects : \", length(price), \"\\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",
" listvars = []\n",
" listvals = []\n",
" listnodes = []\n",
"\n",
" # La meilleur solution et sa valeur\n",
" BestProfit = -1\n",
@ -352,8 +347,12 @@
" # On ajoute le premier noeud à explorer (la racine)\n",
" push!(listvars, [-1 for p in price])\n",
" push!(listvals, Objective(last(listvars), price))\n",
" push!(listnodes, 1)\n",
" push!(trNamenodes, 0)\n",
" newnodeid = 2\n",
"\n",
" while (!stop)\n",
"\n",
" # Le noeud actuel\n",
" x = last(listvars)\n",
"\n",
@ -371,9 +370,28 @@
" if (!is_node_sondable)\n",
" # Le noeud n'est pas sondable, on le sépare en 2 sous-noeuds\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",
" # Le noeud est sondable, on passe au noeud suivant\n",
" listvars, listvals, stop = ExplorerAutreNoeud_relaxlin(listvars, listvals)\n",
"\n",
" pop!(listnodes)\n",
" end\n",
"\n",
" # On évite de spammer l'output donc on n'affiche pas tout les résultats\n",
@ -388,9 +406,19 @@
"\n",
" println(\"\\n******\\n\\nOptimal value = \", BestProfit, \"\\n\\nOptimal x = \", Bestsol)\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",
"SolveKnapInstance(\"data/subset_sum/knapPI_6_50_1000_1_-994.opb\")"
"graphplot(trParentnodes, trChildnodes, names=trNamenodes, method=:tree)"
]
},
{