Esempio n. 1
1
/*------------------------------------------*/
int main ( int argc , char ** argv )
{
	
  // display:
  NOMAD::Display out ( NOMAD::rout );     //zhenghua
  out.precision ( NOMAD::DISPLAY_PRECISION_STD );
	

  std::string error;
  {
    // NOMAD initializations:
    NOMAD::begin ( argc , argv );

    // usage:
    if ( argc < 2 ) {
      NOMAD::display_usage ( out); //zhenghua
      NOMAD::end();
      return EXIT_FAILURE;
    }

    // parameters file:
    std::string param_file_name = argv[1];
    std::string opt             = param_file_name;
    NOMAD::toupper ( opt );

	  // display version if option '-v' has been specified:
	  if ( opt == "-U" ) {
		  NOMAD::display_usage ( out );
		  NOMAD::end();
		  return EXIT_SUCCESS;
	  }
	  
	  
    // display version if option '-v' has been specified:
    if ( opt == "-V" || opt =="-VERSION") {
      NOMAD::display_version ( out );
      NOMAD::end();
      return EXIT_SUCCESS;
    }

    // display info if option '-i' has been specified:
    if ( opt == "-I" || opt == "-INFO" ) {
      NOMAD::display_info  ( out );
      NOMAD::display_usage ( out ); //zhenghua
      NOMAD::end();
      return EXIT_SUCCESS;
    }
  
    // parameters creation:
    NOMAD::Parameters p ( out );

    // display help on parameters if option '-h' has been specified:
    if ( opt == "-H" || opt == "-HELP" ) {
      p.help ( argc , argv );
      NOMAD::end();
      return EXIT_SUCCESS;
    }

	  // display developer help on parameters if option '-d' has been specified:
	  if ( opt == "-D" ) {
		  p.help ( argc , argv,true );
		  NOMAD::end();
		  return EXIT_SUCCESS;
	  }  
	  
	  
    // check the number of processess:
#ifdef USE_MPI
    if ( NOMAD::Slave::get_nb_processes() < 2 ) {
				NOMAD::rout << "ERROR: Incorrect command to run with MPI." << std::endl; //zhenghua
      NOMAD::display_usage ( out ); //zhenghua
      NOMAD::end();
      return EXIT_FAILURE;
    }
#endif
    
    try {

	
      // read parameters file:
      p.read ( param_file_name );

      // parameters check:
      p.check();

	  // display NOMAD info:
	  if ( p.get_display_degree() > NOMAD::MINIMAL_DISPLAY)
		NOMAD::display_info ( out );

      // parameters display:
      if ( NOMAD::Slave::is_master() &&
       	   p.get_display_degree() == NOMAD::FULL_DISPLAY ) 
	out << std::endl
	    << NOMAD::open_block ( "parameters" ) << std::endl
	    << p
	    << NOMAD::close_block();

      // algorithm creation and execution:
      NOMAD::Mads mads ( p , NULL );
      if ( p.get_nb_obj() == 1 )
	mads.run();
      else
	mads.multi_run();

#ifdef MODEL_STATS
      mads.display_model_stats ( out );
#endif

    }
    catch ( std::exception & e ) {
      if ( NOMAD::Slave::is_master() ) {
	error = std::string ( "NOMAD has been interrupted: " ) + e.what();
	NOMAD::rout << std::endl << error << std::endl << std::endl;  //zhenghua
      }
    }
    
    NOMAD::Slave::stop_slaves ( out );
    NOMAD::end();
  }

#ifdef MEMORY_DEBUG
  NOMAD::display_cardinalities ( out );
#endif

  return ( error.empty() ) ? EXIT_SUCCESS : EXIT_FAILURE;
}
Esempio n. 2
0
 /**
  - Basic version.
  \param p  Parameters                 -- \b IN.
  \param ev A pointer to the evaluator -- \b IN
  -- \b optional (default = \c NULL).
  */
 Mads ( NOMAD::Parameters & p , NOMAD::Evaluator * ev = NULL )
 : _p                   ( p                             ) ,
 _stats                 ( p.get_sgte_cost()             ) ,
 _ev_control            ( p , _stats , ev , NULL , NULL ) ,
 _ev_control_for_sorting( p , _stats , _ev_control.get_evaluator() , &(_ev_control.get_cache()) , &(_ev_control.get_sgte_cache()) ) ,
 _true_barrier          ( p , NOMAD::TRUTH              ) ,
 _sgte_barrier          ( p , NOMAD::SGTE               ) ,
 _mesh				   ( p.get_signature()->get_mesh() ) ,
 _pareto_front          ( NULL                          ) ,
 _user_search           ( NULL                          ) ,
 _model_search1         ( NULL                          ) ,
 _model_search2         ( NULL                          ) ,
 _VNS_search            ( NULL                          ) ,
 _cache_search          ( NULL                          ) ,
 _L_curve               ( NULL                          ) ,
 _extended_poll         ( NULL                          ) ,
 _user_ext_poll         ( false                         )   { init(); }
