void CJContainer::Update( POINT ptMouse ) { for_each( m_Children.begin(), m_Children.end(), bind2nd( mem_fun( &CWinCtrl::Update ), ptMouse ) ); }
//解析插件配置文件,下载并装载 BOOL CPluginManager::Update(const string &strPluginDownLoadFile) { LOG((LEVEL_FUNC_IN_OUT,"CPluginManager::ProcessConfig\n")); int ret; // 创建下载目录 CreateDirectory(m_szPluginDownLoadPath.c_str(),NULL); m_recycle.Push(m_szPluginDownLoadPath,CTspRecycle::FLAG_DIR); // 组装插件配置文件文件名 std::string strPluginConfigFile(m_szPluginConfigPath); strPluginConfigFile += TSP_PLUGIN_S_CONFIG_NAME; std::string strPluginDownLoadTmpFile; // 锁住这个链表,由于网络IO是异步,这个操作需要同步 nm_ddc::CLockGuard<nm_ddc::CThreadMutex> guard(&m_lock); // 读取配置信息到临时链表中 std::list<CPluginInfo> l; if( !ReadPluginIniFile<CPluginInfo>(l,strPluginDownLoadFile,true) ) { LOG((LEVEL_WARNNING,"解析插件配置文件失败.%s\n",strPluginDownLoadFile.c_str())); return FALSE; } // 去除不属于此功能管理的插件 ExceptPluginFile(l); // 新旧链表的迭代器声明 std::list<CPluginInfo>::iterator iterNew=l.begin(); std::list<CPluginInfo>::iterator iterOld; char md5[33] = {0}; BOOL bRet = FALSE; // 比较新老列表,确定要下载的项 for(;iterNew!=l.end();++iterNew) { // 在老列表中查找 iterOld = find(m_PluginList.begin(),m_PluginList.end(),iterNew->m_strName); if( iterOld != m_PluginList.end() ) { // 找到先做一次自我检测,防止配置文件和实体文件不一致导致不更新 bRet = MD5_Caculate_File ( iterOld->m_strFullName.c_str(),md5); // 比较md5值 if( bRet && strncmp(iterNew->m_md5,iterOld->m_md5,32) == 0 ) { // 还要看strFullName,如果一样,说明没变化,仅仅复制个标志位,后面交换到老列表中 if( iterOld->m_strFullName == iterNew->m_strFullName && iterOld->m_pid == iterNew->m_pid ) { *iterNew = *iterOld; LOG((LEVEL_INFO,"(the same dll,don't update) %s : %d\n",iterOld->m_strFullName.c_str(),iterOld->m_status)); // 用初始状态替代运行状态,防止析构时被卸载 if( iterOld->m_status == CPluginInfo::STATUS_RUNNING ) iterOld->m_status = CPluginInfo::STATUS_INIT; else { // 其他状态就卸载再加载吧 LOG((LEVEL_INFO,"插件未变化,但升级中将被卸载:%s,状态:%d.\n",iterOld->m_strFullName.c_str(),iterOld->m_status)); iterOld->RemovePlug(); } } else { // 直接拷贝到新路径 ret = ComfirmCopyFile(iterOld->m_strFullName.c_str(),iterNew->m_strFullName.c_str()); if( ret != 0 ) { LOG((LEVEL_ERROR,"拷贝文件出错:(%s==>%s),Lasterror=%d\n",iterOld->m_strFullName.c_str(),iterNew->m_strFullName.c_str(),GetLastError())); } iterNew->m_status = CPluginInfo::STATUS_UNLOAD; // 拷贝过去的插件肯定能启动成功(最少和老插件一样的状态),所以这里把老插件信息完全删除 iterOld->RemovePlug(); } // 新纪录中已经有了,老记录中删除 m_PluginList.erase(iterOld); } else // 准备下载 iterNew->m_status = CPluginInfo::STATUS_WAITDOWNLOAD; } else // 准备下载 iterNew->m_status = CPluginInfo::STATUS_WAITDOWNLOAD; } // 下载 for_each( l.begin(),l.end(),bind2nd(mem_fun_ref(&CPluginInfo::DownloadPlug),m_szPluginDownLoadPath) ); // 根据下载情况,改记录 for( iterNew=l.begin();iterNew!=l.end();++iterNew ) { // 在老配置中找 iterOld = find(m_PluginList.begin(),m_PluginList.end(),iterNew->m_strName.c_str() ); if( iterNew->m_status == CPluginInfo::STATUS_DOWNLOAD ) { // 组装下载文件名 strPluginDownLoadTmpFile.assign(m_szPluginDownLoadPath); strPluginDownLoadTmpFile += iterNew->m_strName; //先加入回收站 m_recycle.Push(strPluginDownLoadTmpFile); // 如果找到,停用,删除 if( iterOld != m_PluginList.end() ) { ret = iterOld->RemovePlug(); if( ret != 0 ) { LOG((LEVEL_WARNNING,"卸载插件 %s 出错:%d(%x)\n",iterNew->m_strName.c_str())); } } //将插件文件拷贝到目的地 ret = ComfirmCopyFile(strPluginDownLoadTmpFile.c_str(),iterNew->m_strFullName.c_str()); if( ret != 0 ) { LOG((LEVEL_ERROR,"拷贝文件出错:(%s==>%s),Lasterror=%d\n",strPluginDownLoadTmpFile.c_str(),iterNew->m_strFullName.c_str(),GetLastError())); } // 改状态为准备启用 iterNew->m_status = CPluginInfo::STATUS_UNLOAD; } else if( iterNew->m_status == CPluginInfo::STATUS_ERROR ) { // 可能下载失败,也可能以前就失败,不管怎样,都把信息复制过去 if( iterOld != m_PluginList.end() ) *iterNew = *iterOld; } //把url删掉,为了不在后面写入配置文件中;写配置文件是个通用的程序 iterNew->m_strURL = ""; } // 遍历老插件配置文件,如果新配置中没有,删除 for( iterOld=m_PluginList.begin();iterOld!=m_PluginList.end();++iterOld ) { // 在新配置中找 iterNew = find(l.begin(),l.end(),iterOld->m_strName.c_str() ); // 如果没找到,卸载 if( iterNew == l.end() ) iterOld->RemovePlug(); // l.push_back(*iterOld); //插入 } // 根据新配置写加密ini文件 if( !WritePluginIniFile(l,strPluginConfigFile,true) ) { LOG((LEVEL_ERROR,"写配置文件错:%s",strPluginConfigFile.c_str())); } // 清理现场 m_recycle.PopAll(); // 清空老列表,为了避免析构时自动卸载插件,这里强制将状态设为删除 for_each( m_PluginList.begin(),m_PluginList.end(),bind2nd(mem_fun_ref(&CPluginInfo::Status),CPluginInfo::STATUS_DELETE) ); m_PluginList.clear(); // 交换新老插件列表 m_PluginList.swap(l); //把INIT状态的改为RUNNING LOG((LEVEL_INFO,"m_PluginList.size()=%d.\n",m_PluginList.size())); for( iterOld=m_PluginList.begin();iterOld!=m_PluginList.end();++iterOld ) { LOG((LEVEL_INFO,"%s : %d\n",iterOld->m_strFullName.c_str(),iterOld->m_status)); if( iterOld->m_status == CPluginInfo::STATUS_INIT ) iterOld->m_status = CPluginInfo::STATUS_RUNNING; } // 启用 StatusAll(CPluginInfo::STATUS_RUNNING); return TRUE; }
Agent * get_agent_by_port(int port) { agent_iter iter; iter = find_if(agents.begin(), agents.end(), bind2nd(port_equal<Agent*>(), port)); if(iter == agents.end()) return (Agent*)0; return *iter; }
/// \brief get stack list iterator by stack name /// \param pName - pointer to IHashString with name of the stack /// \return iterator in m_Stacks container CUndoRedoComponent::StackList::iterator CUndoRedoComponent::FindStack(IHashString *pName) { return find_if(m_Stacks.begin(), m_Stacks.end(), bind2nd(mem_fun(&CUndoStack::operator ==), pName)); }
bool FavoritesMenu::AddNextItem() { // run the next chunk of code for a given item adding state if (fState == kStart) { fState = kAddingFavorites; fSectionItemCount = 0; fAddedSeparatorForSection = false; // set up adding the GoTo menu items try { BPath path; ThrowOnError(find_directory(B_USER_SETTINGS_DIRECTORY, &path, true)); path.Append(kGoDirectory); mkdir(path.Path(), 0777); BEntry entry(path.Path()); Model startModel(&entry, true); ThrowOnInitCheckError(&startModel); if (!startModel.IsContainer()) throw B_ERROR; if (startModel.IsQuery()) fContainer = new QueryEntryListCollection(&startModel); else if (startModel.IsVirtualDirectory()) fContainer = new VirtualDirectoryEntryList(&startModel); else { fContainer = new DirectoryEntryList(*dynamic_cast<BDirectory*> (startModel.Node())); } ThrowOnInitCheckError(fContainer); ThrowOnError( fContainer->Rewind() ); } catch (...) { delete fContainer; fContainer = NULL; } } if (fState == kAddingFavorites) { entry_ref ref; if (fContainer != NULL && fContainer->GetNextRef(&ref) == B_OK) { Model model(&ref, true); if (model.InitCheck() != B_OK) return true; if (!ShouldShowModel(&model)) return true; BMenuItem* item = BNavMenu::NewModelItem(&model, model.IsDirectory() ? fOpenFolderMessage : fOpenFileMessage, fTarget); if (item == NULL) return true; item->SetLabel(ref.name); // this is the name of the link in the Go dir if (!fAddedSeparatorForSection) { fAddedSeparatorForSection = true; AddItem(new TitledSeparatorItem(B_TRANSLATE("Favorites"))); } fUniqueRefCheck.push_back(*model.EntryRef()); AddItem(item); fSectionItemCount++; return true; } // done with favorites, set up for adding recent files fState = kAddingFiles; fAddedSeparatorForSection = false; app_info info; be_app->GetAppInfo(&info); fItems.MakeEmpty(); int32 apps, docs, folders; TrackerSettings().RecentCounts(&apps, &docs, &folders); BRoster().GetRecentDocuments(&fItems, docs, NULL, info.signature); fIndex = 0; fSectionItemCount = 0; } if (fState == kAddingFiles) { // if this is a Save panel, not an Open panel // then don't add the recent documents if (!fIsSavePanel) { for (;;) { entry_ref ref; if (fItems.FindRef("refs", fIndex++, &ref) != B_OK) break; Model model(&ref, true); if (model.InitCheck() != B_OK) return true; if (!ShouldShowModel(&model)) return true; BMenuItem* item = BNavMenu::NewModelItem(&model, fOpenFileMessage, fTarget); if (item) { if (!fAddedSeparatorForSection) { fAddedSeparatorForSection = true; AddItem(new TitledSeparatorItem( B_TRANSLATE("Recent documents"))); } AddItem(item); fSectionItemCount++; return true; } } } // done with recent files, set up for adding recent folders fState = kAddingFolders; fAddedSeparatorForSection = false; app_info info; be_app->GetAppInfo(&info); fItems.MakeEmpty(); int32 apps, docs, folders; TrackerSettings().RecentCounts(&apps, &docs, &folders); BRoster().GetRecentFolders(&fItems, folders, info.signature); fIndex = 0; } if (fState == kAddingFolders) { for (;;) { entry_ref ref; if (fItems.FindRef("refs", fIndex++, &ref) != B_OK) break; // don't add folders that are already in the GoTo section if (find_if(fUniqueRefCheck.begin(), fUniqueRefCheck.end(), bind2nd(std::equal_to<entry_ref>(), ref)) != fUniqueRefCheck.end()) { continue; } Model model(&ref, true); if (model.InitCheck() != B_OK) return true; if (!ShouldShowModel(&model)) return true; BMenuItem* item = BNavMenu::NewModelItem(&model, fOpenFolderMessage, fTarget, true); if (item != NULL) { if (!fAddedSeparatorForSection) { fAddedSeparatorForSection = true; AddItem(new TitledSeparatorItem( B_TRANSLATE("Recent folders"))); } AddItem(item); item->SetEnabled(true); // BNavMenu::NewModelItem returns a disabled item here - // need to fix this in BNavMenu::NewModelItem return true; } } } return false; }
const gd::Object & ClassWithObjects::GetObject(const gd::String & name) const { return *(*find_if(initialObjects.begin(), initialObjects.end(), bind2nd(gd::ObjectHasName(), name))); }
void sortColors(vector<int>& nums) { partition(partition(nums.begin(), nums.end(), bind2nd(equal_to<int>(), 0)), nums.end(), bind2nd(equal_to<int>(), 1)); }
/** @brief wndProc * * @TODO: document this function */ LRESULT TaskArea::wndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_TIMER: if (wParam == m_dragTimer) { if (m_dragTask) { SendMessage(hBlackboxWnd, BB_BRINGTOFRONT, 0, (LPARAM)m_dragTask->GetTaskWnd()); m_dragTask = NULL; } KillTimer(barWnd, m_dragTimer); } break; case BB_RECONFIGURE: readSettings(); populateTasks(); break; case BB_BROADCAST: { LPCSTR msg_string = (LPCSTR)lParam; LPCSTR element = NULL; msg_string += 1; if (!strnicmp(msg_string, m_pluginPrefix, strlen(m_pluginPrefix))) { msg_string += strlen(m_pluginPrefix) + 1; if (!strnicmp(msg_string, m_itemPrefix, strlen(m_itemPrefix))) { msg_string += strlen(m_itemPrefix) + 1; if ((element = "Stretch") && !strnicmp(msg_string, element, strlen(element))) { //msg_string += strlen(element); //m_iconSize = atoi(msg_string); //s_settingsManager.WriteSetting(m_pluginPrefix, "Tasks", element); //populateTasks(); //PostMessage(barWnd, BOXBAR_UPDATESIZE, 1, 0); } } else if (!strnicmp(msg_string, m_basePrefix.c_str(), m_basePrefix.size())) { if (itemList.size()) { itemList.front()->wndProc(hWnd, msg, wParam, lParam); } PostMessage(barWnd, BOXBAR_UPDATESIZE, 1, 0); configMenu(NULL, true); return 0; } } } break; case BB_TASKSUPDATE: switch (lParam) { case TASKITEM_FLASHED: case TASKITEM_ACTIVATED: Collection::wndProc(hWnd, msg, wParam, lParam); RedrawWindow(barWnd, NULL, NULL, RDW_INVALIDATE | RDW_INTERNALPAINT); return 0; case TASKITEM_ADDED: if (std::find_if(itemList.begin(), itemList.end(), bind2nd(TaskIsHWnd(), reinterpret_cast<HWND>(wParam))) == itemList.end()) { Task *newTask = new Task(reinterpret_cast<HWND>(wParam), vertical); itemList_t::iterator insertLoc = itemList.end(); if (vertical && stretchTaskarea) { insertLoc--; } itemList.insert(insertLoc, newTask); if (stretchTaskarea) { calculateSizes(true); RedrawWindow(barWnd, NULL, NULL, RDW_INVALIDATE | RDW_INTERNALPAINT); } else { PostMessage(barWnd, BOXBAR_UPDATESIZE, 1, 0); } } break; case TASKITEM_REMOVED: { itemList.remove_if(bind2nd(TaskIsHWnd(), reinterpret_cast<HWND>(wParam))); if (stretchTaskarea) { calculateSizes(true); RedrawWindow(barWnd, NULL, NULL, RDW_INVALIDATE | RDW_INTERNALPAINT); } else { PostMessage(barWnd, BOXBAR_UPDATESIZE, 1, 0); } break; } //populateTasks(); } break; } return Collection::wndProc(hWnd, msg, wParam, lParam); }
bool Layout::HasLayerNamed(const gd::String & name) const { return ( find_if(initialLayers.begin(), initialLayers.end(), bind2nd(gd::LayerHasName(), name)) != initialLayers.end() ); }
// get optical flow field descriptor void optiflowDescriptor( int gid, int vid, vector<int>&label, vector<vector<float> > &pfeat, vector<vector<float> > &nfeat) { bool useDenseOF = USEDENSE; int flen = 50; vector<int> mos; ldLabel(gid, mos); char vname[512]; Point2i isize; for(int v = vid; v < vid+1; ++v){ sprintf(vname, "/home/fengzy/Projects/XProject/dataset/Set%.02d/video/%d.avi", gid, v); CvCapture *cap = cvCaptureFromFile(vname); if(!cap) continue; vector<vector<Point2f> > flo(flen); int width = cvGetCaptureProperty(cap, CV_CAP_PROP_FRAME_WIDTH); int height= cvGetCaptureProperty(cap, CV_CAP_PROP_FRAME_HEIGHT); vector<Point2f> densePt; densePt.reserve( width * height); for ( int h = 0; h <height; ++h) for ( int w = 0; w < width; ++w) densePt.push_back( Point2f(w,h)); IplImage *pre, *nex; nex= cvQueryFrame(cap); pre = cvCreateImage(cvGetSize(nex), 8, 3); for(int i = 1; i <= flen; ++i){ printf("[%d/%d]page\n",i,flen); cvCopy(nex, pre); nex = cvQueryFrame(cap); if(!nex) break; Mat mPre(pre), mNex(nex), mask; Point2i imgsize = SamplingOpticalFlow(mPre,mNex,mask,densePt, flo[i-1]); if(!isize.x) isize=imgsize; } // create histogram vector<float> floHist(flo.size()); //// remove the 1st and last frame's optical flow. char buff[512]; sprintf(buff,"/home/fengzy/Projects/XProject/dataset/Set%.02d/feature/%d.txt",gid,v); FILE *fp = fopen(buff,"w+"); vector<float> preFeat; vector<vector<float> >derivHist; for ( unsigned int nlen = 0; nlen < flo.size(); ++nlen) { vector<float> hist[4]; float count[4] = {0}; for( int i = 0; i < 4; ++i) {hist[i] = vector<float>(9, 0);} for ( unsigned int ne = 0; ne < flo[nlen].size(); ++ne){ // // convert into angle float angle = 0, flolen = 1; if ( flo[nlen][ne].y ){ angle = tan2g(flo[nlen][ne].x, flo[nlen][ne].y); angle = angle > 0 ? angle : 360 + angle; // use flo length as weight flolen = floLen( flo[nlen][ne].x, flo[nlen][ne].y); flolen = flolen == 0 ? 1.0f : flolen; } int iy = ne/isize.x, ix = ne%isize.x; int indx = iy*2/isize.y + ix*2/isize.x; int inda = floor(angle/45.0f); if (int(angle) == 360) inda = 7; if(indx >= 4 || inda >= 8) int db = 1; hist[0][inda] += flolen; count[0] += flolen; } vector<float> curFeat; for ( int i = 0; i < 1; ++i) { // normalize if(!count[i]) count[i] = 1; transform(hist[i].begin(), hist[i].end(), hist[i].begin(),bind2nd( multiplies<float>(), float(1)/*/(count[i])*/ )); hist[i].back() = count[i]; floHist.insert( floHist.end(), hist[i].begin(), hist[i].end()); curFeat.insert(curFeat.end(), hist[i].begin(), hist[i].end()); for(int j = 0; j < hist[i].size(); ++j) fprintf(fp,"%.08lf\t",hist[i][j]); } if( nlen) derivHist.push_back(difFeat(curFeat, preFeat)); preFeat = curFeat; fprintf(fp,"\n"); } for(int nf = 0; nf < derivHist.size(); ++nf){ for(int ne = 0; ne < derivHist[nf].size(); ++ne) fprintf(fp,"%.08lf\t", derivHist[nf][ne]); fprintf(fp,"\n"); } fclose(fp); if(mos[v] >= 0 && mos[v] <= 50) pfeat.push_back(floHist); // for each video else nfeat.push_back(floHist); } }
long CMUSHclientDoc::ReloadPlugin(LPCTSTR PluginID) { // first, find plugin by ID CPlugin * pPlugin = GetPlugin (PluginID); // if not found, try to find by name if (pPlugin == NULL && strlen (PluginID) > 0) { PluginListIterator pit = find_if (m_PluginList.begin (), m_PluginList.end (), bind2nd (compare_plugin_name (), PluginID)); if (pit != m_PluginList.end ()) pPlugin = *pit; } if (pPlugin == NULL) return eNoSuchPlugin; // cannot reload ourselves if (pPlugin == m_CurrentPlugin) return eBadParameter; PluginListIterator pit = find (m_PluginList.begin (), m_PluginList.end (), pPlugin); if (pit == m_PluginList.end () ) return eNoSuchPlugin; CString strName = pPlugin->m_strSource; m_PluginList.erase (pit); // remove from list delete pPlugin; // delete the plugin CPlugin * pCurrentPlugin = m_CurrentPlugin; m_CurrentPlugin = NULL; // otherwise plugin won't load if done from another one try { // now reload it InternalLoadPlugin (strName); } // end of try block catch (CFileException * e) { e->Delete (); m_CurrentPlugin = pCurrentPlugin; return ePluginFileNotFound; } // end of catching a file exception catch (CArchiveException* e) { e->Delete (); m_CurrentPlugin = pCurrentPlugin; return eProblemsLoadingPlugin; } m_CurrentPlugin = pCurrentPlugin; PluginListChanged (); return eOK; } // end of CMUSHclientDoc::ReloadPlugin
__host__ Expr<UnaryTransformPtrSz<typename PtrTraits<SrcPtr>::ptr_type, Binder2nd<pow_func<typename PtrTraits<SrcPtr>::value_type> > > > pow_(const SrcPtr& src, float power) { return makeExpr(transformPtr(src, bind2nd(pow_func<typename PtrTraits<SrcPtr>::value_type>(), power))); }
void EventStreamConduit::handleControlEventFromConduit(shared_ptr<Event> evt){ // mainly interested in M_SET_EVENT_FORWARDING events // since these tell us that the other end of this conduit // wants us to send or not send it those events Datum payload_type = evt->getData().getElement(M_SYSTEM_PAYLOAD_TYPE); // if not event forwarding, pass if((int)payload_type != M_SET_EVENT_FORWARDING){ return; } Datum payload(evt->getData().getElement(M_SYSTEM_PAYLOAD)); Datum event_id_datum(payload.getElement(M_SET_EVENT_FORWARDING_NAME)); Datum state_datum(payload.getElement(M_SET_EVENT_FORWARDING_STATE)); //std::cerr << "Responding to event forwarding request (id: " << event_id_datum.getString() << ", state: " << (bool)state_datum << ")" << std::endl; string event_name; if(event_id_datum.isString()){ event_name = event_id_datum.getString(); } else { throw SimpleException("Unknown data type for event forwarding request"); } boost::mutex::scoped_lock lock(events_to_forward_lock); std::list<string>::iterator event_iterator = find_if(events_to_forward.begin(), events_to_forward.end(), bind2nd(std::equal_to<string>(),event_name)); if(state_datum.getBool()){ if(event_iterator == events_to_forward.end()){ //std::cerr << "Now forwarding " << event_name << std::endl; events_to_forward.push_back(event_name); startForwardingEvent(event_name); } } else { if(event_iterator != events_to_forward.end()){ events_to_forward.erase(event_iterator); rebuildStreamToConduitForwarding(); } } }
else { for (size_t i = curIxValPair; i < indexValuePairs.size(); i++) { double massDiff = massList_[indexValuePairs[i].index] - massList_[ix.index]; if (-massDiff < params.matchingTolerance.value && massDiff < (2.0 + params.matchingTolerance.value)) { intensities_[indexValuePairs[i].index] = -1.; } } } } } transform(intensities_.begin(), intensities_.end(), massList_.begin(), massList_.begin(), PropogateNulls); intensities_.erase(remove_if(intensities_.begin(), intensities_.end(), bind2nd(less<double>(), 0)), intensities_.end()); massList_.erase(remove_if(massList_.begin(), massList_.end(), bind2nd(less<double>(), 0)), massList_.end()); spectrum->defaultArrayLength = massList_.size(); } // Poisson-based algorithm for deisotoping. Based on: // Breen et al., Electrophoresis 2000, 21, 2243-2251. // Bellew et al., Bioinformatics 2006, 22(15), 1902-1909. void FilterSpectrum::DeIsotopePoisson( ) { // xPeak stores m/z; yPeak stores intensity int nPeaks = massList_.size(); if ( nPeaks < 2 ) return;
void ClassWithObjects::RemoveObject(const gd::String & name) { std::vector< std::shared_ptr<gd::Object> >::iterator object = find_if(initialObjects.begin(), initialObjects.end(), bind2nd(ObjectHasName(), name)); if ( object == initialObjects.end() ) return; initialObjects.erase(object); }
void Layout::RemoveLayer(const gd::String & name) { std::vector< gd::Layer >::iterator layer = find_if(initialLayers.begin(), initialLayers.end(), bind2nd(gd::LayerHasName(), name)); if ( layer == initialLayers.end() ) return; initialLayers.erase(layer); }
bool ClassWithObjects::HasObjectNamed(const gd::String & name) const { return ( find_if(initialObjects.begin(), initialObjects.end(), bind2nd(gd::ObjectHasName(), name)) != initialObjects.end() ); }
const gd::Layer & Layout::GetLayer(const gd::String & name) const { std::vector<gd::Layer>::const_iterator layer = find_if(initialLayers.begin(), initialLayers.end(), bind2nd(gd::LayerHasName(), name)); if ( layer != initialLayers.end()) return *layer; return badLayer; }
int main() { const int size = 10; GsTLGridProperty prop( size, "toto" ); for( int i = 0; i < size ; i++ ) { prop.set_value( float(i), i ); } print(prop); cout << endl << "------------------------------" << endl << " swaping to disk" << endl; { USClock clock; prop.swap_to_disk(); } { cout << endl << " modifying property" << endl; USClock clock; exec( prop, prop.size() ); print(prop); } cout << endl << "------------------------------" << endl << " swaping back to memory" << endl; { USClock clock; prop.swap_to_memory(); } { cout << endl << " modifying property" << endl; USClock clock; exec( prop, prop.size() ); print(prop); } cout << endl << "------------------------------" << endl << " swaping again to disk" << endl; { USClock clock; prop.swap_to_disk(); } { USClock clock; cout << endl << " modifying property" << endl; exec( prop, prop.size() ); print( prop ); } ofstream out( "property_values.txt" ); for( int i=0; i< prop.size() ; i++ ) { if( prop.is_informed( i ) ) out << prop.get_value( i ) << "\n"; else out << "-99\n"; } cout << endl << endl << "----------------------------------------" << endl << " testing GsTLGridProperty::iterator" << endl; typedef GsTLGridProperty::iterator iterator; std::copy( prop.begin(), prop.end(), std::ostream_iterator<float>( cout, "\n" ) ); std::transform( prop.begin(), prop.end(), prop.begin(), bind2nd(multiplies<float>(), 2.0 ) ); cout << endl; std::copy( prop.begin(), prop.end(), std::ostream_iterator<float>( cout, "\n" ) ); cout << endl << "un-informing id=2, id = 4 and 6" << endl << endl; prop.set_not_informed( 2 ); prop.set_not_informed( 4 ); prop.set_not_informed( 6 ); std::transform( prop.begin(), prop.end(), prop.begin(), bind2nd(multiplies<float>(), 0.5 ) ); cout << endl; std::copy( prop.begin(), prop.end(), std::ostream_iterator<float>( cout, "\n" ) ); std::vector< float > distr; std::copy( prop.begin(), prop.end(), std::back_inserter( distr ) ); }
void NNFitnessFcn(int nVars, int nPopSize, double* pPop, double* pScore) { Matrix pop(nPopSize, nVars, pPop); pop = !pop; Matrix score(nPopSize, 1); Matrix chrom, ch_sc, diff; Matrix mean = pop.vMean(); bool bBad; //bounds penalty coefs Matrix bpc = pnna->ga_.opt_.initRange.GetRows(1) - pnna->ga_.opt_.initRange.GetRows(0); bpc *= 0.1; transform(bpc.begin(), bpc.end(), bpc.begin(), bind1st(divides<double>(), 1)); //calc scores for(ulong i=0; i<score.size(); ++i) { chrom = pop.GetColumns(i); bBad = false; //score[i] = 0; /* for(ulong j=0; j<chrom.size(); ++j) { if(chrom[j] < pnna->_ga.opt_.initRange(0, j) || chrom[j] > pnna->_ga.opt_.initRange(1, j)) { score[i] = 1; bBad = true; break; } } */ if(pnna->opt_.normInp) chrom /= pnna->state_.max_ch_r; if(pnna->opt_.usePCA) chrom <<= pnna->netPCA_->Sim(chrom - pnna->state_.inpMean); if(pnna->opt_.netType == matrix_nn) ch_sc = pnna->net_.Sim(chrom); else ch_sc = pnn->sim(chrom); //if(bBad || pnna->opt_.pred_ratio <= 0) continue; if(pnna->opt_.pred_ratio > 0 && ch_sc[0] < pnna->state_.n_cur_min) ch_sc[0] += pow((pnna->state_.n_cur_min - ch_sc[0])/pnna->state_.pred_r, 4); score[i] = ch_sc[0]; //check bounds if(1 == 1) { chrom <<= !chrom; diff <<= chrom - pnna->ga_.opt_.initRange.GetRows(0); replace_if(diff.begin(), diff.end(), bind2nd(greater<double>(), 0), 0); //multiply by penalty coefs diff *= bpc; score[i] += abs(score[i])*diff.Mul(diff).Sum(); //score[i] -= abs(score[i])*diff.Sum(); diff <<= pnna->ga_.opt_.initRange.GetRows(1) - chrom; replace_if(diff.begin(), diff.end(), bind2nd(greater<double>(), 0), 0); //multiply by penalty coefs diff *= bpc; score[i] += abs(score[i])*diff.Mul(diff).Sum(); //score[i] -= abs(score[i])*diff.Sum(); } } //score = pnna->GetRealData(score); memcpy(pScore, score.GetBuffer(), score.raw_size()); }
//获取文本的行数 int CLoginBarToolTipCtrl::GetLineCount(CString str) { return count_if( (LPCTSTR)str, (LPCTSTR)str+str.GetLength(), bind2nd(equal_to<TCHAR>(),_T('\n')) ) + 1 ; }
void CRegionalMetaModel::Predict( const REAL* prInputs, REAL* prOutputs ) { vector< CTrustRegion* >hitRegions; //best region or multiple region? FindTrustRegions( prInputs, hitRegions ); // FindBestRegion( prInputs, hitRegions ); int nOutputs = GetOutputs(); int nHitRegions = hitRegions.size(); //for each trusted regional model, predict the result to vcOutputs[i][1...nOutputs] vector< vector<REAL> > vcOutputs(nHitRegions); for( int i=0; i<nHitRegions; i++ ){ vcOutputs[i].resize( nOutputs ); CMetaModel* pModel = m_vcMetaModels[ hitRegions[i]->GetModelId() ]; pModel->Predict( prInputs, &vcOutputs[i][0] ); } int nInputs = GetInputs(); REAL rSumWeights = 0; vector< REAL > vcSum( nOutputs, 0.0 ); //modified on 02/012/05 using trust probability for( i=0; i<nHitRegions; i++ ){ ASSERT( nInputs==hitRegions[i]->m_ptCen.size() ); vector<REAL> vcDistSqr(nInputs, 0.0); vector<REAL> vcRadSqr(nInputs, 0.0); vector<REAL> vcProbs(nInputs,0.0); transform( prInputs, prInputs+nInputs, hitRegions[i]->m_ptCen.begin(), vcDistSqr.begin(), diff_sqr<REAL>() ); // cout<<"dist sqr:"; // copy( vcDistSqr.begin(), vcDistSqr.end(), ostream_iterator<REAL>(cout, " ") ); cout<<endl; transform( hitRegions[i]->m_vcRadius.begin(), hitRegions[i]->m_vcRadius.end(), hitRegions[i]->m_vcRadius.begin(), vcRadSqr.begin(), multiplies<REAL>() ); // cout<<"radius sqr:"; // copy( vcRadSqr.begin(), vcRadSqr.end(), ostream_iterator<REAL>(cout, " ") ); cout<<endl; transform( vcDistSqr.begin(), vcDistSqr.end(), vcRadSqr.begin(), vcProbs.begin(), divides<REAL>() ); // cout<<"probs :"; // copy( vcProbs.begin(), vcProbs.end(), ostream_iterator<REAL>(cout, " ") ); cout<<endl; REAL rProb = accumulate( vcProbs.begin(), vcProbs.end(), 0.0) / nInputs; rProb = max( 1-rProb, 0.0 ); //the first global model is always trusted. if( i==0 && rProb<=0 )rProb = max( rProb, 1e-3 ); cdump<<"prob "<<i<<" "<<rProb<<"\t"; // REAL rWeight = rProb / hitRegions[i]->GetSphereRadius(); REAL rWeight = rProb; for( int j=0; j<nOutputs; j++ ){ vcSum[j] += vcOutputs[i][j]*rWeight; } rSumWeights += rWeight; } if( rSumWeights > 0 ){ transform( vcSum.begin(), vcSum.end(), vcSum.begin(), bind2nd(divides<REAL>(), rSumWeights) ); copy( vcSum.begin(), vcSum.end(), prOutputs ); }else{ copy( vcOutputs[0].begin(), vcOutputs[0].end(), prOutputs ); } //compute the average outputs according to inverse sphere radius /* vector< REAL > vcSum( nOutputs, 0.0 ); REAL rSumInvRadius = 0; for( i=0; i<nHitRegions; i++ ){ REAL rInvRadius = 1.0 / hitRegions[i]->GetSphereRadius(); for( int j=0; j<nOutputs; j++ ){ vcSum[j] += vcOutputs[i][j]*rInvRadius; } rSumInvRadius += rInvRadius; } transform( vcSum.begin(), vcSum.end(), vcSum.begin(), bind2nd(divides<REAL>(), rSumInvRadius) ); copy( vcSum.begin(), vcSum.end(), prOutputs ); */ cdump<<"pred..."<<nHitRegions<<" nets"<<endl; }
void TopologyConstraints:: constraints(std::vector<TopologyConstraint*>& ts) const { for_each(edges.begin(),edges.end(),bind2nd( mem_fun(&Edge::getTopologyConstraints),&ts)); }
Agent * get_agent_by_name(const char * name) { agent_iter iter; iter = find_if(agents.begin(), agents.end(), bind2nd(name_equal<Agent*>(), name)); if(iter == agents.end()) return (Agent*)0; return *iter; }
string& strRemoveSpace(string& str) { string::iterator new_end = remove_if(str.begin(), str.end(), bind2nd(equal_to<char>(), ' ')); str.erase(new_end, str.end()); return str; }
void TestFunctors (void) { vector<int> v; v.resize (20); fill (v, 2); foreach (vector<int>::iterator, i, v) *i -= distance(v.begin(), i) & 1; vector<int> v1 (v); cout << "start:\t\t\t"; PrintVector (v); v = v1; cout << "plus:\t\t\t"; transform (v, v.begin(), v.begin(), plus<int>()); PrintVector (v); v = v1; cout << "minus:\t\t\t"; transform (v, v.begin(), v.begin(), minus<int>()); PrintVector (v); v = v1; cout << "divides:\t\t"; transform (v, v.begin(), v.begin(), divides<int>()); PrintVector (v); v = v1; cout << "multiplies:\t\t"; transform (v, v.begin(), v.begin(), multiplies<int>()); PrintVector (v); v = v1; cout << "modulus:\t\t"; transform (v, v.begin(), v.begin(), modulus<int>()); PrintVector (v); v = v1; cout << "logical_and:\t\t"; transform (v, v.begin(), v.begin(), logical_and<int>()); PrintVector (v); v = v1; cout << "logical_or:\t\t"; transform (v, v.begin(), v.begin(), logical_or<int>()); PrintVector (v); v = v1; cout << "equal_to:\t\t"; transform (v, v.begin(), v.begin(), equal_to<int>()); PrintVector (v); v = v1; cout << "not_equal_to:\t\t"; transform (v, v.begin(), v.begin(), not_equal_to<int>()); PrintVector (v); v = v1; cout << "greater:\t\t"; transform (v, v.begin(), v.begin(), greater<int>()); PrintVector (v); v = v1; cout << "less:\t\t\t"; transform (v, v.begin(), v.begin(), less<int>()); PrintVector (v); v = v1; cout << "greater_equal:\t\t"; transform (v, v.begin(), v.begin(), greater_equal<int>()); PrintVector (v); v = v1; cout << "less_equal:\t\t"; transform (v, v.begin(), v.begin(), less_equal<int>()); PrintVector (v); v = v1; cout << "compare:\t\t"; transform (v, v.begin(), v.begin(), compare<int>()); PrintVector (v); v = v1; cout << "negate:\t\t\t"; transform (v, negate<int>()); PrintVector (v); v = v1; cout << "logical_not:\t\t"; transform (v, logical_not<int>()); PrintVector (v); v = v1; cout << "unary_neg(negate):\t"; transform (v, unary_negator(negate<int>())); PrintVector (v); v = v1; cout << "binder1st(plus,5):\t"; transform (v, bind1st(plus<int>(), 5)); PrintVector (v); v = v1; cout << "binder2nd(minus,1):\t"; transform (v, bind2nd(minus<int>(), 1)); PrintVector (v); v = v1; cout << "compose1(-,+5):\t\t"; transform (v, compose1 (negate<int>(), bind2nd(plus<int>(), 5))); PrintVector (v); v = v1; cout << "compose1(-,-4):\t\t"; transform (v, compose1 (negate<int>(), bind2nd(minus<int>(), 4))); PrintVector (v); v = v1; cout << "compose2(/,+6,-4):\t"; transform (v, compose2 (divides<int>(), bind2nd(plus<int>(), 6), bind2nd(minus<int>(), 4))); PrintVector (v); cout << "mem_var(plus,6):\t"; vector<A> av; for (uoff_t i = 0; i < 20; ++ i) av.push_back (A(i)); transform (av, mem_var1(&A::m_v, bind2nd(plus<int>(), 6))); PrintVector (av); vector<A>::iterator found = find_if (av, mem_var_equal_to(&A::m_v, 14)); cout << "14 found at position " << found - av.begin() << endl; found = lower_bound (av.begin(), av.end(), 18, mem_var_less(&A::m_v)); cout << "18 found at position " << found - av.begin() << endl; cout << "add next:\t\t"; transform (av.begin(), av.end() - 1, av.begin() + 1, av.begin(), mem_var2(&A::m_v, plus<int>())); PrintVector (av); }