il ne manque plus qu'a commenter
This commit is contained in:
parent
21646a6fde
commit
4a9cc998c6
211
notebook.ipynb
211
notebook.ipynb
|
@ -16,7 +16,7 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 2,
|
"execution_count": 1,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [
|
"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[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 2 seconds (158 already precompiled)\n"
|
" 1 dependency successfully precompiled in 3 seconds (158 already precompiled)\n"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
@ -54,7 +54,7 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 3,
|
"execution_count": 1,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
|
@ -63,7 +63,7 @@
|
||||||
"readKnapInstance (generic function with 1 method)"
|
"readKnapInstance (generic function with 1 method)"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"execution_count": 3,
|
"execution_count": 1,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"output_type": "execute_result"
|
"output_type": "execute_result"
|
||||||
}
|
}
|
||||||
|
@ -108,7 +108,7 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 4,
|
"execution_count": 2,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
|
@ -117,33 +117,50 @@
|
||||||
"TestsSondabilite_relaxlin (generic function with 1 method)"
|
"TestsSondabilite_relaxlin (generic function with 1 method)"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"execution_count": 4,
|
"execution_count": 2,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"output_type": "execute_result"
|
"output_type": "execute_result"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"source": [
|
"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",
|
" TA, TO, TR = false, false, false\n",
|
||||||
" if (!Constraints(x, weight, capacity)) # Test de faisabilite\n",
|
" if (!Constraints(x, weight, capacity)) # Test de faisabilite\n",
|
||||||
" TA = true\n",
|
" TA = true\n",
|
||||||
|
" if affich\n",
|
||||||
" println(\"TA\")\n",
|
" println(\"TA\")\n",
|
||||||
|
" end\n",
|
||||||
" elseif (Objective(x, price) <= BestProfit) # Test d'optimalite\n",
|
" elseif (Objective(x, price) <= BestProfit) # Test d'optimalite\n",
|
||||||
" TO = true\n",
|
" TO = true\n",
|
||||||
|
" if affich\n",
|
||||||
" println(\"TO\")\n",
|
" println(\"TO\")\n",
|
||||||
|
" end\n",
|
||||||
" elseif (AllDef(x)) # Test de resolution\n",
|
" elseif (AllDef(x)) # Test de resolution\n",
|
||||||
" TR = true\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 (value(benef) >= BestProfit)\n",
|
||||||
" if (Objective(x, price) >= 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",
|
" Bestsol = x\n",
|
||||||
" #BestProfit=value(benef)\n",
|
" #BestProfit=value(benef)\n",
|
||||||
" BestProfit = Objective(x, price)\n",
|
" BestProfit = Objective(x, price)\n",
|
||||||
|
" else\n",
|
||||||
|
" if affich\n",
|
||||||
|
" println(\"\\t-> Cette solution est moins bonne.\")\n",
|
||||||
|
" end\n",
|
||||||
" end\n",
|
" end\n",
|
||||||
" else\n",
|
" else\n",
|
||||||
|
" if affich \n",
|
||||||
" println(\"non sondable\")\n",
|
" println(\"non sondable\")\n",
|
||||||
" end\n",
|
" end\n",
|
||||||
|
" end\n",
|
||||||
|
" if affich\n",
|
||||||
|
" println(\"\\n\")\n",
|
||||||
|
" end\n",
|
||||||
" TA, TO, TR, Bestsol, BestProfit\n",
|
" TA, TO, TR, Bestsol, BestProfit\n",
|
||||||
"end"
|
"end"
|
||||||
]
|
]
|
||||||
|
@ -157,7 +174,7 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 5,
|
"execution_count": 3,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
|
@ -166,7 +183,7 @@
|
||||||
"ExplorerAutreNoeud_relaxlin (generic function with 1 method)"
|
"ExplorerAutreNoeud_relaxlin (generic function with 1 method)"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"execution_count": 5,
|
"execution_count": 3,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"output_type": "execute_result"
|
"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",
|
" # 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",
|
"\n",
|
||||||
" # Cas du noeud le plus à gauche\n",
|
" # Cas du noeud le plus à gauche\n",
|
||||||
" predX = first(listvars)\n",
|
" predX = pop!(listvars)\n",
|
||||||
" n = length(predX)\n",
|
" n = length(predX)\n",
|
||||||
" nextX0 = predX\n",
|
" nextX0 = copy(predX)\n",
|
||||||
" nextX1 = predX\n",
|
" nextX1 = copy(predX)\n",
|
||||||
" val0 = 0\n",
|
" val0 = 0\n",
|
||||||
" val1 = 0\n",
|
" val1 = 0\n",
|
||||||
" for i in 1:n\n",
|
" for i in 1:n\n",
|
||||||
|
@ -193,11 +210,10 @@
|
||||||
" break\n",
|
" break\n",
|
||||||
" end\n",
|
" end\n",
|
||||||
" end\n",
|
" end\n",
|
||||||
"\n",
|
|
||||||
" push!(listvars, nextX0)\n",
|
|
||||||
" push!(listvars, nextX1)\n",
|
" push!(listvars, nextX1)\n",
|
||||||
" push!(listvals, val0)\n",
|
" push!(listvars, nextX0)\n",
|
||||||
" push!(listvals, val1)\n",
|
" push!(listvals, val1)\n",
|
||||||
|
" push!(listvals, val0)\n",
|
||||||
" listvars, listvals\n",
|
" listvars, listvals\n",
|
||||||
"end\n",
|
"end\n",
|
||||||
"\n",
|
"\n",
|
||||||
|
@ -222,16 +238,16 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 6,
|
"execution_count": 4,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
"data": {
|
"data": {
|
||||||
"text/plain": [
|
"text/plain": [
|
||||||
"true"
|
"AllDef (generic function with 1 method)"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"execution_count": 6,
|
"execution_count": 4,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"output_type": "execute_result"
|
"output_type": "execute_result"
|
||||||
}
|
}
|
||||||
|
@ -241,7 +257,7 @@
|
||||||
"Objective(x, price) = \n",
|
"Objective(x, price) = \n",
|
||||||
" sum(\n",
|
" sum(\n",
|
||||||
" if x[i] < 0\n",
|
" if x[i] < 0\n",
|
||||||
" 1\n",
|
" price[i]\n",
|
||||||
" else\n",
|
" else\n",
|
||||||
" price[i]*x[i] \n",
|
" price[i]*x[i] \n",
|
||||||
" end\n",
|
" end\n",
|
||||||
|
@ -260,113 +276,34 @@
|
||||||
" ) <= capacity\n",
|
" ) <= capacity\n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
"AllDef(x) =\n",
|
"function AllDef(x)\n",
|
||||||
" for xi in x\n",
|
" for i in 1:length(x)\n",
|
||||||
" if xi < 0\n",
|
" if x[i] < 0\n",
|
||||||
" return false\n",
|
" return false\n",
|
||||||
" end\n",
|
" end\n",
|
||||||
" end\n",
|
" end\n",
|
||||||
" return true"
|
" return true\n",
|
||||||
|
"end"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 7,
|
"execution_count": null,
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [
|
"outputs": [
|
||||||
{
|
{
|
||||||
"name": "stdout",
|
"ename": "Error",
|
||||||
"output_type": "stream",
|
"evalue": "Session cannot generate requests",
|
||||||
"text": [
|
"output_type": "error",
|
||||||
"\n",
|
"traceback": [
|
||||||
"Node number 0: \n",
|
"Error: Session cannot generate requests",
|
||||||
"-----\n",
|
"at S.executeCodeCell (/home/damien/.vscode/extensions/ms-toolsai.jupyter-2021.10.1101450599/out/client/extension.js:66:301742)",
|
||||||
"\n",
|
"at S.execute (/home/damien/.vscode/extensions/ms-toolsai.jupyter-2021.10.1101450599/out/client/extension.js:66:300732)",
|
||||||
"\n",
|
"at S.start (/home/damien/.vscode/extensions/ms-toolsai.jupyter-2021.10.1101450599/out/client/extension.js:66:296408)",
|
||||||
"Noeud actuel\tx_1 = -1\tx_2 = -1\tx_3 = -1\tx_4 = -1 \n",
|
"at processTicksAndRejections (internal/process/task_queues.js:93:5)",
|
||||||
"\n",
|
"at async t.CellExecutionQueue.executeQueuedCells (/home/damien/.vscode/extensions/ms-toolsai.jupyter-2021.10.1101450599/out/client/extension.js:66:312326)",
|
||||||
"Previous Solution memorized Any[] with bestprofit -1\n",
|
"at async t.CellExecutionQueue.start (/home/damien/.vscode/extensions/ms-toolsai.jupyter-2021.10.1101450599/out/client/extension.js:66:311862)"
|
||||||
"\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"
|
|
||||||
]
|
]
|
||||||
},
|
|
||||||
{
|
|
||||||
"data": {
|
|
||||||
"text/plain": [
|
|
||||||
"(-1, Any[], Int64[], Int64[], Any[])"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"execution_count": 7,
|
|
||||||
"metadata": {},
|
|
||||||
"output_type": "execute_result"
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"source": [
|
"source": [
|
||||||
|
@ -374,6 +311,8 @@
|
||||||
"\n",
|
"\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",
|
||||||
|
"\n",
|
||||||
" #create the structure to memorize the search tree for visualization at the end\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",
|
" trParentnodes=Int64[] #will store orig node of arc in search tree\n",
|
||||||
" trChildnodes=Int64[] #will store destination node of arc in search tree\n",
|
" trChildnodes=Int64[] #will store destination node of arc in search tree\n",
|
||||||
|
@ -388,46 +327,50 @@
|
||||||
"\n",
|
"\n",
|
||||||
" current_node_number=0\n",
|
" current_node_number=0\n",
|
||||||
" stop = false\n",
|
" stop = false\n",
|
||||||
|
" affich = false\n",
|
||||||
"\n",
|
"\n",
|
||||||
" push!(listvars, [-1 for p in price])\n",
|
" push!(listvars, [-1 for p in price])\n",
|
||||||
" push!(listvals, Objective(first(listvars), price))\n",
|
" push!(listvals, Objective(last(listvars), price))\n",
|
||||||
"\n",
|
"\n",
|
||||||
" while (!stop)\n",
|
" while (!stop)\n",
|
||||||
|
" x = last(listvars)\n",
|
||||||
"\n",
|
"\n",
|
||||||
" println(\"\\nNode number \", current_node_number, \": \\n-----\\n\")\n",
|
" if affich\n",
|
||||||
"\n",
|
" print(\"----------\\nNode n°\", current_node_number, \" : \")\n",
|
||||||
" x = first(listvars)\n",
|
" println(\" \")\n",
|
||||||
"\n",
|
" println(\"\\nPrevious Solution memorized \", \" with bestprofit \", BestProfit, \"\\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",
|
|
||||||
" end\n",
|
" end\n",
|
||||||
" println(\" \");\n",
|
|
||||||
" println(\"\\nPrevious Solution memorized \", Bestsol, \" with bestprofit \", BestProfit, \"\\n\")\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",
|
" \n",
|
||||||
" is_node_sondable = TA || TO || TR\n",
|
" is_node_sondable = TA || TO || TR\n",
|
||||||
"\n",
|
|
||||||
" if (!is_node_sondable)\n",
|
" if (!is_node_sondable)\n",
|
||||||
" listvars, listvals = SeparerNoeud_relaxlin(price, listvars, listvals)\n",
|
" listvars, listvals = SeparerNoeud_relaxlin(price, listvars, listvals)\n",
|
||||||
" else\n",
|
" else\n",
|
||||||
" listvars, listvals, stop = ExplorerAutreNoeud_relaxlin(listvars, listvals)\n",
|
" listvars, listvals, stop = ExplorerAutreNoeud_relaxlin(listvars, listvals)\n",
|
||||||
" end\n",
|
" end\n",
|
||||||
"\n",
|
"\n",
|
||||||
|
" if current_node_number % 1000000 == 1000\n",
|
||||||
|
" affich = true\n",
|
||||||
|
" else\n",
|
||||||
|
" affich = false\n",
|
||||||
|
" end\n",
|
||||||
" 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",
|
||||||
" return BestProfit, Bestsol, trParentnodes, trChildnodes, trNamenodes\n",
|
|
||||||
"\n",
|
|
||||||
"end\n",
|
"end\n",
|
||||||
"\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": {
|
"metadata": {
|
||||||
|
|
Loading…
Reference in a new issue