Topic
1 reply Latest Post - ‏2012-10-15T01:49:35Z by EmmaHsieh
EmmaHsieh
EmmaHsieh
2 Posts
ACCEPTED ANSWER

Pinned topic Questions about adding array into row/column via java cplex

‏2012-10-14T20:43:30Z |
I use x[i] as x variable the range is i=0..1000*1000

My problem is, I need to sum up the xi value in row and column vectors ,but somehow I was unable to restore the value,

That is, I want to separate the array as

x[0], x[1],..., x999 wanna adding this row as row[0]
x100,x101,...,x1999 wanna adding this row as row[1]
. same in remaining row and column
.
.
..................x9999

the ways I tried were

1. official method for add variables:
code with: for ex. adding x[i] in row[0]

cplex.addEq(x[i],xi+1,xi+2.....to xi+999, row[0]);
***flaw: this method only allows me to add up to 7 variables.

2. use += method in java cplex
code with:

for (int b=0; b<1000; b++)
//assign the column/row
{ IloLinearNumExpr accurow = cplex.linearNumExpr();
//assign the space for adding numbers
for(int i=0;i<1000*1000;i++){
//index of x variables
if((i % 1000) ==b){
//calculating the row/column vector
accurow.addTerm(1, x[i]);
//adding x[i]+xi+1+...to a row/column
cplex.addEq(accurow, inbound[b]);
//assign the value to xji,xij
}
}
}

***flaw: I need to assign different particular value for IloLinearNumExpr "accurow" = cplex.linearNumExpr();
the " " part cannot use a loop to generate in order to adding x[i] into accurow.addTerm method.
I cannot assign an loop for accurow[i], samely, if i assign different space for storing row/column value
like

IloLinearNumExpr "accurow0" = cplex.linearNumExpr();
IloLinearNumExpr "accurow1" = cplex.linearNumExpr();
IloLinearNumExpr "accurow2" = cplex.linearNumExpr(); ...etc
for all row/columns, it will shows the msg of out of memory
3. directly assign a new variables to store the sum{i,j} xij
which will code with ex:

IloNumVar[] row0 = cplex.intVarArray(1200, 0, 1);
IloNumVar[] row1 = cplex.intVarArray(1200, 0, 1);
IloNumVar[] row2 = cplex.intVarArray(1200, 0, 1);...ect

***flaw: still, I will need to compile new variables for storing the space for outgoing and ingoing variables(for here is xij and xji) and while i adding the new variables for amount 1200 for storing, it's running out of the memory

4. use loop to adding variables

for(int b=0; b<1000;b++){
for(int i=0; i< 1000*1000;i++){
if( (i/1000) == b)
cplex.addEq( (cplex.sum(x[i])) , row[b])
}
}

***flaw: somehow it shows and underline error of the " sum"...

Does anybody can help me to solve the problem of this question?
I want to separate an variable x[i], i=0..1000*1000
and I want to sum up the value of different row/column value like (use 1000 as row/column unit)

x[0], x[1],..., x999 sum up this row as row[0]
x100,x101,...,x1999 sum up adding this row as row[1]
. same in remaining row and column
.
.
..................x9999

Thank you so much!!!
you may also replies to my email
my email address: sacidoo@gmail.com
Thanks!!!
Updated on 2012-10-15T01:49:35Z at 2012-10-15T01:49:35Z by EmmaHsieh
  • EmmaHsieh
    EmmaHsieh
    2 Posts
    ACCEPTED ANSWER

    Re: Questions about adding array into row/column via java cplex

    ‏2012-10-15T01:49:35Z  in response to EmmaHsieh
    OMG...I have some typo in this content, the range of x[i] is from i=0...999999,

    and the array is

    x[0], x[1],..., x999
    x100,x101,...,x1999
    .
    .
    .
    ..................x999999

    sry about the confusing but i am still waiting for the solution for this problems....thanks!