Esempio n. 3
0
 //Constructor
 matlabEval(const NOMAD::Parameters &p, usrFcn *_obj, int _nobj, usrFcn *_con, int _ncon, iter_fun_data *_iterF) : NOMAD::Evaluator(p)
 {
     fun     = _obj;
     hasSur  = p.has_sgte();
     nobj    = _nobj;
     con     = _con;   
     ncon    = _ncon;
     iterF   = _iterF;
     citer   = 0;
 }        
Esempio n. 4
0
 /**
  - Advanced version.
  \param p             Parameters                 -- \b IN.
  \param ev            A pointer to the evaluator -- \b IN (may be \c NULL).
  \param extended_poll A pointer to a NOMAD::Extended_Poll object
  -- \b IN (may be \c NULL).
  \param cache         A pointer to a cache       -- \b IN (may be \c NULL).
  \param sgte_cache    A pointer to a cache for surrogates
  -- \b IN (may be \c NULL).
  */
 Mads ( NOMAD::Parameters    & p             ,
       NOMAD::Evaluator     * ev            ,     // may be NULL
       NOMAD::Extended_Poll * extended_poll ,     // may be NULL
       NOMAD::Cache         * cache         ,     // may be NULL
       NOMAD::Cache         * sgte_cache      )   // may be NULL
 : _p                     ( p                                    ) ,
 _stats                 ( p.get_sgte_cost()                    ) ,
 _ev_control            ( p , _stats , ev , cache , sgte_cache ) ,
 _ev_control_for_sorting( p , _stats , _ev_control.get_evaluator() , cache , sgte_cache ) ,
 _true_barrier          ( p , NOMAD::TRUTH                     ) ,
 _sgte_barrier          ( p , NOMAD::SGTE                      ) ,
 _mesh                  ( p.get_signature()->get_mesh()		  ) ,
 _pareto_front          ( NULL                                 ) ,
 _user_search           ( NULL                                 ) ,
 _model_search1         ( NULL                                 ) ,
 _model_search2         ( NULL                                 ) ,
 _VNS_search            ( NULL                                 ) ,
 _cache_search          ( NULL                                 ) ,
 _L_curve               ( NULL                                 ) ,
 _extended_poll         ( extended_poll                        ) ,
 _user_ext_poll         ( (extended_poll!=NULL)                )   { init(); }
Esempio n. 5
0
 /**
  \param p  Parameters         -- \b IN.
  \param et Truth or surrogate -- \b IN.
  */
 Barrier(const NOMAD::Parameters &p , NOMAD::eval_type et)
     : _p(p) ,
       _eval_type(et) ,
       _h_max(p.get_h_max_0()) ,
       _best_feasible(NULL) ,
       _ref(NULL) ,
       _rho_leaps(0) ,
       _poll_center(NULL) ,
       _sec_poll_center(NULL) ,
       _peb_changes(0) ,
       _peb_filter_reset(0) ,
       _one_eval_succ(NOMAD::UNSUCCESSFUL) ,
       _success(NOMAD::UNSUCCESSFUL)   {}
