il ne manque plus qu'a commenter

This commit is contained in:
gdamms 2021-11-27 11:20:11 +01:00
parent 21646a6fde
commit 4a9cc998c6

View file

@ -16,7 +16,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 1,
"metadata": {},
"outputs": [
{
@ -35,7 +35,7 @@
"\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 2 seconds (158 already precompiled)\n"
" 1 dependency successfully precompiled in 3 seconds (158 already precompiled)\n"
]
}
],
@ -54,7 +54,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 1,
"metadata": {},
"outputs": [
{
@ -63,7 +63,7 @@
"readKnapInstance (generic function with 1 method)"
]
},
"execution_count": 3,
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
@ -108,7 +108,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 2,
"metadata": {},
"outputs": [
{
@ -117,32 +117,49 @@
"TestsSondabilite_relaxlin (generic function with 1 method)"
]
},
"execution_count": 4,
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"function TestsSondabilite_relaxlin(x, price, weight, capacity, BestProfit, Bestsol)\n",
"function TestsSondabilite_relaxlin(x, price, weight, capacity, BestProfit, Bestsol, affich)\n",
" TA, TO, TR = false, false, false\n",
" if (!Constraints(x, weight, capacity)) # Test de faisabilite\n",
" TA = true\n",
" println(\"TA\")\n",
" if affich\n",
" println(\"TA\")\n",
" end\n",
" elseif (Objective(x, price) <= BestProfit) # Test d'optimalite\n",
" TO = true\n",
" println(\"TO\")\n",
" if affich\n",
" println(\"TO\")\n",
" end\n",
" elseif (AllDef(x)) # Test de resolution\n",
" TR = true\n",
" println(\"TR\")\n",
" if affich\n",
" println(\"TR : solution \", \" de profit \", Objective(x, price))\n",
" end\n",
" #if (value(benef) >= BestProfit)\n",
" if (Objective(x, price) >= BestProfit)\n",
" println(\"oiuiiiiii\")\n",
" if affich\n",
" println(\"\\t-> Cette solution a un meilleur profit.\")\n",
" end\n",
" Bestsol = x\n",
" #BestProfit=value(benef)\n",
" BestProfit = Objective(x, price)\n",
" else\n",
" if affich\n",
" println(\"\\t-> Cette solution est moins bonne.\")\n",
" end\n",
" end\n",
" else\n",
" println(\"non sondable\")\n",
" if affich \n",
" println(\"non sondable\")\n",
" end\n",
" end\n",
" if affich\n",
" println(\"\\n\")\n",
" end\n",
" TA, TO, TR, Bestsol, BestProfit\n",
"end"
@ -157,7 +174,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 3,
"metadata": {},
"outputs": [
{
@ -166,7 +183,7 @@
"ExplorerAutreNoeud_relaxlin (generic function with 1 method)"
]
},
"execution_count": 5,
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
@ -177,10 +194,10 @@
" # le noeud est non-sondable. Appliquer le critère de séparation pour le séparer en sous-noeuds et choisir un noeud-fils le plus à gauche \n",
"\n",
" # Cas du noeud le plus à gauche\n",
" predX = first(listvars)\n",
" predX = pop!(listvars)\n",
" n = length(predX)\n",
" nextX0 = predX\n",
" nextX1 = predX\n",
" nextX0 = copy(predX)\n",
" nextX1 = copy(predX)\n",
" val0 = 0\n",
" val1 = 0\n",
" for i in 1:n\n",
@ -193,11 +210,10 @@
" break\n",
" end\n",
" end\n",
"\n",
" push!(listvars, nextX0)\n",
" push!(listvars, nextX1)\n",
" push!(listvals, val0)\n",
" push!(listvars, nextX0)\n",
" push!(listvals, val1)\n",
" push!(listvals, val0)\n",
" listvars, listvals\n",
"end\n",
"\n",
@ -222,16 +238,16 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"true"
"AllDef (generic function with 1 method)"
]
},
"execution_count": 6,
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
@ -241,7 +257,7 @@
"Objective(x, price) = \n",
" sum(\n",
" if x[i] < 0\n",
" 1\n",
" price[i]\n",
" else\n",
" price[i]*x[i] \n",
" end\n",
@ -260,113 +276,34 @@
" ) <= capacity\n",
"\n",
"\n",
"AllDef(x) =\n",
" for xi in x\n",
" if xi < 0\n",
"function AllDef(x)\n",
" for i in 1:length(x)\n",
" if x[i] < 0\n",
" return false\n",
" end\n",
" end\n",
" return true"
" return true\n",
"end"
]
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"Node number 0: \n",
"-----\n",
"\n",
"\n",
"Noeud actuel\tx_1 = -1\tx_2 = -1\tx_3 = -1\tx_4 = -1 \n",
"\n",
"Previous Solution memorized Any[] with bestprofit -1\n",
"\n",
"non sondable\n",
"\n",
"Node number 1: \n",
"-----\n",
"\n",
"\n",
"Noeud actuel\tx_1 = 1\tx_2 = -1\tx_3 = -1\tx_4 = -1 \n",
"\n",
"Previous Solution memorized Any[] with bestprofit -1\n",
"\n",
"non sondable\n",
"\n",
"Node number 2: \n",
"-----\n",
"\n",
"\n",
"Noeud actuel : NOT AVAILABLE (probably infeasible or ressources limit reached) \n",
"\n",
"Previous Solution memorized Any[] with bestprofit -1\n",
"\n",
"TA\n",
"\n",
"Node number 3: \n",
"-----\n",
"\n",
"\n",
"Noeud actuel : NOT AVAILABLE (probably infeasible or ressources limit reached) \n",
"\n",
"Previous Solution memorized Any[] with bestprofit -1\n",
"\n",
"TA\n",
"\n",
"Node number 4: \n",
"-----\n",
"\n",
"\n",
"Noeud actuel : NOT AVAILABLE (probably infeasible or ressources limit reached) \n",
"\n",
"Previous Solution memorized Any[] with bestprofit -1\n",
"\n",
"TA\n",
"\n",
"Node number 5: \n",
"-----\n",
"\n",
"\n",
"Noeud actuel : NOT AVAILABLE (probably infeasible or ressources limit reached) \n",
"\n",
"Previous Solution memorized Any[] with bestprofit -1\n",
"\n",
"TA\n",
"\n",
"Node number 6: \n",
"-----\n",
"\n",
"\n",
"Noeud actuel : NOT AVAILABLE (probably infeasible or ressources limit reached) \n",
"\n",
"Previous Solution memorized Any[] with bestprofit -1\n",
"\n",
"TA\n",
"\n",
"FINISHED\n",
"\n",
"******\n",
"\n",
"Optimal value = -1\n",
"\n",
"Optimal x=Any[]\n"
"ename": "Error",
"evalue": "Session cannot generate requests",
"output_type": "error",
"traceback": [
"Error: Session cannot generate requests",
"at S.executeCodeCell (/home/damien/.vscode/extensions/ms-toolsai.jupyter-2021.10.1101450599/out/client/extension.js:66:301742)",
"at S.execute (/home/damien/.vscode/extensions/ms-toolsai.jupyter-2021.10.1101450599/out/client/extension.js:66:300732)",
"at S.start (/home/damien/.vscode/extensions/ms-toolsai.jupyter-2021.10.1101450599/out/client/extension.js:66:296408)",
"at processTicksAndRejections (internal/process/task_queues.js:93:5)",
"at async t.CellExecutionQueue.executeQueuedCells (/home/damien/.vscode/extensions/ms-toolsai.jupyter-2021.10.1101450599/out/client/extension.js:66:312326)",
"at async t.CellExecutionQueue.start (/home/damien/.vscode/extensions/ms-toolsai.jupyter-2021.10.1101450599/out/client/extension.js:66:311862)"
]
},
{
"data": {
"text/plain": [
"(-1, Any[], Int64[], Int64[], Any[])"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
@ -374,6 +311,8 @@
"\n",
" price, weight, capacity = readKnapInstance(filename)\n",
"\n",
" println(\"Capacity : \", capacity, \" | Number of objects : \", length(price), \"\\n\")\n",
"\n",
" #create the structure to memorize the search tree for visualization at the end\n",
" trParentnodes=Int64[] #will store orig node of arc in search tree\n",
" trChildnodes=Int64[] #will store destination node of arc in search tree\n",
@ -388,46 +327,50 @@
"\n",
" current_node_number=0\n",
" stop = false\n",
" affich = false\n",
"\n",
" push!(listvars, [-1 for p in price])\n",
" push!(listvals, Objective(first(listvars), price))\n",
" push!(listvals, Objective(last(listvars), price))\n",
"\n",
" while (!stop)\n",
" x = last(listvars)\n",
"\n",
" println(\"\\nNode number \", current_node_number, \": \\n-----\\n\")\n",
"\n",
" x = first(listvars)\n",
"\n",
" print(\"\\nNoeud actuel\"); \n",
" if (!Constraints(x, weight, capacity)) # (has_values(model2))\n",
" print(\" : NOT AVAILABLE (probably infeasible or ressources limit reached)\")\n",
" else\n",
" [print(\"\\tx_\", i, \" = \", x[i]) for i in 1:length(x)] \n",
" if affich\n",
" print(\"----------\\nNode n°\", current_node_number, \" : \")\n",
" println(\" \")\n",
" println(\"\\nPrevious Solution memorized \", \" with bestprofit \", BestProfit, \"\\n\")\n",
" end\n",
" println(\" \");\n",
" println(\"\\nPrevious Solution memorized \", Bestsol, \" with bestprofit \", BestProfit, \"\\n\")\n",
"\n",
" TA, TO, TR, Bestsol, BestProfit = TestsSondabilite_relaxlin(x, price, weight, capacity, BestProfit, Bestsol)\n",
" TA, TO, TR, Bestsol, BestProfit = TestsSondabilite_relaxlin(x, price, weight, capacity, BestProfit, Bestsol, affich)\n",
" \n",
" is_node_sondable = TA || TO || TR\n",
"\n",
" if (!is_node_sondable)\n",
" listvars, listvals = SeparerNoeud_relaxlin(price, listvars, listvals)\n",
" else\n",
" listvars, listvals, stop = ExplorerAutreNoeud_relaxlin(listvars, listvals)\n",
" end\n",
"\n",
" if current_node_number % 1000000 == 1000\n",
" affich = true\n",
" else\n",
" affich = false\n",
" end\n",
" current_node_number += 1\n",
" end\n",
"\n",
" println(\"\\n******\\n\\nOptimal value = \", BestProfit, \"\\n\\nOptimal x=\", Bestsol)\n",
"\n",
" return BestProfit, Bestsol, trParentnodes, trChildnodes, trNamenodes\n",
"\n",
"end\n",
"\n",
"SolveKnapInstance(\"data/test.opb\")"
"SolveKnapInstance(\"data/subset_sum/knapPI_6_100_10000_2_-10726.opb\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {