uint64_t
StringExtractor::GetHexWithFixedSize (uint32_t byte_size, bool little_endian, uint64_t fail_value)
{
    if (byte_size <= 8 && GetBytesLeft() >= byte_size * 2)
    {
        uint64_t result = 0;
        uint32_t i;
        if (little_endian)
        {
            // Little Endian
            uint32_t shift_amount;
            for (i = 0, shift_amount = 0;
                 i < byte_size && IsGood();
                 ++i, shift_amount += 8)
            {
                result |= ((uint64_t)GetHexU8() << shift_amount);
            }
        }
        else
        {
            // Big Endian
            for (i = 0; i < byte_size && IsGood(); ++i)
            {
                result <<= 8;
                result |= GetHexU8();
            }
        }
    }
    m_index = UINT64_MAX;
    return fail_value;
}
bool OBConformerSearch::Setup(const OBMol &mol, int numConformers, int numChildren, int mutability, int convergence)
{
    // copy some variables
    m_mol = mol;
    m_numConformers = numConformers;
    m_numChildren = numChildren;
    m_mutability = mutability;
    m_convergence = convergence;

    if (m_mol.GetCoordinates() == NULL)
        return false;

    // Initialize the OBRotorList
    m_rotorList.SetFixedBonds(m_fixedBonds);
    m_rotorList.Setup(m_mol);
    if (!m_rotorList.Size()) { // only one conformer
        return false;
    }

    // create initial population
    OBRandom generator;
    generator.TimeSeed();

    RotorKey rotorKey(m_rotorList.Size() + 1, 0); // indexed from 1
    if (IsGood(rotorKey))
        m_rotorKeys.push_back(rotorKey);
    else {
        cout << "Initial conformer does not pass filter!" << endl;
    }

    int tries = 0;
    while (m_rotorKeys.size() < m_numConformers && tries < numConformers * 1000) {
        tries++;
        // perform random mutation(s)
        OBRotorIterator ri;
        OBRotor *rotor = m_rotorList.BeginRotor(ri);
        for (int i = 1; i < m_rotorList.Size() + 1; ++i, rotor = m_rotorList.NextRotor(ri)) {
            if (generator.NextInt() % m_mutability == 0)
                rotorKey[i] = generator.NextInt() % rotor->GetResolution().size();
        }
        // duplicates are always rejected
        if (!IsUniqueKey(m_rotorKeys, rotorKey))
            continue;
        // execute filter(s)
        if (!IsGood(rotorKey))
            continue;
        // add the key
        m_rotorKeys.push_back(rotorKey);
    }

    // print out initial conformers
    cout << "Initial conformer count: " << m_rotorKeys.size() << endl;
    for (unsigned int i = 0; i < m_rotorKeys.size(); ++i) {
        for (unsigned int j = 1; j < m_rotorKeys[i].size(); ++j)
            std::cout << m_rotorKeys[i][j] << " ";
        std::cout << std::endl;
    }

    return true;
}
示例#3
0
bool NMEA0183L::PreParse( void )
{
    wxCharBuffer buf = sentence.Sentence.ToUTF8();
    if ( !buf.data() )                           // badly formed sentence?
        return false;

    if ( IsGood() )
    {
        wxString mnemonic = sentence.Field( 0 );

        /*
              ** See if this is a proprietary field
        */

        if ( mnemonic.Left( 1 ) == 'P' )
            mnemonic = _T( "P" );

        else
            mnemonic = mnemonic.Right( 3 );


        LastSentenceIDReceived = mnemonic;

        return true;
    }
    else
        return false;
}
示例#4
0
bool ArrayElementToken::CanConvertTo(Token_Type to) const
{
	if (!IsGood())
		return false;
	else if (to == kTokenType_ArrayElement)
		return true;

	UInt8 elemType = g_ArrayMap.GetElementType(GetOwningArrayID(), key);
	if (elemType == kDataType_Invalid)
		return false;

	switch (to)
	{
	case kTokenType_Boolean:
		return elemType == kDataType_Form || elemType == kDataType_Numeric;
	case kTokenType_String:
		return elemType == kDataType_String;
	case kTokenType_Number:
		return elemType == kDataType_Numeric;
	case kTokenType_Array:
		return elemType == kDataType_Array;
	case kTokenType_Form:
		return elemType == kDataType_Form;
	}

	return false;
}
示例#5
0
int 
ann_mex_t::annkFRSearch(					// approx fixed-radius kNN search
            const mxArray*	mxQ,			// query point
            ANNdist         sqRad,			// squared radius of query ball
            int				k,				// number of near neighbors to return
            mxArray**		mxIdx,			// nearest neighbor array (modified)
            mxArray**       mxDst,			// dist to near neighbors (modified)
            double			eps)		// error bound
{
    index_t j(0);
    
    if ( ! IsGood() )
        mexErrMsgIdAndTxt("annmex:annkFRSearch","Class integrity check failed");
    
    // check input point(s)
    // dimension of points
    if (m_idim != mxGetM(mxQ))
        mexErrMsgIdAndTxt("annmex:annkFRSearch","point dimension does not match");
    
    if ( mxGetN(mxQ) != 1 )
        mexErrMsgIdAndTxt("annmex:annkFRSearch","FR search can be done for a single point at each time");
    
    if ( k <= 0 )
        mexErrMsgIdAndTxt("annmex:annkFRSearch","k must be positive");
    
    if ( k > m_inpoints ) {
        // generate warning
        mexWarnMsgIdAndTxt("annmex:annkFRSearch","searching for more points than in tree - returning only %d",m_inpoints);
        k = m_inpoints;
    }
    if ( sqRad < 0 )
       mexErrMsgIdAndTxt("annmex:annkFRSearch","radius must be positive");
    
    ANNpoint pp   = (ANNpoint)mxGetData(mxQ);
    
    ANNidx* tmpidx = new ANNidx[k];
    ANNdist* tmpdist = new ANNdist[k];
    if ( tmpidx == NULL || tmpdist == NULL )
        mexErrMsgIdAndTxt("annmex:annkFRSearch","cannot allocate memory for outputs");
    
    int gotp = m_pTree->annkFRSearch(pp, sqRad, k, tmpidx, tmpdist, eps);
    
    // allocate space for outputs
    *mxIdx = mxCreateNumericMatrix(1, min(gotp,k), mxIDX_CLASS, mxREAL);
    *mxDst = mxCreateNumericMatrix(1, min(gotp,k), mxDIST_CLASS, mxREAL);
    if ( *mxIdx == NULL || *mxDst == NULL ) 
        mexErrMsgIdAndTxt("annmex:annkPriSearch","cannot allocate memory for outputs");
    
    ANNidx * pidx = (ANNidx*)mxGetData(*mxIdx);
    ANNdist* pdist= (ANNdist*)mxGetData(*mxDst);
    
    for ( j = 0 ; j < min(gotp,k) ; j++ ) {
        pidx[j] = tmpidx[j];
        pdist[j] = tmpdist[j];
    }
    delete [] tmpidx;
    delete [] tmpdist;   
    return gotp; // how many points in range
}
示例#6
0
Particle::Particle(int _ft, double _fE, double _fz) {
	ftype = _ft;
	fE0ph = _fE;
	fz0ph = _fz;
	SetBetaAndMass();
	fIsGood = IsGood();
	fwi = 1;
}
const HAL_CONFIG_BLOCK* HAL_CONFIG_BLOCK::Next() const
{
    if(IsGood())
    {
        return (const HAL_CONFIG_BLOCK*)((size_t)Data() + RoundLength( Size ));
    }

    return NULL;
}
示例#8
0
ann_mex_t::~ann_mex_t()
{
    // free the tree
    if (IsGood() && m_pTree) {
        delete m_pTree;        
        delete [] pa[0];
        delete [] pa;
    }
    
    // cancel the integrity check
    m_clintck = 0;        
}
示例#9
0
void 
ann_mex_t::annkPriSearch( 				// priority k near neighbor search
            const mxArray*	mxQ,			// query point
            int				k,				// number of near neighbors to return
            mxArray**		mxIdx,			// nearest neighbor array (modified)
            mxArray**       mxDst,			// dist to near neighbors (modified)
            double			eps)		// error bound
{
    index_t j(0);
    int nqp(0); // number of query points
    
    if ( ! IsGood() )
        mexErrMsgIdAndTxt("annmex:annkPriSearch","Class integrity check failed");
    
    // check input point(s)
    // dimension of points
    if (m_idim != mxGetM(mxQ))
        mexErrMsgIdAndTxt("annmex:annkPriSearch","point dimension does not match");

    nqp = mxGetN(mxQ);
    if (nqp <= 0) 
        mexErrMsgIdAndTxt("annmex:annkPriSearch","need at least one query point");

    if ( k <= 0 )
        mexErrMsgIdAndTxt("annmex:annkPriSearch","k must be positive");
    
    if ( k > m_inpoints ) {
        // generate warning
        mexWarnMsgIdAndTxt("annmex:annkPriSearch","searching for more points than in tree - returning only %d",m_inpoints);
        k = m_inpoints;
    }
        
    // allocate space for outputs
    *mxIdx = mxCreateNumericMatrix(k, nqp, mxIDX_CLASS, mxREAL);
    *mxDst = mxCreateNumericMatrix(k, nqp, mxDIST_CLASS, mxREAL);
    if ( *mxIdx == NULL || *mxDst == NULL ) 
        mexErrMsgIdAndTxt("annmex:annkPriSearch","cannot allocate memory for outputs");
    
    ANNidx * pidx = (ANNidx*)mxGetData(*mxIdx);
    ANNdist* pdist= (ANNdist*)mxGetData(*mxDst);
    ANNpoint pp   = (ANNpoint)mxGetData(mxQ);
    
    for ( j = 0 ; j < nqp ; j++ ) {
        m_pTree->annkPriSearch(pp, k, pidx, pdist, eps);
        pp += m_idim;
        pidx += k;
        pdist += k;
    }
   
}
示例#10
0
int main() {
	int nLoop, nFrom, nTo;
	int arrnSum[MAX];

	arrnSum[0] = 1;
	for (nLoop = 1; nLoop < MAX; nLoop++)
		arrnSum[nLoop] = IsGood(nLoop) ? arrnSum[nLoop - 1] + 1 : arrnSum[nLoop - 1];
		

	while (scanf("%d %d", &nFrom, &nTo) == 2)
		printf("%d\n", arrnSum[nTo] - arrnSum[nFrom - 1]);

	return 0;
}
示例#11
0
size_t StringExtractor::GetHexBytes(llvm::MutableArrayRef<uint8_t> dest,
                                    uint8_t fail_fill_value) {
  size_t bytes_extracted = 0;
  while (!dest.empty() && GetBytesLeft() > 0) {
    dest[0] = GetHexU8(fail_fill_value);
    if (!IsGood())
      break;
    ++bytes_extracted;
    dest = dest.drop_front();
  }

  if (!dest.empty())
    ::memset(dest.data(), fail_fill_value, dest.size());

  return bytes_extracted;
}
//Definition of StartPerforming
//This function starts processing commands in stack
//This function contains an almost never ending loop.
//It shouldn't be called in interrupt, etc..
void StartPerforming(void)
{
	bool configured = false;
	while(continuePerf && (configured = IsConfigured()))//until it is allowed and machine is configured
	{
		if(commandStack.first != commandStack.last && IsGood())//There are unprocessed items and no errors
		{
			if(RedistributeCommandForPerf(&(commandStack.buffer[commandStack.first]), true, false) == COMMAND_PROC_OK)//Distribute item
			{
				commandStack.lastItem = commandStack.buffer[commandStack.first].ID;
				//Item processed successfully - increase counter
				commandStack.first = CommandStackIncreaseValue(commandStack.first);
			}
		}
	}
}
示例#13
0
peBool proFile::Open(const char* path, peBool bCreate, peBool bDestroyOld)
{
	if(!m_fileDef.m_pFileStream)
	{
		m_fileDef.m_iSize = -1;
		if(bDestroyOld)
		{
			m_fileDef.m_pFileStream = new std::fstream(path, std::ios::binary|std::ios::out|std::ios::in|std::ios::trunc);
		}
		else
		{
			m_fileDef.m_pFileStream = new std::fstream(path, std::ios::binary|std::ios::out|std::ios::in);
		}		
		if(m_fileDef.m_pFileStream->is_open())
		{
			m_fileDef.m_pFileStream->seekg(0, std::ios::end);
			m_fileDef.m_iSize = m_fileDef.m_pFileStream->tellg();
			m_fileDef.m_pFileStream->seekg(0, std::ios::beg);
		}
	}	
	if(!IsGood() && bCreate)
	{
		Close();
		
		if(bDestroyOld)
		{
			m_fileDef.m_pFileStream = new std::fstream(path, std::ios::binary|std::ios::out|std::ios::trunc);
		}
		else
		{
			m_fileDef.m_pFileStream = new std::fstream(path, std::ios::binary|std::ios::out);
		}		
		m_fileDef.m_pFileStream->write("0", 2);
		Close();
		if(bDestroyOld)
		{
			m_fileDef.m_pFileStream = new std::fstream(path, std::ios::binary|std::ios::out|std::ios::trunc);
		}
		else
		{
			m_fileDef.m_pFileStream = new std::fstream(path, std::ios::binary|std::ios::out);
		}		
	}	
	return m_fileDef.m_pFileStream->is_open();
}
示例#14
0
size_t
StringExtractor::GetHexBytes (void *dst_void, size_t dst_len, uint8_t fail_fill_value)
{
    uint8_t *dst = (uint8_t*)dst_void;
    size_t bytes_extracted = 0;
    while (bytes_extracted < dst_len && GetBytesLeft ())
    {
        dst[bytes_extracted] = GetHexU8 (fail_fill_value);
        if (IsGood())
            ++bytes_extracted;
        else
            break;
    }

    for (size_t i = bytes_extracted; i < dst_len; ++i)
        dst[i] = fail_fill_value;

    return bytes_extracted;
}
void OBConformerSearch::NextGeneration()
{
    // create next generation population
    OBRandom generator;
    generator.TimeSeed();

    // generate the children
    int numConformers = m_rotorKeys.size();
    for (int c = 0; c < numConformers; ++c) {
        for (int child = 0; child < m_numChildren; ++child) {
            bool foundKey = false;
            int tries = 0;
            while (!foundKey) {
                tries++;
                if (tries > 1000)
                    foundKey = true;
                RotorKey rotorKey = m_rotorKeys[c]; // copy parent gene
                // perform random mutation(s)
                OBRotorIterator ri;
                OBRotor *rotor = m_rotorList.BeginRotor(ri);
                for (int i = 1; i < m_rotorList.Size() + 1; ++i, rotor = m_rotorList.NextRotor(ri)) {
                    if (generator.NextInt() % m_mutability == 0)
                        rotorKey[i] = generator.NextInt() % rotor->GetResolution().size(); // permutate gene
                }
                // duplicates are always rejected
                if (!IsUniqueKey(m_rotorKeys, rotorKey))
                    continue;
                // execute the filter(s)
                if (!IsGood(rotorKey))
                    continue;
                // add the key
                m_rotorKeys.push_back(rotorKey); // append child to population
                // set foundKey to generate the next child
                foundKey = true;
            }
        }
    }
}
示例#16
0
bool NMEA0183::PreParse( void )
{
      if ( IsGood() )
      {
            wxString mnemonic = sentence.Field( 0 );

      /*
            ** See if this is a proprietary field
      */

            if ( mnemonic.Left( 1 ) == 'P' )
                  mnemonic = _T("P");

            else
                  mnemonic = mnemonic.Right( 3 );


            LastSentenceIDReceived = mnemonic;

            return true;
      }
      else
            return false;
}
示例#17
0
static int IsGoodAndVisible(TActor *a)
{
    return IsGood(a) && (a->flags & FLAGS_VISIBLE);
}
示例#18
0
static int IsBad(TActor *a)
{
    return !IsGood(a);
}
示例#19
0
文件: main.cpp 项目: isghe/sudoku
	static bool IsGoodSchema (const MatrixOfCellPtr * theSchema){
        LogicAssert(true == IsGoodPtr(theSchema));
		return IsGood (theSchema, IsGoodSchemaSequence);
	}
