私は Java で cplex を使用しており、別のクラスから変数の値にアクセスしたい (解決後)。
変数 p15[i][j][q] を出力する必要がある私のプログラム構成クラスは次のようになります。
import [...]
public class Ausführung {
public static void main(String[] args) throws IOException {
try{
String filename = "[...]
Data data = new Data(filename);
IloCplex cplex = new IloCplex();
IloNumVar[][][] w = new IloIntVar[n][n][n];
MainTSP.buildModel(cplex, data, w);
if(cplex.solve()){
for(int q=0; q< data.distance1.length-1; q++){
for(int ii=0; ii<data.distance1.length; ii++){
for(int j=0; j<data.distance1.length; j++){
if(cplex.getValue(p15[i][j][q]) >= 1) System.out.println("p15");
}
}
}
cplex.end();
}
[...]
}
}
変数は、次のようにメイン プログラム クラスで初期化されます。
public class MainTSP {
static void buildModel(IloMPModeler model, Data data, IloNumVar[][][] w) throws IloException{
IloNumVar[][][] p15 = new IloIntVar[n][n][n];
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
for(int q=0; q<n; q++){
p15[i][j][q] = model.intVar(lb, ub);
}
}
}
[...]
残念ながら、構成クラスで「p15 を変数に解決できません」というエラー メッセージが表示されます。変数が別のクラスで初期化されているためですか?
問題を解決する最もエレガントな方法は何ですか?