ArrayXd CMADS::NOMADPoint2ArrayXd(const NOMAD::Point &p) { int i,n=p.size(); ArrayXd x(n); for ( i=0; i<n; i++ ) x(i)=p[i].value(); return x; }
/*---------------------------------------------------------*/ bool NOMAD::LH_Search::LH_points ( int n , int m , int p , const NOMAD::Point & lb , const NOMAD::Point & ub , std::vector<NOMAD::Eval_Point *> & pts ) { if ( n <= 0 || p <= 0 || !lb.is_defined() || !ub.is_defined() || lb.size() != n || ub.size() != n ) return false; for ( size_t j = 0 ; j < pts.size() ; ++j ) delete pts[j]; pts.clear(); NOMAD::Eval_Point * x; int i; int pm1 = p-1; NOMAD::Random_Pickup ** rps = new NOMAD::Random_Pickup *[n]; for ( int k = 0 ; k < p ; ++k ) { x = new NOMAD::Eval_Point ( n , m ); for ( i = 0 ; i < n ; ++i ) { if ( k==0 ) rps[i] = new NOMAD::Random_Pickup(p); (*x)[i] = lb[i] + (ub[i]-lb[i]) * ( rps[i]->pickup() + NOMAD::RNG::rand()/(1.0+NOMAD::D_INT_MAX)) / p; if ( k==pm1 ) delete rps[i]; } pts.push_back(x); } delete [] rps; return true; }
/*---------------------------------------------------------*/ NOMAD::Model_Sorted_Point::Model_Sorted_Point ( NOMAD::Point * x , const NOMAD::Point & center ) : _x(x) { int i , n = center.size(); if ( x && x->size() == n ) { _dist = 0.0; for ( i = 0 ; i < n ; ++i ) if ( (*x)[i].is_defined() && center[i].is_defined() ) { _dist += ( (*x)[i] - center[i] ).pow2(); } else { _dist.clear(); break; } } }
/*-----------------------------------------------------------*/ void NOMAD::SMesh::update ( NOMAD::success_type success , NOMAD::Point & mesh_indices, const NOMAD::Direction *dir ) const { if ( mesh_indices.is_defined() ) { for (int i=0; i < mesh_indices.size() ; i++) { if ( success == NOMAD::FULL_SUCCESS ) { mesh_indices[i] -= _coarsening_step; if ( mesh_indices[i] < -NOMAD::L_LIMITS ) mesh_indices[i] = -NOMAD::L_LIMITS; } else if ( success == NOMAD::UNSUCCESSFUL ) mesh_indices[i] -= _refining_step; } } }
/*----------------------------------------------------------------*/ void NOMAD::TGP_Model::eval_hf(const NOMAD::Point &bbo , const NOMAD::Double &h_min , NOMAD::hnorm_type h_norm , NOMAD::Double &h , NOMAD::Double &f) const { f.clear(); h = 0.0; int m = bbo.size(); if (m != static_cast<int>(_bbot.size())) throw NOMAD::Exception("TGP_Model.cpp" , __LINE__ , "TGP_Model::eval_hf() called with an invalid bbo argument"); NOMAD::Double bboi; for (int i = 0 ; i < m ; ++i) { bboi = bbo[i]; if (bboi.is_defined()) { if (_bbot[i] == NOMAD::EB || _bbot[i] == NOMAD::PEB_E) { if (bboi > h_min) { h.clear(); return; } } else if ((_bbot[i] == NOMAD::FILTER || _bbot[i] == NOMAD::PB || _bbot[i] == NOMAD::PEB_P)) { if (bboi > h_min) { switch (h_norm) { case NOMAD::L1: h += bboi; break; case NOMAD::L2: h += bboi * bboi; break; case NOMAD::LINF: if (bboi > h) h = bboi; break; } } } else if (_bbot[i] == NOMAD::OBJ) f = bboi; } } if (h_norm == NOMAD::L2) h = h.sqrt(); }
/*---------------------------------------------------------*/ void NOMAD::Variable_Group::get_directions ( std::list<NOMAD::Direction> & dirs , NOMAD::poll_type poll , const NOMAD::Point & poll_center , int mesh_index , const NOMAD::Direction & feas_success_dir , const NOMAD::Direction & infeas_success_dir ) { int nc = static_cast<int>(_var_indexes.size()); // vectors are of size nc : // ------------------------ if ( nc == poll_center.size() ) { _directions->compute ( dirs , poll , poll_center , mesh_index , -1 , feas_success_dir , infeas_success_dir ); return; } // construct vectors of size nc from vectors of size < nc : // -------------------------------------------------------- std::set<int>::const_iterator it ; int i = 0; NOMAD::Point new_poll_center ( nc ); NOMAD::Direction new_fsd , new_isd; if ( feas_success_dir.is_defined() ) new_fsd = NOMAD::Direction ( nc , 0.0 , feas_success_dir.get_type() ); if ( infeas_success_dir.is_defined() ) new_isd = NOMAD::Direction ( nc , 0.0 , infeas_success_dir.get_type() ); for ( it = _var_indexes.begin() ; it != _var_indexes.end() ; ++it ) { new_poll_center[i] = poll_center[*it]; if ( feas_success_dir.is_defined() ) new_fsd[i] = feas_success_dir [*it]; if ( infeas_success_dir.is_defined() ) new_isd[i] = infeas_success_dir[*it]; ++i; } _directions->compute ( dirs , poll , new_poll_center , mesh_index , -1 , new_fsd , new_isd ); }