8.7.2. 解属性

C API对应参数接口参考

参数

说明

MDO_REAL_ATTR_SOLUTION_TIME

“SolutionTime”

求解总时间(以秒为单位)

MDO_REAL_ATTR_PRESOLVER_TIME

“PresolverTime”

Presolve处理时间(以秒为单位)

MDO_REAL_ATTR_SOLVER_TIME

“SolverTime”

核心求解模块处理时间(以秒为单位)

MDO_INT_ATTR_HAS_SOLUTION

“HasSolution”

指示优化解是否可用

MDO_INT_ATTR_HAS_PRIMAL_RAY

“HasPrimalRay”

指示原始射线是否可用

MDO_INT_ATTR_HAS_DUAL_RAY

“HasDualRay”

指示对偶射线是否可用

MDO_REAL_ATTR_PRIMAL_OBJ_VAL

“PrimalObjVal”

原始目标值

MDO_REAL_ATTR_DUAL_OBJ_VAL

“DualObjVal”

对偶目标值

MDO_REAL_ATTR_PRIMAL_SOLN

“PrimalSoln”

原始解

MDO_REAL_ATTR_DUAL_SOLN

“DualSoln”

对偶解

MDO_INT_ATTR_COL_BASIS

“ColBasis”

原始解的基

MDO_INT_ATTR_ROW_BASIS

“RowBasis”

对偶解的基

MDO_REAL_ATTR_ACTIVITY

“Activity”

Primal activity 的值

MDO_REAL_ATTR_REDUCED_COST

“ReducedCost”

Reduced costs 的值

MDO_REAL_ATTR_SYM_MAT_PRIMAL_SOLN

“SymMatPrimalSoln”

原始块变量的值

MDO_REAL_ATTR_MIP_GAP_ABS

“MIP/GapAbs”

MIP解GAP的绝对值。

MDO_REAL_ATTR_MIP_GAP_REL

“MIP/GapRel”

MIP解GAP的相对值。

Note

需要注意的是,若在求解之后对优化模型进行任何改变,则解属性的相关信息将被全部清空,此时需要重新进行求解以获得新的模型的解属性。C++、Java、Python的参数API在 MDO_INT_PARAM 的namespace里,可参见 属性的别名 章节。

8.7.2.1. “SolutionTime”

此属性用于查询优化求解使用的总时间(以秒为单位)

  • Group: Solution

  • Type: Real

  • Modifiable: No

示例

C

Mdo_getRealAttr(model, "SolutionTime", &solution_time);

C++

solution_time = model.getRealAttr("SolutionTime");

Python

solution_time = model.get_real_attr("SolutionTime")

8.7.2.2. “PresolverTime”

此属性用于查询优化的Presolve处理时间(以秒为单位)

  • Group: Solution

  • Type: Real

  • Modifiable: No

示例

C

Mdo_getRealAttr(model, "PresolverTime", &presolve_time);

C++

presolve_time = model.getRealAttr("PresolverTime");

Python

presolve_time = model.get_real_attr("PresolverTime")

8.7.2.3. “SolverTime”

此属性用于查询优化的核心求解模块处理时间(以秒为单位)

  • Group: Solution

  • Type: Real

  • Modifiable: No

示例

C

Mdo_getRealAttr(model, "SolverTime", &solver_time);

C++

solver_time = model.getRealAttr("SolverTime");

Python

solver_time = model.get_real_attr("SolverTime")

8.7.2.4. “HasSolution”

此属性用于查询优化解是否可用

  • Group: Solution

  • Type: Integer

  • Modifiable: No

选项

说明

0

解不可用

1

解可用

示例

C

Mdo_getIntAttr(model, "HasSolution", &has_solution);

C++

has_solution = model.getIntAttr("HasSolution");

Python

has_solution = model.get_int_attr("HasSolution")

8.7.2.5. “HasPrimalRay”

此属性用于查询原始射线是否可用。

  • Group: Solution

  • Type: Integer

  • Modifiable: No

选项

说明

0

原始射线不可用

1

原始射线可用

示例

C

Mdo_getIntAttr(model, "HasPrimalRay", &has_primal_ray);

C++

has_primal_ray = model.getIntAttr("HasPrimalRay");

Python

has_primal_ray = model.get_int_attr("HasPrimalRay")

8.7.2.6. “HasDualRay”

此属性用于查询对偶射线是否可用(Check if an unbounded ray of the dual is available)。

  • Group: Solution

  • Type: Integer

  • Modifiable: No

选项

说明

0

对偶射线不可用

1

对偶射线可用

示例

C

Mdo_getIntAttr(model, "HasDualRay", &has_dual_ray);

C++

has_dual_ray = model.getIntAttr("HasDualRay");

Python

has_dual_ray = model.get_int_attr("HasDualRay")

8.7.2.7. “PrimalObjVal”

此属性用于查询原始目标值。

  • Group: Solution

  • Type: Real

  • Modifiable: No

示例

C

Mdo_getRealAttr(model, "PrimalObjVal", &primal_obj_val);

C++

primal_obj_val = model.getRealAttr("PrimalObjVal");

Python

primal_obj_val = model.get_real_attr("PrimalObjVal")

8.7.2.8. “DualObjVal”

此属性用于查询对偶目标值。

  • Group: Solution

  • Type: Real

  • Modifiable: No

示例

C

Mdo_getRealAttr(model, "DualObjVal", &dual_obj_val);

C++

dual_obj_val = model.getRealAttr("DualObjVal");

Python

dual_obj_val = model.get_real_attr("DualObjVal")

8.7.2.9. “PrimalSoln”

此属性用于查询当前原始解。

  • Group: Model

  • Type: Real

  • Modifiable: No

示例

C

Mdo_getRealAttrIndex(model, "PrimalSoln", 0, &primal_soln);
Mdo_getRealAttrArray(model, "PrimalSoln", 0, 4, primal_soln_array);

C++

primal_soln = model.getRealAttrIndex("PrimalSoln", 0);
primal_soln_array = model.getRealAttrArray("PrimalSoln", 0, 4);
primal_soln = var.getRealAttr("PrimalSoln");

Python

primal_soln = model.get_real_attr_index("PrimalSoln", 0)
primal_soln_array = model.get_real_attr_array("PrimalSoln", 0, 4)
primal_soln = var.get_real_attr("PrimalSoln")

8.7.2.10. “DualSoln”

此属性用于查询当前对偶解。

  • Group: Model

  • Type: Real

  • Modifiable: No

示例

C

Mdo_getRealAttrIndex(model, "DualSoln", 0, &dual_soln);
Mdo_getRealAttrArray(model, "DualSoln", 0, 4, dual_soln_array);

C++

dual_soln = model.getRealAttrIndex("DualSoln", 0);
dual_soln_array = model.getRealAttrArray("DualSoln", 0, 4);
dual_soln = cons.getRealAttr("DualSoln");

Python

dual_soln = model.get_real_attr_index("DualSoln", 0)
dual_soln_array = model.get_real_attr_array("DualSoln", 0, 4)
dual_soln = cons.get_real_attr("DualSoln")

8.7.2.11. “ColBasis”

此属性用于查询与设置原始变量的单纯形的基的状态。基的状态以及对应的值分别为:

isFree = 0,
basic = 1,
atUpperBound = 2,
atLowerBound = 3,
superBasic = 4,
isFixed = 5,
  • Group: Model

  • Type: Int

  • Modifiable: Yes

示例

C

Mdo_setIntAttrIndex(model, "ColBasis", 0, 1);
Mdo_setIntAttrArray(model, "ColBasis", 0, 4, col_basis_array);
Mdo_getIntAttrIndex(model, "ColBasis", 0, &col_basis);
Mdo_getIntAttrArray(model, "ColBasis", 0, 4, col_basis_array);

C++

model.setIntAttrIndex("ColBasis", 0, 1);
model.setIntAttrArray("ColBasis", 0, 4, col_basis_array);
col_basis = model.getIntAttrIndex("ColBasis", 0);
col_basis_array = model.getIntAttrArray("ColBasis", 0, 4);
var.setIntAttr("ColBasis", 1);
col_basis = var.getIntAttr("ColBasis");

Python

model.set_int_attr_index("ColBasis", 0, 1)
model.set_int_attr_array("ColBasis", 0, 4, col_basis_array)
col_basis = model.get_int_attr_index("ColBasis", 0)
col_basis_array = model.get_int_attr_array("ColBasis", 0, 4)
var.set_int_attr("ColBasis", 1)
col_basis = var.get_int_attr("ColBasis")

8.7.2.12. “RowBasis”

此属性用于查询与设置对偶变量的单纯形的基的状态。基的状态以及对应的值分别为:

isFree = 0,
basic = 1,
atUpperBound = 2,
atLowerBound = 3,
superBasic = 4,
isFixed = 5,
  • Group: Model

  • Type: Int

  • Modifiable: No

示例

C

Mdo_setIntAttrIndex(model, "RowBasis", 0, 1);
Mdo_setIntAttrArray(model, "RowBasis", 0, 4, row_basis_array);
Mdo_getIntAttrIndex(model, "RowBasis", 0, &row_basis);
Mdo_getIntAttrArray(model, "RowBasis", 0, 4, row_basis_array);

C++

model.setIntAttrIndex("RowBasis", 0, 1);
model.setIntAttrArray("RowBasis", 0, 4, row_basis_array);
row_basis = model.getIntAttrIndex("RowBasis", 0);
row_basis_array = model.getIntAttrArray("RowBasis", 0, 4);
cons.setIntAttr("RowBasis", 1);
row_basis = cons.getIntAttr("RowBasis");

Python

model.set_int_attr_index("RowBasis", 0, 1)
model.set_int_attr_array("RowBasis", 0, 4, row_basis_array)
row_basis = model.get_int_attr_index("RowBasis", 0)
row_basis_array = model.get_int_attr_array("RowBasis", 0, 4)
cons.set_int_attr("RowBasis", 1)
row_basis = cons.get_int_attr("RowBasis")

8.7.2.13. “Activity”

此属性用于查询当前 primal activities 中的值。 以 线性规划建模 中的问题为例,primal activity 定义为:

\[A \cdot x.\]
  • Group: Model

  • Type: Real

  • Modifiable: No

示例

C

Mdo_getRealAttrIndex(model, "Activity", 0, &activity);
Mdo_getRealAttrArray(model, "Activity", 0, 4, activity_array);

C++

activity = model.getRealAttrIndex("Activity", 0);
activity_array = model.getRealAttrArray("Activity", 0, 4);
activity = cons.getRealAttr("Activity");

Python

activity = model.get_real_attr_index("Activity", 0)
activity_array = model.get_real_attr_array("Activity", 0, 4)
activity = cons.get_real_attr("Activity")

8.7.2.14. “ReducedCost”

此属性用于查询当前 reduced costs 中的值。 以 线性规划建模 中的问题为例,reduced costs 定义为:

\[c - A^\top \cdot y.\]

其中 \(y\) 是对偶变量的值。

  • Group: Model

  • Type: Real

  • Modifiable: No

示例

C

Mdo_getRealAttrIndex(model, "ReducedCost", 0, &reduced_cost);
Mdo_getRealAttrArray(model, "ReducedCost", 0, 4, reduced_cost_array);

C++

reduced_cost = model.getRealAttrIndex("ReducedCost", 0);
reduced_cost_array = model.getRealAttrArray("ReducedCost", 0, 4);
reduced_cost = var.getRealAttr("ReducedCost");

Python

reduced_cost = model.get_real_attr_index("ReducedCost", 0)
reduced_cost_array = model.get_real_attr_array("ReducedCost", 0, 4)
reduced_cost = var.get_real_attr("ReducedCost")

8.7.2.15. “SymMatPrimalSoln”

此属性用于查询块变量相对应的原始解。

  • Group: Model

  • Type: Real

  • Modifiable: No

示例

C

MDO_CHECK_CALL(Mdo_getRealAttrSymMat(model, "SymMatPrimalSoln",
    0, dim_mat * dim_mat, NULL, NULL, soln));

C++

soln = model.getRealAttrSymMat("SymMatPrimalSoln", b,
    dim_mats[b] * dim_mats[b], NULL, NULL);

Python

soln = model.get_real_attr_sym_mat("SymMatPrimalSoln", 0,
    [i * 2 + j for i in range(2) for j in range(2)],
    [j * 2 + i for i in range(2) for j in range(2)])

8.7.2.16. “MIP/GapAbs”

此属性用于查询MIP求解GAP的绝对值。

  • Group: Solution

  • Type: Real

  • Modifiable: No

示例

C

Mdo_getRealAttr(model, "MIP/GapAbs", &mip_gap_abs);

C++

mip_gap_abs = model.getRealAttr("MIP/GapAbs");

Python

mip_gap_abs = model.get_real_attr("MIP/GapAbs")

8.7.2.17. “MIP/GapRel”

此属性用于查询MIP求解GAP的相对值。

  • Group: Solution

  • Type: Real

  • Modifiable: No

示例

C

Mdo_getRealAttr(model, "MIP/GapRel", &mip_gap_rel);

C++

mip_gap_rel = model.getRealAttr("MIP/GapRel");

Python

mip_gap_rel = model.get_real_attr("MIP/GapRel")