Skip to main content

  | मौसम…

411 समाचार
Public archive edition · Attributed source reporting with original dates · AI drafts are excluded

411 REFERENCE · Wikibooks

Scientific Calculations with Julia/Cost Minimization

Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.

Scientific Calculations with Julia Cost Minimization Profit Maximization Shortest Path Cost minimization is a classic example of linear programming that in its standard form is expressed in three parts: A linear function to be minimized: Constraint problem of the following form: Non-negative variables The problem is usually expressed in matrix form as follows: Example calculation with Julia A company needs three types of wood units x1, x2, x3 to produce chairs, which cost €10, €20, and €5, respectively. Type 1 and 2 units must be more than 300, type 2 units more than 100, and type 1 and 3 units more than 300. Therefore, the model to analyze is as follows: First, install the JuMP and HiGHS packages. From the REPL, type: using Pkg Pkg.add("JuMP") Pkg.add("HiGHS") From Jupyter, in two code cells, type: ] add HiGHS ] add JuMP And then click Run. Then run the code to create the linear programming model: using JuMP using HiGHS model = Model(HiGHS.Optimizer) @variable(model, x1 >= 0) @variable(model, x2 >= 0) @variable(model, x3 >= 0) @objective(model, Min, 10*x1 +20*x2+ 5*x3) @constraint(model, c1, x1+x2>=300) @constraint(model, c2, x2>=100) @constraint(model, c3, x1+x3>=300) print(model) optimize!(model) min 10𝑥1+20𝑥2+5𝑥3 Subject to 𝑥1+𝑥2≥300 𝑥2≥100 𝑥1+𝑥3≥300 𝑥1≥0 𝑥2≥0 𝑥3≥0 Running HiGHS 1.5.3 [date: 1970-01-01, git hash: 45a127b78] Copyright (c) 2023 HiGHS under MIT licence terms Presolving model 2 rows, 2 cols, 3 nonzeros 0 rows, 0 cols, 0 nonzeros Presolve : Reductions: rows 0(-3); columns 0(-3); elements 0(-5) - Reduced to empty Solving the original LP from the solution after postsolve Model status : Optimal Objective value : 4.5000000000e+03 HiGHS run time : 0.00 println("termination_status = ",termination_status(model)) println("primal_status = ",primal_status(model)) println("dual_status = ",dual_status(model)) println("objective_value = ",objective_value(model)) println("x1 = ",value(x1)) println("x2 = ",value(x2)) println("x3 = ",value(x3)) println("c1 = ",shadow_price(c1)) println("c2 = ",shadow_price(c2)) println("c3 = ",shadow_price(c3)) termination_status = OPTIMAL primal_status = FEASIBLE_POINT dual_status = FEASIBLE_POINT objective_value = 4500.0 x1 = 200.0 x2 = 100.0 x3 = 100.0 c1 = -5.0 c2 = -15.0 c3 = -5.0 That is, the company has a minimum cost of €4500, purchasing 200 units of type 1 wood, 100 units of type 2 wood, and 100 units of type 3 wood to produce the chairs, satisfying the indicated constraints.