Fw: [問題] cplex 變數累加問題

看板Eclipse作者 (33)時間11年前 (2012/10/15 04:50), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
※ [本文轉錄自 java 看板 #1GUo1HpA ] 作者: sacidoO (33) 看板: java 標題: [問題] cplex 變數累加問題 時間: Mon Oct 15 04:27:58 2012 哈囉板上大大大家好, 想請問一個有關cplex變數累加的問題 我現在有一個變數 x[i], i=0..9999 因為我想把他轉成矩陣以1000為單位,對各行各列作累加 變成 x[0], x[1],..., x[999] x[100],x[101],...,x[1999] . . . ..................x[9999] 想對各行各列做加總,但是因為cplex 對+ - =有固定的表示方式 像是加法cplex.sum 等於 cplex.addEq 所以不能直接對各行以"+="表示 下面是我試過的方式 可是都無效 1. official method for add variables: code with: 以加總第一列為例 cplex.addEq(x[i],x[i+1],x[i+2].....to x[i+999], row[0]); 因為變數最多只能加七個, fail 2.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]+x[i+1]+...to a row/column cplex.addEq(accurow, inbound[b]); //assign the value to xji,xij } } } 簡畫的邏輯就是 新訂一個儲存空間 叫做accurow, ex: 存x[0]+x[1]+...+x[999]=accurow 但是因為每行每列的總不一樣 這個method又不能讓我對accurow做腳碼的loop 像如果我可以表示accurow[i]就代表i列的總加 所以這個方法也失敗 如果我直接定義不同accurow0, accurow1...accurow1000 這樣會造成記憶體空間不足 3. directly assign a new variables to store the sum{i,j} xij which will code with ex: IloNumVar[] outgoing_row0 = cplex.intVarArray(1200, 0, 1); 仍然,因為有1000row, 1000column 會造成記憶體空間不足 4.我看網路上有人直接以 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]) } } 這個方法就是對各列做加總 但不知道為什麼我這邊的cplex.sum 的sum會讓我error.... 不知道板上有沒有人可以幫忙我解決這個問題呢? 謝謝!!! -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 70.176.16.247 ※ 發信站: 批踢踢實業坊(ptt.cc) ※ 轉錄者: sacidoO (70.176.16.247), 時間: 10/15/2012 04:50:19
文章代碼(AID): #1GUoMDFS (Eclipse)