TP-recherche-operationnelle/TP1/exo1/voitures.ipynb

187 lines
6.8 KiB
Plaintext
Raw Normal View History

2021-11-23 21:56:53 +00:00
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Exemple de modèle et résolution du problème de Fabrication du voitures"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"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": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Max 10000 voitures[1] + 9000 voitures[2]\n",
"Subject to\n",
" 10 voitures[1] + 20 voitures[2] ≤ 15000.0\n",
" 6 voitures[1] + 5 voitures[2] ≤ 6000.0\n",
" voitures[1] ≤ 800.0\n",
" voitures[1] ≥ 0.0\n",
" voitures[2] ≥ 0.0\n",
" voitures[1] integer\n",
" voitures[2] integer\n",
"\n",
"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 1.02857e+07 - 0.00 seconds\n",
"Cgl0004I processed model has 2 rows, 2 columns (2 integer (0 of which binary)) and 4 elements\n",
"Cutoff increment increased from 1e-05 to 1000\n",
"Cbc0012I Integer solution of -10272000 found by DiveCoefficient after 0 iterations and 0 nodes (0.00 seconds)\n",
"Cbc0012I Integer solution of -10284000 found by DiveCoefficient after 3 iterations and 0 nodes (0.01 seconds)\n",
"Cbc0031I 1 added rows had average density of 2\n",
"Cbc0013I At root node, 1 cuts changed objective from -10285714 to -10284000 in 21 passes\n",
"Cbc0014I Cut generator 0 (Probing) - 0 row cuts average 0.0 elements, 47 column cuts (47 active) in 0.001 seconds - new frequency is 1\n",
"Cbc0014I Cut generator 1 (Gomory) - 4 row cuts average 2.0 elements, 0 column cuts (0 active) in 0.001 seconds - new frequency is 1\n",
"Cbc0014I Cut generator 2 (Knapsack) - 0 row cuts average 0.0 elements, 0 column cuts (0 active) in 0.000 seconds - new frequency is -100\n",
"Cbc0014I Cut generator 3 (Clique) - 0 row cuts average 0.0 elements, 0 column cuts (0 active) in 0.000 seconds - new frequency is -100\n",
"Cbc0014I Cut generator 4 (MixedIntegerRounding2) - 0 row cuts average 0.0 elements, 0 column cuts (0 active) in 0.000 seconds - new frequency is -100\n",
"Cbc0014I Cut generator 5 (FlowCover) - 0 row cuts average 0.0 elements, 0 column cuts (0 active) in 0.000 seconds - new frequency is -100\n",
"Cbc0001I Search completed - best objective -10284000, took 3 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 -1.02857e+07 to -1.0284e+07\n",
"Probing was tried 21 times and created 47 cuts of which 0 were active after adding rounds of cuts (0.001 seconds)\n",
"Gomory was tried 21 times and created 4 cuts of which 0 were active after adding rounds of cuts (0.001 seconds)\n",
"Knapsack was tried 21 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)\n",
"Clique was tried 21 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)\n",
"MixedIntegerRounding2 was tried 21 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)\n",
"FlowCover was tried 21 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)\n",
"TwoMirCuts was tried 1 times and created 0 cuts of which 0 were active after adding rounds of cuts (0.000 seconds)\n",
"ZeroHalf was tried 1 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: 10284000.00000000\n",
"Enumerated nodes: 0\n",
"Total iterations: 3\n",
"Time (CPU seconds): 0.01\n",
"Time (Wallclock seconds): 0.01\n",
"\n",
"Total time (CPU seconds): 0.01 (Wallclock seconds): 0.01\n",
"\n"
]
}
],
"source": [
"using Cbc\n",
"using JuMP\n",
"\n",
"# data\n",
"N = 2 # nombre de voitures disponibles\n",
"c = [10000, 9000] # prix de vente par voitures\n",
"b = [15000, 6000, 800] \n",
"A = [10 20 ; 6 5 ; 1 0]\n",
"\n",
"# set optimizer\n",
"model = Model(Cbc.Optimizer)\n",
"\n",
"# define variables\n",
"@variable(model, voitures[1:N] >= 0, integer=true)\n",
"\n",
"# define objective function\n",
"@objective(model, Max, sum(c[i] * voitures[i] for i = 1:N))\n",
"\n",
"# define constraints\n",
"for i = 1:length(b)\n",
" @constraint(model, sum(A[i, j] * voitures[j] for j = 1:N) <= b[i])\n",
"end\n",
"\n",
"println(model)\n",
"\n",
"# run optimization\n",
"optimize!(model)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Solution obtenue:\n",
"\t benefice = 1.0284e7\n",
"\t quantite de voitures 1 = 645.0\n",
"\t quantite de voitures 2 = 426.0\n"
]
}
],
"source": [
"# print solution\n",
"println(\"Solution obtenue:\")\n",
"println(\"\\t benefice = $(objective_value(model))\")\n",
"for i = 1:N\n",
" println(\"\\t quantite de voitures $i = $(value(voitures[i]))\")\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
}