【问题标题】:Displaying top five solutions SCIP显示排名前五的解决方案 SCIP
【发布时间】:2014-09-28 22:53:19
【问题描述】:

我已经编写了一个整数规划模型并使用 SCIP 解决了它。我可以轻松获得最佳解决方案,但我也有兴趣获得接下来的四个最佳解决方案。我可以输入 display allsolutions 来向我展示 SCIP shell 中的一些解决方案,但我最多对其他 4 个解决方案感兴趣,并且希望从 c++ 程序而不是 shell 中执行此操作。我怎样才能做到这一点?

【问题讨论】:

    标签: scip


    【解决方案1】:

    您可以使用 scip.h 提供的解决方法:

    #define SOLSTOPRINT 5;
    
    SCIP* scip;
    SCIP_SOL** sols;
    int nsols, i;
    
    // ...
    // put here your code to create a SCIP instance, read in a problem and call the 
    // the solving method of SCIP
    // ...
    
    sols = SCIPgetSols(scip);
    nsols = SCIPgetNSols(scip);
    
    for( i = 0; i < MIN(nsols, SOLSTOPRINT); ++i )
    {
         SCIP_CALL( SCIPprintSol(scip, sols[i], NULL, FALSE) );
    }
    

    SCIP 自动存储从最好到最差的解决方案,因此它足以迭代 sols-array 的前 5 个解决方案。请注意,默认情况下 SCIP 最多存储 找到的最佳 100 个解决方案。您可以通过参数limits/maxsol 更改此行为,例如,通过添加行

    SCIP_CALL( SCIPsetIntParam(scip, "limits/maxsol", 200) );
    

    到上面的代码之前解决问题。

    【讨论】:

    • 谢谢!我已经被困了一段时间了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-17
    • 2011-02-04
    • 2013-09-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多