当前位置:网站首页>gurobi解的状态及其属性获取
gurobi解的状态及其属性获取
2022-06-10 00:19:00 【云湖在成长】
根据之前的文章线性规划和对偶规划学习总结,我们知道,解有三种状态:
1.无解;
2.有界解;
3.无界解。
在gurobi中,可以通过提取状态,知道模型状态。也就是利用对偶理论可以知道当前模型解的可能情况。
(1)获取解的状态
model.status
可能的取值如上所示。status==2,代表最优;status==3,代表无可行解;status==5,为无界解。刚好与最上边的三种状态对应。
(2)获取对应属性信息
a)最优,可以直接获取变量及其约束所对应的对偶变量值(也叫影子价格)
#获取变量的值
for v in model.getVars():
print(v.varName, '=', v.x)
# 获取对偶变量的值,与约束相关
model.getAttr(grb.GRB.Attr.Pi, model.getConstrs())
或者可以写成循环形式
for con in model.getConstrs(): #循环获取
print(con.ConstrName, '----', con.Pi)b)无解,可以获取约束的极射线
for con in model.getConstrs():
print(con.ConstrName, '----', con.FarkasDual)c)无界,可以获取无界射线
仅仅适用于无界线性模型,可以提供一个向量,当添加到任何可行解时,该向量将生成一个新的可行解,但会改进目标。
model.getAttr(grb.GRB.Attr.UnbdRay)注意,后两种情况,必须在model.optimize()之前设定,model.setParam('InfUnbdInfo', 1) 。
边栏推荐
- MySql事务
- Reading and saving TIF format raster image in MATLAB
- 采云端&采云链:从订单协同到采购供应链,让采购供应链互联互通
- Blue Bridge Cup · winter vacation hundred schools' real topic league tournament (Phase V) real topic exercise of cargo placement for graduate students and university group A
- Transformer
- Manjaro kconsole turns on translucency
- Win10 how to delete an account
- 浅谈Cookie 和 Session——含案例及详细注解
- BGP总结
- Illustration Google V8 06: prototype chain: how does V8 implement object inheritance?
猜你喜欢

Collection backup | summary of some common problems about oauth2

最低通行费

Syntaxe des points d'interrogation doubles, syntaxe des barres verticales doubles et syntaxe des chaînes optionnelles pour l'attribution logique de l'espace JS

慢查询如何优化?(实战慢查询)

Sentinel-3 data introduction

wps怎么合并大小不一致的单元格

Minimum toll

Enterprise worry free | apipost privatization deployment activity is about to start

Go Technology Daily (June 8, 2022) -- talk about 10 scenarios of index failure. It's too stupid

收藏备用 | 关于OAuth2的一些常见问题总结
随机推荐
PTP授时服务器(NTP网络时间服务器)技术方案应用
力扣 旋转字符串 C语言 题解
OSPF实验
Solution to C language problems of force buckle rotation string
rip实验
[typecho]some problems in SQL programming
试题 历届真题 成绩分析【第十一届】【省赛】【B组】
ECA-Net: Efficient Channel Attention for Deep Convolutional Neural Networks
46 year old new academician: when I was a graduate student, I unloaded all the Games
工藤正男:如何一年发表5篇SCI
if判断是否为空时的函数选择
BP neural network inversion of water quality parameters based on MATLAB
Benders decompositon学习笔记记录
Cloudcompare & PCL principal curvature, mean curvature and Gaussian curvature calculation
Syntaxe des points d'interrogation doubles, syntaxe des barres verticales doubles et syntaxe des chaînes optionnelles pour l'attribution logique de l'espace JS
Score of sub series of previous test questions and [11th] [provincial competition] [group B]
IDC fait autorité pour prédire que l'industrie manufacturière chinoise est sur le point de monter dans le nuage
Pop up frequently: an error occurred when vscode tried to create a file in the target directory. Try again. Skip this file and close setup
Binary search (half search) summary
德国乌尔姆大学 | 3D蛋白结构的对比表征学习