|
JuMP(“Julia for Mathematical Programming”)是一种嵌入在 Julia 中的开源建模语言。
该项目(以及 MathJax等项目)由 NumFOCUS 赞助。NumFOCUS 将再次申请作为 Google Summer of Code 2022 的伞式指导组织。NumFOCUS 支持和推广世界级的创新开源科学软件。
An example
Here's the problem:\begin{aligned}
& \min & 12x + 20y \\
& \;\;\text{s.t.} & 6x + 8y \geq 100 \\
& & 7x + 12y \geq 120 \\
& & x \geq 0 \\
& & y \in [0, 3] \\
\end{aligned}And here's the code to solve this problem:
julia> using JuMP
julia> using HiGHS
julia> model = Model(HiGHS.Optimizer)
A JuMP Model
Feasibility problem with:
Variables: 0
Model mode: AUTOMATIC
CachingOptimizer state: EMPTY_OPTIMIZER
Solver name: HiGHS
julia> @variable(model, x >= 0)
x
julia> @variable(model, 0 <= y <= 3)
y
julia> @objective(model, Min, 12x + 20y)
12 x + 20 y
julia> @constraint(model, c1, 6x + 8y >= 100)
c1 : 6 x + 8 y ≥ 100.0
julia> @constraint(model, c2, 7x + 12y >= 120)
c2 : 7 x + 12 y ≥ 120.0
julia> print(model)
Min 12 x + 20 y
Subject to
c1 : 6 x + 8 y ≥ 100.0
c2 : 7 x + 12 y ≥ 120.0
x ≥ 0.0
y ≥ 0.0
y ≤ 3.0
julia> optimize!(model)
Running HiGHS 1.5.1 [date: 1970-01-01, git hash: 93f1876e4]
Copyright (c) 2023 HiGHS under MIT licence terms
Presolving model
2 rows, 2 cols, 4 nonzeros
2 rows, 2 cols, 4 nonzeros
Presolve : Reductions: rows 2(-0); columns 2(-0); elements 4(-0) - Not reduced
Problem not reduced by presolve: solving the LP
Using EKK dual simplex solver - serial
Iteration Objective Infeasibilities num(sum)
0 0.0000000000e+00 Pr: 2(220) 0s
2 2.0500000000e+02 Pr: 0(0) 0s
Model status : Optimal
Simplex iterations: 2
Objective value : 2.0500000000e+02
HiGHS run time : 0.00
julia> termination_status(model)
OPTIMAL::TerminationStatusCode = 1
julia> primal_status(model)
FEASIBLE_POINT::ResultStatusCode = 1
julia> dual_status(model)
FEASIBLE_POINT::ResultStatusCode = 1
julia> objective_value(model)
204.99999999999997
julia> value(x)
15.000000000000005
julia> value(y)
1.249999999999996
julia> shadow_price(c1)
-0.24999999999999922
julia> shadow_price(c2)
-1.5000000000000007 |
|