gpt4 book ai didi

CPLEX MIP 当前节点 LP 松弛

转载 作者:行者123 更新时间:2023-11-30 21:06:34 27 4
gpt4 key购买 nike

在使用 CPLEX C API 进行 MIP 优化期间,是否可以检索当前节点(即每 n 个节点)的线性松弛(双变量、降低的成本等)?

我注册了一个回调函数 (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 松弛,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47867148/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com