8.1. 属性

以下为使用四种语言分别获取当前属性的示例

Python:

# Obtain model attributes
model.status # case insensitive
model.getAttr("Status")
# Obtain variable attributes
var.X # case insensitive
var.get("X")
# Obtain constraint attributes
constr.lhs # case insensitive
constr.get("LHS")
# Obtain the PSD variable attribute
px.psdx
px.get("PsdX")
# Obtain the PSD constraint attribute
pconstr.psdcname # case insensitive
pconstr.get("PsdCName")

Java:

// Obtain model attributes
// get int attr Status
model.get(MDO.IntAttr.Status);
// get double attr ObjVal
model.get(MDO.DoubleAttr.ObjVal);
// get string attr ModelName
model.get(MDO.StringAttr.ModelName);
// Obtain variable attributes
// get int attr IsInteger
var.get(MDO.IntAttr.IsInteger);
// get double attr Obj
var.get(MDO.DoubleAttr.Obj);
// get string attr VarName
var.get(MDO.StringAttr.VarName);
// Obtain constraint attributes
// get int attr RowBasis
constr.get(MDO.IntAttr.RowBasis);
// get double attr LHS
constr.get(MDO.DoubleAttr.LHS);
// get string attr ConstrName
constr.get(MDO.StringAttr.ConstrName);
// Obtain the PSD variable attribute
// get int attr Dim
px.get(MDO.IntAttr.Dim);
// get matrix attr PsdObj
px.get(MDO.MatAttr.PsdObj);
// get string attr PsdVarName
px.get(MDO.StringAttr.PsdVarName);
// Obtain the PSD constraint attribute
// get double attr PsdCLHS
pconstr.get(MDO.DoubleAttr.PsdCLHS);
// get string attr PsdCName
pconstr.get(MDO.StringAttr.PsdCName);

CPP:

// Obtain model attributes
// get int attr Status
model.get(MDO_IntAttr_Status);
// get double attr ObjVal
model.get(MDO_DoubleAttr_ObjVal);
// get string attr ModelName
model.get(MDO_StringAttr_ModelName);
// Obtain variable attributes
// get int attr IsInteger
var.get(MDO_IntAttr_IsInteger);
// get double attr Obj
var.get(MDO_DoubleAttr_Obj);
// get string attr VarName
var.get(MDO_StringAttr_VarName);
// Obtain constraint attributes
// get int attr RowBasis
constr.get(MDO_IntAttr_RowBasis);
// get double attr LHS
constr.get(MDO_DoubleAttr_LHS);
// get string attr ConstrName
constr.get(MDO_StringAttr_ConstrName);
// Obtain the PSD variable attribute
// get int attr Dim
px.get(MDO_IntAttr_Dim);
// get matrix attr PsdObj
px.get(MDO_MatAttr_PsdObj);
// get string attr PsdVarName
px.get(MDO_StringAttr_PsdVarName);
// Obtain the PSD constraint attribute
// get double attr PsdCLHS
pconstr.get(MDO_DoubleAttr_PsdCLHS);
// get string attr PsdCName
pconstr.get(MDO_StringAttr_PsdCName);

C:

// Obtain model attributes
// get int attr Status
int status;
MDOgetintattr(m, "Status", &status);
// get double attr ObjVal
double obj;
MDOgetdblattr(m, "ObjVal", &obj)
// get string attr ModelName
char* nameget;
MDOgetstrattr(m, "ModelName", &nameget);
// Obtain variable attributes
// i is the index of this variable in this model
// get int attr IsInteger
int isint;
MDOgetintattrelement(m, "IsInteger", i, &isint);
// get double attr X
double x;
MDOgetdblattrelement(m, "X", i, &x);
// get string attr VarName
char* varname;
MDOgetstrattrelement(m, "VarName", i, &varname);
// Obtain constraint attributes
// i is the index of this constraint in this model
// get int attr RowBasis
int rowbasis;
MDOgetintattrelement(m, "RowBasis", i, &rowbasis);
// get double attr LHS
double lhs;
MDOgetdblattrelement(m, "LHS", i, &lhs);
// get string attr ConstrName
char* constrname;
MDOgetstrattrelement(m, "ConstrName", i, &constrname);
// Obtain the PSD variable attribute
// i is the index of this PSD variable in this model
// get int attr Dim
int dim;
MDOgetintattrelement(m, "Dim", i, &dim);
// get matrix attr PsdObj
int nummatnz, rows, cols, *ind;
double *data;
MDOgetmatattrelement(m, "PsdObj", i, &nummatnz, &rows, &cols, NULL, NULL);
ind = (int *)malloc(sizeof(nummatnz));
data = (double *)malloc(sizeof(nummatnz));
MDOgetmatattrelement(m, "PsdObj", i, &nummatnz, &rows, &cols, ind, data);
// get string attr PsdVarName
char* psdvarname;
MDOgetstrattrelement(m, "PsdVarName", i, &psdvarname);
// Obtain the PSD constraint attribute
// i is the index of this PSD variable in this model
// get double attr PsdCLHS
double psdclhs;
MDOgetdblattrelement(m, "PsdCLHS", i, &psdclhs);
// get string attr PsdCName
char* psdcname;
MDOgetstrattrelement(m, "PsdCName", i, &psdcname);

