2014-09-28 72 views
1

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

回答

3

您可以使用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的第5个解决方案 - 阵列。请注意,默认情况下,SCIP最多可以存储找到的最好的100个解决方案中的 。您可以通过添加行

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

上述代码之前解决这个问题通过参数limits/maxsol改变这种行为,例如。

+0

谢谢!我一直陷在这个问题上。 – migs 2014-09-29 19:04:15