void FormulaCreationMenu::create_max_formula(CNFFormula & f) { ask_k(); ask_n(); int numassg; while(1){ try{ numassg = ui->getint("How many satisfying assignments does this formula have?"); break; } catch(UserInputException e){ std::cout << e.what() << std::endl; } } //now we get the assignments one by one std::vector<Assignment> assignments(numassg,Assignment(n)); for(int i = 0; i<numassg; i++){ while(1){ try{ std::string assg = ui->getstring(std::string("Assignment #").append(std::to_string(i+1)).append("?")); assignments[i].set_assignment(assg); break; } catch(UserInputException e){ std::cout << e.what() << std::endl; } } } MaxSatGenerator mg(n, k, assignments); mg.generate_sat(f); }
void CDbapiConnMgr::DelConnect(void) { CMutexGuard mg(m_Mutex); if (m_NumConnect > 0) --m_NumConnect; }
string CDriverContext::GetHostName(void) const { CMutexGuard mg(m_CtxMtx); return m_HostName; }
void solve_with_Cpp(MultiFab& soln, MultiFab& gphi, Real a, Real b, MultiFab& alpha, PArray<MultiFab>& beta, MultiFab& rhs, const BoxArray& bs, const Geometry& geom) { BL_PROFILE("solve_with_Cpp()"); BndryData bd(bs, 1, geom); set_boundary(bd, rhs, 0); ABecLaplacian abec_operator(bd, dx); abec_operator.setScalars(a, b); abec_operator.setCoefficients(alpha, beta); MultiGrid mg(abec_operator); mg.setVerbose(verbose); mg.solve(soln, rhs, tolerance_rel, tolerance_abs); PArray<MultiFab> grad_phi(BL_SPACEDIM, PArrayManage); for (int n = 0; n < BL_SPACEDIM; ++n) grad_phi.set(n, new MultiFab(BoxArray(soln.boxArray()).surroundingNodes(n), 1, 0)); #if (BL_SPACEDIM == 2) abec_operator.compFlux(grad_phi[0],grad_phi[1],soln); #elif (BL_SPACEDIM == 3) abec_operator.compFlux(grad_phi[0],grad_phi[1],grad_phi[2],soln); #endif // Average edge-centered gradients to cell centers. BoxLib::average_face_to_cellcenter(gphi, grad_phi, geom); }
void solve(MultiFab& soln, const MultiFab& anaSoln, Real a, Real b, MultiFab& alpha, MultiFab beta[], MultiFab& rhs, const BoxArray& bs, const Geometry& geom, solver_t solver) { BL_PROFILE("solve"); soln.setVal(0.0); const Real run_strt = ParallelDescriptor::second(); BndryData bd(bs, 1, geom); set_boundary(bd, rhs); ABecLaplacian abec_operator(bd, dx); abec_operator.setScalars(a, b); abec_operator.setCoefficients(alpha, beta); MultiGrid mg(abec_operator); mg.setMaxIter(maxiter); mg.setVerbose(verbose); mg.setFixedIter(1); mg.solve(soln, rhs, tolerance_rel, tolerance_abs); Real run_time = ParallelDescriptor::second() - run_strt; ParallelDescriptor::ReduceRealMax(run_time, ParallelDescriptor::IOProcessorNumber()); if (ParallelDescriptor::IOProcessor()) { std::cout << "Run time : " << run_time << std::endl; } }
void CDBConnectionFactory::SetMaxNumOfServerAlternatives(unsigned int max_num) { CFastMutexGuard mg(m_Mtx); m_MaxNumOfServerAlternatives = max_num; }
void SOCKS5BytestreamServer::handleDisconnect( const ConnectionBase* connection, ConnectionError /*reason*/ ) { util::MutexGuard mg( m_mutex ); m_connections.erase( const_cast<ConnectionBase*>( connection ) ); m_oldConnections.push_back( connection ); }
void CDBConnectionFactory::Configure(const IRegistry* registry) { CFastMutexGuard mg(m_Mtx); ConfigureFromRegistry(registry); }
void CDBConnectionFactory::SetMaxNumOfValidationAttempts(unsigned int max_num) { CFastMutexGuard mg(m_Mtx); m_MaxNumOfValidationAttempts = max_num; }
void CDBServiceMapperCoR::Configure(const IRegistry* registry) { CFastMutexGuard mg(m_Mtx); ConfigureFromRegistry(registry); }
void CDBConnectionFactory::SetLoginTimeout(unsigned int timeout) { CFastMutexGuard mg(m_Mtx); m_LoginTimeout = timeout; }
ConnectionError ConnectionTCPServer::connect() { MutexGuard mg( &m_sendMutex ); if( m_socket >= 0 || m_state > StateDisconnected ) return ConnNoError; m_state = StateConnecting; if( m_socket < 0 ) m_socket = DNS::getSocket(); if( m_socket < 0 ) return ConnIoError; struct sockaddr_in local; local.sin_family = AF_INET; local.sin_port = htons( m_port ); local.sin_addr.s_addr = m_server.empty() ? INADDR_ANY : inet_addr( m_server.c_str() ); memset( &(local.sin_zero), '\0', 8 ); if( bind( m_socket, (struct sockaddr*)&local, sizeof( struct sockaddr ) ) < 0 ) return ConnIoError; if( listen( m_socket, 10 ) < 0 ) return ConnIoError; m_cancel = false; return ConnNoError; }
void CDBDefaultServiceMapper::CleanExcluded(const string& service) { CFastMutexGuard mg(m_Mtx); m_SrvSet.erase(service); }
void CDBConnectionFactory::SetMaxNumOfDispatches(unsigned int max_num) { CFastMutexGuard mg(m_Mtx); m_MaxNumOfDispatches = max_num; }
IDataSource* CDriverManager::CreateDsFrom(const string& drivers, const IRegistry* reg, const string& tag) { CMutexGuard mg(m_Mutex); list<string> names; NStr::Split(drivers, ":", names); list<string>::iterator i_name = names.begin(); for( ; i_name != names.end(); ++i_name ) { I_DriverContext* ctx = NULL; if( reg != NULL ) { // Get parameters from registry, if any map<string, string> attr; list<string> entries; reg->EnumerateEntries(*i_name, &entries); list<string>::iterator i_param = entries.begin(); for( ; i_param != entries.end(); ++i_param ) { attr[*i_param] = reg->Get(*i_name, *i_param); } ctx = GetDriverContextFromMap( *i_name, &attr ); } else { ctx = GetDriverContextFromMap( *i_name, NULL ); } if( ctx != 0 ) { return RegisterDs( *i_name + tag, ctx ); } } return 0; }
void Network::_announceMulticastGroupsTo(const Address &peerAddress,const std::vector<MulticastGroup> &allMulticastGroups) const { // Assumes _lock is locked // We push COMs ahead of MULTICAST_LIKE since they're used for access control -- a COM is a public // credential so "over-sharing" isn't really an issue (and we only do so with roots). if ((_config)&&(_config->com())&&(!_config->isPublic())) { Packet outp(peerAddress,RR->identity.address(),Packet::VERB_NETWORK_MEMBERSHIP_CERTIFICATE); _config->com().serialize(outp); RR->sw->send(outp,true,0); } { Packet outp(peerAddress,RR->identity.address(),Packet::VERB_MULTICAST_LIKE); for(std::vector<MulticastGroup>::const_iterator mg(allMulticastGroups.begin());mg!=allMulticastGroups.end();++mg) { if ((outp.size() + 18) >= ZT_UDP_DEFAULT_PAYLOAD_MTU) { RR->sw->send(outp,true,0); outp.reset(peerAddress,RR->identity.address(),Packet::VERB_MULTICAST_LIKE); } // network ID, MAC, ADI outp.append((uint64_t)_id); mg->mac().appendTo(outp); outp.append((uint32_t)mg->adi()); } if (outp.size() > ZT_PROTO_MIN_PACKET_LENGTH) RR->sw->send(outp,true,0); } }
// verify is there draw or mat void Board::verifyState() { if ( matState() || drawState() ) return; #ifndef NDEBUG Board board0(*this); #endif MovesGenerator mg(*this); bool found = false; for ( ; !found; ) { const Move & m = mg.move(); if ( !m ) break; if ( validateMove(m) ) found = true; } if ( !found ) { setNoMoves(); // update move's state because it is last one if ( halfmovesCounter_ > 0 ) { UndoInfo & undo = undoInfo(halfmovesCounter_-1); undo.state_ = state_; } } }
void CDriverContext::SetHostName(const string& host_name) { CMutexGuard mg(m_CtxMtx); m_HostName = host_name; }
string CDriverContext::GetApplicationName(void) const { CMutexGuard mg(m_CtxMtx); return m_AppName; }
void CDriverContext::SetApplicationName(const string& app_name) { CMutexGuard mg(m_CtxMtx); m_AppName = app_name; }
void CDBLB_ServiceMapper::CleanExcluded(const string& service) { CFastMutexGuard mg(m_Mtx); _TRACE("For " << service << ": cleaning excluded list"); m_ExcludeMap[service].clear(); }
bool CDriverContext::SetLoginTimeout (unsigned int nof_secs) { CMutexGuard mg(m_CtxMtx); m_LoginTimeout = nof_secs; return true; }
void CDBDefaultServiceMapper::Exclude(const string& service, const TSvrRef& server) { CFastMutexGuard mg(m_Mtx); m_SrvSet.insert(service); }
void Buffer::push(Task * task) { MutexGuard mg(_mutex); while(isfull()){ _notfull.wait(); _que.push(task); _notempty.notify(); } }
Task * Buffer::pop(){ MutexGuard mg(_mutex); while(isempty()) _notempty.wait(); Task * task = _que.front(); _que.pop(); _notfull.notify(); return task; }
MyEvent::MyEvent() { start=time(NULL); done=0; MutexGuard mg( serlock ); serial = ++ser; f=ser + 1000 ; hooked = false; FDBG( "MyEvent", "Ctor",(unsigned long int)this ); };
IDataSource* CDriverManager::RegisterDs(const string& driver_name, I_DriverContext* ctx) { CMutexGuard mg(m_Mutex); IDataSource* ds = new CDataSource(ctx); m_ds_list.insert(TDsContainer::value_type(driver_name, ds)); return ds; }
void CDBLB_ServiceMapper::SetPreference(const string& service, const TSvrRef& preferred_server, double preference) { CFastMutexGuard mg(m_Mtx); m_PreferenceMap[service] = make_pair(preference, preferred_server); }
void CDBServiceMapperCoR::Exclude(const string& service, const TSvrRef& server) { CFastMutexGuard mg(m_Mtx); NON_CONST_ITERATE(TDelegates, dg_it, m_Delegates) { (*dg_it)->Exclude(service, server); }
void CDriverManager::DestroyDs(const string& driver_name) { CMutexGuard mg(m_Mutex); TDsContainer::iterator it; while ((it = m_ds_list.find(driver_name)) != m_ds_list.end()) { delete it->second; m_ds_list.erase(it); } }