以下为使用四种语言分别修改当前属性的示例

Python:

# Modify model attributes
model.modelname = "DietProblem" # case insensitive
model.setAttr("ModelName", "DietProblem")
# Modify variable attributes
x.lb = -10 # case insensitive
x.setAttr("LB", -10)
# Modify constraint attributes
constr.constrname = "c1" # case insensitive
constr.setAttr("ConstrName", "c1")
# Modify the attributes of the PSD variable.
psdx.psdvarname = "psd1" # case insensitive
psdx.setAttr("PsdVarName", "psd1")
# Modify the PSD constraint properties
psdc.psdcname = "psdconstr1" # case insensitive
psdc.setAttr("PsdCName", "psdconstr1")

Java:

// Modify model attributes
// set int attr ModelSense
model.set(MDO.IntAttr.ModelSense, MDO.MINIMIZE);
// set double attr ObjCon
model.set(MDO.DoubleAttr.ObjCon, 5.0);
// set string attr ModelName
model.set(MDO.StringAttr.ModelName, "diet");
// Modify variable attributes
// set int attr ColBasis
var.set(MDO.IntAttr.ColBasis, 1);
// set double attr Obj
var.set(MDO.DoubleAttr.Obj, 2.0);
// set char attr VType
var.set(MDO.CharAttr.VType, MDO.CONTINUOUS);
// set string attr VarName
var.set(MDO.StringAttr.VarName, "var1");
// Modify constraint attributes
// set int attr RowBasis
constr.set(MDO.IntAttr.RowBasis, 3);
// set double attr LHS
constr.set(MDO.DoubleAttr.LHS, 1.88);
// set string attr ConstrName
constr.set(MDO.StringAttr.ConstrName, "c1");
// Modify the attributes of the PSD variable.
// set matirx attr PsdObj
MDOMatrix c = new MDOMatrix(0, 0, 0, 0,null, null);
psdx.set(MDO.MatAttr.PsdObj, c.full(4, 4, 12));
// set string attr PsdVarName
psdx.set(MDO.StringAttr.PsdVarName, "psd1");
// Modify the PSD constraint properties
// set double attr PsdCLHS
pconstr.set(MDO.DoubleAttr.PsdCLHS, 1.88);
// set string attr PsdCName
pconstr.set(MDO.StringAttr.PsdCName, "pc1");

CPP:

// Modify model attributes
// set int attr ModelSense
model.set(MDO_IntAttr_ModelSense, MDO_MAXIMIZE);
// set double attr ObjVal
model.set(MDO_DoubleAttr_ObjVal, 5.0);
// set string attr ModelName
model.set(MDO_StringAttr_ModelName, "diet");
// Modify variable attributes
// set int attr ColBasis
var.set(MDO_IntAttr_ColBasis, 1);
// set double attr Obj
var.set(MDO_DoubleAttr_Obj, 2.0);
// set char attr VType
var.set(MDO_CharAttr_VType, MDO_CONTINUOUS);
// set string attr VarName
var.set(MDO_StringAttr_VarName, "var1");
// Modify constraint attributes
// set int attr RowBasis
constr.set(MDO_IntAttr_RowBasis, 3);
// set double attr LHS
constr.set(MDO_DoubleAttr_LHS, 1.88);
// set string attr ConstrName
constr.set(MDO_StringAttr_ConstrName, "c1");
// Modify the attributes of the PSD variable.
// set matirx attr PsdObj
MDOMatrix c = new MDOMatrix(0, 0, 0, 0,null, null);
psdx.set(MDO_MatAttr_PsdObj, c.full(4, 4, 12));
// set string attr PsdVarName
psdx.set(MDO_StringAttr_PsdVarName, "psd1");
// Modify the PSD constraint properties
// set double attr PsdCLHS
pconstr.set(MDO_DoubleAttr_PsdCLHS, 1.88);
// set string attr PsdCName
pconstr.set(MDO_StringAttr_PsdCName, "pc1");

