ArrayXd CMADS::optimize(COptimizationProblem *_pOP,std::ostream &_out) { pOP=_pOP; pOP->openOptimization(); int j,M=pOP->constraintsSize(); NOMAD::Display out; //(_out); NOMAD::begin(0,NULL); NOMAD::Parameters p(out); p.set_DISPLAY_DEGREE(NOMAD::NO_DISPLAY);// (NOMAD::NORMAL_DISPLAY); p.set_DIMENSION(pOP->dimension()); p.set_X0(ArrayXd2NOMADPoint(pOP->initialValue())); p.set_LOWER_BOUND(ArrayXd2NOMADPoint(pOP->lowerBound())); p.set_UPPER_BOUND(ArrayXd2NOMADPoint(pOP->upperBound())); p.set_MAX_BB_EVAL(maxeval); p.set_LH_SEARCH(lh0,lhi); p.set_INITIAL_MESH_SIZE(ArrayXd2NOMADPoint((pOP->upperBound()-pOP->lowerBound())*ims)); p.set_MIN_POLL_SIZE(ArrayXd2NOMADPoint((pOP->upperBound()-pOP->lowerBound())*mps)); std::vector <NOMAD::bb_output_type> bbot(M+2); bbot[0]=NOMAD::OBJ; bbot[1]=NOMAD::PB; for ( j=2; j<M+2; j++ ) bbot[j]=NOMAD::PB; p.set_BB_OUTPUT_TYPE(bbot); p.set_DIRECTION_TYPE(NOMAD::GPS_NP1_RAND_UNIFORM); p.check(); CMADSEvaluator ev(p,pOP); NOMAD::Mads mads(p,&ev); mads.run(); const NOMAD::Eval_Point *best=mads.get_best_feasible(); if (best) Xbest=NOMADPoint2ArrayXd(NOMAD::Point(*best)); else Xbest=pOP->initialValue(); if (!best) cout<<"no best"<<endl; ArrayXd epbest; pOP->evaluate(Xbest,epbest); ybest=epbest(0); NOMAD::end(); pOP->closeOptimization(); pOP=NULL; return Xbest; }
//----------------------------------------------------------------------------------------------- // Sets up the parameters object //----------------------------------------------------------------------------------------------- void NomadIpoptOptimizer::generateParameters() { p_param = new NOMAD::Parameters(*p_disp); // finding the number of variables int n_var = runner()->model()->binaryVariables().size() + runner()->model()->integerVariables().size(); p_param->set_DIMENSION (n_var); // number of variables NOMAD::Point sp(n_var); // starting point NOMAD::Point ub(n_var); // upper bounds NOMAD::Point lb(n_var); // lower bounds // setting all the values for each variable int var_num = 0; for(int i = 0; i < runner()->model()->binaryVariables().size(); ++i) { shared_ptr<BinaryVariable> v = runner()->model()->binaryVariables().at(i); // setting the type p_param->set_BB_INPUT_TYPE(var_num, NOMAD::BINARY); // setting the starting point sp[var_num] = v->value(); // setting the upper bound ub[var_num] = v->max(); //setting the lower bound lb[var_num] = v->min(); ++var_num; } for(int i = 0; i < runner()->model()->integerVariables().size(); ++i) { shared_ptr<IntVariable> v = runner()->model()->integerVariables().at(i); // setting the type p_param->set_BB_INPUT_TYPE(var_num, NOMAD::INTEGER); // setting the starting point sp[var_num] = v->value(); // setting the upper bound ub[var_num] = v->max(); //setting the lower bound lb[var_num] = v->min(); ++var_num; } // setting the starting point, upper and lower bounds to the parameters p_param->set_X0(sp); p_param->set_UPPER_BOUND(ub); p_param->set_LOWER_BOUND(lb); // setting the objective and constraint info int n_con = runner()->model()->constraints().size(); vector<NOMAD::bb_output_type> bbot (n_con + 1); // definition of output types bbot[0] = NOMAD::OBJ; // the first is the objective for(int i = 1; i < n_con + 1; ++i) bbot[i] = NOMAD::PB; // the rest are constraints p_param->set_BB_OUTPUT_TYPE ( bbot ); // not sure what this does... p_param->set_DISPLAY_STATS ( "bbe ( sol ) obj" ); // setting the maximum number of iterations p_param->set_MAX_BB_EVAL(maxIterations()); // checking if the parameters file exits QDir dir(runner()->reservoirSimulator()->folder()); if(dir.exists("nomad_param.dat")) { cout << "### Found a NOMAD parameters file... ###" << endl; p_param->read(dir.absoluteFilePath("nomad_param.dat").toStdString()); } // parameters validation: p_param->check(); cout << "NOMAD Parameters:" << endl; cout << *p_param << endl; }