Example #1
0
void mdeath::ratking(monster *z)
{
    g->u.remove_effect("rat");
    if (g->u_see(z)) {
        add_msg(m_warning, _("Rats suddenly swarm into view."));
    }

    std::vector <point> ratspots;
    int ratx, raty;
    for (int i = -1; i <= 1; i++) {
        for (int j = -1; j <= 1; j++) {
            ratx = z->posx() + i;
            raty = z->posy() + j;
            if (g->is_empty(ratx, raty)) {
                ratspots.push_back(point(ratx, raty));
            }
        }
    }
    monster rat(GetMType("mon_sewer_rat"));
    for (int rats = 0; rats < 7 && !ratspots.empty(); rats++) {
        int rn = rng(0, ratspots.size() - 1);
        point rp = ratspots[rn];
        ratspots.erase(ratspots.begin() + rn);
        rat.spawn(rp.x, rp.y);
        g->add_zombie(rat);
    }
}
Example #2
0
void mdeath::ratking(monster *z)
{
    g->u.rem_disease("rat");
    if (g->u_see(z)) {
        add_msg(m_warning, _("Rats suddenly swarm into view."));
    }

    std::vector <point> ratspots;
    int ratx, raty;
    for (int i = -1; i <= 1; i++) {
        for (int j = -1; j <= 1; j++) {
            ratx = z->posx() + i;
            raty = z->posy() + i;
            if (g->m.move_cost(ratx, raty) > 0 && g->mon_at(ratx, raty) == -1 &&
                !(g->u.posx == ratx && g->u.posy == raty)) {
                ratspots.push_back(point(ratx, raty));
            }
        }
    }
    int rn;
    monster rat(GetMType("mon_sewer_rat"));
    for (int rats = 0; rats < 7 && !ratspots.empty(); rats++) {
        rn = rng(0, ratspots.size() - 1);
        rat.spawn(ratspots[rn].x, ratspots[rn].y);
        g->add_zombie(rat);
        ratspots.erase(ratspots.begin() + rn);
    }
}
Example #3
0
void mdeath::ratking(game *g, monster *z)
{
    g->u.rem_disease("rat");
    if (g->u_see(z)) {
        g->add_msg(_("Rats swarm from nowhere to avenge the %s."), z->name().c_str());
    }

    std::vector <point> ratspots;
    int ratx, raty;
    for (int i = -1; i <= 1; i++) {
        for (int j = -1; j <= 1; j++) {
            ratx = z->posx() + i;
            raty = z->posy() + i;
            if (g->m.move_cost(ratx, raty) > 0 && g->mon_at(ratx, raty) == -1 &&
                  !(g->u.posx == ratx && g->u.posy == raty)) {
                ratspots.push_back(point(ratx, raty));
            }
        }
    }
    int rn;
    monster rat(g->mtypes[mon_sewer_rat]);
    for (int rats = 0; rats < 7 && ratspots.size() > 0; rats++) {
        rn = rng(0, ratspots.size() - 1);
        rat.spawn(ratspots[rn].x, ratspots[rn].y);
        g->add_zombie(rat);
        ratspots.erase(ratspots.begin() + rn);
 }
}
Example #4
0
/*
 * Transform all methods using the information about constant method arguments
 * that analyze() obtained.
 */