C:

// Modify model attributes
// set int attr ModelSense
MDOsetintattr(m, "ModelSense", MDO_MINIMIZE);
// set double attr ObjCon
MDOsetdblattr(m, "ObjCon", 5.0);
// set string attr ModelName
char *mname[20];
sprintf(mname, "diet_problem");
MDOsetstrattr(m, "ModelName", mname);
// Modify variable attributes
// i is the index of this variable in this model
// set int attr ColBasis
MDOsetintattrelement(m, "ColBasis", i, val);
// set double attr Obj
MDOsetdblattrelement(m, "Obj", i, 2.0);
// set char attr VType
MDOsetcharattrelement(m, "VType", i, 'c');
// set string attr VarName
char *varname[20];
sprintf(varname, "var1");
MDOsetstrattrelement(m, "VarName", i, varname);
// Modify constraint attributes
// i is the index of this constraint in this model
// set int attr RowBasis
MDOsetintattrelement(m, "ColBRowBasissis", i, 3);
// set double attr LHS
MDOsetdblattrelement(m, "LHS", i, 2.0);
// set string attr ConstrName
char *cname[20];
sprintf(cname, "constr1");
MDOsetstrattrelement(m, "ConstrName", i, cname);
// Modify the attributes of the PSD variable.
// i is the index of this PSD variable in this model
// set matirx attr PsdObj
int nummatnz, rows, cols, *ind;
double *data;
// allocate memory for these variables and assign values
MDOsetmatattrelement(m, "PsdObj", i, nummatnz, rows, cols, ind, data);
// set string attr PsdVarName
char *pxname[20];
sprintf(pxname, "psdv1");
MDOsetstrattrelement(m, "PsdVarName", i, pxname);
// Modify the PSD constraint properties
// i is the index of this PSD constraint in this model
// set double attr PsdCLHS
MDOsetdblattrelement(m, "MDO_DoubleAttr_PsdCLHS", i, 2.0);
// set string attr PsdCName
char *pcname[20];
sprintf(pcname, "psdc1");
MDOsetstrattrelement(m, "PsdCName", i, pcname);

8.1.1. 模型属性

DualObjVal

double

对偶目标值

HasDualRay

int

指示对偶射线是否可用

HasPrimalRay

int

指示原始射线是否可用

HasSolution

int

指示优化解是否可用

IPM/NumIters

int

内点法总迭代次数

MIP/GapAbs

double

MIP求解GAP的绝对值

MIP/GapRel

double

MIP求解GAP的相对值

MinSense

int

优化问题是否为最小化问题

ModelName

string

当前优化模型的名称

ModelSense

int

目标函数目标方向,1表示最小值,-1表示最大值

NumConss

int

当前优化模型中的约束总数

NumConstrs

int

NumConss的别名

NumEnts

int

当前优化模型中非零元的总数

NumGenConstrs

int

一般约束的总数

NumNZs

int

NumEnts的别名

NumPsdConstrs

int

psd约束的总数

NumPsdVars

int

psd变量的总数

NumSOS

int

模型中特殊有序集 (SOS) 约束的总数

NumVars

int

变量的总数

ObjCon

double

ObjConst的别名

ObjConst

double

目标函数的常量偏移量

ObjVal

double

PrimalObjVal的别名

PresolverTime

double

Presolver执行时间 (秒)

PrimalObjVal

double

原始解决方案的目标函数值

ProbName

string

问题名称

SPX/NumIters

int

单纯形法完成后的总迭代次数

SolutionTime

double

总执行时间 (秒)

SolverTime

double

求解器执行时间 (秒)

Status

int

模型优化后的优化状态

8.1.1.1. DualObjVal

对偶目标值

  • 类型: double

  • 可设置: 否

8.1.1.2. HasDualRay

指示对偶射线是否可用

  • 类型: int

  • 可设置: 否

0

对偶射线不可用

1

对偶射线可用

8.1.1.3. HasPrimalRay

指示原始射线是否可用

  • 类型: int

  • 可设置: 否

0

原始射线不可用

1

原始射线可用

8.1.1.4. HasSolution

指示优化解是否可用

  • 类型: int

  • 可设置: 否

