如何修复宏BranchCallback中的边界/更改变量边界? C ++

问题描述 投票:0回答:1

在下面的代码中,我正在尝试使用CPLEX宏ILOBRANCHCALLBACK2创建一个分支回调,我正在选择修复某些可变参数的方法。但是在进行修复时,我在读取一些空间时会遇到访问冲突错误。有人能告诉我这样做的正确方法吗?我是否必须为所有变量执行make分支,或者branchcallback会自己执行吗?

ILOBRANCHCALLBACK2(simetria, const Instance&, instance, const IloNumVarMatrix&, X) {
    vector<coordenates> F_zeros;
    vector<coordenates> F_ones;
    vector<int> a;
    a.resize(instance.getNbClients());
    a[0] = 0;
    coordenates first;
    first.x = 0;
    first.y = 0;
    F_ones.push_back(first);

    // Je verifie s'il y a deja des variables fixées
    for(int i = 1; i < instance.getNbClients() - 1; ++i) {
        for(int j = 1; j < instance.getNbVehicles() - 1; ++j) {
            if(getUB(X[i][j]) <= 0.001) {
                coordenates obj;
                obj.x = i;
                obj.y = j;
                F_zeros.push_back(obj);
            }

            if(getLB(X[i][j]) >= 0.99) {
                coordenates obj;
                obj.x = i;
                obj.y = j;
                F_ones.push_back(obj);
            }
        }
    }

    // Je vais construir mon a.
    for(int k = 1; k < instance.getNbClients() - 1; k++) {
        // Zero setting
        if(a[k - 1] == instance.getNbVehicles() - 1 || findInVector(F_zeros, k, a[k - 1] + 1)) {
            a[k] = a[k - 1];
            coordenates obj;
            obj.x = k;
            obj.y = a[k - 1];

        } else {
            a[k] = a[k - 1] + 1;
            coordenates obj;
            obj.x = k;
            obj.y = a[k - 1] + 1;
        }
    }

    // Je mets a jour le F_zero a partir de a
    for(int k = 1; k < instance.getNbClients() - 1; k++) {
        for(int p = 1; p < instance.getNbVehicles() - 1; p++) {
            if(p > a[k]) {
                coordenates obj;
                obj.x = k;
                obj.y = p;
                F_zeros.push_back(obj);
            }
        }
    }

    // je fixe tout ce qui est en  F_zero en zero (Changer les bornnes)
    for(int i = 0; i < F_zeros.size(); i++) {
        int a = F_zeros[i].x;
        int b = F_zeros[i].y;
        X[a][b].setUB(0);
        // X[F_zeros[i].x][F_zeros[i].y].setBounds(0, 0);
        // makeBranch(X[F_zeros[i].x][F_zeros[i].y], 0, IloCplex::BranchUp, getBestObjValue());
        // makeBranch(X[F_zeros[i].x][F_zeros[i].y], 0, IloCplex::BranchDown, getBestObjValue());
    }
c++ callback branch cplex
1个回答
1
投票

您无法在解决模型时修改模型(例如,请参阅文档here中的注释)。如您所知,这可能导致段错误。因此,您不能在回调中使用setUB方法。

您可能知道(基于您已注释掉的代码),您可以使用makeBranch方法,其中:

指示调用IloCplex对象如何通过为一组变量指定新的,更严格的边界来从当前节点创建子节点。

© www.soinside.com 2019 - 2024. All rights reserved.