void PassImpl::optimize(const Scope& scope, const FixpointIterator& fp_iter) {
  using Data = std::nullptr_t;
  m_transform_stats = walk::parallel::reduce_methods<Data, Transform::Stats>(
      scope,
      [&](Data&, DexMethod* method) {
        if (method->get_code() == nullptr) {
          return Transform::Stats();
        }
        auto& code = *method->get_code();
        auto intra_cp = fp_iter.get_intraprocedural_analysis(method);

        if (m_config.create_runtime_asserts) {
          RuntimeAssertTransform rat(m_config.runtime_assert);
          rat.apply(*intra_cp, fp_iter.get_whole_program_state(), method);
          return Transform::Stats();
        } else {
          Transform tf(m_config.transform);
          return tf.apply(*intra_cp, fp_iter.get_whole_program_state(), &code);
        }
      },
      [](Transform::Stats a, Transform::Stats b) { // reducer
        return a + b;
      },
      [&](unsigned int) { // data initializer
        return nullptr;
      });
}
Example #5
0
Monomial LCM(Monomial a, Monomial b)
{
	Rational rat(1, 1);
	Monomial c(rat, a.powers);
	for (int i = 0; i < size; i++)
	{
		if (a.powers[i] < b.powers[i])
			c.powers[i] = b.powers[i];
	}
	return c;//Return the new monomial
}
int main()
{
   boost::rational<int> rat(2);
   rat -= 0.5;
}
Example #7
0
void DumpModel::dump(Amr* parent, int force_dump)
{

  // Exit if it isn't the right time to do the dump

  if (force_dump == 0 &&
      parent->levelSteps(0) % interval != 0) {
    return;
  }

  // Create flattened list of ordered, disjoint boxes from the grid hierarchy

  list<Box> bxlist;
  list<int> lnlist;

  vector<int> rat(parent->finestLevel(), 1);

  for (int ln = 0; ln <= parent->finestLevel(); ln++) {

    // rat[lnp] will be ratio between levels lnp and ln

    if (ln > 0) {
      for (int lnp = 0; lnp < ln; lnp++) {
        rat[lnp] *= parent->refRatio(ln - 1)[0];
      }
    }

    // Insert grids of level ln into list, trimming coarser grids as needed

    const BoxArray& grids = parent->boxArray(ln);
    for (int igr = 0; igr < grids.size(); igr++) {
      const Box& reg = grids[igr];
      list<Box>::iterator bi = bxlist.begin();
      list<int>::iterator li = lnlist.begin();
      for ( ; bi != bxlist.end(); ) {
        if (*li == ln) {
          if (bi->smallEnd(0) > reg.bigEnd(0)) {
            // Insert reg before bi and break
            bxlist.insert(bi, reg);
            lnlist.insert(li, ln);
            break;
          }
          // Increment and continue loop as reg not inserted yet
        }
        else { // *li < ln
          Box bx(BoxLib::refine(*bi,rat[*li]));
          if (bx.bigEnd(0) >= reg.smallEnd(0)) {
            if (bx.smallEnd(0) < reg.smallEnd(0) &&
                bx.bigEnd(0) <= reg.bigEnd(0)) {
              // Trim overlap with reg from *bi leaving low end of *bi
              bx.setBig(0, reg.smallEnd(0) - 1);
              bx.coarsen(rat[*li]);
              *bi = bx;
              // Increment and continue loop as reg not inserted yet
            }
            else if (bx.smallEnd(0) >= reg.smallEnd(0) &&
                     bx.bigEnd(0) <= reg.bigEnd(0)) {
              // Remove *bi from list as reg covers it completely
              list<Box>::iterator bt = bi;
              list<int>::iterator lt = li;
              ++bi;
              ++li;
              bxlist.erase(bt);
              lnlist.erase(lt);
              // Continue loop as reg not inserted yet; but bypass
              // increment at end of loop since we've done it already.
              continue;
            }
            else {
              // To get this far (bx.bigEnd(0) > reg.bigEnd(0)) must be true
              if (bx.smallEnd(0) < reg.smallEnd(0)) {
                // Trim overlap with reg from middle of *bi, extract low frag
                Box bxx(bx);
                bxx.setBig(0, reg.smallEnd(0) - 1);
                bxx.coarsen(rat[*li]);
                // Insert this low fragment of *bi before remainder of *bi
                bxlist.insert(bi, bxx);
                lnlist.insert(li, *li);
              }
              if (bx.smallEnd(0) <= reg.bigEnd(0)) {
                // Trim overlap with reg leaving end high end of *bi
                bx.setSmall(0, reg.bigEnd(0) + 1);
                bx.coarsen(rat[*li]);
                *bi = bx;
              }
              // Insert reg before high end of *bi and break
              bxlist.insert(bi, reg);
              lnlist.insert(li, ln);
              break;
            }
          }
        }

        // Increment and continue loop as reg not inserted yet
        ++bi;
        ++li;

      } // end of loop over bi, li

      if (bi == bxlist.end()) {
        // We made it to the end without finding another place to insert reg
        bxlist.push_back(reg);
        lnlist.push_back(ln);
      }
    }
  }

  // bxlist now contains an ordered list of disjoint boxes representing
  // the exposed portions of all levels of the hierarchy.  Each box is
  // at the resolution of its respective level, and the corresponding
  // entry of lnlist contains the level number.

  if (ParallelDescriptor::IOProcessor() && verbose >= 2) {
    cout << "Printing disjoint box list" << endl;

    list<Box>::iterator bi = bxlist.begin();
    list<int>::iterator li = lnlist.begin();
    for ( ; bi != bxlist.end(); ++bi, ++li) {
      cout << "Level " << *li << ", box " << *bi << endl;
    }
  }

  if (ParallelDescriptor::IOProcessor() && verbose >= 1) {
    cout << "Creating modelDump" << endl;
  }

  ofstream dumpfile;
  if (ParallelDescriptor::IOProcessor()) {
    dumpfile.open("modelDump", std::ios::out);
  }

  const int bufsiz = 200; // must hold 9 fields of width 16 plus a little more
  char buf[bufsiz];

  // The following are not parallel loops.
  // We are doing the Fab copy portion on all processors because
  // all must participate, but the write is done only on IOProcessor.

  int k = 1;
  list<Box>::iterator bi = bxlist.begin();
  list<int>::iterator li = lnlist.begin();
  for ( ; bi != bxlist.end(); ++bi, ++li) {
    const Box& reg = *bi;
    int ln         = *li;
    Castro *castro = dynamic_cast<Castro*>(&parent->getLevel(ln));

    MultiFab& S_new = castro->get_new_data(State_Type);

    Fab stmp(reg, S_new.nComp());

    S_new.copy(stmp);

    if (ParallelDescriptor::IOProcessor()) {
      for (int i = reg.smallEnd(0); i <= reg.bigEnd(0); i++) {
        IntVect p(i);

        // Quantities written as 0.0 are not currently used, so we
        // don't bother to derive them.

        sprintf(buf,
                "%16.8E%16.8E%16.8E%16.8E%16.8E%16.8E%16.8E%16.8E%16.8E %d\n",
                parent->Geom(ln).CellCenter(i, 0), // radius
                stmp(p, Density),                      // density
                stmp(p, Xmom) / stmp(p, Density),      // velocity
                0.0,                               // pressure
                stmp(p, Temp),                    // temperature (MeV ?)
                stmp(p, Eint) / stmp(p, Density),      // internal energy e
                0.0,                               // entropy
                0.0,                               // cumulative mass
                stmp(p, FirstAux / stmp(p, Density),       // Ye
                k++);
        std::string Buf = buf;
        dumpfile << Buf;
      }
    }
  }

  if (ParallelDescriptor::IOProcessor()) {
    dumpfile << Radiation::nGroups << '\n';
  }

  k = 1;
  bi = bxlist.begin();
  li = lnlist.begin();
  for ( ; bi != bxlist.end(); ++bi, ++li) {
    const Box& reg = *bi;
    int ln         = *li;
    Castro *castro = dynamic_cast<Castro*>(&parent->getLevel(ln));

    MultiFab& R_new = castro->get_new_data(Rad_Type);

    Fab rtmp(reg, R_new.nComp());

    R_new.copy(rtmp);

    if (ParallelDescriptor::IOProcessor()) {
      for (int i = reg.smallEnd(0); i <= reg.bigEnd(0); i++) {
        IntVect p(i);
        char* bufp = buf;
        for (int j = 0; ; j++) {
          sprintf(bufp, "%16.8E", rtmp(p, j));
          bufp += 16;
          if (j + 1 == Radiation::nGroups) {
            sprintf(bufp, " %d\n", k++);
            std::string Buf = buf;
            dumpfile << Buf;
            break;
          }
          else if (j % 4 == 3) {
            sprintf(bufp, "\n");
            std::string Buf = buf;
            dumpfile << Buf;
            bufp = buf;
          }
        }
      }
    }
  }

  if (ParallelDescriptor::IOProcessor()) {
    dumpfile.close();
  }
}
int main()
{
   boost::rational<int> rat(2);
   rat = rat + 0.5;
}
int main()
{
   boost::rational<int> rat(3.14);
}
Constante* Analyseur::ToConstante(QString s) const
{
    Historique* h =Historique::GetInstance();


    if (EstConstante(s))
    {
        if (!(h->ModeComplexe()))//Dans ce cas, il ne faut pas utiliser les complexes
        {


            if (EstExpression(s))
            {
                /* Il faut retirer les '*/
                s=s.left(s.length()-1);
                s=s.right(s.length()-1);
                return new Expression(s);

            }



            if (EstComplexe(s))
            {
                Reel temp(0);
                Reel temp2(0);
                QStringList list=s.split("$", QString::SkipEmptyParts);

                if (EstRationnel(list[0]))
                {
                    QStringList tempList=list[0].split("/", QString::SkipEmptyParts);
                    Rationnel rat(tempList[0].toInt(),tempList[1].toInt());
                    temp=Reel(rat);


                }

                else
                {
                    temp=Reel(VirguleToPoint(list[0]).toDouble());
                }

                if (EstRationnel(list[1]))
                {
                    QStringList tempList2=list[1].split("/", QString::SkipEmptyParts);

                    Rationnel rat(tempList2[0].toInt(),tempList2[1].toInt());
                    temp2=Reel(rat);


                }

                else
                {
                    temp2=Reel(VirguleToPoint(list[1]).toDouble());
                }



                return new Complexe(temp,temp2);


            }



            if (EstReel(s))
            {
                return new Reel(VirguleToPoint(s).toDouble());

            }



            if (EstRationnel(s))
            {
                QStringList list=s.split("/", QString::SkipEmptyParts);
                Entier temp=list[0].toInt();
                Entier temp2=list[1].toInt();

                return new Rationnel(temp,temp2);


            }




            if (EstEntier(s))
            {
                return new Entier(s.toInt());

            }

        }

        else//Il faut tout couvertir en Complexe!!!
        {
            Entier entierNull(0);
            if (EstExpression(s))
            {
                /* Il faut retirer les '*/
                s=s.left(s.length()-1);
                s=s.right(s.length()-1);
                return new Expression(s);

            }



            if (EstComplexe(s))
            {
                Reel temp(0);
                Reel temp2(0);
                QStringList list=s.split("$", QString::SkipEmptyParts);

                if (EstRationnel(list[0]))
                {
                    QStringList tempList=list[0].split("/", QString::SkipEmptyParts);
                    Rationnel rat(tempList[0].toInt(),tempList[1].toInt());
                    temp=Reel(rat);


                }

                else
                {
                    temp=Reel(VirguleToPoint(list[0]).toDouble());
                }

                if (EstRationnel(list[1]))
                {
                    QStringList tempList2=list[1].split("/", QString::SkipEmptyParts);

                    Rationnel rat(tempList2[0].toInt(),tempList2[1].toInt());
                    temp2=Reel(rat);


                }

                else
                {
                    temp2=Reel(VirguleToPoint(list[1]).toDouble());
                }



                return new Complexe(temp,temp2);


            }



            if (EstReel(s))
            {
                return new Complexe(Reel(VirguleToPoint(s).toDouble()),entierNull);

            }



            if (EstRationnel(s))
            {
                QStringList list=s.split("/", QString::SkipEmptyParts);
                Entier temp=list[0].toInt();
                Entier temp2=list[1].toInt();

                return new Complexe(temp/temp2,entierNull);


            }




            if (EstEntier(s))
            {
                return new Complexe(Entier(s.toInt()),entierNull);

            }


        }





    }

        else
        {
            throw Exception("Ce n'est pas une instruction !");
        }

      return 0;

}