简体   繁体   中英

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.

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:

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

I get a arrayoutofboundsexception error when I run it.

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:

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}

and x is defined like 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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