/*////////////////////////// GATEWAY HEADER //////////////////////////// // // _| _| _|_|_| _|_|_| _|_| _|_|_| _|_| // _|_| _|_| _| _| _| _| _| _| _| _| // _| _| _| _| _| _| _|_|_|_| _| _| _| // _| _| _| _| _| _| _| _| _| _| // _| _| _|_|_| _|_|_| _| _| _|_|_| _|_| // // Version 6.0 // //////////////////////////////////////////////////////////////////////// // // ========= PARALLEL VERSION ========= // ========= PARALLEL VERSION ========= // ========= PARALLEL VERSION ========= // //////////////////////////////////////////////////////////////////////// // // See the MIDACO user manual for detailed information // //////////////////////////////////////////////////////////////////////// // // Author (C) : Dr. Martin Schlueter // Information Initiative Center, // Division of Large Scale Computing Systems, // Hokkaido University, JAPAN. // // Email : info@midaco-solver.com // // URL : http://www.midaco-solver.com // //////////////////////////////////////////////////////////////////////*/ import java.util.HashMap; import static java.util.Arrays.asList; import java.util.concurrent.ForkJoinPool; import java.util.concurrent.RecursiveAction; /*////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////*/ class Midaco { public HashMap run( HashMap problem, double[] x_, double[] xl_, double[] xu_, HashMap option, HashMap parameter, String key ) { int o = problem.get("o"); int n = problem.get("n"); int ni = problem.get("ni"); int m = problem.get("m"); int me = problem.get("me"); int maxeval = option.get("maxeval"); int maxtime = option.get("maxtime"); int printeval = option.get("printeval"); int save2file = option.get("save2file"); double[] param = new double[13]; param[ 0] = parameter.get("param1"); /* ACCURACY */ param[ 1] = parameter.get("param2"); /* SEED */ param[ 2] = parameter.get("param3"); /* FSTOP */ param[ 3] = parameter.get("param4"); /* ALGOSTOP */ param[ 4] = parameter.get("param5"); /* EVALSTOP */ param[ 5] = parameter.get("param6"); /* FOCUS */ param[ 6] = parameter.get("param7"); /* ANTS */ param[ 7] = parameter.get("param8"); /* KERNEL */ param[ 8] = parameter.get("param9"); /* ORACLE */ param[ 9] = parameter.get("param10"); /* PARETOMAX */ param[10] = parameter.get("param11"); /* EPSILON */ param[11] = parameter.get("param12"); /* BALANCE */ param[12] = parameter.get("param13"); /* CHARACTER */ int p = option.get("parallel"); if(p < 1){ p = 1; } ForkJoinPool parallelexecution = new ForkJoinPool(p); /*////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////*/ int lrw = 120*n+20*m+20*o+20*p+p*(m+2*o)+o*o+5000; int liw = 3*n+p+1000; int lpf = 1; if ( o >= 2 ) { lpf = 1000 * (o+m+n) + 1; if ( param[9] >= 1.0 ) { lpf = (int)param[9] * (o+m+n) + 1; } if ( param[9] <=-1.0 ) { lpf = -(int)param[9] * (o+m+n) + 1; } } double[] x = new double[p*n]; double[] f = new double[p*o]; double[] g = new double[p*m]; double[] xl = new double[n]; double[] xu = new double[n]; double[] rw = new double[lrw]; double[] pf = new double[lpf]; int[] iw = new int[liw]; int[] iflag = new int[1]; iflag[0]=0; int[] istop = new int[1]; istop[0]=0; for(int c=0; c < p; c++) { for(int i=0; i < n; i++){ x[c*n+i] = x_[i]; } } for(int i=0; i < n; i++){ xl[i] = xl_[i]; } for(int i=0; i < n; i++){ xu[i] = xu_[i]; } /*////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////*/ runmidaco( 0, p,o,n,ni,m,me,x,f,g,xl,xu,iflag,istop,param, rw,lrw,iw,liw,pf,lpf,key,maxeval,maxtime, printeval,save2file); while ( istop[0] == 0 ) { if( p <= 1 ) { Example.problem(f,g,x); // Evaluate problem function } else { RecursiveAction task = new Parallelpool(0,p,o,m,n,f,g,x); parallelexecution.invoke(task); } runmidaco( 1, p,o,n,ni,m,me,x,f,g,xl,xu,iflag,istop,param, rw,lrw,iw,liw,pf,lpf,key,maxeval,maxtime, printeval,save2file); } /*////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////*/ HashMap solution= new HashMap(); solution.put("f", f); solution.put("g", g); solution.put("x", x); return solution; } /*////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////*/ public native void runmidaco( int mark, int p, int o, int n , int ni, int m, int me, double[] x, double[] f, double[] g, double[] xl, double[] xu, int[] iflag, int[] istop, double[] param, double[] rw, int lrw, int[] iw, int liw, double[] pf, int lpf, String key, int maxeval, int maxtime, int printeval, int save2file ); /**********************************/ /* Loading the MIDACO DLL library */ /**********************************/ // There are two possible ways to load the MIDACO DLL library "midacoj.dll". // The first one is a fixed path call, e.g. the MIDACO DLL is located at the Desktop. // The second one is a current directoy path call, where the MIDACO DLL is located at the current working directory. // Below code will try both options, where the fixed path is a dummy path to the user Desktop. // If the fixed path method is preferred, the user must provide the specific path in the below code. /**********************************/ static { // System.out.println("Working directory: " + System.getProperty("user.dir")); // System.out.println("Try loading MIDACO DLL library."); int s=0; // variable to indicate successful DLL loading try { System.load("C:\\Users\\Name\\Desktop\\midacoj.dll");s=1;} // fixed path Windows catch (UnsatisfiedLinkError e) {} try { System.load("/home/user/Desktop/midacoj.dll");s=1;} // fixed path Linux and Mac catch (UnsatisfiedLinkError e) {} try { System.load(System.getProperty("user.dir")+"\\midacoj.dll");s=1;} // current directory path Windows catch (UnsatisfiedLinkError e) {} try { System.load(System.getProperty("user.dir")+"/midacoj.dll");s=1;} // current directory path Linux and Mac catch (UnsatisfiedLinkError e) {} if( s == 0) System.out.println("ERROR: MIDACO DLL library file not found"); // if( s == 1) System.out.println("Success loading MIDACO DLL library."); } } /*////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////*/ class Parallelpool extends RecursiveAction { final int start, finih, o, m, n; final double[] f, g, x; public Parallelpool( int start, int finih, int o, int m, int n, double[] f, double[] g, double[] x) { this.start = start; this.finih = finih; this.o = o; this.m = m; this.n = n; this.f = f; this.g = g; this.x = x; } @Override protected void compute() { if (finih - start > 1) { int split = (start + finih) >>> 1; invokeAll(asList( new Parallelpool(start,split,o,m,n,f,g,x), new Parallelpool(split,finih,o,m,n,f,g,x) )); } else { double[] px = new double[n]; double[] pf = new double[o]; double[] pg = new double[m]; for (int i=0;i