TP-recherche-operationnelle/exemple/solution_ciment.ipynb
2021-11-23 22:56:53 +01:00

149 lines
3.7 KiB
Plaintext

{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Exemple de modèle et résolution du problème de Fabrication du ciment"
]
},
{
"cell_type": "code",
"execution_count": 7,
"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": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Max 50 ciment[1] + 70 ciment[2]\n",
"Subject to\n",
" 40 ciment[1] + 12 ciment[2] ≤ 360.0\n",
" 20 ciment[1] + 30 ciment[2] ≤ 480.0\n",
" ciment[1] ≥ 0.0\n",
" ciment[2] ≥ 0.0\n",
"\n",
"Presolve 2 (0) rows, 2 (0) columns and 4 (0) elements\n",
"0 Obj -0 Dual inf 120 (2)\n",
"2 Obj 1137.5\n",
"Optimal - objective value 1137.5\n",
"Optimal objective 1137.5 - 2 iterations time 0.002\n"
]
}
],
"source": [
"using Cbc\n",
"using JuMP\n",
"\n",
"# data\n",
"N = 2 # nombre de ciments disponibles\n",
"c = [50,70] # prix de vente par ciment\n",
"b = [360,480] # temps de disponibilité du four et de l'atelier\n",
"A = [40 12;20 30] # temps nécessaire de calcination (four) et de broyage (atelier) par ciment\n",
"\n",
"# set optimizer\n",
"model = Model(Cbc.Optimizer)\n",
"\n",
"# define variables\n",
"@variable(model, ciment[1:N] >= 0)\n",
"\n",
"# define objective function\n",
"@objective(model, Max, sum(c[i]*ciment[i] for i in 1:N))\n",
"\n",
"# define constraints\n",
"for i in 1:length(b)\n",
" @constraint(model, sum(A[i,j]*ciment[j] for j in 1:N) <= b[i])\n",
"end\n",
"\n",
"println(model)\n",
"\n",
"# run optimization\n",
"optimize!(model)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Solution obtenue:\n",
"\t benefice = 1137.5\n",
"\t quantite de ciment 1 = 5.249999999999999\n",
"\t quantite de ciment 2 = 12.5\n"
]
}
],
"source": [
"# print solution\n",
"println(\"Solution obtenue:\")\n",
"println(\"\\t benefice = $(objective_value(model))\")\n",
"for i in 1:N\n",
" println(\"\\t quantite de ciment $i = $(value(ciment[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
}