Exemple #1
0
void Astar::resetSort(int last)
{
    // 根据步长进行堆排序
    while(last > 1) {
        int half = last/2;
        auto itemHalf = (AstarItem*)_open->getObjectAtIndex(half);
        auto itemLast = (AstarItem*)_open->getObjectAtIndex(last);

        if(itemHalf->getF() <= itemLast->getF()) {
            break;
        }

        /*if(((AstarItem*)_open->getObjectAtIndex(half))->getF() <= ((AstarItem*)_open->getObjectAtIndex(last))->getF()) {
            break;
        }*/

        AstarItem* temp = (AstarItem*)_open->getObjectAtIndex(last);
        _open->replaceObjectAtIndex(last, _open->getObjectAtIndex(half), false);
        _open->replaceObjectAtIndex(half, temp, true);

        //temp->release();

        last = half;
    }
}
Complexity Complexity::operator * (Complexity& t){
    Complexity res(*this);
    double f = getF()*t.getF() - getS()*t.getS();
    double s = getF()*t.getS() + getF()*t.getS();
    res.set(f, s);
    return res;
}
Exemple #3
0
// Print the BWT
void SBWT::print(const ReadTable* pRT, const SuffixArray* pSA) const
{
    std::cout << "i\tL(i)\tF(i)\tO(-,i)\tSUFF\n";
    for(size_t i = 0; i < m_bwStr.length(); ++i)
    {
        assert(getF(i) == pSA->getSuffix(i, pRT)[0]);
        std::cout << i << "\t" << m_bwStr.get(i) << "\t" << getF(i) << "\t" << m_occurrence.get(m_bwStr, i) << pSA->getSuffix(i, pRT) << "\n";
    }
}
NOX::Abstract::Group::ReturnType
NOX::Belos::Group::computeNewton(NOX::Parameter::List& params) 
{
  if (isValidNewton)
    return NOX::Abstract::Group::Ok;

  if (!isF()) {
    std::cerr << "ERROR: NOX::Belos::Group::computeNewton() - invalid RHS" << std::endl;
    throw "NOX Error";
  }

  if (!isJacobian()) {
    std::cerr << "ERROR: NOX::Belos::Group::computeNewton() - invalid Jacobian" 
	 << std::endl;
    throw "NOX Error";
  }

  Abstract::Group::ReturnType status;

  // zero out newton vec -- used as initial guess for some linear solvers
  newtonVecPtr->init(0.0);

  status = applyJacobianInverse(params, getF(), *newtonVecPtr);
 
  newtonVecPtr->scale(-1.0);

  // Update state EVEN IF LINEAR SOLVE FAILED
  // We still may want to use the vector even it it just missed it's 
  isValidNewton = true;

  return status;
}
Exemple #5
0
    int getF(string &s, string &p, int i, int j) {
        if (F)
            return F;

        // case 1: regex is empty
        if (j < 0) {
            // s must be empty
            return F = (i < 0 ? 1 : 2);
        }
        
        // case 2: start with a dot
        if (p[j] == '.') {
            // s is not empty, check next
            if (i >= 0)
                return F = getF(s, p, i - 1, j - 1);
            else
                return F = 2;
        }
        
        // case 3: start with a char
        if (p[j] != '*') {
            // s shares the same first letter with p, check next
            if (i >= 0 && s[i] == p[j])
                return F = getF(s, p, i - 1, j - 1);
            else
                return F = 2;
        }
        
        // case 4: start with a asterisk
        char prev = j ? p[j - 1] : '-';
        if (prev == '*') return F = getF(s, p, i, j - 1);
        
        if (getF(s, p, i, j - 2) == 1) // skip
            return F = 1;
        for (int k = 0; i - k >= 0; ++k)
            if (prev == '.' || prev == s[i - k]) {
                // it matches
                if (getF(s, p, i - k - 1, j - 2) == 1) {
                    return F = 1;
                }
            } else {
                break;
            }
        return F = 2;
    }
