feat: ajout personnel.ipynb
Co-authored-by: gdamms <gdamms@users.noreply.github.com>
This commit is contained in:
parent
9f1515c8b8
commit
90204b2dfd
239
exo2/personnel.ipynb
Normal file
239
exo2/personnel.ipynb
Normal file
|
@ -0,0 +1,239 @@
|
||||||
|
{
|
||||||
|
"cells": [
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"Exemple de modèle et résolution du problème de Fabrication du perm"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 1,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stderr",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"\u001b[32m\u001b[1m Updating\u001b[22m\u001b[39m registry at `~/.julia/registries/General`\n"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "stderr",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"\u001b[32m\u001b[1m Resolving\u001b[22m\u001b[39m package versions...\n"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "stderr",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"\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"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "stderr",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"\u001b[32m\u001b[1m Resolving\u001b[22m\u001b[39m package versions...\n"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "stderr",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"\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"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"#importer les packages utiles\n",
|
||||||
|
"import Pkg;\n",
|
||||||
|
"Pkg.add(\"Cbc\")\n",
|
||||||
|
"Pkg.add(\"JuMP\")"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 4,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"Min perm[1,1] + 2 perm[1,2] + 3 perm[1,3] + 4 perm[1,4] + 2 perm[2,1] + 3 perm[2,2] + perm[2,3] + 4 perm[2,4] + 2 perm[3,1] + perm[3,2] + 3 perm[3,3] + 4 perm[3,4] + 4 perm[4,1] + 2 perm[4,2] + 3 perm[4,3] + perm[4,4]"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"\n",
|
||||||
|
"Subject to\n",
|
||||||
|
" "
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"perm[1,1] + perm[1,2] + perm[1,3] + perm[1,4] = 1.0\n",
|
||||||
|
" perm[1,1] + perm[2,1] + perm[3,1] + perm[4,1] = 1.0\n",
|
||||||
|
" perm[2,1] + perm[2,2] + perm[2,3] + perm[2,4] = 1.0\n",
|
||||||
|
" perm[1,2] + perm[2,2] + perm[3,2] + perm[4,2] = 1.0\n",
|
||||||
|
" perm[3,1] + perm[3,2] + perm[3,3] + perm[3,4] = 1.0\n",
|
||||||
|
" perm[1,3] + perm[2,3] + perm[3,3] + perm[4,3] = 1.0\n",
|
||||||
|
" perm[4,1] + perm[4,2] + perm[4,3] + perm[4,4] = 1.0\n",
|
||||||
|
" perm[1,4] + perm[2,4] + perm[3,4] + perm[4,4] = 1.0\n",
|
||||||
|
" perm[1,1] binary\n",
|
||||||
|
" perm[2,1] binary\n",
|
||||||
|
" perm[3,1] binary\n",
|
||||||
|
" perm[4,1] binary\n",
|
||||||
|
" perm[1,2] binary\n",
|
||||||
|
" perm[2,2] binary\n",
|
||||||
|
" perm[3,2] binary\n",
|
||||||
|
" perm[4,2] binary\n",
|
||||||
|
" perm[1,3] binary\n",
|
||||||
|
" perm[2,3] binary\n",
|
||||||
|
" perm[3,3] binary\n",
|
||||||
|
" perm[4,3] binary\n",
|
||||||
|
" perm[1,4] binary\n",
|
||||||
|
" perm[2,4] binary\n",
|
||||||
|
" perm[3,4] binary\n",
|
||||||
|
" perm[4,4] binary\n",
|
||||||
|
"\n"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"Welcome to the CBC MILP Solver \n",
|
||||||
|
"Version: 2.10.5 \n",
|
||||||
|
"Build Date: Jan 1 1970 \n",
|
||||||
|
"\n",
|
||||||
|
"command line - Cbc_C_Interface -solve -quit (default strategy 1)\n",
|
||||||
|
"Continuous objective value is 4 - 0.00 seconds\n",
|
||||||
|
"Cgl0004I processed model has 8 rows, 16 columns (16 integer (16 of which binary)) and 32 elements\n",
|
||||||
|
"Cutoff increment increased from 1e-05 to 0.9999\n",
|
||||||
|
"Cbc0038I Initial state - 0 integers unsatisfied sum - 0\n",
|
||||||
|
"Cbc0038I Solution found of 4\n",
|
||||||
|
"Cbc0038I Before mini branch and bound, 16 integers at bound fixed and 0 continuous\n",
|
||||||
|
"Cbc0038I Mini branch and bound did not improve solution (0.01 seconds)\n",
|
||||||
|
"Cbc0038I After 0.01 seconds - Feasibility pump exiting with objective of 4 - took 0.00 seconds\n",
|
||||||
|
"Cbc0012I Integer solution of 4 found by feasibility pump after 0 iterations and 0 nodes (0.01 seconds)\n",
|
||||||
|
"Cbc0001I Search completed - best objective 4, took 0 iterations and 0 nodes (0.01 seconds)\n",
|
||||||
|
"Cbc0035I Maximum depth 0, 0 variables fixed on reduced cost\n",
|
||||||
|
"Cuts at root node changed objective from 4 to 4\n",
|
||||||
|
"Probing was tried 0 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)\n",
|
||||||
|
"Gomory was tried 0 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)\n",
|
||||||
|
"Knapsack was tried 0 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)\n",
|
||||||
|
"Clique was tried 0 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)\n",
|
||||||
|
"MixedIntegerRounding2 was tried 0 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)\n",
|
||||||
|
"FlowCover was tried 0 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)\n",
|
||||||
|
"TwoMirCuts was tried 0 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)\n",
|
||||||
|
"ZeroHalf was tried 0 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)\n",
|
||||||
|
"\n",
|
||||||
|
"Result - Optimal solution found\n",
|
||||||
|
"\n",
|
||||||
|
"Objective value: 4.00000000\n",
|
||||||
|
"Enumerated nodes: 0\n",
|
||||||
|
"Total iterations: 0\n",
|
||||||
|
"Time (CPU seconds): 0.01\n",
|
||||||
|
"Time (Wallclock seconds): 0.01\n",
|
||||||
|
"\n",
|
||||||
|
"Total time (CPU seconds): 0.01 (Wallclock seconds): 0.02\n",
|
||||||
|
"\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"using Cbc\n",
|
||||||
|
"using JuMP\n",
|
||||||
|
"\n",
|
||||||
|
"# data\n",
|
||||||
|
"N = 4\n",
|
||||||
|
"M = [\n",
|
||||||
|
" 1 2 3 4\n",
|
||||||
|
" 2 3 1 4\n",
|
||||||
|
" 2 1 3 4\n",
|
||||||
|
" 4 2 3 1\n",
|
||||||
|
"]\n",
|
||||||
|
"\n",
|
||||||
|
"# set optimizer\n",
|
||||||
|
"model = Model(Cbc.Optimizer)\n",
|
||||||
|
"\n",
|
||||||
|
"# define variables\n",
|
||||||
|
"@variable(model, perm[1:N, 1:N], binary=true)\n",
|
||||||
|
"\n",
|
||||||
|
"# define objective function\n",
|
||||||
|
"@objective(model, Min, sum(M[i, j] * perm[i, j] for i = 1:N for j = 1:N))\n",
|
||||||
|
"\n",
|
||||||
|
"# define constraints\n",
|
||||||
|
"for i = 1:N\n",
|
||||||
|
" @constraint(model, sum(perm[i, j] for j = 1:N) == 1)\n",
|
||||||
|
" @constraint(model, sum(perm[j, i] for j = 1:N) == 1)\n",
|
||||||
|
"end\n",
|
||||||
|
"\n",
|
||||||
|
"println(model)\n",
|
||||||
|
"\n",
|
||||||
|
"# run optimization\n",
|
||||||
|
"optimize!(model)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 13,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"Solution obtenue:\n"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"1.0 0.0 0.0 0.0 \n",
|
||||||
|
"0.0 0.0 1.0 0.0 \n",
|
||||||
|
"0.0 1.0 0.0 0.0 \n",
|
||||||
|
"0.0 0.0 0.0 1.0 \n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"# print solution\n",
|
||||||
|
"println(\"Solution obtenue:\")\n",
|
||||||
|
"for i in 1:N\n",
|
||||||
|
" for j in 1:N \n",
|
||||||
|
" print(\"$(value(perm[i,j])) \")\n",
|
||||||
|
" end\n",
|
||||||
|
" println()\n",
|
||||||
|
"end"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"metadata": {
|
||||||
|
"kernelspec": {
|
||||||
|
"display_name": "Julia 1.6.3",
|
||||||
|
"language": "julia",
|
||||||
|
"name": "julia-1.6"
|
||||||
|
},
|
||||||
|
"language_info": {
|
||||||
|
"file_extension": ".jl",
|
||||||
|
"mimetype": "application/julia",
|
||||||
|
"name": "julia",
|
||||||
|
"version": "1.6.3"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nbformat": 4,
|
||||||
|
"nbformat_minor": 4
|
||||||
|
}
|
Loading…
Reference in a new issue