int main(){ int i, x,y,start,end, n, m; while(scanf("%d %d", &n, &m) == 2){ Init(); for(i = 0; i < m; i++){ scanf("%d %d", &x, &y); addEdge(x,y,1); } /* Uncomment if you need copy of graph memcpy(g2, g, sizeof(g2)); memcpy(deg2, deg, sizeof(deg2)); */ switch(isEulerian(n, &start, &end)){ case 0: printf("Graph is not Eulerian\n"); break; case 1: printf("Graph has an Eulerian Cycle\n"); buildPath(n, 0, 0); for(i = 0; i < seqsize; i++) printf("%d ", seq[i]); printf("\n"); break; case 2: printf("Graph has an Eulerian path from %d to %d\n", start, end); buildPath(n,start,end); for(i = 0; i < seqsize; i++) printf("%d ", seq[i]); printf("\n"); break; } } return 0; }
// see header for the rationale void PathFinder::buildSyncedPath(const ESM::Pathgrid::Point &startPoint, const ESM::Pathgrid::Point &endPoint, const MWWorld::CellStore* cell, bool allowShortcuts) { if (mPath.size() < 2) { // if path has one point, then it's the destination. // don't need to worry about bad path for this case buildPath(startPoint, endPoint, cell, allowShortcuts); } else { const ESM::Pathgrid::Point oldStart(*getPath().begin()); buildPath(startPoint, endPoint, cell, allowShortcuts); if (mPath.size() >= 2) { // if 2nd waypoint of new path == 1st waypoint of old, // delete 1st waypoint of new path. std::list<ESM::Pathgrid::Point>::iterator iter = ++mPath.begin(); if (iter->mX == oldStart.mX && iter->mY == oldStart.mY && iter->mZ == oldStart.mZ) { mPath.pop_front(); } } } }
nodePaths buildTree(RST* root, int** instance, int** mst, int mst_length){ //Please note point 0 on Path* is xTraversal and 1 is yTravesal int index=0; nodePaths* childPaths = malloc(sizeof(nodePaths)*7); nodePaths nodePath; for(int i=0; i< mst_length; i++){ if(mst[i][0] == root->index){ //this must contain a child RST* child = buildNode(root, mst[i][1],NULL, mst[i][2], 0); root->child[root->indegree] = child; root->indegree++; index++; childPaths[index] = buildTree(child, instance, mst, mst_length); } } // if(index>0){ // int maxIndex = findMaxOverlap(childPaths, index); // } Path* currentPaths= malloc(sizeof(int)*2*3); // int* nodeA = instance[MST[index][0]]; // int* node = instance[MST[index][1]]; currentPaths[0] = buildPath(instance[root->index], instance[root->parent->index], 0); currentPaths[1] = buildPath(instance[root->index], instance[root->parent->index], 1); nodePath.paths = currentPaths; nodePath.index = root->index; return nodePath; };
vector<string> binaryTreePaths(TreeNode* root) { vector<string> res; if (!root) return res; string rootnode = to_string(root->val); if (!root->left && !root->right) { res.push_back(rootnode); return res; } buildPath(root->left, res, rootnode); buildPath(root->right, res, rootnode); return res; }
void buildPath(TreeNode* root, vector<string>& res, string path) { if (!root) return; path += "->"; path += to_string(root->val); if (!root->left && !root->right) //leaf node { res.push_back(path); return; } buildPath(root->left, res, path); buildPath(root->right, res, path); }
bool Translator::hasTrans(const std::string& path){ //build path std::vector<std::string> cpath; buildPath(path, cpath); //check all first domain of translation std::map<std::string, TranslatorGroup*>::iterator it = root.els.begin(); while(it != root.els.end()){ //explode groups TranslatorGroup* current = it->second; int i = 0; while(current != NULL && i < cpath.size()){ current = current->get(cpath[i]); i++; } if(i == cpath.size() && current != NULL && current->els.size() > 0 && current->els.begin()->second == NULL) return true; it++; } return false; }
bool IoDisk::save(Image & image, JSON & data) { // ---------------------------------------- // The naming convention that will be used // for the image. std::string pathToImage = getFileFormat(); // ------------------------------------------ // Stringify data object: build image path // with data information. static const std::string kTypeNames[] = { "Null", "False", "True", "Object", "Array", "String", "Number" }; for (JSONValue::ConstMemberIterator itr = data.MemberBegin(); itr != data.MemberEnd(); ++itr) { std::string name = itr->name.GetString(); std::string type = kTypeNames[itr->value.GetType()]; if(type == "String") { std::string value = itr->value.GetString(); kerberos::helper::replace(pathToImage, name, value); } else if(type == "Number") { std::string value = kerberos::helper::to_string(itr->value.GetInt()); kerberos::helper::replace(pathToImage, name, value); } else if(type == "Array") { std::string arrayString = ""; for (JSONValue::ConstValueIterator itr2 = itr->value.Begin(); itr2 != itr->value.End(); ++itr2) { type = kTypeNames[itr2->GetType()]; if(type == "String") { arrayString += itr2->GetString(); } else if(type == "Number") { arrayString += kerberos::helper::to_string(itr2->GetInt()); } arrayString += "-"; } kerberos::helper::replace(pathToImage, name, arrayString.substr(0, arrayString.size()-1)); } } /// --------------------- // Replace variables pathToImage = buildPath(pathToImage); // --------------------------------------------------------------------- // Save original version & generate unique timestamp for current image return m_fileManager.save(image, pathToImage); }
//-------------------------------------------------------------- void ofApp::setup(){ ofSetFrameRate(60); ofSetVerticalSync(true); ofBackground(0); ofSetLogLevel(OF_LOG_SILENT); setupViewports(); parameters.setup(); robot.setup("192.168.1.9",parameters); // <-- swap with your robot's ip address setupGUI(); positionGUI(); // setup path controller path.setup(); line = buildPath(); // load/create different paths path.set(line); vector<Path *> pathPtrs; pathPtrs.push_back(&path); paths.setup(pathPtrs); feedRate = 0.001; }
void URI::mergePath(const std::string& path) { std::vector<std::string> segments; std::vector<std::string> normalizedSegments; bool addLeadingSlash = false; if (!_path.empty()) { getPathSegments(segments); bool endsWithSlash = *(_path.rbegin()) == '/'; if (!endsWithSlash && !segments.empty()) segments.pop_back(); addLeadingSlash = _path[0] == '/'; } getPathSegments(path, segments); addLeadingSlash = addLeadingSlash || (!path.empty() && path[0] == '/'); bool hasTrailingSlash = (!path.empty() && *(path.rbegin()) == '/'); bool addTrailingSlash = false; for (std::vector<std::string>::const_iterator it = segments.begin(); it != segments.end(); ++it) { if (*it == "..") { addTrailingSlash = true; if (!normalizedSegments.empty()) normalizedSegments.pop_back(); } else if (*it != ".") { addTrailingSlash = false; normalizedSegments.push_back(*it); } else addTrailingSlash = true; } buildPath(normalizedSegments, addLeadingSlash, hasTrailingSlash || addTrailingSlash); }
void tui::MenuItemHandler::create(wxMenuBar *menuBar) { wxMenu* menu; wxMenuItem *menuItem; std::vector<std::string> menuNames; menuNames = split(_menuItem, '/'); if (menuNames.size()==0) return; if (menuNames.size()==1) { //Create new item in main menu menu = new wxMenu(); menuBar->Insert(menuBar->GetMenuCount()-1, menu, wxString(menuNames[0].c_str(), wxConvUTF8)); _inserted = true; return; } menu = buildPath(menuBar, menuNames); //last item std::string insertedString = *(menuNames.end()-1); if (_hotKey !="") insertedString=insertedString+"\t"+_hotKey; menuItem = new wxMenuItem(menu, _ID, wxString(insertedString.c_str(), wxConvUTF8), wxString(_helpString.c_str(), wxConvUTF8)); menu->Append(menuItem); _inserted = true; }
bool IoDisk::save(Image & image) { // ---------------------------------------- // The naming convention that will be used // for the image. std::string pathToImage = getFileFormat(); // --------------------- // Replace variables pathToImage = buildPath(pathToImage); std::string timestamp = kerberos::helper::getTimestamp(); kerberos::helper::replace(pathToImage, "timestamp", timestamp); drawDateOnImage(image, timestamp); std::string microseconds = kerberos::helper::getMicroseconds(); std::string size = kerberos::helper::to_string((int)microseconds.length()); kerberos::helper::replace(pathToImage, "microseconds", size + "-" + microseconds); std::string token = kerberos::helper::to_string(rand()%1000); kerberos::helper::replace(pathToImage, "token", token); // --------------------------------------------------------------------- // Save original version & generate unique timestamp for current image return m_fileManager.save(image, pathToImage); }
static bool writeBindings(const BDescVec &d, const std::string &dir, uint32_t rgssVersion) { if (dir.empty()) return false; char path[1024]; buildPath(dir, rgssVersion, path, sizeof(path)); FILE *f = fopen(path, "wb"); if (!f) return false; Header hd; hd.formVer = FORMAT_VER; hd.rgssVer = rgssVersion; hd.count = d.size(); if (fwrite(&hd, sizeof(hd), 1, f) < 1) { fclose(f); return false; } if (fwrite(&d[0], sizeof(d[0]), hd.count, f) < hd.count) { fclose(f); return false; } fclose(f); return true; }
void URI::removeDotSegments(bool removeLeading) { if (_path.empty()) return; bool leadingSlash = *(_path.begin()) == '/'; bool trailingSlash = *(_path.rbegin()) == '/'; std::vector<std::string> segments; std::vector<std::string> normalizedSegments; getPathSegments(segments); for (std::vector<std::string>::const_iterator it = segments.begin(); it != segments.end(); ++it) { if (*it == "..") { if (!normalizedSegments.empty()) { if (normalizedSegments.back() == "..") normalizedSegments.push_back(*it); else normalizedSegments.pop_back(); } else if (!removeLeading) { normalizedSegments.push_back(*it); } } else if (*it != ".") { normalizedSegments.push_back(*it); } } buildPath(normalizedSegments, leadingSlash, trailingSlash); }
bool AStar::findPath(NavPath& path, NavNode* startNode, Math::Point startPos, NavNode* endNode, Math::Point endPos) { //This search starts at the end node and goes to the start node. mEndPos = startPos; //increment the session ID so nodes will know that their previous data is invalid ++mSessionId; //prepare the Open list for use mOpen.clear(); //add the first cell to the Open list to begin endNode->discover(this, 0, 0); while (!mOpen.empty()) { //pop off the top open cell (the one with the lowest cost) NavNode* thisNode = mOpen.back(); mOpen.pop_back(); if (thisNode == startNode) { //we're done; build the path and exit buildPath(path, startNode, startPos, endNode, endPos); return true; } else { //process the cell, adding any new neighbors to the Open heap thisNode->process(this); } } //no path exists; destination is unreachable. return false; }
void Pathfinder::buildPath(std::vector<v3s16> &path, v3s16 pos, int level) { level ++; if (level > 700) { ERROR_TARGET << LVL "Pathfinder: path is too long aborting" << std::endl; return; } PathGridnode &g_pos = getIndexElement(pos); if (!g_pos.valid) { ERROR_TARGET << LVL "Pathfinder: invalid next pos detected aborting" << std::endl; return; } g_pos.is_element = true; //check if source reached if (g_pos.source) { path.push_back(pos); return; } buildPath(path, pos + g_pos.sourcedir, level); path.push_back(pos); }
void buildPath(bool isBreakable[], string &s, int pos, vector<string> &res, string curP, unordered_set<string>& wordDict, int minlen, int maxlen) { int i, len = s.size(); for(i =minlen; i<= min(maxlen, len - pos); ++i) if( isBreakable[pos+i] && wordDict.count(s.substr(pos,i)) ) if(pos+i == len) res.push_back(curP + s.substr(pos,i)); else buildPath(isBreakable, s, pos+i, res, curP + s.substr(pos,i) + " ", wordDict, minlen, maxlen); }
void Bucket::sample(int x, int y) { Vec3 sample = m_sampler->getSquareSample(); int lightBounces = m_scene->m_settings.m_lightBounces; int cameraBounces = m_scene->m_settings.m_cameraBounces; Ray ray = m_viewPlane->getPixelRay(x,y,*m_sampler); RGBA finalCol(0.0f); RGBA col(0.0f); int numCameraNodes = 0; int numLightNodes = 1; buildPath(m_cameraPath,&ray,numCameraNodes, RGBA(1.0f,1.0f,1.0f,1.0f), 0, cameraBounces); int lightIndex = floor(m_sampler->get1DSample()*m_scene->m_lights.size()); Light *light = m_scene->m_lights[lightIndex]; ray = light->getRay(*m_sampler); m_lightPath[0].m_sr.m_hitPos = ray.m_origin; m_lightPath[0].m_accumColor = RGBA(1.0f,1.0f,1.0f,1.0f); for(int j=0;j<numCameraNodes;j++){ PathNode &cameraNode = m_cameraPath[j]; for(int i=0;i<numLightNodes;i++){ PathNode &lightNode = m_lightPath[i]; Vec3 dir = lightNode.m_sr.m_hitPos - cameraNode.m_sr.m_hitPos; float maxT = dir.length(); dir.normalize(); float delta = 0.001f; Vec3 tmp = dir * delta; tmp = cameraNode.m_sr.m_hitPos - tmp; Ray ray = Ray(tmp,dir,true); ray.computePlucker(); float pdf; col = light->getLightColor(dir, cameraNode.m_sr.m_hitPos, lightNode.m_sr.m_hitPos, &pdf); float shadeVal = float(m_scene->m_lights.size())/pdf; shadeVal *= m_scene->traceShadow(ray,maxT); col *= cameraNode.m_accumColor; cameraNode.m_sr.m_material->shade(cameraNode.m_incident, dir, cameraNode.m_sr, &col, m_shadingContext); col *= shadeVal; finalCol += col; } } if(numCameraNodes != 0){ finalCol[3] = 1.0f; } else{ finalCol = RGBA(0.0f,0.0f,0.0f,0.0f); } m_viewPlane->setPixelValue(x,y,finalCol); }
void ExtendedTbrProposer::determineMove(TreeAln &traln, LikelihoodEvaluator &eval, Randomness& rand, BranchPlain primeBranch, const std::vector<AbstractParameter*> ¶ms) { auto modifiedPath1 = Path{}; auto modifiedPath2 = Path{}; auto bisectedBranch = primeBranch; // determine, if a true TBR move can be executed auto canMove = [&](const BranchPlain &b) -> bool { if(traln.isTipNode(b.getPrimNode())) return false; else { auto desc = traln.getDescendents(b) ; return not(traln.isTipBranch(desc.first) && traln.isTipBranch(desc.second)) ; } }; auto oneMovable = canMove(bisectedBranch); auto otherMovable = canMove(bisectedBranch.getInverted()); auto descOne = BranchPlain{}; if(oneMovable) { buildPath(modifiedPath1, bisectedBranch, traln, rand, params); descOne = modifiedPath1.at( int(modifiedPath1.size() -1) ); } auto descOther = BranchPlain{}; if(otherMovable) { buildPath(modifiedPath2, bisectedBranch.getInverted(), traln, rand, params); descOther = modifiedPath2.at(int(modifiedPath2.size()-1)); } _forwProb = log_double::fromAbs(1.); _move = TbrMove(traln, bisectedBranch, descOne, descOther) ; }
Path OccupancyMap::buildShortestPath(int ind) { Path path; if (map_ == NULL) { ROS_WARN("OccupancyMap::buildShortestPath() Map not set"); return path; } // Recreate path const Eigen::Vector2f &stop = endpoints_.at(ind); int stopi = MAP_GXWX(map_, stop(0)), stopj = MAP_GYWY(map_, stop(1)); buildPath(stopi, stopj, &path); return Path(path.rbegin(), path.rend()); }
void Node::drawSpecial(QPainter& thePainter, QPen& Pen, MapView* theView) { QPen TP(Pen); TP.setWidth(TP.width() / 2); buildPath(theView->projection()); QPoint me(theView->toView(this)); QRect R(me-QPoint(3,3),QSize(6,6)); thePainter.setPen(TP); thePainter.drawRect(R); R.adjust(-7, -7, 7, 7); thePainter.drawEllipse(R); }
int execvp(const char *file, char * const *argv) { char *comd; char *path; /* build the path name, if necessary */ path = buildPath (file); /* build the command line */ if ((comd = buildCmd (argv)) == NULL) return -1; /* execute it */ return(Kexecve(path, comd, &errno)); }
PixelTexture::PixelTexture( std::string filepath, Filtering filtering, Wrap wrap, int suspectedChannels) : Texture() { // Setup stb_image stbi_set_flip_vertically_on_load(true); // Try to load image int width, height, channelCount; unsigned char* data = stbi_load(buildPath(filepath).c_str(), &width, &height, &channelCount, suspectedChannels); // Check whether file was found and parsed if (data == NULL) { throwError(OperationNotifier::Operation::IMAGE_LOADING, "Image file not found or error at parsing", filepath); } // Decide format GLenum glFormat; GLenum glInternalFormat; switch (suspectedChannels) { case 1: glFormat = GL_RED; glInternalFormat = GL_R8; break; case 3: glFormat = GL_RGB; glInternalFormat = GL_RGB8; break; case 4: glFormat = GL_RGBA; glInternalFormat = GL_RGBA8; break; default: glFormat= GL_RGB; glInternalFormat = GL_R8; throwWarning(OperationNotifier::Operation::IMAGE_LOADING, "Unknown number of color channels", filepath); break; } // Create OpenGL texture createOpenGLTexture(data, filtering, wrap, width, height, channelCount, glFormat, glInternalFormat, false, filepath); // Delete raw image data stbi_image_free(data); }
bool Translator::has(const std::string& path){ //build path std::vector<std::string> cpath; buildPath(path, cpath); //explode groups TranslatorGroup* current = &root; int i = 0; while(current != NULL && i < cpath.size()){ current = current->get(cpath[i]); i++; } return (i == cpath.size() && current != NULL && current->els.size() > 0 && current->els.begin()->second == NULL); }
void tui::MenuItemHandler::recreate(wxMenuBar *menuBar) { wxMenu* menu; wxMenuItem *menuItem; std::vector<std::string> menuNames; menuNames = split(_menuItem, '/'); if (menuNames.size()==0) return; if (menuNames.size()==1) { //Create new item in main menu menu = new wxMenu(); menuBar->Insert(menuBar->GetMenuCount()-1, menu, wxString(menuNames[0].c_str(), wxConvUTF8)); _inserted = true; return; } menu = buildPath(menuBar, menuNames); //last item std::string insertedString = *(menuNames.end()-1); if (_hotKey !="") insertedString=insertedString+"\t"+_hotKey; int index = menu->FindItem(wxString(insertedString.c_str(), wxConvUTF8)); menuItem = menu->FindItem(index); if ((index==wxNOT_FOUND)||(menuItem==NULL)) { std::ostringstream ost; ost<<"Error redefining menu"; tell_log(console::MT_ERROR,ost.str()); return; } menuItem->SetText(wxString(insertedString.c_str(), wxConvUTF8)); menuItem->SetHelp(wxString(_helpString.c_str(), wxConvUTF8)); //menuItem = new wxMenuItem(menu, _ID, insertedString.c_str(), _helpString.c_str()); //menu->Append(menuItem); _inserted = true; _changed = false; };
void Pin::rebuild() { if (pinname.hidden) pinname.hide(); else pinname.show(); if (pinnumber.hidden) pinnumber.hide(); else pinnumber.show(); rebuildShape(); setPath(buildPath()); reorient(); updatePostition(); }
std::unique_ptr<Layout> parse(GUI* pGUI, AssetManager* pAssetManager, std::string filepath) { // Check file name if (!checkFileNameExtension(filepath, LAYOUT_EXTENSION)) { throwError(OperationNotifier::Operation::PARSING, "Extension of file not as expected", filepath); } // Read file tinyxml2::XMLDocument doc; doc.LoadFile(buildPath(filepath).c_str()); if (doc.Error()) { throwError(OperationNotifier::Operation::PARSING, std::string("XML could not be parsed: ") + doc.ErrorName(), filepath); } // First xml element should be a layout tinyxml2::XMLElement* xmlLayout = doc.FirstChildElement(); if (!element_parser::validateElement(xmlLayout, "layout")) { throwError(OperationNotifier::Operation::PARSING, "No layout node as root in XML found", filepath); } // Get path to stylesheet std::string stylesheetFilepath = element_parser::parseStringAttribute("stylesheet", xmlLayout); // Create layout std::unique_ptr<Layout> upLayout = std::unique_ptr<Layout>(new Layout(pGUI, pAssetManager, stylesheetFilepath)); // Then there should be an element tinyxml2::XMLElement* xmlRoot = xmlLayout->FirstChildElement(); // Check for existence if (xmlRoot == NULL) { throwError(OperationNotifier::Operation::PARSING, "Layout has no element", filepath); } // Create, parse further internal an attach std::unique_ptr<elementsAndIds> upPair; upPair = std::move(element_parser::parse(upLayout.get(), upLayout->getMainFrame(), pAssetManager, upLayout->getNotificationQueue(), xmlRoot, NULL, filepath)); upLayout->attachElementToMainFrameAsRoot(std::move(upPair->first), std::move(upPair->second)); // Return ready to use layout return(std::move(upLayout)); }
void buildPath(unordered_map<string, vector<string> > &father, vector<string> &path, const string &start, const string &word, vector<vector<string> > &result) { path.push_back(word); if (word == start) { result.push_back(path); reverse(result.back().begin(), result.back().end()); } else { for (auto f : father[word]) { buildPath(father, path, start, f, result); } } path.pop_back(); }
void tui::MenuItemSeparator::create(wxMenuBar *menuBar) { wxMenu* menu; std::vector<std::string> menuNames;// = split std::string menustring; menustring = _menuItem; menuNames = split(menustring, '/'); if (menuNames.size()==0) return; menu = buildPath(menuBar, menuNames); menu->AppendSeparator(); _inserted = true; }
bool IoDisk::save(Image & image) { // ---------------------------------------- // The naming convention that will be used // for the image. std::string pathToImage = getFileFormat(); // --------------------- // Replace variables pathToImage = buildPath(pathToImage); // --------------------------------------------------------------------- // Save original version & generate unique timestamp for current image return m_fileManager.save(image, pathToImage); }
Path OccupancyMap::astar(double startx, double starty, double stopx, double stopy, double max_occ_dist /* = 0.0 */, bool allow_unknown /* = false */) { Path path; if (map_ == NULL) { ROS_WARN("OccupancyMap::astar() Map not set"); return path; } int stopi = MAP_GXWX(map_, stopx), stopj = MAP_GYWY(map_, stopy); if (!MAP_VALID(map_, stopi ,stopj)) { ROS_ERROR("OccupancyMap::astar() Invalid stopping position"); ROS_BREAK(); } if (map_->max_occ_dist < max_occ_dist) { ROS_ERROR("OccupancyMap::astar() CSpace has been calculated up to %f, " "but max_occ_dist=%.2f", map_->max_occ_dist, max_occ_dist); ROS_BREAK(); } initializeSearch(startx, starty); // Set stop to use heuristic stopi_ = stopi; stopj_ = stopj; bool found = false; Node curr_node; while (nextNode(max_occ_dist, &curr_node, allow_unknown)) { if (curr_node.coord.first == stopi && curr_node.coord.second == stopj) { found = true; break; } } // Recreate path if (found) { buildPath(stopi, stopj, &path); } return Path(path.rbegin(), path.rend()); }