bool push( const char * k, const char * v ) { V p; strcpy( p.k, k ); strcpy( p.v, v ); params.push_back( p ); }
void UsiClient::onUpdatePV(const Searcher& searcher, const PV& pv, float elapsed, int depth, Score score) { if (pv.size() == 0) { LOG(warning) << "PV is empty."; return; } auto& info = searcher.getInfo(); auto timeMs = static_cast<uint32_t>(elapsed * 1e3); auto realDepth = depth / Searcher::Depth1Ply; auto totalNodes = info.nodes + info.quiesNodes; auto nps = static_cast<uint32_t>(totalNodes / elapsed); auto hashfull = static_cast<int>(searcher_->ttUsageRates() * 1000); const char* scoreKey; int scoreValue; if (score > -Score::mate() && score < Score::mate()) { scoreKey = "cp"; scoreValue = score.raw() * 100.0 / material::Pawn; } else { scoreKey = "mate"; if (score >= 0) { scoreValue = (Score::infinity() - score).raw(); } else { scoreValue = -(Score::infinity() + score).raw(); } } OUT(info) << std::setw(2) << realDepth << ": " << std::setw(10) << (info.nodes + info.quiesNodes) << ": " << std::setw(7) << timeMs << ' ' << pv.toString() << ": " << score; if (!inPonder_) { send("info", "time", timeMs, "depth", realDepth, "nodes", totalNodes, "nps", nps, "currmove", pv.getMove(0).toStringSFEN(), "score", scoreKey, scoreValue, "pv", pv.toStringSFEN(), "hashfull", hashfull); } }
void Obstaculo::calculaNormales(){ normales = new PV*[nVertices]; for (int i = 0; i < nVertices; i++) { PV* unPunto = vertices[i]; PV* otroPunto = vertices[(i+1)%nVertices]; PV* normal = new PV(unPunto->getY() - otroPunto->getY(), otroPunto->getX() - unPunto->getX()); normal->normaliza(); normales[i] = normal; } }
void example_intersection_polygon1() { typedef boost::geometry::point_xy<double> P; typedef std::vector<boost::geometry::polygon<P> > PV; boost::geometry::box<P> cb(P(1.5, 1.5), P(4.5, 2.5)); boost::geometry::polygon<P> poly; boost::geometry::read_wkt("POLYGON((2 1.3,2.4 1.7,2.8 1.8,3.4 1.2,3.7 1.6,3.4 2,4.1 3,5.3 2.6,5.4 1.2,4.9 0.8,2.9 0.7,2 1.3)" ",(4 2,4.2 1.4,4.8 1.9,4.4 2.2,4 2))", poly); PV v; boost::geometry::intersection_inserter<boost::geometry::polygon<P> >(cb, poly, std::back_inserter(v)); std::cout << "Clipped polygon(s) " << std::endl; for (PV::const_iterator it = v.begin(); it != v.end(); it++) { std::cout << boost::geometry::dsv(*it) << std::endl; } }
virtual bool read( Serialize::Client & ph ) { if ( ! prefs ) { return 0; } if ( feof( prefs ) ) { return 0; } char buf[500]; char key[200]; char value[400]; char *line; while ( fgets( buf, 499, prefs ) ) { line = buf; while ( line[0] == ' ' || line[0] == '\t' ) line ++; if ( line[0] == '\n' ) { ph.read( *this ); params.clear(); return 1; } if ( line[0] == '#' ) { continue; } // nuke whitespace at end of line: size_t l = strlen(line); while (--l) { if ( line[l] == '\n' || line[l] == '\r' || line[l] == '\t' || line[l] == ' ' ) { line[l] = 0; continue; } break; } if ( char * end = strchr( line, '=') ) { *end = 0; strcpy( key, line ); strcpy( value , (end+1) ); push( key , value ); } } return 0; }
void print_vector( const ROL::Vector<Real> &x ) { typedef ROL::Vector<Real> V; typedef ROL::StdVector<Real> SV; typedef ROL::PartitionedVector<Real> PV; typedef typename PV::size_type size_type; const PV eb = Teuchos::dyn_cast<const PV>(x); size_type n = eb.numVectors(); for(size_type k=0; k<n; ++k) { std::cout << "[subvector " << k << "]" << std::endl; Teuchos::RCP<const V> vec = eb.get(k); Teuchos::RCP<const std::vector<Real> > vp = Teuchos::dyn_cast<const SV>(*vec).getVector(); for(size_type i=0; i<vp->size(); ++i) { std::cout << (*vp)[i] << std::endl; } } }
bool name_is_valid() { nsol = 0; sol.clear(); for (int i = 0; i < R; ++i) for (int j = 0; j < C; ++j) dfs(i, j, 0); return nsol < 2; }
const char * get( const char * k ) { for ( int i=0; i<params.size(); i++ ) { if ( ! strcmp( params[i].k, k ) ) { return params[i].v; } } return 0; }
bool Rectangulo::Corte(Pelota* pelota, GLdouble &tIn, PV* &normal) { GLfloat epsilon = 0.000001f; tIn = 0; GLdouble tOut = 1; GLdouble tHit; GLdouble num, den; PV * n; int i = -1; bool enc = false; while (i < nVertices - 1 && !enc) { i++; n = normales[i]; PV ptang = pelota->getPuntoTangente(n); PV * tmpVector = *vertices[i] - pelota->getPuntoTangente(n); num = tmpVector->dot(n); den = n->dot(pelota->getDireccion()); if (fabs(den) > epsilon) { // hay tHit tHit = num / den; if (den > 0) { if (tHit < tOut) tOut = tHit; } else { if (tHit >= tIn) { tIn = tHit; normal = n; } } enc = tIn > tOut; // si se han cruzado, no hay intersección } else { // paralelismo if (num <= 0) enc = true; } } return !enc && !((tIn == 0) && (tIn <= tOut) && (tOut < epsilon)); }
// Metodo que pinta las paredes void Rectangulo::Pinta() { glColor3f(1.0, 1.0, 0.0); glBegin(GL_POLYGON); for (int i = 0; i<nVertices; i++){ glVertex2d(vertices[i]->getX(), vertices[i]->getY()); } glEnd(); /////////////////////////////////// PV** puntosMedios = new PV*[nVertices]; for (int i = 0; i < nVertices; i++) { PV* unPunto = vertices[i]; PV* otroPunto = vertices[(i+1)%nVertices]; PV* puntoMedio = new PV((unPunto->getX() + otroPunto->getX())/2, (unPunto->getY() + otroPunto->getY())/2); puntosMedios[i] = puntoMedio; } glColor3f(1.0, 1.0, 1.0); glBegin(GL_LINES); for (int i = 0; i<nVertices; i++){ glVertex2d(puntosMedios[i]->getX(), puntosMedios[i]->getY()); glVertex2d(puntosMedios[i]->getX()+(normales[i]->getX()*20), puntosMedios[i]->getY()+(normales[i]->getY()*20)); } glEnd(); }
void dfs(int r, int c, int n) { if (quilt[r][c] != name[n]) return; trail[n++] = Pos(r, c); if (n == nlen) { ++nsol; for (int i = 0; i < nlen; ++i) sol.push_back(trail[i]); return; } for (int i = -1; i <= 1; ++i) for (int j = -1; j <= 1; ++j) { Pos p(r + i, c + j); if (! valid_pos(p)) continue; dfs(p.r, p.c, n); } }
//--------------------------------------------------------------------------- bool Circulo::Corte(Pelota* pelota, GLdouble &tIn, PV* &normal) { PV * pc = new PV(*centro->operator -(*pelota->getCentro())); PV *pc_borrar = new PV(centro->getX() - pelota->getCentro()->getX(), centro->getY() - pelota->getCentro()->getY()); PV *s = pelota->getDireccion(); PV *sT = new PV(- s->getY(), s->getX()); GLdouble a = pc->dot(s) / s->dot(s); GLdouble b = pc->dot(sT) / s->dot(s); GLdouble d0 = fabs(b) * sT->modulo(); delete pc; delete sT; if (d0 < (pelota->getRadio() + radio)) { GLdouble d2 = sqrt(pow(pelota->getRadio() + radio, 2) - pow(d0, 2)); GLdouble d1 = fabs(a) * s->modulo() - d2; tIn = d1 / s->modulo(); PV *puntoContacto = new PV(pelota->getCentro()->getX() + tIn * pelota->getDireccion()->getX(),pelota->getCentro()->getY() + tIn * pelota->getDireccion()->getY()); PV * unaNormalTemp = *puntoContacto-*centro; GLdouble mod = unaNormalTemp->modulo(); if (unaNormal != NULL) delete unaNormal; unaNormal = new PV(unaNormalTemp->getX() / mod, unaNormalTemp->getY() / mod); normal = unaNormal; delete puntoContacto; return (a > 0) && (s->modulo() > d1); } else return false; }
int main(int argc, char *argv[]) { using namespace ROL; using Teuchos::RCP; using Teuchos::rcp; typedef Teuchos::ParameterList PL; typedef Vector<RealT> V; typedef PartitionedVector<RealT> PV; typedef OptimizationProblem<RealT> OPT; typedef NonlinearProgram<RealT> NLP; typedef AlgorithmState<RealT> STATE; Teuchos::GlobalMPISession mpiSession(&argc, &argv); // This little trick lets us print to std::cout only if a (dummy) command-line argument is provided. int iprint = argc - 1; RCP<std::ostream> outStream; Teuchos::oblackholestream bhs; // outputs nothing if (iprint > 0) outStream = rcp(&std::cout, false); else outStream = rcp(&bhs, false); int errorFlag = 0; int numProblems = 40; RealT errtol = 1e-5; // Require norm of computed solution error be less than this std::vector<int> passedTests; std::vector<int> failedTests; std::vector<std::string> converged; std::vector<std::string> stepname; HS::ProblemFactory<RealT> factory; RCP<NLP> nlp; RCP<OPT> opt; // Get two copies so we can validate without setting defaults RCP<PL> parlist = rcp( new PL() ); RCP<PL> parlistCopy = rcp( new PL() ); RCP<PL> test = rcp( new PL() ); Teuchos::updateParametersFromXmlFile(std::string("hs_parameters.xml"),parlist.ptr()); Teuchos::updateParametersFromXmlFile(std::string("hs_parameters.xml"),parlistCopy.ptr()); Teuchos::updateParametersFromXmlFile(std::string("test_parameters.xml"),test.ptr()); RCP<const PL> validParameters = getValidROLParameters(); parlistCopy->validateParametersAndSetDefaults(*validParameters); RCP<V> x; RCP<const STATE> algo_state; bool problemSolved; // *** Test body. try { for(int n=1; n<=numProblems; ++n) { *outStream << "\nHock & Schittkowski Problem " << std::to_string(n) << std::endl; nlp = factory.getProblem(n); opt = nlp->getOptimizationProblem(); EProblem problemType = opt->getProblemType(); std::string str; switch( problemType ) { case TYPE_U: str = test->get("Type-U Step","Trust Region"); break; case TYPE_B: str = test->get("Type-B Step","Trust Region"); break; case TYPE_E: str = test->get("Type-E Step","Composite Step"); break; case TYPE_EB: str = test->get("Type-EB Step","Augmented Lagrangian"); break; case TYPE_LAST: TEUCHOS_TEST_FOR_EXCEPTION(true,std::invalid_argument,"Error: Unsupported problem type!"); break; } stepname.push_back(str); parlist->sublist("Step").set("Type",str); OptimizationSolver<RealT> solver( *opt, *parlist ); solver.solve(*outStream); algo_state = solver.getAlgorithmState(); x = opt->getSolutionVector(); if( nlp->dimension_ci() > 0 ) { // Has slack variables, extract optimization vector PV xpv = Teuchos::dyn_cast<PV>(*x); RCP<V> sol = xpv.get(0); problemSolved = nlp->foundAcceptableSolution( *sol, errtol ); } else { problemSolved = nlp->foundAcceptableSolution( *x, errtol ); } RealT tol = std::sqrt(ROL_EPSILON<RealT>()); *outStream << "Target objective value = " << nlp->getSolutionObjectiveValue() << std::endl; *outStream << "Attained objective value = " << opt->getObjective()->value(*x,tol) << std::endl; if( problemSolved ) { *outStream << "Computed an acceptable solution" << std::endl; passedTests.push_back(n); converged.push_back(std::to_string(algo_state->nfval)); } else { *outStream << "Failed to converge" << std::endl; failedTests.push_back(n); converged.push_back("Failed"); } } // end for loop over HS problems *outStream << "\nTests passed: "; for( auto const& value : passedTests ) { *outStream << value << " "; } *outStream << "\nTests failed: "; for( auto const& value : failedTests ) { *outStream << value << " "; } *outStream << std::endl; if( passedTests.size() > failedTests.size() ) { *outStream << "Most tests passed." << std::endl; } else { *outStream << "Most tests failed." << std::endl; errorFlag++; } *outStream << "\n\nPERFORMANCE SUMMARY:\n\n"; *outStream << std::setw(16) << "H&S Problem #" << std::setw(24) << "Step Used" << std::setw(12) << "#fval" << std::endl; *outStream << std::string(52,'-') << std::endl; for(int n=0; n<numProblems; ++n) { *outStream << std::setw(16) << n+1 << std::setw(24) << stepname[n] << std::setw(12) << converged[n] << std::endl; } } catch (std::logic_error err) { *outStream << err.what() << "\n"; errorFlag = -1000; }; // end try if (errorFlag != 0) std::cout << "End Result: TEST FAILED\n"; else std::cout << "End Result: TEST PASSED\n"; return 0; }
int main() { PV pv; My m(2); pv.push_back(&m); foo(pv); }
// Create a MultiVector from a pointer to a single vector MultiVectorDefault(PV vec) : mvec_(APV(1,vec)), numVectors_(1), length_(vec->dimension()) {}