bool TessdataManager::ExtractToFile(const char *filename) { TessdataType type = TESSDATA_NUM_ENTRIES; ASSERT_HOST( tesseract::TessdataManager::TessdataTypeFromFileName(filename, &type)); if (entries_[type].empty()) return false; return SaveDataToFile(entries_[type], filename); }
bool TFile::CloseWrite(const STRING& filename, FileWriter writer) { ASSERT_HOST(is_writing_); if (writer == NULL) return SaveDataToFile(*data_, filename); else return (*writer)(*data_, filename); }
void InitializeSimulations(int argc, char **argv) { int p = MPI::COMM_WORLD.Get_size(); int id = MPI::COMM_WORLD.Get_rank(); std::string simType = argv[2]; ESimulationType simT; if (simType == "MC") { simT = ESimulationType::MonteCarlo; } else if (simType == "LD") { simT = ESimulationType::LangevinDynamics; } else { std::cout << "Unknown simulation type " << simType << ". Exiting." << std::endl; return; } std::string simDataFileName = argv[1]; if (id == p-1) { InitTar(simDataFileName); } std::string samples = argv[3]; for (int i = 1; i <= std::stoi(samples); i++) { std::ifstream simDataFileStream(simDataFileName); cereal::JSONInputArchive simDataArchieve(simDataFileStream); std::shared_ptr<CBaseSimCtrl> sim; switch (simT) { case MonteCarlo: { CMonteCarloSimParams data; data.load(simDataArchieve); sim = std::make_shared<CMonteCarloSimCtrl>(CMonteCarloSimCtrl(data)); break; }; case LangevinDynamics: { CLangevinSimParams data; data.load(simDataArchieve); sim = std::make_shared<CLangevinSimCtrl>(CLangevinSimCtrl(data)); break; }; } std::string fullSaveFileName = "FullData_" + std::to_string(i) + "_" + simDataFileName; std::string miniSaveFileName = "MiniData_" + std::to_string(i) + "_" + simDataFileName; std::string pictSaveFileName = "PictData_" + std::to_string(i) + "_" + simDataFileName + ".eps"; SaveDataToFile(sim, fullSaveFileName, miniSaveFileName, simDataFileName, 0); RunSimulations(sim, fullSaveFileName, miniSaveFileName, pictSaveFileName, simDataFileName); printf("Sample N %i\n", i); } if (id == p-1) { FinishTar(simDataFileName); } }
// Saves to the given filename. bool TessdataManager::SaveFile(const STRING &filename, FileWriter writer) const { ASSERT_HOST(is_loaded_); GenericVector<char> data; Serialize(&data); if (writer == nullptr) return SaveDataToFile(data, filename); else return (*writer)(data, filename); }
bool CBaseHttp::HttpDownload(const char *pUrl, const char *pFilePath) { bool bRet = HttpGet(pUrl, false); if(pFilePath && bRet) { return SaveDataToFile(pFilePath); } return bRet; }
void RunSimulations(std::shared_ptr<CBaseSimCtrl> contr, std::string &fullSaveFileName, std::string &miniSaveFileName, std::string &pictSaveFileName, std::string &simDataFileName) { EPSPlot savePictureFile; InitEpsFile(contr, savePictureFile, pictSaveFileName); std::chrono::time_point<std::chrono::system_clock> start_time; start_time = std::chrono::system_clock::now(); uint64_t prev_measure = 0; uint64_t totalCycles = contr->SimulationParameters.CyclesBetweenSaves * contr->SimulationParameters.NumberOfSavePoints; contr->SimulationParameters.NumberOfImageLines = std::min(totalCycles, contr->SimulationParameters.NumberOfImageLines); for (uint64_t cycle = 1; cycle <= totalCycles; ++cycle) { contr->DoCycle(); if (0 == cycle % (contr->SimulationParameters.CyclesBetweenSaves)) { SaveDataToFile(contr, fullSaveFileName, miniSaveFileName, simDataFileName, cycle); } if (0 == cycle % (totalCycles / contr->SimulationParameters.NumberOfImageLines)) { SavePictureEps(contr, savePictureFile); } auto doFinish = contr->PrintTimeExtrapolation(start_time, prev_measure, totalCycles, cycle); if (doFinish) { SaveDataToFile(contr, fullSaveFileName, miniSaveFileName, simDataFileName, cycle); SavePictureEps(contr, savePictureFile); break; } } FinishEpsFile(contr, savePictureFile, pictSaveFileName, simDataFileName); }
bool CDlgSettingRs232::SaveRS232Data() { bool bOK = true; // tagIfRs232Setting m_IfUIRs232; if( !GetDataFromUI( m_IfUIRs232 ) ) bOK = false; // if( bOK ) SaveDataToFile( m_IfUIRs232 ); return bOK; }
//预测计算方法 map<CString,sYuCeShuangSeQiu>CDataManageCenter::GetDataBySuanFa() { map<CString,sYuCeShuangSeQiu> TempData; int ListCount = m_ShuangSeQiuList.size(); for(int i=0; i < ListCount; i++) { DWORD Sum=m_ShuangSeQiuList[i].m_HongQiuSum; sShuangSeQiu TempQiuData; TempQiuData.m_LanQiu = 0; TempQiuData.m_QiShu = _T("和值预测"); TempQiuData.m_HongQiuSum = 0; sShuangSeQiu TempQiuData2; TempQiuData2.m_LanQiu = 0; TempQiuData2.m_QiShu = _T("和值预测2"); TempQiuData2.m_HongQiuSum = 0; sShuangSeQiu TempLanQiuData; TempLanQiuData.m_LanQiu = 0; TempLanQiuData.m_QiShu = _T("蓝基预测"); TempLanQiuData.m_HongQiuSum = 0; sShuangSeQiu TempACQiuData; TempACQiuData.m_LanQiu = 0; TempACQiuData.m_QiShu = _T("AC预测"); TempACQiuData.m_HongQiuSum = 0; sShuangSeQiu TempWeiQiuData; TempWeiQiuData.m_LanQiu = 0; TempWeiQiuData.m_QiShu = _T("尾值预测"); TempWeiQiuData.m_HongQiuSum = 0; sYuCeShuangSeQiu TempEqual; int ACCount=GetACCount(m_ShuangSeQiuList[i]); int WeiZhiCount=GetWeiZhiParam(m_ShuangSeQiuList[i]); ////预测特码 //int TempLanQiu = m_ShuangSeQiuList[i].m_LanQiu % 5; //int TempLanQiu2 = m_ShuangSeQiuList[i].m_LanQiu % 3; //vector<DWORD> LanQiu1; //vector<DWORD> LanQiu2; //for(int l=1; l <= 16; l++) //{ // if( l%3 == TempLanQiu) // LanQiu1.push_back(l); // if(l%5 == TempLanQiu2) // LanQiu2.push_back(l); //} //DWORD LanQiuYuCe=0; //for(int a=0; a < LanQiu1.size(); a++) //{ // for(int b=0; b < LanQiu2.size(); b++) // { // if(LanQiu1[a] == LanQiu2[b]) // LanQiuYuCe=LanQiu1[a]; // } //} //TempQiuData.m_LanQiu = LanQiuYuCe; for(int j=0; j < QIU_XUN; j++) { int Data = Sum/m_ShuangSeQiuList[i].m_HongQiu[j]; //int Data=(Sum-m_ShuangSeQiuList[i].m_HongQiu[j])/m_ShuangSeQiuList[i].m_HongQiu[j]; TempQiuData.m_HongQiu[j]= Data; TempQiuData2.m_HongQiu[j]=(Sum-m_ShuangSeQiuList[i].m_HongQiu[j])/m_ShuangSeQiuList[i].m_HongQiu[j]; //特码选号 if(i-1>=0) { TempLanQiuData.m_HongQiu[j]=abs(m_ShuangSeQiuList[i-1].m_HongQiu[j]-m_ShuangSeQiuList[i].m_LanQiu); TempWeiQiuData.m_HongQiu[j]=abs(m_ShuangSeQiuList[i-1].m_HongQiu[j]-WeiZhiCount); } else { TempLanQiuData.m_HongQiu[j]=0; TempWeiQiuData.m_HongQiu[j]=0; } //AC差值 TempACQiuData.m_HongQiu[j]=abs(m_ShuangSeQiuList[i].m_HongQiu[j]-ACCount); } if(i+1 < ListCount) { TempEqual.m_ShuangSeQiu = m_ShuangSeQiuList[i+1]; TempEqual.m_YuCeQiuMap[SUANFA_HEZHI_YUCE]=TempQiuData; TempEqual.m_YuCeQiuMap[SUANFA_HEZHI_YUCE2]=TempQiuData2; TempEqual.m_YuCeQiuMap[SUANFA_ACZHI_YUCE]=TempACQiuData; TempEqual.m_YuCeQiuMap[SUANFA_WEIZHI_YUCE]=TempWeiQiuData; TempEqual.m_YuCeQiuMap[SUANFA_LANJI_YUCE]=TempLanQiuData; TempData[m_ShuangSeQiuList[i+1].m_QiShu]=TempEqual; } else { TempEqual.m_ShuangSeQiu.m_QiShu=_T("最新预测"); TempEqual.m_ShuangSeQiu.m_HongQiuSum = 0; TempEqual.m_ShuangSeQiu.m_LanQiu = 0; for(int Index = 0; Index < QIU_XUN; Index++) { TempEqual.m_ShuangSeQiu.m_HongQiu[Index]=0; } TempEqual.m_YuCeQiuMap[SUANFA_HEZHI_YUCE]=TempQiuData; TempEqual.m_YuCeQiuMap[SUANFA_HEZHI_YUCE2]=TempQiuData2; TempEqual.m_YuCeQiuMap[SUANFA_ACZHI_YUCE]=TempACQiuData; TempEqual.m_YuCeQiuMap[SUANFA_WEIZHI_YUCE]=TempWeiQiuData; TempEqual.m_YuCeQiuMap[SUANFA_LANJI_YUCE]=TempLanQiuData; TempData["算法预测"]=TempEqual; SaveDataToFile(TempEqual); } } return TempData; }
int main() { _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); int timer = 0; MapReader mr = MapReader(); //Map data string* map = nullptr; //map = mr.ReadMap("Maps/Randomized128x128-29-0.map"); map = mr.ReadMap("Maps/maze512-1-1.map"); //map = mr.ReadMap("Maps/adaptive-depth-1.map"); //map = mr.ReadMap("Maps/32room_008.map"); //map = GenerateMap(10, 10, 1.0f, mr); int width = mr.GetWidth(); int height = mr.GetHeight(); int nrOfWalls = mr.GetNrOfWalls(map); Vec2D startPos = {1, 1}; Vec2D goalPos = {width-1, height-1}; int clusterSize = 16; Vec2D* wallPos = new Vec2D[nrOfWalls]; sf::RectangleShape* walls = new sf::RectangleShape[nrOfWalls]; AStarNode** grid = nullptr; if (map != nullptr) { if (width > 0 && height > 0) { grid = new AStarNode*[width]; //Initiate the grid** with walkable or non-walkable tiles int wallCounter = 0; for (int i = 0; i < width; i++) { grid[i] = new AStarNode[height]; for (int j = 0; j < height; j++) { grid[i][j] = AStarNode(i, j); if (map[j*width + i] != "@") { grid[i][j]._traversable = true; } else { grid[i][j]._traversable = false; walls[wallCounter] = sf::RectangleShape(sf::Vector2f((float)tileWidth, (float)tileHeight)); walls[wallCounter].setFillColor(sf::Color::White); walls[wallCounter].setPosition(sf::Vector2f(10.0f + (float)(tileWidth * i), 10.0f + (float)(tileHeight * j))); wallCounter++; } } } } } sf::View view; view.setCenter(0.5f * width * tileWidth, 0.5f * height * tileHeight); view.setSize(1.6f * width * tileWidth, 1.2f * height * tileHeight); sf::RenderWindow window(sf::VideoMode(windowWidth, windowHeight), "AI test"); window.setFramerateLimit(60); window.setView(view); ImGui::SFML::SetRenderTarget(window); ImGui::SFML::InitImGuiRendering(); ImGui::SFML::SetWindow(window); ImGui::SFML::InitImGuiEvents(); sf::RectangleShape* openedTiles = nullptr; sf::RectangleShape* expandedTiles = nullptr; sf::Vertex* pathTiles = nullptr; //Mainly for the highlevel graph of HPA* sf::Vertex* abstractGraph = nullptr; sf::Vertex* openedGraph = nullptr; sf::Vertex* expandedGraph = nullptr; Metrics metrics; sf::CircleShape startNode = sf::CircleShape(0.4f*tileHeight); startNode.setPosition(sf::Vector2f(10.0f + startPos._x * (float)tileWidth, 10.0f + startPos._y * (float)tileHeight)); startNode.setFillColor(sf::Color::Red); sf::CircleShape goalNode = sf::CircleShape(0.4f*tileHeight);; goalNode.setPosition(sf::Vector2f(10.0f + goalPos._x * (float)tileWidth, 10.0f + goalPos._y * (float)tileHeight)); goalNode.setFillColor(sf::Color::Yellow); //Other variables bool calculatePaths = false; int choosePathfinding = 0; int chooseHeuristic = 0; //Movement variable int delta = width * 0.05f; float blockSize = 32.0f; //Randomize map variables bool randomizeMap = false; char widthBuffer[4] = "512"; char heightBuffer[4] = "512"; char densityBuffer[3] = "30"; //Set start/goal position variables int startOrGoal = 0; //0 == start pos, 1 == goal pos char xBuffer[4] = "0"; char yBuffer[4] = "0"; //What should be drawn? bool showWalls = false; bool showExpandedNodes = false; bool showOpenedNodes = false; while (window.isOpen()) { ImGui::SFML::UpdateImGui(); ImGui::SFML::UpdateImGuiRendering(); sf::Event event; while (window.pollEvent(event)) { ImGui::SFML::ProcessEvent(event); if (event.type == sf::Event::Closed) { window.close(); } } ImGuiIO &io = ImGui::GetIO(); //ImGui::ShowTestWindow(); window.clear(); /**************************************/ /* Start of GUI code */ /**************************************/ if (ImGui::CollapsingHeader("Choose pathfinding")) { ImGui::RadioButton("A*", &choosePathfinding, 0); ImGui::SameLine(); ImGui::RadioButton("Theta*", &choosePathfinding, 1); ImGui::SameLine(); ImGui::RadioButton("HPA*", &choosePathfinding, 2); ImGui::SameLine(); ImGui::RadioButton("IDA*", &choosePathfinding, 3); ImGui::SameLine(); ImGui::RadioButton("Dijkstra", &choosePathfinding, 4); ImGui::RadioButton("Manhattan", &chooseHeuristic, 0); ImGui::SameLine(); ImGui::RadioButton("Chebyshev", &chooseHeuristic, 1); ImGui::SameLine(); ImGui::RadioButton("Octile", &chooseHeuristic, 2); ImGui::SameLine(); ImGui::RadioButton("Euclidean", &chooseHeuristic, 3); } if (ImGui::CollapsingHeader("Randomize a map")) { //Set width, height and obstacle density ImGui::InputText("Width", widthBuffer, IM_ARRAYSIZE(widthBuffer)); ImGui::InputText("Height", heightBuffer, IM_ARRAYSIZE(heightBuffer)); ImGui::InputText("Density (%)", densityBuffer, IM_ARRAYSIZE(densityBuffer)); if (ImGui::SmallButton("Generate map")) { mr.GenerateRandomMap(stoi(string(widthBuffer)), stoi(string(heightBuffer)), 0.01f*stof(string(densityBuffer))); } } if (ImGui::CollapsingHeader("Set start/goal")) { ImGui::RadioButton("Set start position", &startOrGoal, 0); ImGui::SameLine(); ImGui::RadioButton("Set goal position", &startOrGoal, 1); //Set xPos and yPos ImGui::InputText("X position", xBuffer, IM_ARRAYSIZE(xBuffer)); ImGui::InputText("Y position", yBuffer, IM_ARRAYSIZE(yBuffer)); if (ImGui::SmallButton("Set position")) { Vec2D pos = {stoi(string(xBuffer)), stoi(string(yBuffer))}; if (startOrGoal == 0) //Start pos { startPos = pos; startNode.setPosition(sf::Vector2f(10.0f + startPos._x * (float)tileWidth, 10.0f + startPos._y * (float)tileHeight)); } else if (startOrGoal == 1) //Goal pos { goalPos = pos; goalNode.setPosition(sf::Vector2f(10.0f + goalPos._x * (float)tileWidth, 10.0f + goalPos._y * (float)tileHeight)); } } } if (ImGui::CollapsingHeader("Choose what will be drawn")) { ImGui::Checkbox("Walls", &showWalls); ImGui::Checkbox("Opened nodes", &showOpenedNodes); ImGui::Checkbox("Expanded nodes", &showExpandedNodes); } if (ImGui::SmallButton("Calculate paths")) { calculatePaths = !calculatePaths; } /**************************************/ /* End of GUI code */ /**************************************/ //Moving of the camera if (sf::Keyboard::isKeyPressed(sf::Keyboard::W)) //Move camera west { view.setCenter(view.getCenter().x, view.getCenter().y - delta); } if (sf::Keyboard::isKeyPressed(sf::Keyboard::A)) //Move camera east { view.setCenter(view.getCenter().x - delta, view.getCenter().y); } if (sf::Keyboard::isKeyPressed(sf::Keyboard::S)) //Move camera south { view.setCenter(view.getCenter().x, view.getCenter().y + delta); } if (sf::Keyboard::isKeyPressed(sf::Keyboard::D)) //Move camera north { view.setCenter(view.getCenter().x + delta, view.getCenter().y); } //Zooming with the camera if (sf::Keyboard::isKeyPressed(sf::Keyboard::PageUp) && blockSize <= 32.0f) //Zoom out { view.setSize(sf::Vector2f(width * tileWidth * blockSize++ * 0.05f, height * tileHeight * blockSize++ * 0.0375f)); } if (sf::Keyboard::isKeyPressed(sf::Keyboard::PageDown) && blockSize >= 1.0f) //Zoom in { view.setSize(sf::Vector2f(width * tileWidth * blockSize-- * 0.05f, height * tileHeight * blockSize-- * 0.0375f)); } window.setView(view); //Calculate pathfinding if (calculatePaths) { metrics.clean(); switch (choosePathfinding) { case 0: //A* CalculateAStar(metrics, (Pathfinding::Heuristic)chooseHeuristic, width, height, startPos, goalPos, grid); break; case 1: //Theta* CalculateThetaStar(metrics, (Pathfinding::Heuristic)chooseHeuristic, width, height, startPos, goalPos, grid); break; case 2: //HPA* CalculateHPAStar(metrics, (Pathfinding::Heuristic)chooseHeuristic, width, height, startPos, goalPos, grid, clusterSize); break; case 3: //IDA* CalculateIDAStar(metrics, (Pathfinding::Heuristic)chooseHeuristic, width, height, startPos, goalPos, grid); break; case 4: CalculateDijkstra(metrics, (Pathfinding::Heuristic)chooseHeuristic, width, height, startPos, goalPos, grid); default: break; } if (showOpenedNodes) { if (openedTiles != nullptr) { delete[] openedTiles; } openedTiles = new sf::RectangleShape[metrics.getNrOfOpenedNodes()]; for (int i = 0; i < metrics.getNrOfOpenedNodes(); i++) { openedTiles[i] = sf::RectangleShape(sf::Vector2f((float)tileWidth, (float)tileHeight)); openedTiles[i].setFillColor(sf::Color(0, 200, 200, 120)); openedTiles[i].setPosition(sf::Vector2f(10.0f + (float)tileWidth * metrics.getOpenedNodes()[i]._x, 10.0f + (float)tileHeight * metrics.getOpenedNodes()[i]._y)); window.draw(openedTiles[i]); } } if (showExpandedNodes) { if (expandedTiles != nullptr) { delete[] expandedTiles; } expandedTiles = new sf::RectangleShape[metrics.getNrOfExpandedNodes()]; for (int i = 0; i < metrics.getNrOfExpandedNodes(); i++) { expandedTiles[i] = sf::RectangleShape(sf::Vector2f((float)tileWidth, (float)tileHeight)); expandedTiles[i].setFillColor(sf::Color(200, 0, 0, 120)); expandedTiles[i].setPosition(sf::Vector2f(10.0f + (float)tileWidth * metrics.getExpandedNodes()[i]._x, 10.0f + (float)tileHeight * metrics.getExpandedNodes()[i]._y)); window.draw(expandedTiles[i]); } } if (pathTiles != nullptr) { delete[] pathTiles; } pathTiles = new sf::Vertex[metrics.getNrOfPathNodes() + 1]; for (int i = 0; i < metrics.getNrOfPathNodes(); i++) { pathTiles[i] = sf::Vertex(sf::Vector2f(10.0f + (float)tileWidth * (metrics.getPathNodes()[i]._x + 0.5f), 10.0f + (float)tileHeight * (metrics.getPathNodes()[i]._y + 0.5f))); pathTiles[i].color = sf::Color(200, 0, 200, 255); } pathTiles[metrics.getNrOfPathNodes()] = sf::Vector2f(10.0f + (float)tileWidth * (startPos._x + 0.5f), 10.0f + (float)tileHeight * (startPos._y + 0.5f)); SaveDataToFile(metrics, choosePathfinding, chooseHeuristic); calculatePaths = false; } //Draw the start and goal node(s) window.draw(startNode); window.draw(goalNode); if (choosePathfinding == 2) //Special case for HPA* { window.draw(abstractGraph, metrics.getNrOfGraphNodes(), sf::Lines); if (showOpenedNodes) { window.draw(openedGraph, metrics.getNrOfOpenedNodes(), sf::Lines); } if (showExpandedNodes) { window.draw(expandedGraph, metrics.getNrOfExpandedNodes(), sf::Lines); } } else { if (showOpenedNodes && openedTiles != nullptr) { for (int i = 0; i < metrics.getNrOfOpenedNodes(); i++) { window.draw(openedTiles[i]); } } if (showExpandedNodes) { for (int i = 0; i < metrics.getNrOfExpandedNodes(); i++) { window.draw(expandedTiles[i]); } } } window.draw(pathTiles, metrics.getNrOfPathNodes() + 1, sf::LinesStrip); //Draw all the walls if (showWalls) { for (int i = 0; i < nrOfWalls; i++) { window.draw(walls[i]); } } ImGui::Render(); window.display(); } delete[] expandedTiles; delete[] openedTiles; delete[] pathTiles; delete[] walls; delete[] map; delete[] wallPos; for (__int16 i = 0; i < width; i++) { delete[] grid[i]; } delete[] grid; ImGui::SFML::Shutdown(); return 0; }