diff --git a/Knapsack.ipynb b/Knapsack.ipynb
index 43bc292..0446295 100644
--- a/Knapsack.ipynb
+++ b/Knapsack.ipynb
@@ -16,14 +16,13 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 32,
"metadata": {},
"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",
@@ -48,7 +47,7 @@
},
{
"cell_type": "code",
- "execution_count": 2,
+ "execution_count": 33,
"metadata": {},
"outputs": [
{
@@ -57,7 +56,7 @@
"readKnaptxtInstance (generic function with 1 method)"
]
},
- "execution_count": 2,
+ "execution_count": 33,
"metadata": {},
"output_type": "execute_result"
}
@@ -70,7 +69,7 @@
" open(filename) do f\n",
" for i in 1:3\n",
" tok = split(readline(f))\n",
- " if(tok[1] == \"ListPrices=\")\n",
+ " if (tok[1] == \"ListPrices=\")\n",
" for i in 2:(length(tok)-1)\n",
" push!(price,parse(Int64, tok[i]))\n",
" end\n",
@@ -99,7 +98,7 @@
},
{
"cell_type": "code",
- "execution_count": 3,
+ "execution_count": 34,
"metadata": {},
"outputs": [
{
@@ -108,7 +107,7 @@
"TestsSondabilite_relaxlin (generic function with 1 method)"
]
},
- "execution_count": 3,
+ "execution_count": 34,
"metadata": {},
"output_type": "execute_result"
}
@@ -116,13 +115,13 @@
"source": [
"function TestsSondabilite_relaxlin(model2, x, varsbin, BestProfit, Bestsol)\n",
" TA, TO, TR = false, false, false\n",
- " if(termination_status(model2) == MOI.INFEASIBLE)#Test de faisabilite\n",
+ " if (termination_status(model2) == MOI.INFEASIBLE)#Test de faisabilite\n",
" TA=true\n",
" println(\"TA\")\n",
- " elseif(objective_value(model2) <= BestProfit) #Test d'optimalite\n",
+ " elseif (objective_value(model2) <= BestProfit) #Test d'optimalite\n",
" TO=true\n",
" println(\"TO\")\n",
- " elseif( prod(abs.([round.(v, digits=0) for v in value.(varsbin)]-value.(varsbin)) .<= fill(10^-5, size(varsbin))) \n",
+ " elseif ( prod(abs.([round.(v, digits=0) for v in value.(varsbin)]-value.(varsbin)) .<= fill(10^-5, size(varsbin))) \n",
" ) #Test de resolution\n",
" TR=true\n",
" println(\"TR\")\n",
@@ -148,7 +147,7 @@
},
{
"cell_type": "code",
- "execution_count": 4,
+ "execution_count": 35,
"metadata": {},
"outputs": [
{
@@ -157,7 +156,7 @@
"ExplorerAutreNoeud_relaxlin (generic function with 1 method)"
]
},
- "execution_count": 4,
+ "execution_count": 35,
"metadata": {},
"output_type": "execute_result"
}
@@ -170,9 +169,9 @@
" \n",
" #find a fractionnal variable\n",
" i, var = 1, 0\n",
- " while((i <= length(varsshouldbebinary)) && (var==0))\n",
- " #if(varsshouldbebinary[i] ∉ listvars)\n",
- " if(abs(round(value(varsshouldbebinary[i]), digits=0) - value(varsshouldbebinary[i]) ) >= 10^-5)\n",
+ " while ((i <= length(varsshouldbebinary)) && (var==0))\n",
+ " #if (varsshouldbebinary[i] ∉ listvars)\n",
+ " if (abs(round(value(varsshouldbebinary[i]), digits=0) - value(varsshouldbebinary[i]) ) >= 10^-5)\n",
" var=varsshouldbebinary[i]\n",
" end\n",
" i+=1\n",
@@ -182,7 +181,7 @@
" #find most fractionnal variable ?\n",
" i, var, maxfrac = -1, 0, 0.0\n",
" for i in 1:length(varsshouldbebinary)\n",
- " if(abs(round(value(varsshouldbebinary[i]), digits=0) - value(varsshouldbebinary[i]) ) >= maxfrac) \n",
+ " if (abs(round(value(varsshouldbebinary[i]), digits=0) - value(varsshouldbebinary[i]) ) >= maxfrac) \n",
" #if a variable is more fractinonal\n",
" var=varsshouldbebinary[i]\n",
" maxfrac=abs(round(value(varsshouldbebinary[i]), digits=0) - value(varsshouldbebinary[i]) )\n",
@@ -215,7 +214,7 @@
" set_upper_bound(var,1.0)\n",
"\n",
" #go to right child if possible, otherwise go back to parent\n",
- " while( (theval==0.0) && (length(listvars)>= 1))\n",
+ " while ( (theval==0.0) && (length(listvars)>= 1))\n",
" var=pop!(listvars)\n",
" theval=pop!(listvals)\n",
" tmp=pop!(listnodes)\n",
@@ -251,7 +250,7 @@
},
{
"cell_type": "code",
- "execution_count": 5,
+ "execution_count": 36,
"metadata": {},
"outputs": [
{
@@ -271,7 +270,7 @@
},
{
"cell_type": "code",
- "execution_count": 6,
+ "execution_count": 37,
"metadata": {},
"outputs": [
{
@@ -280,7 +279,7 @@
"CreationModeleLP (generic function with 1 method)"
]
},
- "execution_count": 6,
+ "execution_count": 37,
"metadata": {},
"output_type": "execute_result"
}
@@ -318,7 +317,7 @@
},
{
"cell_type": "code",
- "execution_count": 7,
+ "execution_count": 38,
"metadata": {},
"outputs": [
{
@@ -327,7 +326,7 @@
"SolveKnapInstance (generic function with 1 method)"
]
},
- "execution_count": 7,
+ "execution_count": 38,
"metadata": {},
"output_type": "execute_result"
}
@@ -336,7 +335,7 @@
"\n",
"function SolveKnapInstance(filename)\n",
"\n",
- " if (split(filename,\"/\")[end] != \"test.opb.txt\")\n",
+ " if (split(filename,\"/\")[end] != \"test.opb\")\n",
" println(\"This version of the code works only for the test instance !!!!\")\n",
" else\n",
" price, weight, capacity = readKnaptxtInstance(filename)\n",
@@ -358,13 +357,13 @@
" current_node_number=0\n",
" stop = false\n",
"\n",
- " while(!stop)\n",
+ " while (!stop)\n",
"\n",
" println(\"\\nNode number \", current_node_number, \": \\n-----\\n\", model2)\n",
"\n",
" #Update the search tree\n",
" push!(trNamenodes,current_node_number+1) \n",
- " if(length(trNamenodes)>=2)\n",
+ " if (length(trNamenodes)>=2)\n",
" push!(trParentnodes,listnodes[end]+1) # +1 because the 1st node is \"node 0\"\n",
" push!(trChildnodes, current_node_number+1) # +1 because the 1st node is \"node 0\"\n",
" end\n",
@@ -376,7 +375,7 @@
" println(\"... end\")\n",
"\n",
" print(\"\\nSolution relax lin\"); \n",
- " if(termination_status(model2) == MOI.INFEASIBLE)#(has_values(model2))\n",
+ " if (termination_status(model2) == MOI.INFEASIBLE)#(has_values(model2))\n",
" print(\" : NOT AVAILABLE (probably infeasible or ressources limit reached)\")\n",
" else\n",
" [print(\"\\t\", name(v),\"=\",value(v)) for v in all_variables(model2)] \n",
@@ -387,7 +386,7 @@
"\n",
" is_node_sondable = TA || TO || TR\n",
"\n",
- " if(!is_node_sondable)\n",
+ " if (!is_node_sondable)\n",
" listvars, listvals = SeparerNoeud_relaxlin(varsshouldbebinary, listvars, listvals)\n",
" else\n",
" listvars, listvals, listnodes, stop = ExplorerAutreNoeud_relaxlin(listvars, listvals, listnodes)\n",
@@ -413,7 +412,7 @@
},
{
"cell_type": "code",
- "execution_count": 8,
+ "execution_count": 39,
"metadata": {},
"outputs": [
{
@@ -736,25 +735,18 @@
},
{
"data": {
- "image/svg+xml": "\n\n"
+ "image/svg+xml": "\n\n"
},
- "execution_count": 8,
+ "execution_count": 39,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
- "BestProfit, Bestsol, trParentnodes, trChildnodes, trNamenodes = SolveKnapInstance(\"instancesETU/KNAPnewformat/test.opb.txt\")\n",
+ "BestProfit, Bestsol, trParentnodes, trChildnodes, trNamenodes = SolveKnapInstance(\"data/test.opb\")\n",
"println(\"\\n******\\n\\nOptimal value = \", BestProfit, \"\\n\\nOptimal x=\", Bestsol)\n",
"graphplot(trParentnodes, trChildnodes, names=trNamenodes, method=:tree)"
]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": []
}
],
"metadata": {