### A Pluto.jl notebook ### # v0.14.5 using Markdown using InteractiveUtils # ╔═╡ 4c940f40-71d0-11eb-29ed-8fdad115d814 using JuMP, GLPK # ╔═╡ 9699c0f0-6a0d-11eb-0fa0-2f6ac3a92e93 md"### Tutorial for JuMP The exercise is from [the web](https://people.iee.ihu.gr/~vkostogl/en/files/Educational%20material/SGGW_2016/Linear%20Programming_exercises.pdf). A company manufactures 3 products a, b and c, which sells € 14, €15 and € 22 per unit respectively. These prices are constant and independent of the market state they are addressed to, and it is also supposed that any produced quantity can be sold. For the manufacturing of these products four types of raw materials are required. The prices of raw materials, the raw material units needed for each product type and the corresponding available quantities within a certain time period are included in the following table. Raw material | Unit price | Product a | Product b | Product c | Avaialble raw material units :-------: | :---------------: | :--------: | :--------: | :--------: | :--------: 1|3|0|2|3|50 2|2|3|2|1|200 3|0.5|4|4|6|200 4|1|0|0|2|100 The company's goal is **to determine the quantities of each product which should be produced in order to achieve the highest profit**. Define the corresponding optimization problem and solve the problem using JuMP and an optimization solver (e.g. GLPK). ------------ " # ╔═╡ 21ab39f0-6a11-11eb-01d9-e75bd3ffbe14 md" ##### If you are new to programming / Julia, basic syntax avaialbe in [here](https://htmlpreview.github.io/?https://github.com/mitmath/18S191/blob/Fall20/lecture_notebooks/Basic%20Julia%20syntax.html) and [here](https://juliadocs.github.io/Julia-Cheat-Sheet/) would be helpful." # ╔═╡ 39ac43b0-71cc-11eb-0e1c-01fd18d3a366 md"--- #### IP formulation **Parameters** -$P : \text{The set of products}$ -$R : \text{The set of raw materials}$ -$p_i : \text{Price of product } i,~\forall i\in P$ -$c_j : \text{Price of raw material } j,~\forall j\in R$ -$r_j : \text{Available units of raw material } j,~\forall j\in R$ -$q_{ij} : \text{Quantity of raw material } j \text{ to produce product } i,~\forall i\in P,~j\in R$ **Decision variables** -$X_i : \text{Product quantity of product }i, ~\forall i \in P$ **IP model** $\max \sum_{i \in P}{p_i \cdot X_i} - \sum_{i \in P}\sum_{j \in R}{c_j \cdot q_{ij}\cdot X_i}$ subject to $\sum_{i \in P}{q_{ij}\cdot X_i} \leq r_j \quad \forall j \in R$ $X_i \in \mathbb{Z}^+ \quad \forall i \in P$ " # ╔═╡ bbf6d6d0-71ce-11eb-308a-71f8b97e17e0 function My_optimization_problem() # problem data P = 1:3 # 1 = A, 2 = B, 3 = C R = 1:4 p = [14, 15, 22] c = [3, 2, 0.5, 1] q = [[0, 3, 4, 0]'; [2,2,4,0]'; [3,1,6,2]'] r = [50,200,200,100] # Define a model and assign an optimizer model = Model() set_optimizer(model, GLPK.Optimizer) # Decision variables @variable(model, 0<= X[i in P], Int) # "Int" : Integer decision variables, "Bin" : Binary decision variables # Objective function @objective(model, Max, sum(p[i]*X[i] for i in P) - sum(c[j]*q[i,j]*X[i] for i in P, j in R)) # Constraints @constraint(model, [j in R], sum(q[i,j]*X[i] for i in P) <= r[j]) return model end # ╔═╡ 95f6ae40-71d0-11eb-354c-e74b62f8554a begin model = My_optimization_problem() optimize!(model) end # ╔═╡ d5b88550-71d3-11eb-23a7-df27354ccd7c termination_status(model) # ╔═╡ 8f3ca0a0-71d5-11eb-241c-17f7fb7fed18 md" We can maximize the profit as much as **$(objective_value(model))** by producing **$(value(model[:X][1]))** units of product A, **$(value(model[:X][2]))** units of product B, and **$(value(model[:X][3]))** units of product C. " # ╔═╡ Cell order: # ╟─9699c0f0-6a0d-11eb-0fa0-2f6ac3a92e93 # ╟─21ab39f0-6a11-11eb-01d9-e75bd3ffbe14 # ╟─39ac43b0-71cc-11eb-0e1c-01fd18d3a366 # ╠═4c940f40-71d0-11eb-29ed-8fdad115d814 # ╠═bbf6d6d0-71ce-11eb-308a-71f8b97e17e0 # ╠═95f6ae40-71d0-11eb-354c-e74b62f8554a # ╠═d5b88550-71d3-11eb-23a7-df27354ccd7c # ╠═8f3ca0a0-71d5-11eb-241c-17f7fb7fed18