示例#20
0
void 
ann_mex_t::annkFRSearch(					// approx fixed-radius kNN search
            const mxArray*	mxQ,			// query points
            const mxArray*  mxRad,			// radius of query ball (a scalar or array of size N)
            int				k,				// number of near neighbors to return
            mxArray**		mxIdx,			// nearest neighbor array (modified)
            mxArray**       mxDst,			// dist to near neighbors (modified)
            mxArray**       mxInr,          // number of points within r of each point
            double			eps)		// error bound
{
    index_t j(0);
    
    if ( ! IsGood() )
        mexErrMsgIdAndTxt("annmex:annkFRSearch","Class integrity check failed");
    
    // check input point(s)
    // dimension of points
    if (m_idim != mxGetM(mxQ))
        mexErrMsgIdAndTxt("annmex:annkFRSearch","points dimension does not match");

    // number of query point(s)
    int nqp = mxGetN(mxQ);
   
    if ( k <= 0 )
        mexErrMsgIdAndTxt("annmex:annkFRSearch","k must be positive");
    
    if ( k > m_inpoints ) {
        // generate warning
        mexWarnMsgIdAndTxt("annmex:annkFRSearch","searching for more points than in tree - returning only %d",m_inpoints);
        k = m_inpoints;
    }
    
    int rad_array_inc = 1;
    if ( mxGetNumberOfElements(mxRad) == 1 )
        rad_array_inc = 0;
    else if ( mxGetNumberOfElements(mxRad) != nqp )
        mexErrMsgIdAndTxt("annmex:annkFRSearch","R must be either a scalar or array of size N");
    
    ANNdist* prad = new ANNdist[mxGetNumberOfElements(mxRad)];
    GetArrSq<ANNdist>(mxRad, prad);

   
    // allocate space for outputs
    *mxIdx = mxCreateNumericMatrix(k, nqp, mxIDX_CLASS, mxREAL);
    *mxDst = mxCreateNumericMatrix(k, nqp, mxDIST_CLASS, mxREAL);
    *mxInr = mxCreateNumericMatrix(1, nqp, mxINT32_CLASS, mxREAL);
    if ( *mxIdx == NULL || *mxDst == NULL || mxInr == NULL) 
        mexErrMsgIdAndTxt("annmex:annkPriSearch","cannot allocate memory for outputs");
    
    ANNidx * pidx = (ANNidx*)mxGetData(*mxIdx);
    ANNdist* pdist= (ANNdist*)mxGetData(*mxDst);
    int *    pinr = (int*)mxGetData(*mxInr);
    
    ANNpoint pp   = (ANNpoint)mxGetData(mxQ);
    
    for ( j = 0 ; j < nqp ; j++ ) {
        *pinr = m_pTree->annkFRSearch(pp, prad[rad_array_inc*j], k, pidx, pdist, eps);
        pp += m_idim;
        pidx += k;
        pdist += k;
        pinr ++;
    }
    delete [] prad; 
}
示例#21
0
	explicit operator bool() const noexcept {
		return IsGood();
	}