/*------------------------------------------*/ int main ( int argc , char ** argv ) { // display: Display out ( cout ); out.precision ( DISPLAY_PRECISION_STD ); // NOMAD initializations: begin ( argc , argv ); try { // parameters creation: Parameters p ( out ); p.set_DIMENSION (5); // number of variables vector<bb_output_type> bbot (3); // definition of bbot[0] = OBJ; // output types bbot[1] = OBJ; bbot[2] = EB; p.set_BB_OUTPUT_TYPE ( bbot ); p.set_X0 ( Point ( 5 , 0.0 ) ); // starting point p.set_LOWER_BOUND ( Point ( 5 , -6.0 ) ); // all var. >= -6 Point ub ( 5 ); // x_4 and x_5 have no bounds ub[0] = 5.0; // x_1 <= 5 ub[1] = 6.0; // x_2 <= 6 ub[2] = 7.0; // x_3 <= 7 p.set_UPPER_BOUND ( ub ); p.set_MULTI_OVERALL_BB_EVAL (100); // the algorithm terminates after // 100 black-box evaluations // p.set_TMP_DIR ("/tmp"); // directory for // temporary files // parameters validation: p.check(); // custom evaluator creation: My_Evaluator ev ( p ); // algorithm creation and execution: Mads mads ( p , &ev ); mads.multi_run(); } catch ( exception & e ) { cerr << "\nNOMAD has been interrupted (" << e.what() << ")\n\n"; } Slave::stop_slaves ( out ); end(); return EXIT_SUCCESS; }
/*---------------------------------------*/ void nomad_ ( int * n , // # of variables int * m , // # of outputs (obj + m-1 constraints) double * x , // starting point (IN) / solution (OUT) double * lb , // lower bounds for each variable double * ub , // upper bounds int * max_bbe , // max # of evaluations (-1: not considered) int * display_degree ) { // display_degree (0-4; 0: no display) // display: Display out ( std::cout ); out.precision ( DISPLAY_PRECISION_STD ); try { int i; // parameters creation: Parameters p ( out ); p.set_DIMENSION (*n); // number of variables vector<bb_output_type> bbot (*m); // definition of output types: bbot[0] = OBJ; // first output : objective value to minimize for ( i = 1 ; i < *m ; ++i ) // other outputs: constraints cj <= 0 bbot[i] = PB; p.set_BB_OUTPUT_TYPE ( bbot ); // starting point and bounds: Point px0 ( *n ); Point plb ( *n ); Point pub ( *n ); for ( i = 0 ; i < *n ; ++i ) { px0[i] = x [i]; if ( lb[i] > -1e20 ) plb[i] = lb[i]; if ( ub[i] < 1e20 ) pub[i] = ub[i]; } p.set_X0 ( px0 ); p.set_LOWER_BOUND ( plb ); p.set_UPPER_BOUND ( pub ); p.set_LH_SEARCH ( 50, 0 ); p.set_INITIAL_MESH_SIZE(0.1); // maximum number of black-box evaluations: if ( *max_bbe > 0 ) p.set_MAX_BB_EVAL ( *max_bbe ); // display degree: p.set_DISPLAY_DEGREE ( *display_degree ); // parameters validation: p.check(); // custom evaluator creation: My_Evaluator ev ( p ); // algorithm creation and execution: Mads mads ( p , &ev ); mads.run(); // get the solution: const Eval_Point * bf = mads.get_best_feasible(); if ( bf ) for ( i = 0 ; i < *n ; ++i ) x[i] = (*bf)[i].value(); } catch ( exception & e ) { cerr << "\nNOMAD has been interrupted (" << e.what() << ")\n\n"; } }
/*------------------------------------------*/ int main ( int argc , char ** argv ) { // display: Display out ( std::cout ); out.precision ( DISPLAY_PRECISION_STD ); // NOMAD initializations: begin ( argc , argv ); try { // parameters creation: Parameters p ( out ); int i; if ( USE_SURROGATE ) p.set_HAS_SGTE ( true ); p.set_DIMENSION (42); // number of variables vector<bb_output_type> bbot (1); // definition of bbot[0] = OBJ; // output types p.set_BB_OUTPUT_TYPE ( bbot ); Point x0(42); // double xstart[42] = {-1.8757, -1.7941, -1.8067, -0.3861, 0.2472, -0.0461, 0.0690, 0.1874, 1.7112, 1.7350 // 1.7378, 1.7467, 1.7751, 1.7897, 0.0, 3.1141, 3.0047, 6.2250, -4.0621, 1.2552, 3.6738, // -4.2907, 5.0398, 0.0, 5.0355, 2.4703, 2.5445, 2.4371, 0.0, 0.0, -3.0047, 1.2913, 6.2250, 1.2552, // 1.2125, 3.7093, 0.0, 0.0, 5.0355, 5.0402, 0.0, 2.4371}; double xstart[42] = {-1.87570000000000, -1.79410005000000, -1.80669999000000, -0.38609999000000, -0.25279999000000, -0.04610000000000, 0.06900000000000, 0.18740000000000, 1.71120000000000, 1.73500001000000, 1.73780000000000, 1.74670005000000, 1.77509999000000, 1.78970003000000, 0.0, 3.11409998000000, 3.00469995000000, 6.22499990000000, 3.93790007000000, 1.25520003000000, 3.67379999000000, 3.70930004000000, 5.03980017000000, 0.0, 5.03550005000000, 2.47029996000000, 2.54450011000000, 2.43709993000000, 0.0, 0.0, -3.00469995000000, 1.29130006000000, 6.22499990000000, 1.25520003000000, 1.21249998000000, 3.70930004000000, 0.0, 0.0, 5.03550005000000, 5.04020023000000, 0.0, 2.43709993000000}; for ( i = 0 ; i < 42 ; ++i ) { x0[i] = xstart[i]; // cout << i << " " << x0[i] << "\n" ; } p.set_X0 (x0); // starting point Point lb (42), ub(42); for ( i = 0 ; i < 14 ; ++i ) { lb[i] = -3.0; lb[i+14] = -4.0; lb[i+28] = -4.0; ub[i] = 3.0; ub[i+14] = 10.0; ub[i+28] = 10.0; } p.set_LOWER_BOUND (lb); p.set_UPPER_BOUND (ub); p.set_INITIAL_MESH_SIZE(1.0); p.set_MAX_BB_EVAL (2000); // the algorithm terminates after // 500 black-box evaluations // p.set_TMP_DIR ("/tmp"); // repertory for // temporary files // parameters validation: p.check(); // custom evaluator creation: My_Evaluator ev ( p ); // algorithm creation and execution: Mads mads ( p , &ev ); mads.run(); } catch ( exception & e ) { cerr << "\nNOMAD has been interrupted (" << e.what() << ")\n\n"; } Slave::stop_slaves ( out ); end(); return EXIT_SUCCESS; }
/*----------------------------------------*/ void Master_Slaves::mads_run ( Cache & cache ) { const Eval_Point * best_feasible = NULL; const Eval_Point * best_infeasible = NULL; Double old_f = INF; bool stop_algo = false; int run_index = 0; int mesh_index = 0; double default_eps = Double::get_epsilon(); int n = _p.get_dimension(); int * free_vars = new int [_ns]; Point x0 ( n ) , delta_0 , delta_min; /*---------------------*/ /* main loop */ /*---------------------*/ while ( !stop_algo ) { best_feasible = NULL; best_infeasible = NULL; // random SEED: _p.set_SEED ( get_pid() + run_index ); // Halton seed: _p.set_HALTON_SEED ( 7999 + 99 * _rank + 20 * run_index ); // first run: if ( run_index == 0 ) { // max number of evaluations for regular slaves: if ( _rank != 1 ) _p.set_MAX_BB_EVAL ( _bbe ); // display: // p.set_DISPLAY_STATS ( "process #" + itos(_rank) + " BBE OBJ" ); // p.set_DISPLAY_DEGREE ( FULL_DISPLAY ); _p.set_DISPLAY_DEGREE ( NO_DISPLAY ); } // force the parameters check: _p.force_check_flag(); /*------------------*/ /* pollster slave */ /*------------------*/ if ( _rank == 1 ) { stop_type stop_reason = UNKNOWN_STOP_REASON; Mesh::get_delta_m ( delta_0 , _initial_mesh_size , _mesh_update_basis , _initial_mesh_index , mesh_index ); // we set a very small epsilon in order to accept // very small initial mesh sizes: Double::set_epsilon ( 1e-16 ); if ( !check_delta ( delta_0 ) ) stop_algo = true; else { // first run: if ( run_index == 0 ) { // directions: { int halton_seed = _p.get_halton_seed(); bool use_orthomads = _p.has_orthomads_directions(); _p.reset_directions ( halton_seed ); _p.set_DIRECTION_TYPE ( (use_orthomads) ? ORTHO_1 : LT_1 ); } // cache search: _p.set_CACHE_SEARCH ( true ); _p.set_OPPORTUNISTIC_CACHE_SEARCH ( false ); } // other runs: else { // stop_algo may be set to 'false' here: receive_optimization_data ( stop_algo , x0 , old_f ); // starting point: _p.reset_X0(); _p.set_X0 ( x0 ); } if ( !stop_algo ) { // pollster mesh: _p.set_INITIAL_MESH_INDEX ( mesh_index ); _p.set_MAX_MESH_INDEX ( mesh_index ); _p.set_INITIAL_MESH_SIZE ( delta_0 ); _p.set_MIN_MESH_SIZE ( delta_0 ); // check the parameters: _p.check(); Double::set_epsilon ( default_eps ); Mads mads ( _p , NULL , NULL , &cache , NULL ); stop_reason = mads.run(); best_feasible = mads.get_best_feasible(); best_infeasible = mads.get_best_infeasible(); bool success = false; if ( best_feasible ) { success = (best_feasible->get_f() < old_f); if ( _debug ) _p.out() << "POLLSTER: ELL=" << mesh_index << " BBE=" << mads.get_stats().get_bb_eval() << " OLD_F=" << old_f << " NEW_F=" << best_feasible->get_f() << " SUCCESS=" << success << endl; } // pollster mesh update: if ( success ) --mesh_index; else ++mesh_index; } } send_optimization_result ( mesh_index , stop_algo , best_feasible , best_infeasible , stop_reason ); } /*------------------*/ /* regular slaves */ /*------------------*/ else { int i , j , pollster_mesh_index; receive_optimization_data ( stop_algo , x0 , old_f , pollster_mesh_index , free_vars ); if ( _debug ) { _p.out() << "SLAVE #" << _rank << ": OPTIM. DATA: [STOP=" << stop_algo << "] [POLLSTER_MESH_INDEX=" << pollster_mesh_index << "] [X0=" << x0 << " ] [f(X0)=" << old_f << "] [FREE VARS= "; for ( i = 0 ; i < _ns ; ++i ) _p.out() << free_vars[i] << " "; _p.out() << " ]" << endl; } if ( !stop_algo ) { // starting point: _p.reset_X0(); _p.set_X0 ( x0 ); // mesh of the regular slave: int ell_0 = 0; if ( pollster_mesh_index < ell_0 ) ell_0 = pollster_mesh_index; Mesh::get_delta_m ( delta_0 , _initial_mesh_size , _mesh_update_basis , _initial_mesh_index , ell_0 ); Mesh::get_delta_m ( delta_min , _initial_mesh_size , _mesh_update_basis , _initial_mesh_index , pollster_mesh_index ); Double::set_epsilon ( 1e-16 ); if ( !check_delta ( delta_0 ) || !check_delta ( delta_min ) ) stop_algo = true; else { // mesh of the regular slave: _p.set_INITIAL_MESH_INDEX ( ell_0 ); _p.set_MAX_MESH_INDEX ( pollster_mesh_index ); _p.set_INITIAL_MESH_SIZE ( delta_0 ); _p.set_MIN_MESH_SIZE ( delta_min ); // free variables: { _p.reset_fixed_variables(); bool fix_var; for ( i = 0 ; i < n ; ++i ) { fix_var = true; for ( j = 0 ; j < _ns ; ++j ) if ( free_vars[j] == i ) { fix_var = false; break; } if ( fix_var ) _p.set_FIXED_VARIABLE ( i ); } } // check the parameters: _p.check(); Double::set_epsilon ( default_eps ); // MADS run: Mads mads ( _p , NULL , NULL , &cache , NULL ); mads.run(); best_feasible = mads.get_best_feasible(); best_infeasible = mads.get_best_infeasible(); if ( _debug && best_feasible ) { _p.out() << "RANK #" << _rank << ": POLLSTER_ELL=" << pollster_mesh_index << " VARS = ["; for ( i = 0 ; i < _ns ; ++i ) _p.out() << free_vars[i] << " "; _p.out() << " ] BBE=" << mads.get_stats().get_bb_eval() << " OLD_F=" << old_f << " NEW_F=" << best_feasible->get_f() << " SUCCESS=" << (best_feasible->get_f() < old_f) << endl; } } } { int tmp1 = -1; bool tmp2 = false; stop_type tmp3 = UNKNOWN_STOP_REASON; send_optimization_result ( tmp1 , tmp2 , best_feasible , best_infeasible , tmp3 ); } } // loop increment: ++run_index; } delete [] free_vars; }
/*------------------------------------------*/ int main ( int argc , char ** argv ) { // display: Display out ( std::cout ); out.precision ( DISPLAY_PRECISION_STD ); // NOMAD initializations: begin ( argc , argv ); try { // usage: if ( argc < 2 ) { display_usage ( cerr ); return EXIT_SUCCESS; } // parameters file: string param_file_name = argv[1]; string opt = param_file_name; NOMAD::toupper(opt); // display version if option '-v' has been specified: if ( opt == "-V" ) { display_version ( out ); return EXIT_SUCCESS; } // display info if option '-i' has been specified: if ( opt == "-I" || opt == "-INFO" ) { display_info ( out ); display_usage ( out ); return EXIT_SUCCESS; } // parameters creation: Parameters p ( out ); // display help on parameters if option '-h' has been specified: if ( opt == "-H" || opt == "-HELP" ) { p.help( (argc>2) ? argv[2] : "all" ); return EXIT_SUCCESS; } // read parameters file: p.read ( param_file_name ); // parameters check: p.check(); // display NOMAD info: if ( p.get_display_degree() > 1 ) display_info ( out ); // parameters display: if ( p.get_display_degree() > 2 ) out << endl << "parameters:" << endl << p << endl; // single-objective: if ( p.get_nb_obj() == 1 ) { // custom evaluator: My_Evaluator ev ( p ); // algorithm creation and execution: Mads mads ( p , &ev ); mads.run(); // plot the last point: const Eval_Point * bf = mads.get_best_feasible(); if ( bf ) ev.plot_success ( mads.get_stats().get_bb_eval() , bf->get_f() ); } // bi-objective: else { // custom evaluator: My_Multi_Obj_Evaluator ev ( p ); // algorithm creation and execution: Mads mads ( p , &ev ); mads.multi_run(); } } catch ( exception & e ) { cerr << "\nNOMAD has been interrupted (" << e.what() << ")\n\n"; } GUI_wait(); Slave::stop_slaves ( out ); end(); return EXIT_SUCCESS; }
/*------------------------------------------*/ int main ( int argc , char ** argv ) { // display: Display out ( std::cout ); out.precision ( DISPLAY_PRECISION_STD ); // NOMAD initializations: begin ( argc , argv ); try { // usage: if ( argc != 4 ) { cerr << "\nusage: multi param.txt nb_circles nb_mads_runs\n\n"; return 1; } int NBC = atoi(argv[2] ); if ( NBC < 4 ) { cerr << "\nthe number of circles must be > 3\n\n"; return 1; } int N = 2*NBC-3; //int M = ( NBC * ( NBC + 1 ) - 8 ) / 2; int M = 2; // list of x0 points (LH strategy is used): // ----------------- vector<Point *> x0_pts; // srand ( static_cast<int> ( time(0) ) ); srand(0); rand(); int i; int nb_mads_runs = atoi ( argv[3] ); LH_x0 ( N , nb_mads_runs , x0_pts ); // read best_x.txt: ifstream fin ( "best_x.txt"); if ( !fin.fail() ) for ( int i = 0 ; i < N ; ++i ) fin >> (*x0_pts[0])[i]; fin.close(); // display all starting points: out << endl; for ( int j = 0 ; j < nb_mads_runs ; ++j ) out << "starting point # " << j << ": ( " << *x0_pts[j] << " )" << endl; out << endl; // parameters creation: // -------------------- Parameters param ( out ); param.set_DIMENSION (N); vector<bb_output_type> bbot (M+1); for ( i = 0 ; i < M ; ++i ) bbot[i] = PB; bbot[M] = OBJ; param.set_BB_OUTPUT_TYPE ( bbot ); Point lb ( N , LB ); Point ub ( N , UB ); param.set_LOWER_BOUND ( lb ); param.set_UPPER_BOUND ( ub ); param.read ( argv[1] ); param.set_DISPLAY_DEGREE (0); param.set_X0 ( *x0_pts[0] ); // parameters check: param.check(); // out << param << endl; // custom evaluator creation: My_Evaluator ev ( param , NBC , M ); const Eval_Point * cur_x; Point best_x (N); Double best_f = INF , worst_f = 0.0 , avg_f = 0.0; // MADS runs: // ---------- int bbe = 0; i = 0; while ( true ) { // algorithm creation: Mads mads ( param , &ev ); mads.run(); bbe += mads.get_cache().size(); // displays and remember the best point: out << "run #" << setw(2) << i << ": "; cur_x = mads.get_best_feasible(); if ( cur_x ) { out << "f=" << cur_x->get_f() << endl; if ( cur_x->get_f() < best_f ) { best_f = cur_x->get_f(); best_x = *cur_x; } if ( cur_x->get_f() > worst_f ) worst_f = cur_x->get_f(); avg_f += cur_x->get_f(); } else out << "NULL" << endl; if ( ++i == nb_mads_runs ) break; // preparation of next run: mads.reset(); param.reset_X0(); param.set_X0 ( *x0_pts[i] ); param.check(); } // display the solution: out << endl << "bb eval : " << bbe << endl << "best : " << best_f; out << endl << "worst : " << worst_f << endl << "solution: "; out << "x = ( "; best_x.display ( out , " " , -1 , -1 ); out << " ) f(x) = " << best_f.value(); out << endl << endl; ofstream fout ( "best_x.txt" ); fout << setprecision(32); best_x.display ( fout , " " , -1 , -1 ); fout.close(); // delete x0 points: for ( i = 0 ; i < nb_mads_runs ; ++i ) delete x0_pts[i]; } catch ( exception & e ) { cerr << "\nNOMAD has been interrupted (" << e.what() << ")\n\n"; } end(); return EXIT_SUCCESS; }