当我在模型中添加约束时,向量的值会丢失

时间:2017-09-11 14:23:00

标签: c++ cplex

当我使用visual studio c ++的cplex优化工作室时遇到问题。 我有一个班级“节点”:

typedef vector<vector<int>> Matrix_int;
typedef vector<vector<float>> Matrix_float;

typedef class node {
public:
int nodenum;
bool decided;
Matrix_int full;
Matrix_float argmax;
} node;

我尝试通过以下方式添加约束:

for (int nn = 0; nn < node->full.size(); nn++) {
    if (node->full[nn].size() > 4){
        IloExpr lhs(env);
        for (int ll = 0; ll < (node->full[nn].size() - 3); ll++) {
            for (int lll = 0; lll < (node->full[nn].size() - 3); lll++) {
                cout << node->full[nn][ll] <<"   ";
                if (node->full[nn][ll] =! node->full[nn][lll]){
                    lhs += x[node->full[nn][(node->full[nn].size()) - 3]][node->full[nn][ll]][node->full[nn][lll]][node->full[nn][(node->full[nn].size()) - 2]][node->full[nn][(node->full[nn].size()) - 1]];
                }
            }
        }
        Model.add(lhs <= (node->argmax[nn][1]) - (node->argmax[nn][0]));
        lhs.end();
    }
}

但是这个约束前后的矢量“满”的值是不同的!!  并且它的元素变为0。 添加约束之前,之间和之后的此向量的输出是:

before:
{{4 6 7 0 0 1},
{6 7 0 0 1},
{6 7 8 9 0 0 2},
{4 6 7 8 9 0 0 3},
{6 7 8 9 0 0 3},
{4 0 1 2},
{6 7 1 0 1},
{8 9 1 0 3},
{6 7 1 1 2},
{8 9 1 2 1},
{8 9 3 0 1},
{5 3 0 2},
{6 7 3 1 1},
{5 3 2 1},
{6 7 3 2 2},
{5 6 7 3 2 3},
{6 7 3 2 3}}

in constraint:
{{4 0 0 6 1 0 7 1 1 0 0 1},
{6 0 7 1 0 0 1},
{6 0 0 0 7 1 0 0 8 1 1 0 9 1 1 1 0 0 2},
{4 0 0 0 0 6 1 0 0 0 7 1 1 0 0 8 1 1 1 0 9 1 1 1 1 0 0 3},
{6 0 0 0 7 1 0 0 8 1 1 0 9 1 1 1 0 0 3},
{4 0 1 2},
{6 0 7 1 1 0 1},
{8 0 9 1 1 0 3},
{6 0 7 1 1 1 2},
{8 0 9 1 1 2 1},
{8 0 9 1 3 0 1},
{5 3 0 2},
{6 0 7 1 3 1 1},
{5 3 2 1},
{6 0 7 1 3 2 2},
{5 0 0 6 1 0 7 1 1 3 2 3},
{6 0 7 1 3 2 3}}

after:
{{0 0 0 0 0 1},
{0 0 0 0 1},
{0 0 0 0 0 0 2},
{0 0 0 0 0 0 0 3},
{0 0 0 0 0 0 3},
{4 0 1 2},
{0 0 1 0 1},
{0 0 1 0 3},
{0 0 1 1 2},
{0 0 1 2 1},
{0 0 3 0 1},
{5 3 0 2},
{0 0 3 1 1},
{5 3 2 1},
{0 0 3 2 2},
{0 0 0 3 2 3},
{0 0 3 2 3}}

有人可以帮我找到原因吗?

提前致谢!

0 个答案:

没有答案