TP almost done | TODO : rapport, bonus
This commit is contained in:
parent
4a9cc998c6
commit
75e9c40e9f
|
@ -140,13 +140,12 @@
|
|||
" 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",
|
||||
" if (Objective(x, price) >= BestProfit) # Le profit de la solution trouvée est meilleur que les autres\n",
|
||||
" if affich\n",
|
||||
" println(\"\\t-> Cette solution a un meilleur profit.\")\n",
|
||||
" end\n",
|
||||
" # On remplace la solution et le profit par les nouvelles valeurs\n",
|
||||
" Bestsol = x\n",
|
||||
" #BestProfit=value(benef)\n",
|
||||
" BestProfit = Objective(x, price)\n",
|
||||
" else\n",
|
||||
" if affich\n",
|
||||
|
@ -191,47 +190,60 @@
|
|||
"source": [
|
||||
"\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 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 \n",
|
||||
"\n",
|
||||
" # Cas du noeud le plus à gauche\n",
|
||||
"\n",
|
||||
" # On sépare le noeud actuel en 2 sous-noeuds\n",
|
||||
" predX = pop!(listvars)\n",
|
||||
" n = length(predX)\n",
|
||||
" nextX0 = copy(predX)\n",
|
||||
" nextX1 = copy(predX)\n",
|
||||
"\n",
|
||||
" # On initialise leurs valeurs à zéro\n",
|
||||
" val0 = 0\n",
|
||||
" val1 = 0\n",
|
||||
"\n",
|
||||
" # On fixe la nouvelle variable des deux sous-noeuds\n",
|
||||
" n = length(predX)\n",
|
||||
" for i in 1:n\n",
|
||||
" if predX[i] == -1\n",
|
||||
" # L'un a zéro\n",
|
||||
" nextX0[i] = 0\n",
|
||||
" # L'autre a un\n",
|
||||
" nextX1[i] = 1\n",
|
||||
"\n",
|
||||
" # On calcule leurs valeurs\n",
|
||||
" val0 = Objective(nextX0, price)\n",
|
||||
" val1 = Objective(nextX1, price)\n",
|
||||
" break\n",
|
||||
" end\n",
|
||||
" end\n",
|
||||
" # On ajoute les sous-noeuds a la pile des noeuds a explorer\n",
|
||||
" push!(listvars, nextX1)\n",
|
||||
" push!(listvars, nextX0)\n",
|
||||
"\n",
|
||||
" # On ajoute aussi leurs valeurs\n",
|
||||
" push!(listvals, val1)\n",
|
||||
" push!(listvals, val0)\n",
|
||||
"\n",
|
||||
" listvars, listvals\n",
|
||||
"end\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"function ExplorerAutreNoeud_relaxlin(listvars, listvals)\n",
|
||||
" # this node is sondable, go back to parent node then right child if possible\n",
|
||||
" # Le noeud est sondable, on l'enlève de la pile des noeuds à sonder\n",
|
||||
" \n",
|
||||
" stop = false\n",
|
||||
" # check if we are not at the root node\n",
|
||||
" if (length(listvars) > 1)\n",
|
||||
" # go back to parent node\n",
|
||||
" # On passe au noeud suivant\n",
|
||||
" var = pop!(listvars)\n",
|
||||
" val = pop!(listvals)\n",
|
||||
" else\n",
|
||||
" # the root node was sondable\n",
|
||||
" # Il n'y a pas d'autre noeud\n",
|
||||
" println(\"\\nFINISHED\")\n",
|
||||
" stop = true\n",
|
||||
" end\n",
|
||||
"\n",
|
||||
" listvars, listvals, stop \n",
|
||||
"end"
|
||||
]
|
||||
|
@ -253,7 +265,7 @@
|
|||
}
|
||||
],
|
||||
"source": [
|
||||
"# fonction objectif que l'on souhaite maximiser/minimiser\n",
|
||||
"# Fonction objectif que l'on souhaite maximiser/minimiser (évalué dans le meilleur des cas)\n",
|
||||
"Objective(x, price) = \n",
|
||||
" sum(\n",
|
||||
" if x[i] < 0\n",
|
||||
|
@ -264,7 +276,7 @@
|
|||
" for i in 1:length(x)\n",
|
||||
" )\n",
|
||||
"\n",
|
||||
"# fonction permettant de vérfier toutes les contraintes du modèle\n",
|
||||
"# Fonction permettant de vérfier toutes les contraintes du modèle (dans le meilleur des cas)\n",
|
||||
"Constraints(x, weight, capacity) =\n",
|
||||
" sum(\n",
|
||||
" if x[i] < 0\n",
|
||||
|
@ -275,7 +287,7 @@
|
|||
" for i in 1:length(x)\n",
|
||||
" ) <= capacity\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# Fonction qui nous dis si toutes les variables de x sont fixées\n",
|
||||
"function AllDef(x)\n",
|
||||
" for i in 1:length(x)\n",
|
||||
" if x[i] < 0\n",
|
||||
|
@ -288,21 +300,31 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 5,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"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)"
|
||||
"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"
|
||||
]
|
||||
}
|
||||
],
|
||||
|
@ -313,26 +335,26 @@
|
|||
"\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",
|
||||
" trNamenodes=[] #will store names of nodes in search tree\n",
|
||||
" \n",
|
||||
" #intermediate structure to navigate in the search tree\n",
|
||||
" # Liste des variable pour naviguer de noeuds en noeuds\n",
|
||||
" listvars=[]\n",
|
||||
" listvals=[]\n",
|
||||
"\n",
|
||||
" # La meilleur solution et sa valeur\n",
|
||||
" BestProfit=-1\n",
|
||||
" Bestsol=[]\n",
|
||||
"\n",
|
||||
" # Compter le nombre de noeud explorés\n",
|
||||
" current_node_number = 0\n",
|
||||
"\n",
|
||||
" stop = false\n",
|
||||
" affich = false\n",
|
||||
"\n",
|
||||
" # On ajoute le premier noeud à explorer (la racine)\n",
|
||||
" push!(listvars, [-1 for p in price])\n",
|
||||
" push!(listvals, Objective(last(listvars), price))\n",
|
||||
"\n",
|
||||
" while (!stop)\n",
|
||||
" # Le noeud actuel\n",
|
||||
" x = last(listvars)\n",
|
||||
"\n",
|
||||
" if affich\n",
|
||||
|
@ -341,20 +363,26 @@
|
|||
" println(\"\\nPrevious Solution memorized \", \" with bestprofit \", BestProfit, \"\\n\")\n",
|
||||
" end\n",
|
||||
"\n",
|
||||
" # Test de sondabilité du noeud actuel\n",
|
||||
" # -> On mets a jour la solution et sa valeur si besoin\n",
|
||||
" TA, TO, TR, Bestsol, BestProfit = TestsSondabilite_relaxlin(x, price, weight, capacity, BestProfit, Bestsol, affich)\n",
|
||||
" \n",
|
||||
" is_node_sondable = TA || TO || TR\n",
|
||||
" 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",
|
||||
" else\n",
|
||||
" # Le noeud est sondable, on passe au noeud suivant\n",
|
||||
" listvars, listvals, stop = ExplorerAutreNoeud_relaxlin(listvars, listvals)\n",
|
||||
" end\n",
|
||||
"\n",
|
||||
" if current_node_number % 1000000 == 1000\n",
|
||||
" # On évite de spammer l'output donc on n'affiche pas tout les résultats\n",
|
||||
" if current_node_number % 1000000 == 100\n",
|
||||
" affich = true\n",
|
||||
" else\n",
|
||||
" affich = false\n",
|
||||
" end\n",
|
||||
"\n",
|
||||
" current_node_number += 1\n",
|
||||
" end\n",
|
||||
"\n",
|
||||
|
@ -362,7 +390,7 @@
|
|||
"\n",
|
||||
"end\n",
|
||||
"\n",
|
||||
"SolveKnapInstance(\"data/subset_sum/knapPI_6_100_10000_2_-10726.opb\")"
|
||||
"SolveKnapInstance(\"data/subset_sum/knapPI_6_50_1000_1_-994.opb\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue