stupid things when using mosek

1.2016-8-14

我希望把一个qp问题的代码从conic constraints改为无外加约束,仅适用variable bounds的线性不等式约束

于是原来的约束代码为

if (r == MSK_RES_OK)
{
    if (_debug) { MYOUT << "Q: " << std::endl; }
    for (int i = 0; i < numvar/6; i++)
    {
        // the structure have (numvar/6) nodes
        MSKint32t qsubi[] = { 6 * i, 6 * i + 1, 6 * i + 2 };
        MSKint32t qsubj[] = { 6 * i, 6 * i + 1, 6 * i + 2 };
        double      qval[] = { 2 * x_w[i], 2 * x_w[i], 2 * x_w[i]};
        //double      qval[] = { 2, 2, 2};

// Replaces all the quadratic entries in one constraint k
        // In our program, this specifies the deformation constrains:
        // d_{i}_t.norm < tol
        r = MSK_putqconk(task, i, 3, qsubi, qsubj, qval);
    }
}

for (j = 0; j<numvar && r == MSK_RES_OK; ++j)
{
    /* Set the bounds on variable j.
    blx[j] <= x_j <= bux[j] */
    if (r == MSK_RES_OK)
    {

r = MSK_putvarbound(task,
            j,           /* Index of variable.*/
            MSK_BK_FR,      /* Bound key.*/
            -MYINF,      /* Numerical value of lower bound.*/
            MYINF);     /* Numerical value of upper bound.*/
    }
}

/* Set the bounds on constraints.
for i=1, ...,NUMCON : blc[i] <= constraint i <= buc[i] */
for (i = 0; i<numcon && r == MSK_RES_OK; ++i)
{
        r = MSK_putconbound(task,
            i,                            /* Index of constraint.*/
            MSK_BK_UP,    /* Bound key.*/
            -MYINF,            /* Numerical value of lower bound.*/
            pow(d_tol,2));            /* Numerical value of upper bound.*/
}

请注意上面的

r = MSK_putvarbound(task,
            j,           /* Index of variable.*/
            MSK_BK_FR,      /* Bound key.*/
            -MYINF,      /* Numerical value of lower bound.*/
            MYINF);     /* Numerical value of upper bound.*/

虽然看起来无用,因为他是声明变量是free的,即无界变量,不要小看他哦!

okay我开始改代码,把上面的conic的约束换成简单的变量不等式约束:

/* variable bounds */
for (j = 0; j < numvar/6 && r == MSK_RES_OK; ++j)
{
    r = MSK_putvarbound(task,
        j * 6,           /* Index of variable.*/
        MSK_BK_RA,      /* Bound key.*/
        -temp_bound,      /* Numerical value of lower bound.*/
        temp_bound);     /* Numerical value of upper bound.*/

r = MSK_putvarbound(task,
        j * 6 + 1,           /* Index of variable.*/
        MSK_BK_RA,      /* Bound key.*/
        -temp_bound,      /* Numerical value of lower bound.*/
        temp_bound);     /* Numerical value of upper bound.*/
   
    r = MSK_putvarbound(task,
        j * 6 + 2,           /* Index of variable.*/
        MSK_BK_RA,      /* Bound key.*/
        -temp_bound,      /* Numerical value of lower bound.*/
        temp_bound);     /* Numerical value of upper bound.*/

}
看起来很对对不?

但是程序崩了。

原因在于我们需要对每个变量都设置范围,

否则

/* Append ‘NUMVAR‘ variables.
The variables will initially be b_fixed at zero (x=0). */
if (r == MSK_RES_OK)
    r = MSK_appendvars(task, numvar);

所以,正确的代码应该为:

/* variable bounds */
for (j = 0; j < numvar/6 && r == MSK_RES_OK; ++j)
{
    r = MSK_putvarbound(task,
        j * 6,           /* Index of variable.*/
        MSK_BK_RA,      /* Bound key.*/
        -temp_bound,      /* Numerical value of lower bound.*/
        temp_bound);     /* Numerical value of upper bound.*/

r = MSK_putvarbound(task,
        j * 6 + 1,           /* Index of variable.*/
        MSK_BK_RA,      /* Bound key.*/
        -temp_bound,      /* Numerical value of lower bound.*/
        temp_bound);     /* Numerical value of upper bound.*/
   
    r = MSK_putvarbound(task,
        j * 6 + 2,           /* Index of variable.*/
        MSK_BK_RA,      /* Bound key.*/
        -temp_bound,      /* Numerical value of lower bound.*/
        temp_bound);     /* Numerical value of upper bound.*/

r = MSK_putvarbound(task,
        j * 6 + 3,           /* Index of variable.*/
        MSK_BK_FR,      /* Bound key.*/
        -MYINF,      /* Numerical value of lower bound.*/
        MYINF);     /* Numerical value of upper bound.*/

r = MSK_putvarbound(task,
        j * 6 + 4,           /* Index of variable.*/
        MSK_BK_FR,      /* Bound key.*/
        -MYINF,      /* Numerical value of lower bound.*/
        MYINF);     /* Numerical value of upper bound.*/

r = MSK_putvarbound(task,
        j * 6 + 5,           /* Index of variable.*/
        MSK_BK_FR,      /* Bound key.*/
        -MYINF,      /* Numerical value of lower bound.*/
        MYINF);     /* Numerical value of upper bound.*/
}

#The end of 1.

时间: 2024-11-10 00:00:08

stupid things when using mosek的相关文章

Mosek.ApS.Mosek.v7.1 MOSEK数学优化软件包/线性分析HEEDS.MDO.2015.04.2

Mosek.ApS.Mosek.v7.1 MOSEK数学优化软件包Mosek.ApS.Mosek.v7.1.Win32_64 2CD Mosek.ApS.Mosek.v7.1.Linux32_64 2CD Mosek.ApS.Mosek.v7.1.MacOSX 1CDMosek Optimization Tools 是一款MOSEK优化软件包,是一款用来解决大规模级别数学优化问题的软件.MOSEK提供了特定解决线性编程.混 合整数编程以及其它非线性转换优化问题.+++++++++++++++++

Simulation.Lab.Software.SimLab.Composer.2015.v6.1.MACOSX 1CD

CA Spectrum Linux VM 10.01.00.00.103 Linux 2DVD  Tahoe Design HYDROFLO v3.0.0.4 1CD  CA Spectrum Windows VM 10.01.00.00.103 Win64 2DVD  Delcam Exchange 2016 R2 CR 8.3.1005 Win64 1CD  Delcam PowerSHAPE 2016 SP2 Update only 1CD  ESI Group VA One 2015.0

Rivix.RiverTools.V3.0.3 地形和河流网系提取及分析软件

Mosek.Optimization.Tools.v6.0.0.52 SCHLUMBERGER.PETREL.V2009.1 油藏模拟软件 SIEMENS.PLM.NX.NASTRAN.V7.0 SIEMENS.PLM.NX.V7.0.CAST Simufact.Forming.v9.0 SOLIDCAM2009SP2 Tekla.Structures.V15SR5 WaveMetrics.IGOR.Pro.v6.1.2 鸿业市政道路8.0 Altera.Quartus.II.v9.1 AUTO

Mutation.Surveyor.v2.2.rar基因变异(SNP)、基因突变(Mutation) 检测软件

Altium Vault 2.5.9.45043.rarCRTECH_THERMAL_DESKTOP_V4.8D.zipCST STUDIO SUITE-2015.zipFormtec Ncspeed v6.1.1.2.rar(模仿并解析如何加工材料的工具.) 一款模仿并解析如何加工材料的工具.可以模仿3到5轴系处理加工过程,它考虑到机器的运行时间和安全系数,在可 能的情况下还可以检查工具路径.软件工作原理:1.考虑到磨损程度,磨损越小越好.2考虑到耐久性,工作的时间越 久越好.3考虑到零件之间

AutoDWG.DWG.PDF.Converter.2016.v4.92 1CD

2015.10.14最新软件表 AVL CRUISE M 2015.0 Win32_64 1DVD  Nemetschek.SCIA.Engineer.2015.v15.1.106 1DVD  pyaoaoaosoft109.1  Type3 CAA V5 Based v5.5A for CATIA V5R19-R24 Win64 6CD  Chemstations.CHEMCAD.Suite.v6.5.7.8139 1CD  Optitex.v15.0.198.0.Win32 1DVD  Au

MentorGraphics_FloEFD_14.2.3186_Standalone_Win64

3DCS Variation Analyst 7.3 3DCS_Variation_Analyst_MultiCAD_7.2.2.0 Aquaveo.Groundwater.Modeling.System.Premium.v10.0.11 x64 Aquaveo.Surface-water.Modeling.System.Premium.v11.2.12 x64 DeskArtes.3Data.Expert.v10.2.1.7 DeskArtes.Dimensions.Expert.v10.2.

破性改进Stat-Ease Design-Expert v10.0.0.3

Stat-Ease Design-Expert v10.0.0.3+SAS JMP Pro 12.1.0 MacOSX 1CD     Design-Expert 包含 Design-Ease 的所有功能,并提供工序要素或混合配料成分的深入分析.在您的设计中结合混合配料变量与工序变量.Design-Expert 提供可以旋转的三维绘图,帮助您查看您的响应面.使用您的鼠标来仔细检查二维轮廓,沿着轮廓线设置标记以识别坐标与预计响应.可以通过此程序的数值优化功能找到满足您所有需求的最佳位置,该功能同时

Global.Mapper.v17.1.0.b020216.Win32_64 2CD地图图形+Didger.v5.11.1438

Global.Mapper.v17.1.0.b020216.Win32_64 2CD地图图形 它还提供距离和面积计算,光栅混合.对比度调节.海拔高度查询.视线计算,以及一些高级功能,如图像校正.通过地表数据进行轮廓生成.通过地表数据观察分水岭.对3Dpoint数据转换为三角多边形和网格化等.通过内建的脚本语言或众多的批处理转换选项能够高效地完成重复性任务.地图绘制软件. Golden.Software.Didger.v5.11.1438.Win32_64 1CD Software.Didger一

NextLimit.Maxwell.Render.for.SketchUp.v3.2.5.MacOSX 1CD

Global.Mapper.v17.1.0.b020216.Win32_64 2CD  Siemens.LMS.Virtual.Lab.Rev13.5.Win64 1DVD  AutoDesSys formZ Pro v8.5.3 Win32_64 2CD  CSI.SAP2000.v18.1.0.1227.Win32_64 2CD  FilmLight.Daylight.v4.4m1.8005.MacOSX 1CD  The Foundry Modo v902 SP2 Linux64 1CD