2017-06-06 29 views
0

林加載從OPL工作室的數據文件2由兩個矩陣,現在用的是下面的腳本如何在OPL ILOG Studio上正確加載2乘2矩陣而不出錯?

P=5; 
Customers={"1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31","32","33","34","35","36","37","38","39","40","41","42","43","44","45","46","47","48","49","50"}; 
Warehouses={"A","B","C","D","E"}; 
Demand=[3,14,1,14,19,2,14,6,7,6,10,18,3,6,20,4,14,11,19,15,15,4,13,13,5,16,3,7,14,17,3,3,12,14,20,13,10,9,6,18,7,20,9,1,8,5,1,7,9,2]; 
prepare { 
    function read(element, name) { 
     var customDataSource = 
IloOplCallJava("externaldatasource.SimpleTextReader","<init>", "(Ljava.lang.String;Ljava.lang.String;)V","C:/Users/Brian/opl/ccp/data.txt", ","); 
     customDataSource.fillOplElement(element); 
     return true; 
    } 
} 

Distance = invoke read; 

即時得到一個「數據解析錯誤:語法錯誤,意想不到的準備,期待$結束」 我想從文件中的數據加載具有以下格式,並從文件中讀取到OPL工作室

0 86 42 67 54 76 78 107 100 57 
42 93 44 21 25 35 56 16 60 101 
10 54 58 72 82 60 58 72 43 67 
70 15 36 61 102 14 69 64 23 83 
19 52 94 10 62 50 69 53 52  4 


86  0 76 23 47 18 60 23 16 51 
70  7 62 97 63 75 51 70 37 19 
75 49 74 27 32 71 28 30 47 43 
42 86 72 80 16 77 21 46 63  6 
94 81 15 78 62 87 47 72 42 85 

我公司開發上述使用OPL文件

回答

0

你可以做y中的解析腳本我們的模型。 假設你的文本是toto.txt

int N=10; 

execute 
{ 
var f=new IloOplInputFile("toto.txt"); 
var str1=f.readline(); 
var str2=f.readline(); 
var rank=1; 
while (!f.eof) 
{ 
var str=f.readline(); 
while (str.charAt(0)==" ") str=str.substring(1); 
writeln(str); 
var ar=new Array(N+1); 
var arindex=0; 
while (str.indexOf(" ")!=-1) 
{ 
    ar[arindex]=str.substring(0,str.indexOf(" ")); 
    writeln(ar[arindex]); 
    str=str.substring(str.indexOf(" ")+1); 
    while (str.charAt(0)==" ") str=str.substring(1); 
    arindex++; 
} 

ar[arindex]=str; 
writeln(ar[arindex]); 
rank++; 
} 
f.close(); 
} 

西港島線解析所有的號碼,那麼你可以做任何你需要 問候