NS_IMETHODIMP inCSSValueSearch::SearchSync() { InitSearch(); nsCOMPtr<nsIURI> baseURL; nsCOMPtr<nsIDOM3Node> dom3Node = do_QueryInterface(mDocument); if (dom3Node) { nsAutoString uri; dom3Node->GetBaseURI(uri); NS_NewURI(getter_AddRefs(baseURL), uri); } nsCOMPtr<nsIDOMDocumentStyle> doc = do_QueryInterface(mDocument); if (doc) { nsCOMPtr<nsIDOMStyleSheetList> sheets; nsresult rv = doc->GetStyleSheets(getter_AddRefs(sheets)); NS_ENSURE_SUCCESS(rv, NS_OK); PRUint32 length; sheets->GetLength(&length); for (PRUint32 i = 0; i < length; ++i) { nsCOMPtr<nsIDOMStyleSheet> sheet; sheets->Item(i, getter_AddRefs(sheet)); nsCOMPtr<nsIDOMCSSStyleSheet> cssSheet = do_QueryInterface(sheet); if (cssSheet) SearchStyleSheet(cssSheet, baseURL); } } // XXX would be nice to search inline style as well. return NS_OK; }
NS_IMETHODIMP inCSSValueSearch::SearchSync() { InitSearch(); if (!mDocument) { return NS_OK; } nsCOMPtr<nsIURI> baseURI; nsCOMPtr<nsIDocument> idoc = do_QueryInterface(mDocument); if (idoc) { baseURI = idoc->GetBaseURI(); } nsCOMPtr<nsIDOMStyleSheetList> sheets; nsresult rv = mDocument->GetStyleSheets(getter_AddRefs(sheets)); NS_ENSURE_SUCCESS(rv, NS_OK); PRUint32 length; sheets->GetLength(&length); for (PRUint32 i = 0; i < length; ++i) { nsCOMPtr<nsIDOMStyleSheet> sheet; sheets->Item(i, getter_AddRefs(sheet)); nsCOMPtr<nsIDOMCSSStyleSheet> cssSheet = do_QueryInterface(sheet); if (cssSheet) SearchStyleSheet(cssSheet, baseURI); } // XXX would be nice to search inline style as well. return NS_OK; }
NS_IMETHODIMP inCSSValueSearch::SearchAsync(inISearchObserver *aObserver) { InitSearch(); mObserver = aObserver; return NS_OK; }
IPath::SearchResult CPathFinder::GetPath( const MoveData& moveData, const float3& startPos, const CPathFinderDef& pfDef, IPath::Path& path, bool testMobile, bool exactPath, unsigned int maxNodes, bool needPath, int ownerId, bool synced ) { // Clear the given path. path.path.clear(); path.squares.clear(); path.pathCost = PATHCOST_INFINITY; // Store som basic data. maxSquaresToBeSearched = std::min(MAX_SEARCHED_NODES_PF - 8U, maxNodes); this->testMobile = testMobile; this->exactPath = exactPath; this->needPath = needPath; start = startPos; startxSqr = (int(start.x) / SQUARE_SIZE)|1; startzSqr = (int(start.z) / SQUARE_SIZE)|1; // Clamp the start position if (startxSqr < 0) startxSqr = 0; if (startxSqr >= gs->mapx) startxSqr = gs->mapx - 1; if (startzSqr < 0) startzSqr = 0; if (startzSqr >= gs->mapy) startzSqr = gs->mapy - 1; startSquare = startxSqr + startzSqr * gs->mapx; // Start up the search. IPath::SearchResult result = InitSearch(moveData, pfDef, ownerId, synced); // Respond to the success of the search. if (result == IPath::Ok || result == IPath::GoalOutOfRange) { FinishSearch(moveData, path); if (PATHDEBUG) { LogObject() << "Path found.\n"; LogObject() << "Nodes tested: " << testedNodes << "\n"; LogObject() << "Open squares: " << openSquareBuffer.GetSize() << "\n"; LogObject() << "Path nodes: " << path.path.size() << "\n"; LogObject() << "Path cost: " << path.pathCost << "\n"; } } else { if (PATHDEBUG) { LogObject() << "No path found!\n"; LogObject() << "Nodes tested: " << testedNodes << "\n"; LogObject() << "Open squares: " << openSquareBuffer.GetSize() << "\n"; } } return result; }
/* Storing data and doing some top-administration. */ IPath::SearchResult CPathEstimator::GetPath(const MoveData& moveData, float3 start, const CPathFinderDef& peDef, Path& path, unsigned int maxSearchedBlocks) { // START_TIME_PROFILE; start.CheckInBounds(); //Clear path. path.path.clear(); path.pathCost = PATHCOST_INFINITY; //Initial calculations. maxBlocksToBeSearched = std::min(maxSearchedBlocks, (unsigned int) MAX_SEARCHED_BLOCKS); startBlock.x = (int)(start.x / BLOCK_PIXEL_SIZE); startBlock.y = (int)(start.z / BLOCK_PIXEL_SIZE); startBlocknr = startBlock.y * nbrOfBlocksX + startBlock.x; int2 goalBlock; goalBlock.x=peDef.goalSquareX/BLOCK_SIZE; goalBlock.y=peDef.goalSquareZ/BLOCK_SIZE; CPathCache::CacheItem* ci=pathCache->GetCachedPath(startBlock,goalBlock,peDef.sqGoalRadius,moveData.pathType); if(ci){ // logOutput.Print("Using cached path %i",BLOCK_SIZE); path=ci->path; /* if(BLOCK_SIZE==8){ END_TIME_PROFILE("Estimater 8"); }else{ END_TIME_PROFILE("Estimater 32"); }*/ return ci->result; } // logOutput.Print("----Creating new path %i",BLOCK_SIZE); //Search SearchResult result = InitSearch(moveData, peDef); //If successful, generate path. if(result == Ok || result == GoalOutOfRange) { FinishSearch(moveData, path); pathCache->AddPath(&path,result,startBlock,goalBlock,peDef.sqGoalRadius,moveData.pathType); //only add succesfull paths to the cache if(PATHDEBUG) { logOutput << "PE: Search completed.\n"; logOutput << "Tested blocks: " << testedBlocks << "\n"; logOutput << "Open blocks: " << (float)(openBlockBufferPointer - openBlockBuffer) << "\n"; logOutput << "Path length: " << (int)(path.path.size()) << "\n"; logOutput << "Path cost: " << path.pathCost << "\n"; } } else { if(PATHDEBUG) { logOutput << "PE: Search failed!\n"; logOutput << "Tested blocks: " << testedBlocks << "\n"; logOutput << "Open blocks: " << (float)(openBlockBufferPointer - openBlockBuffer) << "\n"; } } /* if(BLOCK_SIZE==8){ END_TIME_PROFILE("Estimater 8"); }else{ END_TIME_PROFILE("Estimater 32"); }*/ return result; }
int main(int argc, char ** argv) { if (argc >= 2) { pthread_t network_thread; printf("\nCode testing..."); InitGlobalConfig(&GC); Init(); InitSearch(); GPIO_Init(0xFFFFFFFF); pthread_create(&network_thread, NULL, thread_network, NULL); CodeTest(atoi(argv[1])); GPIO_Close(); } else { pthread_t network_thread; printf("\n电力电压和开关状态上传"); InitGlobalConfig(&GC); Init(); InitSearch(); GPIO_Init(0xFFFFFFFF); pthread_create(&network_thread, NULL, thread_network, NULL); thread_CommonSearch(Search); GPIO_Close(); } return 0; }
/* * stores data and does some top-administration */ IPath::SearchResult CPathEstimator::GetPath(const MoveData& moveData, float3 start, const CPathFinderDef& peDef, Path& path, unsigned int maxSearchedBlocks) { start.CheckInBounds(); // clear the path path.path.clear(); path.pathCost = PATHCOST_INFINITY; // initial calculations maxBlocksToBeSearched = std::min(maxSearchedBlocks, (unsigned int) MAX_SEARCHED_BLOCKS); startBlock.x = (int)(start.x / BLOCK_PIXEL_SIZE); startBlock.y = (int)(start.z / BLOCK_PIXEL_SIZE); startBlocknr = startBlock.y * nbrOfBlocksX + startBlock.x; int2 goalBlock; goalBlock.x = peDef.goalSquareX / BLOCK_SIZE; goalBlock.y = peDef.goalSquareZ / BLOCK_SIZE; CPathCache::CacheItem* ci = pathCache->GetCachedPath(startBlock, goalBlock, peDef.sqGoalRadius, moveData.pathType); if (ci) { // use a cached path if we have one path = ci->path; return ci->result; } // oterhwise search SearchResult result = InitSearch(moveData, peDef); // if search successful, generate new path if (result == Ok || result == GoalOutOfRange) { FinishSearch(moveData, path); // only add succesful paths to the cache pathCache->AddPath(&path, result, startBlock, goalBlock, peDef.sqGoalRadius, moveData.pathType); if (PATHDEBUG) { LogObject() << "PE: Search completed.\n"; LogObject() << "Tested blocks: " << testedBlocks << "\n"; LogObject() << "Open blocks: " << (float)(openBlockBufferPointer - openBlockBuffer) << "\n"; LogObject() << "Path length: " << (int)(path.path.size()) << "\n"; LogObject() << "Path cost: " << path.pathCost << "\n"; } } else { if (PATHDEBUG) { LogObject() << "PE: Search failed!\n"; LogObject() << "Tested blocks: " << testedBlocks << "\n"; LogObject() << "Open blocks: " << (float)(openBlockBufferPointer - openBlockBuffer) << "\n"; } } return result; }
/* Store som data and doing some basic top-administration. */ IPath::SearchResult CPathFinder::GetPath(const MoveData& moveData, const float3 startPos, const CPathFinderDef& pfDef, Path& path, bool testMobile, bool exactPath, unsigned int maxNodes,bool needPath) { //Clear the given path. path.path.clear(); path.pathCost = PATHCOST_INFINITY; //Store som basic data. maxNodesToBeSearched = min((unsigned int)MAX_SEARCHED_SQARES, maxNodes); this->testMobile=testMobile; this->exactPath = exactPath; this->needPath=needPath; start = startPos; startxSqr = (int(start.x) / SQUARE_SIZE)|1; startzSqr = (int(start.z) / SQUARE_SIZE)|1; startSquare = startxSqr + startzSqr * gs->mapx; //Clamp the start position if (startxSqr < 0) startxSqr=0; if (startxSqr >= gs->mapx) startxSqr = gs->mapx-1; if (startzSqr < 0) startzSqr =0; if (startzSqr >= gs->mapy) startzSqr = gs->mapy-1; //Start up the search. SearchResult result = InitSearch(moveData, pfDef); //Respond to the success of the search. if(result == Ok || result == GoalOutOfRange) { FinishSearch(moveData, path); if(PATHDEBUG) { *info << "Path found.\n"; *info << "Nodes tested: " << (int)testedNodes << "\n"; *info << "Open squares: " << (float)(openSquareBufferPointer - openSquareBuffer) << "\n"; *info << "Path steps: " << (int)(path.path.size()) << "\n"; *info << "Path cost: " << path.pathCost << "\n"; } } else { if(PATHDEBUG) { *info << "Path not found!\n"; *info << "Nodes tested: " << (int)testedNodes << "\n"; *info << "Open squares: " << (float)(openSquareBufferPointer - openSquareBuffer) << "\n"; } } return result; }
/** * @function FindVarietyPaths2 * @brief Using Free Space */ std::vector< std::vector<Eigen::Vector3i> > LJM2::FindVarietyPaths2( int _x1, int _y1, int _z1, int _x2, int _y2, int _z2, int _times, float _alpha ) { mAlpha = _alpha; std::vector< std::vector<Eigen::Vector3i> > paths; std::vector<Eigen::Vector3i> path; std::vector< std::vector<int> > nodePaths; std::vector<int> allNodePaths; time_t ts; time_t tf; double dt; //-- Find the nearest points int startIndex = ref( _x1, _y1, _z1 ); int targetIndex = ref( _x2, _y2, _z2 ); printf("--> Start: %d Target: %d \n", startIndex, targetIndex ); InitSearch(); for( size_t i = 0; i < _times; ++i ) { path.resize(0); //ts = clock(); path = FindPath( startIndex, targetIndex ); //tf = clock(); printf("--[%d] Found Path of size %d \n", i, path.size() ); //printf(" Time elapsed: %.3f \n", (double) (tf - ts)/CLOCKS_PER_SEC ); paths.push_back( path ); nodePaths.push_back( mPath ); //-- Update the values //ts = clock(); ResetSearch(); //tf = clock(); //printf("--[%d] Search : Time elapsed: %.3f \n", i, (double) (tf - ts)/CLOCKS_PER_SEC ); allNodePaths = JoinPaths( nodePaths ); ts = clock(); UpdateNodeValues( allNodePaths ); //tf = clock(); //printf("--[%d] UpdateNodes : Time elapsed: %.3f \n", i, (double) (tf - ts)/CLOCKS_PER_SEC ); } return paths; }
static LRESULT CALLBACK Child_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_PAINT: return Child_OnPaint(hWnd); case WM_SIZE: return Child_OnSize(hWnd); case WM_NOTIFY: { HHInfo *info = (HHInfo*)GetWindowLongPtrW(hWnd, GWLP_USERDATA); NMHDR *nmhdr = (NMHDR*)lParam; switch(nmhdr->code) { case TCN_SELCHANGE: return OnTabChange(hWnd); case TVN_SELCHANGEDW: return OnTopicChange(info, (void*)((NMTREEVIEWW *)lParam)->itemNew.lParam); case NM_DBLCLK: if(!info) return 0; switch(info->current_tab) { case TAB_INDEX: return OnTopicChange(info, (void*)((NMITEMACTIVATE *)lParam)->lParam); case TAB_SEARCH: return OnTopicChange(info, (void*)((NMITEMACTIVATE *)lParam)->lParam); } break; case NM_RETURN: if(!info) return 0; switch(info->current_tab) { case TAB_INDEX: { HWND hwndList = info->tabs[TAB_INDEX].hwnd; LVITEMW lvItem; lvItem.iItem = (int) SendMessageW(hwndList, LVM_GETSELECTIONMARK, 0, 0); lvItem.mask = TVIF_PARAM; SendMessageW(hwndList, LVM_GETITEMW, 0, (LPARAM)&lvItem); OnTopicChange(info, (void*) lvItem.lParam); return 0; } case TAB_SEARCH: { if(nmhdr->hwndFrom == info->search.hwndEdit) { char needle[100]; DWORD i, len; len = GetWindowTextA(info->search.hwndEdit, needle, sizeof(needle)); if(!len) { FIXME("Unable to get search text.\n"); return 0; } /* Convert the requested text for comparison later against the * lower case version of HTML file contents. */ for(i=0;i<len;i++) needle[i] = tolower(needle[i]); InitSearch(info, needle); return 0; }else if(nmhdr->hwndFrom == info->search.hwndList) { HWND hwndList = info->search.hwndList; LVITEMW lvItem; lvItem.iItem = (int) SendMessageW(hwndList, LVM_GETSELECTIONMARK, 0, 0); lvItem.mask = TVIF_PARAM; SendMessageW(hwndList, LVM_GETITEMW, 0, (LPARAM)&lvItem); OnTopicChange(info, (void*) lvItem.lParam); return 0; } break; } } break; } break; } default: return DefWindowProcW(hWnd, message, wParam, lParam); } return 0; }
IPath::SearchResult IPathFinder::GetPath( const MoveDef& moveDef, const CPathFinderDef& pfDef, const CSolidObject* owner, float3 startPos, IPath::Path& path, const unsigned int maxNodes ) { startPos.ClampInBounds(); // Clear the path path.path.clear(); path.squares.clear(); path.pathCost = PATHCOST_INFINITY; // initial calculations if (isEstimator) { maxBlocksToBeSearched = std::min(MAX_SEARCHED_NODES_PE - 8U, maxNodes); } else { maxBlocksToBeSearched = std::min(MAX_SEARCHED_NODES_PF - 8U, maxNodes); } mStartBlock.x = startPos.x / BLOCK_PIXEL_SIZE; mStartBlock.y = startPos.z / BLOCK_PIXEL_SIZE; mStartBlockIdx = BlockPosToIdx(mStartBlock); assert((unsigned)mStartBlock.x < nbrOfBlocks.x && (unsigned)mStartBlock.y < nbrOfBlocks.y); // Check cache (when there is one) int2 goalBlock; goalBlock.x = pfDef.goalSquareX / BLOCK_SIZE; goalBlock.y = pfDef.goalSquareZ / BLOCK_SIZE; const CPathCache::CacheItem* ci = GetCache(mStartBlock, goalBlock, pfDef.sqGoalRadius, moveDef.pathType, pfDef.synced); if (ci != nullptr) { path = ci->path; return ci->result; } // Start up a new search IPath::SearchResult result = InitSearch(moveDef, pfDef, owner); // If search was successful, generate new path if (result == IPath::Ok || result == IPath::GoalOutOfRange) { FinishSearch(moveDef, pfDef, path); // Save to cache AddCache(&path, result, mStartBlock, goalBlock, pfDef.sqGoalRadius, moveDef.pathType, pfDef.synced); if (LOG_IS_ENABLED(L_DEBUG)) { LOG_L(L_DEBUG, "==== %s: Search completed ====", (isEstimator) ? "PE" : "PF"); LOG_L(L_DEBUG, "Tested blocks: %u", testedBlocks); LOG_L(L_DEBUG, "Open blocks: %u", openBlockBuffer.GetSize()); LOG_L(L_DEBUG, "Path length: " _STPF_, path.path.size()); LOG_L(L_DEBUG, "Path cost: %f", path.pathCost); LOG_L(L_DEBUG, "=============================="); } } else { if (LOG_IS_ENABLED(L_DEBUG)) { LOG_L(L_DEBUG, "==== %s: Search failed! ====", (isEstimator) ? "PE" : "PF"); LOG_L(L_DEBUG, "Tested blocks: %u", testedBlocks); LOG_L(L_DEBUG, "Open blocks: %u", openBlockBuffer.GetSize()); LOG_L(L_DEBUG, "============================"); } } return result; }
int main() { fl_reading_personality = 0; fl_separate_books = 0; // opening book files can be defined in a personality description fl_elo_slider = 0; time_percentage = 100; use_book = 1; panel_style = 0; verbose = 1; hist_limit = 24576; hist_perc = 175; Timer.Init(); BB.Init(); Mask.Init(); Init(); InitWeights(); Param.Default(); Param.DynamicInit(); InitSearch(); #ifdef _WIN32 || _WIN64 // if we are on Windows search for books and settings in same directory as rodentII.exe MainBook.bookName = "books/rodent.bin"; GuideBook.bookName = "books/guide.bin"; ReadPersonality("basic.ini"); #elif __linux || __unix // if we are on Linux // first check, if compiler got told where books and settings are stored #ifdef BOOKPATH char path[255]; // space for complete path and filename char nameMainbook[20] = "/rodent.bin"; char nameGuidebook[20]= "/guide.bin"; char namePersonality[20]= "/basic.ini"; // process Mainbook strcpy(path, ""); // first clear strcpy(path, STR(BOOKPATH)); // copy path from c preprocessor here strcat(path, nameMainbook); // append bookname MainBook.bookName = path; // store it // process Guidebook strcpy(path, ""); strcpy(path, STR(BOOKPATH)); strcat(path, nameGuidebook); GuideBook.bookName = nameGuidebook; // process Personality file strcpy(path, ""); strcpy(path, STR(BOOKPATH)); strcat(path, namePersonality); ReadPersonality(path); #else // if no path was given than we assume that files are stored at /usr/share/rodentII MainBook.bookName = "/usr/share/rodentII/rodent.bin"; GuideBook.bookName = "/usr/share/rodentII/guide.bin"; ReadPersonality("/usr/share/rodentII/basic.ini"); #endif #else // a platform we have not tested yet. We assume that opening books and // settings are stored within the same directory. Similiar to Windows. printf("Platform unknown. We assume that opening books and settings are stored within RodentII path"); MainBook.bookName = "books/rodent.bin"; GuideBook.bookName = "books/guide.bin"; ReadPersonality("basic.ini"); #endif MainBook.OpenPolyglot(); GuideBook.OpenPolyglot(); UciLoop(); MainBook.ClosePolyglot(); GuideBook.ClosePolyglot(); return 0; }