CPLEX MIP当前节点LP松弛
在使用CPLEX C API进行MIP优化期间,是否可以检索当前节点(即每n个节点)的线性松弛(双变量,降低的成本等)?CPLEX MIP当前节点LP松弛
我注册了一个回调函数(CPXsetsolvecallbackfunc),以便每次有新节点可用时都会收到通知。在回调函数中,我使用CPXgetcallbackinfo检索节点信息,并使用CPXgetcallbacknodelp检索线性松弛,但不幸的是,程序CPXsolution返回没有解决方案并且MIP优化退出。
下面是一个示例代码,从IBM example开始实现,其中假设环境和问题已正确初始化。
struct noderange { int startnode;
int endnode;
};
typedef struct noderange NODERANGE;
NODERANGE nodeswritten;
nodeswritten.startnode = -1;
nodeswritten.endnode = 2100000000;
status = CPXsetsolvecallbackfunc(environment, usersolve, &nodeswritten);
if(status) {goto TERMINATE;}
status = CPXmipopt(environment, problem);
if(status) {goto TERMINATE;}
其中usersolve过程
static int CPXPUBLIC usersolve(CPXCENVptr env, void *cbdata, int wherefrom, void *cbhandle, int *useraction_p) { int status = 0;
int nodecount;
static int count = 0;
CPXLPptr nodelp;
NODERANGE *nodeswritten;
*useraction_p = CPX_CALLBACK_DEFAULT;
nodeswritten = (NODERANGE *)cbhandle;
/* Find out what node is being processed */
status = CPXgetcallbackinfo(env, cbdata, wherefrom, CPX_CALLBACK_INFO_NODE_COUNT, &nodecount);
if (status) goto TERMINATE;
if (nodecount >= nodeswritten->startnode && nodecount <= nodeswritten->endnode) {
/* Get pointer to LP subproblem, then write a SAV file. */
status = CPXgetcallbacknodelp(env, cbdata, wherefrom, &nodelp);
if (status) goto TERMINATE;
int rows = CPXgetnumcols(env, nodelp);
int cols = CPXgetnumrows(env, nodelp);
int lpstat;
double objval;
double* x = (double*)malloc(sizeof(double) * CPXgetnumcols(env, nodelp));
double* dj = (double*)malloc(sizeof(double) * CPXgetnumcols(env, nodelp));
double* pi = (double*)malloc(sizeof(double) * CPXgetnumrows(env, nodelp));
double* slack = (double*)malloc(sizeof(double) * CPXgetnumrows(env, nodelp));
status = CPXsolution(env, nodelp, &lpstat, &objval, x, pi, slack, dj);
printf("Solutionstatus = %d\n", lpstat);
if (status) { goto TERMINATE; } // <--- HERE it returns no solution exists
free(x);
free(dj);
free(pi);
free(slack);
printf("[%d]\trows = %d cols = %d\t sol stat = %d\t z = %f\n", nodecount, rows, cols, lpstat, objval);
if (nodecount == nodeswritten->endnode) status = 1;
count++;
}
TERMINATE:
return (status);
}
回答:
我发现了问题,调用回调前的子问题已解决,使CPXsolution返回无解的存在。
以上是 CPLEX MIP当前节点LP松弛 的全部内容, 来源链接: utcz.com/qa/262773.html