double
NOX::Belos::Group::getNormNewtonSolveResidual() const 
{
  NOX::Abstract::Group::ReturnType status;
  Teuchos::RCP<NOX::Abstract::Vector> residual = 
    getF().clone(NOX::DeepCopy);
  
  status = applyJacobian(*newtonVecPtr, *residual);
  if (status != NOX::Abstract::Group::Ok) {
    std::cerr << "Error:  NOX::Belos::Group::getNormNewtonSolveResidual() -- applyJacobian failed!" << std::endl;
    throw "NOX Error";
  }

  residual->update(1.0, getF(), 1.0);
  double resid_norm = residual->norm();

  return resid_norm;
}
Exemple #7
0
void UVarHist::logDataDouble(int idx)
{
  if (isLogOpen())
  {
    double * data = &histData[idx * colCnt];
    UTime * t = & histTime[idx];
    // save timestamp
    fprintf(getF(), "%lu.%06lu", t->getSec(), t->getMicrosec());
    // save data elements
    for (int i = 0; i < colCnt; i++)
      fprintf(getF(), " %.10g", data[i]);
    // end line
    fprintf(getF(), "\n");
    // remenber to flush if requested
    if (logFlush)
      fflush(getF());
  }
}
void Union(int id1, int id2)
{
	int fA, fB;
	fA = getF(id1);
	fB = getF(id2);

	if (fA == fB)
		return;
	if (set[fA] < set[fB])
	{
		set[fA] += set[fB];
		set[fB] = fA;
	}
	else
	{
		set[fB] += set[fA];
		set[fA] = fB;
	}
}
void uion(int id1, int id2)
{
	int fA, fB;
	fA = getF(id1);
	fB = getF(id2);

	if (fA == fB)
		return;
	if (students[fA] < students[fB])
	{
		students[fA] += students[fB];
		students[fB] = fA;
	}
	else
	{
		students[fB] += students[fA];
		students[fA] = fB;
	}
}
 int longestIncreasingContinuousSubsequenceII(vector<vector<int>>& A) {
     // Write your code here
     if(A.size() == 0 || A[0].size() == 0) return 0;
     int m = A.size(), n = A[0].size();
     vector<vector<int>> f(m, vector<int>(n, 0));
     int ans = 0;
     for(int i = 0; i < m; i++)
         for(int j = 0; j < n; j++)
             ans = max(ans, getF(A, f, i, j));
     return ans;
 }
 /**
  * @param A an integer matrix
  * @return  an integer
  */
 int getF(vector<vector<int>>& A, vector<vector<int>>& f, int x, int y) {
     if(f[x][y] > 0) return f[x][y];
     int a = 1;
     int g[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
     for(int i = 0;i < 4; i++) {
         int j = x + g[i][0], k = y + g[i][1];
         if(j >= 0 && j < A.size() && k >= 0 && k < A[0].size() && A[j][k] > A[x][y])
             a = max(a, 1+getF(A, f, j, k));
     }
     f[x][y] = a;
     return a;
 }
Eigen::MatrixXd TranslationRotation3D::adjoint() const {
  double F_ptr[4 * 4];
  Eigen::Map<const Eigen::Matrix<double, 4, 4, Eigen::RowMajor> > F(F_ptr);
  getF(F_ptr);
  Eigen::MatrixXd adj(6, 6);
  Eigen::Vector3d T = F.topRightCorner<3, 1>();
  Eigen::Matrix3d R = F.topLeftCorner<3, 3>();
  Eigen::Matrix3d skewT;
  skewT << 0.0, -T(2), T(1), T(2), 0.0, -T(0), -T(1), T(0), 0.0;
  adj << R, skewT *R, Eigen::Matrix3d::Zero(), R;
  return adj;
}
Exemple #13
0
peano::applications::faxen::records::RegularGridCell peano::applications::faxen::records::RegularGridCellPacked::convert() const{
   return RegularGridCell(
      getP(),
      getU(),
      getV(),
      getF(),
      getG(),
      getRhs(),
      getRes(),
      getIsInside()
   );
}
const Vector&
PFEMElement2DBubble::getResistingForceIncInertia()
{

    // resize P
    int ndf = this->getNumDOF();
    P.resize(ndf);
    P.Zero();

    // get velocity, accleration
    Vector v(ndf), vdot(ndf);
    for(int i=0; i<3; i++) {
        const Vector& accel = nodes[2*i]->getTrialAccel();
        vdot(numDOFs(2*i)) = accel(0);
        vdot(numDOFs(2*i)+1) = accel(1);

        const Vector& accel2 = nodes[2*i+1]->getTrialAccel();  // pressure
        vdot(numDOFs(2*i+1)) = accel2(0);

        const Vector& vel = nodes[2*i]->getTrialVel();
        v(numDOFs(2*i)) = vel(0);
        v(numDOFs(2*i)+1) = vel(1);

        const Vector& vel2 = nodes[2*i+1]->getTrialVel();   // pressure
        v(numDOFs(2*i+1)) = vel2(0);

    }

    // bubble force
    Vector fp(3);
    getFp(fp);

    // internal force
    P.addMatrixVector(1.0, getMass(), vdot, 1.0);
    P.addMatrixVector(1.0, getDamp(), v, 1.0);

    // external force
    Vector F(6);
    getF(F);
    for(int i=0; i<3; i++) {
        P(numDOFs(2*i)) -= F(2*i);
        P(numDOFs(2*i)+1) -= F(2*i+1);
        P(numDOFs(2*i+1)) -= fp(i);
    }

    //opserr<<"F = "<<F;
    return P;
}
Exemple #15
0
int LuaArgs::getF(int idx, const char *key)
{
	if (tbl > 0 && lua_checkstack(L, 1)) {
		lua_getfield(L, tbl, key);
		if (!lua_isfunction(L, -1) && idx > 0) {
			lua_pop(L, 1);
			lua_pushinteger(L, idx);
			lua_gettable(L, tbl);
		}
		int ret = fcopy(-1);
		lua_pop(L, 1);
		return ret;
	} else {
		return getF(idx);
	}
}
//----------------------------------------------------------------------------------
void FunctionsSingleton::coutAll() const
{
	std::cout << getD() << std::endl;
	std::cout << getF() << std::endl;
	std::cout << getG() << std::endl;
	std::cout << getM() << std::endl;
	std::cout << getN() << std::endl;
	std::cout << getP() << std::endl;
	std::cout << getQ() << std::endl;
	std::cout << getR() << std::endl;
	std::cout << getW() << std::endl;
	
	std::cout << "Alpha: " << mAlpha << std::endl;
	std::cout << "Beta: "  << mBeta  << std::endl;
	std::cout << "Gamma: " << mGamma << std::endl;
}
void ExtendedKalman::predict() {
	{
		Matrix F;
		getF(F, X);
	//  X = F * X
		X.dotSelf(F, true);
	//	P = F * P * F.T + Q

		P.dotSelf(F, true).dotSelf(F.transposed());
	}
	{
		Matrix Q;
		getQ(Q);
		P += Q;
	}
}
Exemple #18
0
// Print the current time and A/B signal levels on the console
void showTime() {
  unsigned int s = getSeconds();

  //-- Newline + whole time every minute
  if ( s == 0 )
    p("\r\n%02u%s:%02u:%02u ", getHours(), getDST() ? "D" : "", getMinutes(), s);
  else if ( (s % 10 ) == 0)
    p("%02u", s );
  else
    p("-");

  //-- Show the A/B/D/E pulse status, F level
  if (getA()) p("A");
  if (getB()) p("B");
  if (getD()) p("D");
  if (getE()) p("E");
  if (getF()) p("F");
}
Exemple #19
0
void peano::applications::faxen::records::RegularGridCellPacked::toString (std::ostream& out) const {
   out << "("; 
   out << "P:" << getP();
   out << ",";
   out << "U:" << getU();
   out << ",";
   out << "V:" << getV();
   out << ",";
   out << "F:" << getF();
   out << ",";
   out << "G:" << getG();
   out << ",";
   out << "rhs:" << getRhs();
   out << ",";
   out << "res:" << getRes();
   out << ",";
   out << "isInside:" << getIsInside();
   out <<  ")";
}
Exemple #20
0
int main(int argc, char **argv)
{
   walberla::Environment env( argc, argv );

   const uint_t cells [] = { 1,1,1 };
   const uint_t blockCount [] = { 1, 1,1 };
   const uint_t nrOfTimeSteps = 20;

   // Create BlockForest
   auto blocks = blockforest::createUniformBlockGrid(blockCount[0],blockCount[1],blockCount[2],  //blocks
                                                     cells[0],cells[1],cells[2], //cells
                                                     1,                          //dx
                                                     false,                      //one block per process
                                                     true,true,true);            //periodicity


   // In addition to the normal GhostLayerField's  we allocated additionally a field containing the whole global simulation domain for each block
   // we can then check if the GhostLayer communication is correct, by comparing the small field to the corresponding part of the big field
   BlockDataID pdfField     = field::addToStorage<PdfField>( blocks, "Src" );

   // Init src field with some values
   for( auto blockIt = blocks->begin(); blockIt != blocks->end(); ++blockIt ) // block loop
   {
      // Init PDF field
      PdfField * src = blockIt->getData<PdfField>(pdfField);
      for( auto cellIt = src->beginWithGhostLayerXYZ(); cellIt != src->end(); ++cellIt ) // over all x,y,z,f
      {
         for( auto d = stencil::D3Q19::begin(); d != stencil::D3Q19::end(); ++d )
            cellIt.getF( d.toIdx() ) = real_c( d.toIdx() );
      }

   }

   // Create TimeLoop
   SweepTimeloop timeloop (blocks, nrOfTimeSteps );

   GUI gui (timeloop, blocks, argc, argv);
   gui.run();
   //timeloop.singleStep();
   return EXIT_SUCCESS;
}
Exemple #21
0
void DepositionCell::preUpdate(double epsilon[], BaseCell* neighbors[], Grid *grid, Vector3i ) {
    double surroundingConcentration = 0;
    for (int i = 0; i < 9; i++) {
        BaseCell* neighbor = neighbors[i];
        if (neighbor != 0) {
            double newF = (1 - 1 / epsilon[1]) * getF(i, 1) + LBUtil::W[9][i] * concentration / epsilon[1];
            neighbor->setNextF(i, newF, 1);
            if (i != 0) {
                double neighborConcentration = 0;
                if (neighbor->isFluid()) {
                    neighborConcentration = neighbor->getP(0);
                } else if (dynamic_cast<DepositionWall*>(neighbor) != 0) {
                    neighborConcentration = 1;
                }
                surroundingConcentration += neighborConcentration * 9 / 5 * LBUtil::W[9][i];
            }
        }
    }
    deposited += surroundingConcentration * concentration * grid->getConfig()->getDepositionRate();
    if (deposited > 1) {
        deposited = 1;
    }
}
int main()
{
	char c;
	int ncase, i, a, b, m, n;
	int oppos[N];

	scanf("%d", &ncase);

	while(ncase--)
	{
		makeSet();
		memset(oppos, -1, sizeof(oppos));
		scanf("%d %d", &n, &m);
		for(i = 0;i < m;i++)
		{
			getchar();
			scanf("%c %d %d", &c, &a, &b);
			if(c == 'A')
			{
				if (oppos[a] == -1 || oppos[b] == -1)
					printf("Not sure yet.\n");
				else if (getF(a) == getF(b))
					printf("In the same gang.\n");
				else if (getF(a) == getF(oppos[b]) || getF(b) == getF(oppos[a]))
					printf("In different gangs.\n");
				else
					printf("Not sure yet.\n");
			}
			else
			{
				if (oppos[a] == -1)
					oppos[a] = b;
				if (oppos[b] == -1)
					oppos[b] = a;
				Union(a, oppos[b]);
				Union(b, oppos[a]);
			}
		}
	}
	return 0;
}
Exemple #23
0
inline int getFlagC(){
	return (getF()&0x10)>>4;
}
Exemple #24
0
inline int getFlagH(){
	return (getF()&0x20)>>5;
}
Exemple #25
0
inline int getFlagN(){
	return (getF()&0x40)>>6;
}
Exemple #26
0
inline int getFlagZ(){
	return (getF()&0x80)>>7;
}
Exemple #27
0
inline void clearFlagC(){
	writeF(getF()&(~(0x10)));
}
Exemple #28
0
inline void clearFlagH(){
	writeF(getF()&(~(0x20)));
}
Exemple #29
0
inline void clearFlagN(){
	writeF(getF()&(~(0x40)));
}
Exemple #30
0
inline void clearFlagZ(){
	writeF(getF()&(~(0x80)));
}