0

解不可用

1

解可用

8.1.1.5. IPM/NumIters

内点法总迭代次数

  • 类型: int

  • 可设置: 否

8.1.1.6. MIP/GapAbs

MIP求解GAP的绝对值

  • 类型: double

  • 可设置: 否

8.1.1.7. MIP/GapRel

MIP求解GAP的相对值

  • 类型: double

  • 可设置: 否

8.1.1.8. MinSense

优化问题是否为最小化问题

  • 类型: int

  • 可设置: 是

0

最大化

1

最小化

8.1.1.9. ModelName

当前优化模型的名称

  • 类型: string

  • 可设置: 是

8.1.1.10. ModelSense

目标函数目标方向,1表示最小值,-1表示最大值

  • 类型: int

  • 可设置: 是

1

最小化

-1

最大化

8.1.1.11. NumConss

当前优化模型中的约束总数

  • 类型: int

  • 可设置: 否

8.1.1.12. NumConstrs

NumConss的别名。约束的总数

  • 类型: int

  • 可设置: 否

8.1.1.13. NumEnts

当前优化模型中非零元的总数

  • 类型: int

  • 可设置: 否

8.1.1.14. NumGenConstrs

一般约束的总数。

  • 类型: int

  • 可设置: 否

8.1.1.15. NumNZs

NumEnts的别名。约束矩阵非零的总数

  • 类型: int

  • 可设置: 否

8.1.1.16. NumPsdConstrs

psd约束的总数

  • 类型: int

  • 可设置: 否

8.1.1.17. NumPsdVars

psd变量的总数

  • 类型: int

  • 可设置: 否

8.1.1.18. NumSOS

模型中特殊有序集 (SOS) 约束的总数

  • 类型: int

  • 可设置: 否

8.1.1.19. NumVars

变量的总数

  • 类型: int

  • 可设置: 否

8.1.1.20. ObjCon

ObjConst的别名。目标函数的常数偏移量

  • 类型: double

  • 可设置: 是

8.1.1.21. ObjConst

目标函数的常量偏移量

  • 类型: double

  • 可设置: 是

8.1.1.22. ObjVal

PrimalObjVal的别名。原始解决方案的目标函数值

  • 类型: double

  • 可设置: 否

8.1.1.23. PresolverTime

Presolver执行时间 (秒)

  • 类型: double

  • 可设置: 否

8.1.1.24. PrimalObjVal

原始解决方案的目标函数值

  • 类型: double

  • 可设置: 否

8.1.1.25. ProbName

问题名称

  • 类型: string

  • 可设置: 是

8.1.1.26. SPX/NumIters

单纯形法完成后的总迭代次数

  • 类型: int

  • 可设置: 否

8.1.1.27. SolutionTime

总执行时间 (秒)

  • 类型: double

  • 可设置: 否

8.1.1.28. SolverTime

求解器执行时间 (秒)

  • 类型: double

  • 可设置: 否

8.1.1.29. Status

模型优化后的优化状态

  • 类型: int

  • 可设置: 否

8.1.2. 变量属性

ColBasis

int

原始解的基

ColName

string

变量名称

IISCol

int

IISVar的别名,用于测试该变量的上界和 (或) 下界是否属于IIS

IISVar

int

指示该变量的上界和 (或) 下界是否属于IIS

IsInteger

int

如果变量是整型

LB

double

变量的下界

Obj

double

变量在约束矩阵里的系数

PrimalSoln

double

原始问题的解

RC

double

ReducedCost的别名

ReducedCost

double

降低的成本

Start

double

当前MIP起始向量

UB

double

变量的上界

VType

char

变量类型

VarName

string

ColName的别名,变量名称

X

double

PrimalSoln的别名

8.1.2.1. ColBasis

原始解的基

  • 类型: int

  • 可设置: 是

0

isFree

1

basic

2

atUpperBound

3

atLowerBound

4

superBasic

5

isFixed

8.1.2.2. ColName

变量名称

  • 类型: string

  • 可设置: 是

8.1.2.3. IISCol

IISVar的别名,用于测试该变量的上界和 (或) 下界是否属于IIS

  • 类型: int

  • 可设置: 否

8.1.2.4. IISVar

指示该变量的上界和 (或) 下界是否属于IIS

  • 类型: int

  • 可设置: 否

2

变量的上界属于IIS

3

变量的下界属于IIS

5

变量是固定值的(上界等于下界),它的值属于IIS

6

变量的任何边界都不属于IIS