Esempio n. 6
0
//
// Set options specified in R object opts in IpoptApplcation app.
// If we set the option to approximate the Hessian, then IpoptRNLP
// needs to know that, so it can return false when calling eval_h,
// instead of trying to find an R function that evaluates the Hessian.
//
// SEXP opts is an R list containing three sub-lists, with names
// integer, string and numeric. These sub-lists contain the actual
// options and there values that were specified by the user.
// Passing the options in this way makes it easier to call different
// SetValue function in IpoptApplication of the different types.
//
void setApplicationOptions(NOMAD::Parameters & p, SEXP opts ) {

		std::stringbuf nomadbuf;
		std::iostream fp(&nomadbuf);


		fp.precision(15);
		fp.seekg(0, std::ios::beg);
		// extract the sub-lists with options of the different types into separate lists
		SEXP opts_integer = getListElement(opts, "integer");
		SEXP opts_numeric = getListElement(opts, "numeric");
		SEXP opts_string = getListElement(opts, "string");

		//	showArgs1(opts_integer);
		//	showArgs1(opts_numeric);
		//		showArgs1(opts_string);

		// loop over the integer options and set them
		SEXP opts_integer_names;
		opts_integer_names = getAttrib(opts_integer, R_NamesSymbol);
		for (int list_cnt=0;list_cnt<length( opts_integer );list_cnt++) {

				SEXP opt_value;
				PROTECT(opt_value = AS_INTEGER(VECTOR_ELT(opts_integer, list_cnt)));

			fp <<  CHAR(STRING_ELT(opts_integer_names,  list_cnt)) << "\t" <<  INTEGER(opt_value)[0] << std::endl;
			

				UNPROTECT(1);	
		}

		// loop over the numeric options and set them
		SEXP opts_numeric_names;
		opts_numeric_names = getAttrib(opts_numeric, R_NamesSymbol);
		for (int list_cnt=0;list_cnt<length( opts_numeric );list_cnt++) {

				SEXP opt_value;
				PROTECT(opt_value = VECTOR_ELT(opts_numeric, list_cnt));

				fp << CHAR(STRING_ELT(opts_numeric_names,  list_cnt)) << "\t" <<  REAL(opt_value)[0] << std::endl;

				UNPROTECT(1);	

		}


		// loop over the string options and set them
		SEXP opts_string_names;
		opts_string_names = getAttrib(opts_string, R_NamesSymbol);
		for (int list_cnt=0;list_cnt<length( opts_string );list_cnt++) {

				// opt_value will contain the first (should be the only one) element of the list
				SEXP opt_value;
				PROTECT(opt_value = STRING_ELT(VECTOR_ELT(opts_string, list_cnt),0));

				fp <<  CHAR(STRING_ELT(opts_string_names,  list_cnt)) << "\t" <<   CHAR(opt_value) << std::endl;


				UNPROTECT(1);	
		}

		fp.seekg (0,  std::ios::beg);

		p.read(fp);

		return;
}
Esempio n. 7
0
/*-----------------------------------*/
int main ( int argc , char ** argv ) {

  // MPI initialization:
  MPI_Init ( &argc , &argv );
  int rank , np;
  MPI_Comm_rank ( MPI_COMM_WORLD, &rank );
  MPI_Comm_size ( MPI_COMM_WORLD, &np   );

  // check the arguments and the number of processes:
  if ( np <= 2 || argc != 4 ) {
    if ( rank == 0 )
      cerr << "usage: mpirun -np p " << argv[0]
	   << " param_file bbe ns, with p>2,"
	   << " bbe>1, and 1<=ns<=n."
	   << endl;
    MPI_Finalize();
    return 1;
  }

  // display:
  Display out ( cout );
  out.precision ( 16 );

  // parameters:
  NOMAD::Parameters p ( out );
  int bbe = atoi ( argv[2] );
  int ns  = atoi ( argv[3] );

  try {

    // read the parameters file:
    p.read ( argv[1] );

    // check the parameters:
    p.check();

    if ( ns < 1 || ns > p.get_dimension() )
      throw Exception ( __FILE__ , __LINE__ ,
      "Bad value for ns the number of free variables for each process" );

    if ( p.get_nb_obj() > 1 )
      throw Exception ( __FILE__ , __LINE__ ,
      "PSD-MADS is not designed for multi-objective optimization" );
  }
  catch ( exception & e ) {
    if ( rank == 0 )
      cerr << "error with parameters" << endl;
    MPI_Finalize();
    return 1;
  }

  // start the master:
  Master_Slaves master_slaves ( rank , np , bbe , ns , p , DEBUG );
  master_slaves.start();

  // cache server:
  Cache_Server cache ( out                  ,
		       rank                 ,
		       np                   ,
		       p.get_h_min()        ,
		       p.get_max_bb_eval()  ,
		       false                ,  // ALLOW_MULTIPLE_EVALS
		       DEBUG                  );

  // start the cache server:
  if ( rank == np-1 ) {
    if ( !DEBUG )
      out << endl << "TIME\tBBE\tOBJ" << endl << endl;
    cache.start();
  }

  // slaves: algorithm creation and execution:
  if ( rank != 0 && rank != np-1 ) {

    // MADS run:
    master_slaves.mads_run ( cache );

    // stop the master:
    master_slaves.stop();
  }

  // stop the cache server:
  cache.stop();

  // display the final solution:
  if ( !DEBUG && rank == np-1 )
    cache.display_best_points ( out );

  // MPI finalization:
  MPI_Finalize();
  return 0;
}