我如何在每个节点的所有非整数变量上创建分支?

How can i make branch on all not integer variables at each node?

在每个节点,我想对所有值不是整数的变量进行分支。之后我想在每个分支打印 objective 的值。我用 C++ 编写了这段代码,但出现错误 1006。

ILOBRANCHCALLBACK1(callback1, IloNumVarArray, vars)
{
    for (int i = 0; i < vars.getSize(); ++i)
      {
        if (getValue(vars[i]) > 0 && getValue(vars[i]) < 1)
        {
        int xidown = IloFloor(getValue(vars[i]));
        int xiup   = IloFloor(getValue(vars[i])) + 1;
        makeBranch(vars[i], xidown, IloCplex::BranchDown, getObjValue());
        makeBranch(vars[i], xiup, IloCplex::BranchUp, getObjValue());
        cout << "objvalueDown_" << vars[i] << "," << getObjValue() << endl;
        cout << "objvalueUp_"   << vars[i] << "," << getObjValue() << endl;
        }
     }
}

您不能在一个节点上创建两个以上的分支,这就是您收到此错误的原因。

此外,新创建的节点不会立即被评估,它们只是被放入节点队列。所以此时不​​能查询新创建的节点的objective值

如果您正在尝试执行强分支之类的操作,请在参考手册中搜索 "strong branching"。有专门的功能。