8.1.2.5. IsInteger

如果变量是整型

  • 类型: int

  • 可设置: 是

0

连续变量类型

1

整数变量类型

8.1.2.6. LB

变量的下界

  • 类型: double

  • 可设置: 是

8.1.2.7. Obj

变量在约束矩阵里的系数

  • 类型: double

  • 可设置: 是

8.1.2.8. PrimalSoln

原始问题的解

  • 类型: double

  • 可设置: 否

8.1.2.9. RC

ReducedCost的别名。指降低的成本

  • 类型: double

  • 可设置: 否

8.1.2.10. ReducedCost

降低的成本

  • 类型: double

  • 可设置: 否

8.1.2.11. Start

当前MIP起始向量

  • 类型: double

  • 可设置: 是

8.1.2.12. UB

变量的上界

  • 类型: double

  • 可设置: 是

8.1.2.13. VType

变量类型

  • 类型: char

  • 可设置: 是

8.1.2.14. VarName

ColName的别名,变量名称

  • 类型: string

  • 可设置: 是

8.1.2.15. X

PrimalSoln的别名。原始问题的解

  • 类型: double

  • 可设置: 否

8.1.3. 约束属性

Activity

double

用于查询当前 PrimalActivity 中的值

ConstrName

string

RowName的别名

DualSoln

double

对偶解

IISConstr

int

指示该约束的左侧值和 (或) 右侧值是否属于IIS

IISRow

int

IISConstr的别名,用于测试该约束的左侧值和 (或) 右侧值是否属于IIS

LHS

double

约束的左侧值

RHS

double

约束的右侧值

RowBasis

int

对偶解的基

RowName

string

约束名称

8.1.3.1. Activity

用于查询当前 PrimalActivity 中的值

  • 类型: double

  • 可设置: 否

8.1.3.2. ConstrName

RowName的别名。约束名称

  • 类型: string

  • 可设置: 是

8.1.3.3. DualSoln

对偶解

  • 类型: double

  • 可设置: 否

8.1.3.4. IISConstr

指示该约束的左侧值和 (或) 右侧值是否属于IIS

  • 类型: int

  • 可设置: 否

2

约束的右值属于IIS

3

约束的左值属于IIS

5

约束是等值约束(左右值相等),它的固定值属于IIS

6

约束的左右边界都不属于IIS

8.1.3.5. IISRow

IISConstr的别名,用于测试该约束的左侧值和 (或) 右侧值是否属于IIS

  • 类型: int

  • 可设置: 否

8.1.3.6. LHS

约束的左侧值

  • 类型: double

  • 可设置: 是

8.1.3.7. RHS

约束的右侧值

  • 类型: double

  • 可设置: 是

8.1.3.8. RowBasis

对偶解的基

  • 类型: int

  • 可设置: 是

0

isFree

1

basic

2

atUpperBound

3

atLowerBound

4

superBasic

5

isFixed

8.1.3.9. RowName

约束名称

  • 类型: string

  • 可设置: 是

8.1.4. 一般约束属性

GenConstrName

string

一般约束的名称

GenConstrType

int

一般约束的类型

8.1.4.1. GenConstrName

一般约束的名称

  • 类型: string

  • 可设置: 是

8.1.4.2. GenConstrType

一般约束的类型

  • 类型: int

  • 可设置: 否

6

Indicator约束

8.1.5. PSD变量属性

Dim

int

psd变量的维数

PsdObj

matrix

psd变量的目标系数

PsdVarName

string

psd变量名称

PsdX

matrix

原始问题中psd变量的求解

8.1.5.1. Dim

psd变量的维数

  • 类型: int

  • 可设置: 否

8.1.5.2. PsdObj

psd变量的目标系数

  • 类型: matrix

  • 可设置: 是

8.1.5.3. PsdVarName

psd变量名称

  • 类型: string

  • 可设置: 是

8.1.5.4. PsdX

原始问题中psd变量的求解

  • 类型: matrix

  • 可设置: 否

8.1.6. PSD约束属性

PsdCLHS

double

psd约束的左侧值

PsdCName

string

psd约束名称

PsdCRHS

double

psd约束右侧值

8.1.6.1. PsdCLHS

psd约束的左侧值

  • 类型: double

  • 可设置: 是

8.1.6.2. PsdCName

psd约束名称

  • 类型: string

  • 可设置: 是

8.1.6.3. PsdCRHS

psd约束右侧值

  • 类型: double

  • 可设置: 是