您的位置:首页 > 游戏 > 手游 > 小程序搭建赚钱是真的吗_企业外贸网站建设方案_百度快照怎么用_青岛seo代理计费

小程序搭建赚钱是真的吗_企业外贸网站建设方案_百度快照怎么用_青岛seo代理计费

2024/12/22 4:26:55 来源:https://blog.csdn.net/serpenttom/article/details/144194289  浏览:    关键词:小程序搭建赚钱是真的吗_企业外贸网站建设方案_百度快照怎么用_青岛seo代理计费
小程序搭建赚钱是真的吗_企业外贸网站建设方案_百度快照怎么用_青岛seo代理计费

线性规划模型

线性规划是起源最早, 使用最为广泛的数学规划模型,

min ⁡ x ∈ R n ∑ i = 1 n c i x i s.t. l j ≤ ∑ i = 1 n a i j x i ≤ u j j = 1 … m l i ≤ x i ≤ u i i = 1 + m … n . \begin{aligned} \min_{x \in \mathbb{R}^n} & \sum\limits_{i=1}^n c_i x_i \\ \;\;\text{s.t.} & l_j \le \sum\limits_{i=1}^n a_{ij} x_i \le u_j & j = 1 \ldots m \\ & l_i \le x_i \le u_i & i = 1+m \ldots n.\end{aligned} xRnmins.t.i=1ncixilji=1naijxiujlixiuij=1mi=1+mn.

[JuMP] 02 线性规划以及灵敏度分析

例子

using JuMP; import HiGHS; import DataFrames
model = Model(HiGHS.Optimizer)
# 变量
@variable(model, x >= 0); @variable(model, 0 <= y <= 3);@variable(model, z <= 1)  
# 目标函数
@objective(model, Min, 12x + 20y - z)
# 约束
@constraint(model, c1, 6x + 8y >= 100)
@constraint(model, c2, 7x + 12y >= 120)
@constraint(model, c3, x + y <= 20)
# 打印模型
print(model)

min ⁡ 12 x + 20 y − z S u b j e c t t o 6 x + 8 y ≥ 100.0 7 x + 12 y ≥ 120.0 x + y ≤ 20.0 x ≥ 0.0 y ≥ 0.0 y ≤ 3.0 z ≤ 1.0 \begin{aligned} \min ~& 12x+20y−z\\ \mathrm{Subject~to} ~ &6x+8y≥100.0\\ &7x+12y≥120.0\\ &x+y≤20.0\\ &x≥0.0\\ &y≥0.0\\ &y≤3.0\\ &z≤1.0 \end{aligned} min Subject to 12x+20yz6x+8y100.07x+12y120.0x+y20.0x0.0y0.0y3.0z1.0

#  求解
optimize!(model)
solution_summary(model; verbose = true)  # 汇总主要信息

线性规划灵敏性分析

report = lp_sensitivity_report(model)
function variable_report(xi)return (name = name(xi),   # 变量名lower_bound = has_lower_bound(xi) ? lower_bound(xi) : -Inf,  #下界value = value(xi),  # 数值解upper_bound = has_upper_bound(xi) ? upper_bound(xi) : Inf, # 上界reduced_cost = reduced_cost(xi),  # 降低成本, 等价于有效变量的影子价格obj_coefficient = coefficient(objective_function(model), xi),  # 目标函数的线性系数# 目标函数系数的变化范围, 保持基底最优性  allowed_decrease = report[xi][1], # 允许减少allowed_increase = report[xi][2], # 允许增长)
end
variable_report(x)
variable_df =  DataFrames.DataFrame(variable_report(xi) for xi in all_variables(model))
namelower_boundvalueupper_boundreduced_costobj_coefficientallowed_decrease
StringFloat64Float64Float64Float64Float64Float64
1x0.015.0Inf0.012.0
2y0.01.253.00.020.0
3z-Inf1.01.0-1.0-1.0

约束集合灵敏性

function constraint_report(ci)return (name = name(ci),  # 变量名value = value(ci),  # 约束左侧值rhs = normalized_rhs(ci),  # 约束右侧值slack = normalized_rhs(ci) - value(ci),shadow_price = shadow_price(ci), # 影子价格allowed_decrease = report[ci][1], # 基底最优性 allowed_increase = report[ci][2], # 基底最优性 )
end
c1_report = constraint_report(c1)
constraint_df = DataFrames.DataFrame(constraint_report(ci) for (F, S) in list_of_constraint_types(model) for ci in all_constraints(model, F, S) if F == AffExpr
)
namevaluerhsslackshadow_priceallowed_decreaseallowed_increase
StringFloat64Float64Float64Float64Float64Float64
1c1100.0100.00.0-0.25-4.0
2c2120.0120.00.0-1.5-3.33333
3c316.2520.03.750.0-3.75

分析问题

basic = filter(row -> iszero(row.reduced_cost), variable_df)  # 过滤等号成立的变量
namelower_boundvalueupper_boundreduced_costobj_coefficientallowed_decrease
StringFloat64Float64Float64Float64Float64Float64
1x0.015.0Inf0.012.0
2y0.01.253.00.020.0
non_basic = filter(row -> !iszero(row.reduced_cost), variable_df)  # 过滤等号不成立的变量
binding = filter(row -> iszero(row.slack), constraint_df)  # 过滤等号成立的约束条件
binding2 = filter(row -> !iszero(row.shadow_price), constraint_df)#  过滤等号不成立的约束条件

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com