Пример #1
0
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);
}
Пример #2
0
void CDbapiConnMgr::DelConnect(void)
{
    CMutexGuard mg(m_Mutex);

    if (m_NumConnect > 0)
        --m_NumConnect;
}
Пример #3
0
string
CDriverContext::GetHostName(void) const
{
    CMutexGuard mg(m_CtxMtx);

    return m_HostName;
}
Пример #4
0
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);
}
Пример #5
0
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;
  }
}
Пример #6
0
void
CDBConnectionFactory::SetMaxNumOfServerAlternatives(unsigned int max_num)
{
    CFastMutexGuard mg(m_Mtx);

    m_MaxNumOfServerAlternatives = max_num;
}
Пример #7
0
 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 );
 }
Пример #8
0
void
CDBConnectionFactory::Configure(const IRegistry* registry)
{
    CFastMutexGuard mg(m_Mtx);

    ConfigureFromRegistry(registry);
}
Пример #9
0
void
CDBConnectionFactory::SetMaxNumOfValidationAttempts(unsigned int max_num)
{
    CFastMutexGuard mg(m_Mtx);

    m_MaxNumOfValidationAttempts = max_num;
}
Пример #10
0
void
CDBServiceMapperCoR::Configure(const IRegistry* registry)
{
    CFastMutexGuard mg(m_Mtx);

    ConfigureFromRegistry(registry);
}
Пример #11
0
void
CDBConnectionFactory::SetLoginTimeout(unsigned int timeout)
{
    CFastMutexGuard mg(m_Mtx);

    m_LoginTimeout = timeout;
}
Пример #12
0
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;
}
Пример #13
0
void
CDBDefaultServiceMapper::CleanExcluded(const string& service)
{
    CFastMutexGuard mg(m_Mtx);

    m_SrvSet.erase(service);
}
Пример #14
0
void
CDBConnectionFactory::SetMaxNumOfDispatches(unsigned int max_num)
{
    CFastMutexGuard mg(m_Mtx);

    m_MaxNumOfDispatches = max_num;
}
Пример #15
0
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;
}
Пример #16
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);
	}
}
Пример #17
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_;
    }
  }
}
Пример #18
0
void
CDriverContext::SetHostName(const string& host_name)
{
    CMutexGuard mg(m_CtxMtx);

    m_HostName = host_name;
}
Пример #19
0
string
CDriverContext::GetApplicationName(void) const
{
    CMutexGuard mg(m_CtxMtx);

    return m_AppName;
}
Пример #20
0
void
CDriverContext::SetApplicationName(const string& app_name)
{
    CMutexGuard mg(m_CtxMtx);

    m_AppName = app_name;
}
Пример #21
0
void
CDBLB_ServiceMapper::CleanExcluded(const string& service)
{
    CFastMutexGuard mg(m_Mtx);

    _TRACE("For " << service << ": cleaning excluded list");
    m_ExcludeMap[service].clear();
}
Пример #22
0
bool CDriverContext::SetLoginTimeout (unsigned int nof_secs)
{
    CMutexGuard mg(m_CtxMtx);

    m_LoginTimeout = nof_secs;

    return true;
}
Пример #23
0
void
CDBDefaultServiceMapper::Exclude(const string&  service,
                                 const TSvrRef& server)
{
    CFastMutexGuard mg(m_Mtx);

    m_SrvSet.insert(service);
}
Пример #24
0
	void Buffer::push(Task * task)
	{
		MutexGuard mg(_mutex);
		while(isfull()){
			_notfull.wait();
			_que.push(task);
			_notempty.notify();
		}
	}
Пример #25
0
	Task *  Buffer::pop(){
		MutexGuard mg(_mutex);
		while(isempty())
			_notempty.wait();
		Task * task = _que.front();
		_que.pop();
		_notfull.notify();
		return task;
	}
Пример #26
0
MyEvent::MyEvent() {
    start=time(NULL);
    done=0;
    MutexGuard mg( serlock );
    serial = ++ser;
    f=ser + 1000 ;
    hooked = false;
    FDBG( "MyEvent", "Ctor",(unsigned long int)this );
};
Пример #27
0
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;
}
Пример #28
0
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);
}
Пример #29
0
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);
    }
Пример #30
0
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);
    }
}