简体   繁体   English

以array [i]作为值的CPLEX决策变量

[英]CPLEX decision variables with array[i] as values

I try to create a set of decision variables which is not using the integer values from the for-Loop but instead gets the value from an array. 我尝试创建一组决策变量,该决策变量不使用来自for-Loop的整数值,而是从数组中获取值。

The reason is that I want the indices to be the same like the numbers in the arrays. 原因是我希望索引与数组中的数字相同。 The numbering of Array could look like: Array的编号如下所示:

int [] Array = {12,11,10,15,16,17};

I get a arrayoutofboundsexception error when I run it. 我在运行时收到arrayoutofboundsexception错误。

Here the part of the code: 这是代码的一部分:

 x = new IloNumVar[inputData.Array().length][inputData.Array().length][inputData.Arraytwo().length];
    for (int i=0; i< inputData.Array().length;i++){
        this.x[inputData.Array()[i]]= new IloNumVar[inputData.Array().length][]; 
            for (int j=0; j< inputData.Array().length;j++){
            this.x[inputData.Array()[[i][j] = new IloNumVar[inputData.Arraytwo().length];
            for (int k=0; k<inputData.get_sub_K_set().length;k++){
                this.xx[inputData.Array()[i]][inputData.Array()[j]][inputData.Arraytwo()[k]]= this.boolVar("x:i_"+inputData.Array()[i]+"-j_"+inputData.Array()[j]+"-k_"+inputData.Arraytwo()[k]);
            }
        }
    }

I appreciate any help. 感谢您的帮助。 Thank you guys! 感谢大伙们!

You are declaring Array as: 您将Array声明为:

int [] Array = {12,11,10,15,16,17};

and then iterating in: 然后迭代:

for (int i=0; i< inputData.Array().length;i++){

this means that the values of i are {0,1,2,3,4,5} 这意味着i的值为{0,1,2,3,4,5}

and x is defined like IloNumVar[6][6][6] 和x的定义类似IloNumVar[6][6][6]

when you do: 当您这样做时:

this.x[inputData.Array()[i]]

is and error because you dont have indexes {12,11,10,15,16,17} in the x variable. is和error是因为您在x变量中没有索引{12,11,10,15,16,17}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM