feat: doc + test readKnapInstance

This commit is contained in:
Laureηt 2021-12-05 15:25:55 +01:00
parent c11a20d70b
commit ce320c4a77
2 changed files with 62 additions and 513 deletions

View file

@ -16,29 +16,9 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 1, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"name": "stderr",
"output_type": "stream",
"text": [
"\u001b[32m\u001b[1m Updating\u001b[22m\u001b[39m registry at `~/.julia/registries/General`\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 6 seconds (158 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 2 seconds (158 already precompiled)\n"
]
}
],
"source": [ "source": [
"import Pkg; \n", "import Pkg; \n",
"Pkg.add(\"GraphRecipes\"); Pkg.add(\"Plots\"); \n", "Pkg.add(\"GraphRecipes\"); Pkg.add(\"Plots\"); \n",
@ -54,20 +34,9 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 2, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"data": {
"text/plain": [
"readKnaptxtInstance (generic function with 1 method)"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [ "source": [
"function readKnaptxtInstance(filename)\n", "function readKnaptxtInstance(filename)\n",
" price=[]\n", " price=[]\n",
@ -105,20 +74,9 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 3, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"data": {
"text/plain": [
"TestsSondabilite_relaxlin (generic function with 1 method)"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [ "source": [
"function TestsSondabilite_relaxlin(model2, x, varsbin, BestProfit, Bestsol)\n", "function TestsSondabilite_relaxlin(model2, x, varsbin, BestProfit, Bestsol)\n",
" TA, TO, TR = false, false, false\n", " TA, TO, TR = false, false, false\n",
@ -154,20 +112,9 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 4, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"data": {
"text/plain": [
"ExplorerAutreNoeud_relaxlin (generic function with 1 method)"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [ "source": [
"\n", "\n",
"function SeparerNoeud_relaxlin(varsshouldbebinary, listvars, listvals)\n", "function SeparerNoeud_relaxlin(varsshouldbebinary, listvars, listvals)\n",
@ -257,22 +204,9 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 9, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"name": "stderr",
"output_type": "stream",
"text": [
"\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 (167 already precompiled)\n"
]
}
],
"source": [ "source": [
"Pkg.add(\"Clp\");\n", "Pkg.add(\"Clp\");\n",
"using JuMP, Clp" "using JuMP, Clp"
@ -280,20 +214,9 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 10, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"data": {
"text/plain": [
"CreationModeleLP (generic function with 1 method)"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [ "source": [
"function CreationModeleLP(price, weight, capacity)\n", "function CreationModeleLP(price, weight, capacity)\n",
"# ROOT NODE\n", "# ROOT NODE\n",
@ -327,20 +250,9 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 11, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"data": {
"text/plain": [
"SolveKnapInstance (generic function with 1 method)"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [ "source": [
"\n", "\n",
"function SolveKnapInstance(filename)\n", "function SolveKnapInstance(filename)\n",
@ -422,331 +334,9 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 12, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"name": "stdout",
"output_type": "stream",
"text": [
"Max 42 x[1] + 40 x[2] + 12 x[3] + 25 x[4]\n",
"Subject to\n",
" 7 x[1] + 4 x[2] + 3 x[3] + 5 x[4] ≤ 10.0\n",
" x[1] ≥ 0.0\n",
" x[2] ≥ 0.0\n",
" x[3] ≥ 0.0\n",
" x[4] ≥ 0.0\n",
" x[1] ≤ 1.0\n",
" x[2] ≤ 1.0\n",
" x[3] ≤ 1.0\n",
" x[4] ≤ 1.0\n",
"\n",
"\n",
"Node number 0: \n",
"-----\n",
"Max 42 x[1] + 40 x[2] + 12 x[3] + 25 x[4]\n",
"Subject to\n",
" 7 x[1] + 4 x[2] + 3 x[3] + 5 x[4] ≤ 10.0\n",
" x[1] ≥ 0.0\n",
" x[2] ≥ 0.0\n",
" x[3] ≥ 0.0\n",
" x[4] ≥ 0.0\n",
" x[1] ≤ 1.0\n",
" x[2] ≤ 1.0\n",
" x[3] ≤ 1.0\n",
" x[4] ≤ 1.0\n",
"\n",
"Solve model2 to compute the bounds of the current node: start ... ... end\n",
"\n",
"Solution relax lin\tx[1]=0.857142857142857\tx[2]=1.0\tx[3]=0.0\tx[4]=0.0 \n",
"\n",
"Previous Solution memorized Any[] with bestprofit -1\n",
"\n",
"non sondable\n",
"\n",
"Node number 1: \n",
"-----\n",
"Max 42 x[1] + 40 x[2] + 12 x[3] + 25 x[4]\n",
"Subject to\n",
" 7 x[1] + 4 x[2] + 3 x[3] + 5 x[4] ≤ 10.0\n",
" x[1] ≥ 1.0\n",
" x[2] ≥ 0.0\n",
" x[3] ≥ 0.0\n",
" x[4] ≥ 0.0\n",
" x[1] ≤ 1.0\n",
" x[2] ≤ 1.0\n",
" x[3] ≤ 1.0\n",
" x[4] ≤ 1.0\n",
"\n",
"Solve model2 to compute the bounds of the current node: start ... ... end\n",
"\n",
"Solution relax lin\tx[1]=1.0\tx[2]=0.7500000000000001\tx[3]=0.0\tx[4]=0.0 \n",
"\n",
"Previous Solution memorized Any[] with bestprofit -1\n",
"\n",
"non sondable\n",
"\n",
"Node number 2: \n",
"-----\n",
"Max 42 x[1] + 40 x[2] + 12 x[3] + 25 x[4]\n",
"Subject to\n",
" 7 x[1] + 4 x[2] + 3 x[3] + 5 x[4] ≤ 10.0\n",
" x[1] ≥ 1.0\n",
" x[2] ≥ 1.0\n",
" x[3] ≥ 0.0\n",
" x[4] ≥ 0.0\n",
" x[1] ≤ 1.0\n",
" x[2] ≤ 1.0\n",
" x[3] ≤ 1.0\n",
" x[4] ≤ 1.0\n",
"\n",
"Solve model2 to compute the bounds of the current node: start ... ... end\n",
"\n",
"Solution relax lin : 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",
"Max 42 x[1] + 40 x[2] + 12 x[3] + 25 x[4]\n",
"Subject to\n",
" 7 x[1] + 4 x[2] + 3 x[3] + 5 x[4] ≤ 10.0\n",
" x[1] ≥ 1.0\n",
" x[2] ≥ 0.0\n",
" x[3] ≥ 0.0\n",
" x[4] ≥ 0.0\n",
" x[1] ≤ 1.0\n",
" x[2] ≤ 0.0\n",
" x[3] ≤ 1.0\n",
" x[4] ≤ 1.0\n",
"\n",
"Solve model2 to compute the bounds of the current node: start ... ... end\n",
"\n",
"Solution relax lin\tx[1]=1.0\tx[2]=0.0\tx[3]=0.0\tx[4]=0.6 \n",
"\n",
"Previous Solution memorized Any[] with bestprofit -1\n",
"\n",
"non sondable\n",
"\n",
"Node number 4: \n",
"-----\n",
"Max 42 x[1] + 40 x[2] + 12 x[3] + 25 x[4]\n",
"Subject to\n",
" 7 x[1] + 4 x[2] + 3 x[3] + 5 x[4] ≤ 10.0\n",
" x[1] ≥ 1.0\n",
" x[2] ≥ 0.0\n",
" x[3] ≥ 0.0\n",
" x[4] ≥ 1.0\n",
" x[1] ≤ 1.0\n",
" x[2] ≤ 0.0\n",
" x[3] ≤ 1.0\n",
" x[4] ≤ 1.0\n",
"\n",
"Solve model2 to compute the bounds of the current node: start ... ... end\n",
"\n",
"Solution relax lin : 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",
"Max 42 x[1] + 40 x[2] + 12 x[3] + 25 x[4]\n",
"Subject to\n",
" 7 x[1] + 4 x[2] + 3 x[3] + 5 x[4] ≤ 10.0\n",
" x[1] ≥ 1.0\n",
" x[2] ≥ 0.0\n",
" x[3] ≥ 0.0\n",
" x[4] ≥ 0.0\n",
" x[1] ≤ 1.0\n",
" x[2] ≤ 0.0\n",
" x[3] ≤ 1.0\n",
" x[4] ≤ 0.0\n",
"\n",
"Solve model2 to compute the bounds of the current node: start ... ... end\n",
"\n",
"Solution relax lin\tx[1]=1.0\tx[2]=0.0\tx[3]=1.0\tx[4]=0.0 \n",
"\n",
"Previous Solution memorized Any[] with bestprofit -1\n",
"\n",
"TR\n",
"\n",
"Node number 6: \n",
"-----\n",
"Max 42 x[1] + 40 x[2] + 12 x[3] + 25 x[4]\n",
"Subject to\n",
" 7 x[1] + 4 x[2] + 3 x[3] + 5 x[4] ≤ 10.0\n",
" x[1] ≥ 0.0\n",
" x[2] ≥ 0.0\n",
" x[3] ≥ 0.0\n",
" x[4] ≥ 0.0\n",
" x[1] ≤ 0.0\n",
" x[2] ≤ 1.0\n",
" x[3] ≤ 1.0\n",
" x[4] ≤ 1.0\n",
"\n",
"Solve model2 to compute the bounds of the current node: start ... ... end\n",
"\n",
"Solution relax lin\tx[1]=0.0\tx[2]=1.0\tx[3]=0.3333333333333332\tx[4]=1.0 \n",
"\n",
"Previous Solution memorized [1.0, 0.0, 1.0, 0.0] with bestprofit 54.0\n",
"\n",
"non sondable\n",
"\n",
"Node number 7: \n",
"-----\n",
"Max 42 x[1] + 40 x[2] + 12 x[3] + 25 x[4]\n",
"Subject to\n",
" 7 x[1] + 4 x[2] + 3 x[3] + 5 x[4] ≤ 10.0\n",
" x[1] ≥ 0.0\n",
" x[2] ≥ 0.0\n",
" x[3] ≥ 1.0\n",
" x[4] ≥ 0.0\n",
" x[1] ≤ 0.0\n",
" x[2] ≤ 1.0\n",
" x[3] ≤ 1.0\n",
" x[4] ≤ 1.0\n",
"\n",
"Solve model2 to compute the bounds of the current node: start ... ... end\n",
"\n",
"Solution relax lin\tx[1]=0.0\tx[2]=1.0\tx[3]=1.0\tx[4]=0.6000000000000001 \n",
"\n",
"Previous Solution memorized [1.0, 0.0, 1.0, 0.0] with bestprofit 54.0\n",
"\n",
"non sondable\n",
"\n",
"Node number 8: \n",
"-----\n",
"Max 42 x[1] + 40 x[2] + 12 x[3] + 25 x[4]\n",
"Subject to\n",
" 7 x[1] + 4 x[2] + 3 x[3] + 5 x[4] ≤ 10.0\n",
" x[1] ≥ 0.0\n",
" x[2] ≥ 0.0\n",
" x[3] ≥ 1.0\n",
" x[4] ≥ 1.0\n",
" x[1] ≤ 0.0\n",
" x[2] ≤ 1.0\n",
" x[3] ≤ 1.0\n",
" x[4] ≤ 1.0\n",
"\n",
"Solve model2 to compute the bounds of the current node: start ... ... end\n",
"\n",
"Solution relax lin\tx[1]=0.0\tx[2]=0.5\tx[3]=1.0\tx[4]=1.0 \n",
"\n",
"Previous Solution memorized [1.0, 0.0, 1.0, 0.0] with bestprofit 54.0\n",
"\n",
"non sondable\n",
"\n",
"Node number 9: \n",
"-----\n",
"Max 42 x[1] + 40 x[2] + 12 x[3] + 25 x[4]\n",
"Subject to\n",
" 7 x[1] + 4 x[2] + 3 x[3] + 5 x[4] ≤ 10.0\n",
" x[1] ≥ 0.0\n",
" x[2] ≥ 1.0\n",
" x[3] ≥ 1.0\n",
" x[4] ≥ 1.0\n",
" x[1] ≤ 0.0\n",
" x[2] ≤ 1.0\n",
" x[3] ≤ 1.0\n",
" x[4] ≤ 1.0\n",
"\n",
"Solve model2 to compute the bounds of the current node: start ... ... end\n",
"\n",
"Solution relax lin : NOT AVAILABLE (probably infeasible or ressources limit reached) \n",
"\n",
"Previous Solution memorized [1.0, 0.0, 1.0, 0.0] with bestprofit 54.0\n",
"\n",
"TA\n",
"\n",
"Node number 10: \n",
"-----\n",
"Max 42 x[1] + 40 x[2] + 12 x[3] + 25 x[4]\n",
"Subject to\n",
" 7 x[1] + 4 x[2] + 3 x[3] + 5 x[4] ≤ 10.0\n",
" x[1] ≥ 0.0\n",
" x[2] ≥ 0.0\n",
" x[3] ≥ 1.0\n",
" x[4] ≥ 1.0\n",
" x[1] ≤ 0.0\n",
" x[2] ≤ 0.0\n",
" x[3] ≤ 1.0\n",
" x[4] ≤ 1.0\n",
"\n",
"Solve model2 to compute the bounds of the current node: start ... ... end\n",
"\n",
"Solution relax lin\tx[1]=0.0\tx[2]=0.0\tx[3]=1.0\tx[4]=1.0 \n",
"\n",
"Previous Solution memorized [1.0, 0.0, 1.0, 0.0] with bestprofit 54.0\n",
"\n",
"TO\n",
"\n",
"Node number 11: \n",
"-----\n",
"Max 42 x[1] + 40 x[2] + 12 x[3] + 25 x[4]\n",
"Subject to\n",
" 7 x[1] + 4 x[2] + 3 x[3] + 5 x[4] ≤ 10.0\n",
" x[1] ≥ 0.0\n",
" x[2] ≥ 0.0\n",
" x[3] ≥ 1.0\n",
" x[4] ≥ 0.0\n",
" x[1] ≤ 0.0\n",
" x[2] ≤ 1.0\n",
" x[3] ≤ 1.0\n",
" x[4] ≤ 0.0\n",
"\n",
"Solve model2 to compute the bounds of the current node: start ... ... end\n",
"\n",
"Solution relax lin\tx[1]=0.0\tx[2]=1.0\tx[3]=1.0\tx[4]=0.0 \n",
"\n",
"Previous Solution memorized [1.0, 0.0, 1.0, 0.0] with bestprofit 54.0\n",
"\n",
"TO\n",
"\n",
"Node number 12: \n",
"-----\n",
"Max 42 x[1] + 40 x[2] + 12 x[3] + 25 x[4]\n",
"Subject to\n",
" 7 x[1] + 4 x[2] + 3 x[3] + 5 x[4] ≤ 10.0\n",
" x[1] ≥ 0.0\n",
" x[2] ≥ 0.0\n",
" x[3] ≥ 0.0\n",
" x[4] ≥ 0.0\n",
" x[1] ≤ 0.0\n",
" x[2] ≤ 1.0\n",
" x[3] ≤ 0.0\n",
" x[4] ≤ 1.0\n",
"\n",
"Solve model2 to compute the bounds of the current node: start ... ... end\n",
"\n",
"Solution relax lin\tx[1]=0.0\tx[2]=1.0\tx[3]=0.0\tx[4]=1.0 \n",
"\n",
"Previous Solution memorized [1.0, 0.0, 1.0, 0.0] with bestprofit 54.0\n",
"\n",
"TR\n",
"\n",
"FINISHED\n",
"\n",
"******\n",
"\n",
"Optimal value = 65.0\n",
"\n",
"Optimal x=[0.0, 1.0, 0.0, 1.0]\n",
"\n",
"******\n",
"\n",
"Optimal value = 65.0\n",
"\n",
"Optimal x=[0.0, 1.0, 0.0, 1.0]\n",
"[1, 2, 2, 4, 4, 1, 7, 8, 9, 9, 8, 7]\n",
"[2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]\n",
"Any[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]\n"
]
}
],
"source": [ "source": [
"BestProfit, Bestsol, trParentnodes, trChildnodes, trNamenodes = SolveKnapInstance(\"data/test.opb\")\n", "BestProfit, Bestsol, trParentnodes, trChildnodes, trNamenodes = SolveKnapInstance(\"data/test.opb\")\n",
"println(\"\\n******\\n\\nOptimal value = \", BestProfit, \"\\n\\nOptimal x=\", Bestsol)\n", "println(\"\\n******\\n\\nOptimal value = \", BestProfit, \"\\n\\nOptimal x=\", Bestsol)\n",
@ -774,7 +364,7 @@
"file_extension": ".jl", "file_extension": ".jl",
"mimetype": "application/julia", "mimetype": "application/julia",
"name": "julia", "name": "julia",
"version": "1.6.4" "version": "1.6.3"
} }
}, },
"nbformat": 4, "nbformat": 4,

View file

@ -16,32 +16,32 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 1, "execution_count": 8,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stderr", "name": "stderr",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"\u001b[32m\u001b[1m Updating\u001b[22m\u001b[39m registry at `~/.julia/registries/General`\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 6 seconds (167 already precompiled)\n", " 1 dependency successfully precompiled in 4 seconds (270 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 (167 already precompiled)\n" " 1 dependency successfully precompiled in 3 seconds (270 already precompiled)\n"
] ]
} }
], ],
"source": [ "source": [
"import Pkg; \n", "import Pkg; \n",
"Pkg.add(\"GraphRecipes\"); Pkg.add(\"Plots\"); \n", "Pkg.add(\"GraphRecipes\");\n",
"Pkg.add(\"Plots\"); \n",
"using GraphRecipes, Plots #only used to visualize the search tree at the end of the branch-and-bound" "using GraphRecipes, Plots #only used to visualize the search tree at the end of the branch-and-bound"
] ]
}, },
@ -54,21 +54,21 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 2, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"data": {
"text/plain": [
"readKnapInstance (generic function with 1 method)"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [ "source": [
"\"\"\"Open and read a KnapFile.\n",
"\n",
"Args:\n",
" filename (String): the name of the file to read.\n",
"\n",
"Returns:\n",
" price (Vector{Int64}): prices of items to put in the KnapSack.\n",
" weight (Vector{Int64}): weights of items to put in the KnapSack.\n",
" capacity (Int64): the maximum capacity of the KnapSack.\n",
"\n",
"\"\"\"\n",
"function readKnapInstance(filename)\n", "function readKnapInstance(filename)\n",
" price=[]\n", " price=[]\n",
" weight=[]\n", " weight=[]\n",
@ -91,12 +91,24 @@
" end \n", " end \n",
" end\n", " end\n",
" end\n", " end\n",
" \n",
" return price, weight, capacity\n", " return price, weight, capacity\n",
"end\n", "end"
"\n", ]
"# readKnapInstance(\"data/test.opb\")\n", },
"# readKnapInstance(\"data/almost_strongly_correlated/knapPI_5_50_1000_1_-2096.opb\")" {
"cell_type": "code",
"execution_count": 26,
"metadata": {},
"outputs": [],
"source": [
"# on teste de lire tous les fichiers .opb\n",
"for (root, dirs, files) in walkdir(\"data\")\n",
" for file in files\n",
" if endswith(file, \".opb\")\n",
" readKnapInstance(root * \"/\" * file)\n",
" end\n",
" end\n",
"end"
] ]
}, },
{ {
@ -108,20 +120,9 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 3, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"data": {
"text/plain": [
"TestsSondabilite_relaxlin (generic function with 1 method)"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [ "source": [
"function TestsSondabilite_relaxlin(x, price, weight, capacity, BestProfit, Bestsol, affich)\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",
@ -174,22 +175,10 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 4, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"data": {
"text/plain": [
"ExplorerAutreNoeud_relaxlin (generic function with 1 method)"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [ "source": [
"\n",
"function SeparerNoeud_relaxlin(price, listvars, listvals)\n", "function SeparerNoeud_relaxlin(price, listvars, listvals)\n",
" # Le noeud est non-sondable. Appliquer le critère de séparation pour le séparer en sous-noeuds \n", " # Le noeud est non-sondable. Appliquer le critère de séparation pour le séparer en sous-noeuds \n",
"\n", "\n",
@ -252,20 +241,9 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 5, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"data": {
"text/plain": [
"AllDef (generic function with 1 method)"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [ "source": [
"# Fonction objectif que l'on souhaite maximiser/minimiser (évalué dans le meilleur des cas)\n", "# Fonction objectif que l'on souhaite maximiser/minimiser (évalué dans le meilleur des cas)\n",
"Objective(x, price) = \n", "Objective(x, price) = \n",
@ -302,20 +280,9 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 6, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"data": {
"text/plain": [
"SolveKnapInstance (generic function with 1 method)"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [ "source": [
"function SolveKnapInstance(filename)\n", "function SolveKnapInstance(filename)\n",
"\n", "\n",
@ -412,21 +379,13 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 15, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"trParentnodes, trChildnodes, trNamenodes = SolveKnapInstance(\"data/circle/knapPI_16_8_1000_1_-2291.opb\")\n", "trParentnodes, trChildnodes, trNamenodes = SolveKnapInstance(\"data/circle/knapPI_16_8_1000_1_-2291.opb\")\n",
"\n",
"graphplot(trParentnodes, trChildnodes, names=trNamenodes, method=:tree)" "graphplot(trParentnodes, trChildnodes, names=trNamenodes, method=:tree)"
] ]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
} }
], ],
"metadata": { "metadata": {
@ -439,7 +398,7 @@
"file_extension": ".jl", "file_extension": ".jl",
"mimetype": "application/julia", "mimetype": "application/julia",
"name": "julia", "name": "julia",
"version": "1.6.4" "version": "1.6.3"
} }
}, },
"nbformat": 4, "nbformat": 4,