Example #1
0
void test_transform_binary_async(ExPolicy p, IteratorTag)
{
    typedef std::vector<int>::iterator base_iterator;
    typedef test::test_iterator<base_iterator, IteratorTag> iterator;

    std::vector<int> c1(10007);
    std::vector<int> c2(c1.size());
    std::vector<int> d1(c1.size()); //-V656
    std::iota(std::begin(c1), std::end(c1), std::rand());
    std::iota(std::begin(c2), std::end(c2), std::rand());

    auto f =
        hpx::parallel::transform(p,
            iterator(std::begin(c1)), iterator(std::end(c1)),
            std::begin(c2), std::begin(d1), add());
    f.wait();

    hpx::util::tuple<iterator, base_iterator, base_iterator> result = f.get();
    HPX_TEST(hpx::util::get<0>(result) == iterator(std::end(c1)));
    HPX_TEST(hpx::util::get<1>(result) == std::end(c2));
    HPX_TEST(hpx::util::get<2>(result) == std::end(d1));

    // verify values
    std::vector<int> d2(c1.size());
    std::transform(std::begin(c1), std::end(c1),
        std::begin(c2), std::begin(d2), add());

    std::size_t count = 0;
    HPX_TEST(std::equal(std::begin(d1), std::end(d1), std::begin(d2),
        [&count](int v1, int v2) -> bool {
            HPX_TEST_EQ(v1, v2);
            ++count;
            return v1 == v2;
        }));
    HPX_TEST_EQ(count, d2.size());
}
Example #2
0
void Triangle<NNODES>::init(const std::vector<Point> &points)
{
    points_ = points;

    Triangle<NNODES> &t = *this;
    Point d1(t[1][0]-t[0][0], t[1][1]-t[0][1]);
    Point d2(t[2][0]-t[0][0], t[2][1]-t[0][1]);   //Point d2 = t[2] - t[0]; non funziona, reimplementare sottrazione

    M_J_(0,0) = d1[0];			// (x2-x1)
    M_J_(1,0) = d1[1];			// (y2-y1)
    M_J_(0,1) = d2[0];			// (x3-x1)
    M_J_(1,1) = d2[1];			// (y3-y1)

    detJ_ = M_J_(0,0) * M_J_(1,1) - M_J_(1,0) * M_J_(0,1);

    Real idet = 1. / detJ_;

    M_invJ_(0,0) =  idet * M_J_(1,1);	// (y3-y1)	-(x3-x1)
    M_invJ_(1,0) = -idet * M_J_(1,0);	// -(y2-y1) (x2-x1)
    M_invJ_(0,1) = -idet * M_J_(0,1);	//
    M_invJ_(1,1) =  idet * M_J_(0,0);	//	è la trasposta di quella della Sangalli (Ael)

    metric_ = M_invJ_ * M_invJ_.transpose();
}
double Trajectory::calcDirCoherence( const _2Real::Vec2 &p, double time, double dirTolerance ) const
{
	if( !this->canCalcDirCoherence() )
		throw _2Real::Exception( "cannot calc directional coherence -- not enough values" );

	_2Real::Vec2 d0( m_v1 - m_v0 );
	_2Real::Vec2 d1( p - m_v1 );

	double len0 = d0.norm();
	double len1 = d1.norm();

	double dt = time - m_prevTime;

	double compDir = 0.0;
	if( len0 * len1 > std::numeric_limits<double>::epsilon() )
	{
		if( len0 > dirTolerance && len1 > dirTolerance )
			compDir = ( 1.0 - ( d0.dot( d1 ) / ( len0 * len1 ) ) ) * 0.5f;
		else
			compDir = 0.5f;		//cannot make a decision -> tie value.
	}

	return compDir / ( dt * 30.0 );
}
Example #4
0
void analyze(Int_t step){

  // TOF propagation factors (TOF efficiencies)
  fEfficiencyPiTOF = new TF1("fEfficiencyPiTOF","(x > 0.3)*0.7",0,10);
  fEfficiencyKaTOF = new TF1("fEfficiencyKaTOF","(x > 0.3)*(x-0.3)*(x<1) + (x>1)*0.7",0,10);
  fEfficiencyPrTOF = new TF1("fEfficiencyPrTOF","(x > 0.3)*(x-0.3)*(x<1) + (x>1)*0.7",0,10);

  // teoretical separation (perfect if equal to the one simualted in sim.C)
  fseparation = new TF1("f","[0]+[1]/x",0,100);
  fseparation->SetParameter(0,0.);
  fseparation->SetParameter(1,7.);
 
  fseparationPiKa = new TF1("fPiKa","[0]+[1]/TMath::Power(x,2.5)",0,100);
  fseparationPiKa->SetParameter(0,2.34);
  fseparationPiKa->SetParameter(1,10);

  fseparationKaPr = new TF1("fKaPr","[0]+[1]/TMath::Power(x,2.5)",0,100);
  fseparationKaPr->SetParameter(0,1);
  fseparationKaPr->SetParameter(1,56);

  // x=p, y=pt/p (normalized at the number of sigma assuming 80 ps resolution)
  fTOFpi = new TF2("fTOFpi","3.7/y*(sqrt(x*x+0.0193210)/x-1)*37.47405725",0.3,10,0.5,1);
  fTOFka = new TF2("fTOFka","3.7/y*(sqrt(x*x+0.243049)/x-1)*37.47405725",0.3,10,0.5,1);
  fTOFpr = new TF2("fTOFpr","3.7/y*(sqrt(x*x+0.879844)/x-1)*37.47405725",0.3,10,0.5,1);


  // x=p, already normalized in number of sigma (sigma assumed 3.5=7% of the MIP)
  fTPCpi = new TF1("fTPCpi",BetheBlochAleph,0,10,6);
  fTPCpi->SetParameter(0,fKp1);
  fTPCpi->SetParameter(1,fKp2);
  fTPCpi->SetParameter(2,fKp3);
  fTPCpi->SetParameter(3,fKp4);
  fTPCpi->SetParameter(4,fKp5);
  fTPCpi->SetParameter(5,0.139);
  fTPCka = new TF1("fTPCka",BetheBlochAleph,0,10,6);
  fTPCka->SetParameter(0,fKp1);
  fTPCka->SetParameter(1,fKp2);
  fTPCka->SetParameter(2,fKp3);
  fTPCka->SetParameter(3,fKp4);
  fTPCka->SetParameter(4,fKp5);
  fTPCka->SetParameter(5,0.493);
  fTPCpr = new TF1("fTPCpr",BetheBlochAleph,0,10,6);
  fTPCpr->SetParameter(0,fKp1);
  fTPCpr->SetParameter(1,fKp2);
  fTPCpr->SetParameter(2,fKp3);
  fTPCpr->SetParameter(3,fKp4);
  fTPCpr->SetParameter(4,fKp5);
  fTPCpr->SetParameter(5,0.938);

  Float_t width = 1.0;
  addshift =0;

  invwidth = 1./width;

  Float_t widthTOF = 1.0;
  addshiftTOF =0;

  invwidthTOF = 1./widthTOF;

  TH1D *priorsPt[6];
  TH1D *newpriorsPt[6];
  TH1D *truePt[6];
  TH1D *allPtPos = new TH1D("allPtP","All positive;p_{T} (GeV/#it{c});N",100,0,10);
  TH1D *allPtNeg = new TH1D("allPtN","All negative;p_{T} (GeV/#it{c});N",100,0,10);

  TH3D *priorsKs[3][3];
  TH3D *newpriorsKs[3][3];
  TH3D *truePidKs[3][3];
  TH3D *trueKs;

  TH2D *priorsPhi[3][3];
  TH2D *newpriorsPhi[3][3];
  TH2D *truePidPhi[3][3];
  TH2D *truePhi;

  TH3D *priorsLc[3][3][3];
  TH3D *newpriorsLc[3][3][3];
  TH3D *truePidLc[3][3][3];
  TH3D *trueLc,*mypidLc;

  TH3D *priorsLcbar[3][3][3];
  TH3D *newpriorsLcbar[3][3][3];
  TH3D *truePidLcbar[3][3][3];
  TH3D *trueLcbar,*mypidLcbar;

  Int_t nbinPtFrKa = 8;
  Int_t nbinPtFrPi = 8;
  Int_t nbinY = 1;
  Int_t nbinpol=nbinPtFrKa*nbinPtFrPi*nbinY;
  Double_t normbin = 1./nbinpol;
  Int_t nbinmlc = 100;
  Int_t nbinptlc = 10;

  const char *spec[3] = {"Pi","Ka","Pr"};

  if(step==0){
    priorsPt[0] = new TH1D("oldpriorsPtPiP","Pion (+) priors;p_{T} (GeV/#it{c});N",100,0,10);
    for(Int_t i=1;i<=100;i++)
      priorsPt[0]->SetBinContent(i,1);
    priorsPt[1] = new TH1D("oldpriorsPtKaP","Kaon (+) priors;p_{T} (GeV/#it{c});N",100,0,10);
    priorsPt[2] = new TH1D("oldpriorsPtPrP","Proton (+) priors;p_{T} (GeV/#it{c});N",100,0,10);
    priorsPt[3] = new TH1D("oldpriorsPtPiM","Pion (-) priors;p_{T} (GeV/#it{c});N",100,0,10);
    priorsPt[4] = new TH1D("oldpriorsPtKaM","Kaon (-) priors;p_{T} (GeV/#it{c});N",100,0,10);
    priorsPt[5] = new TH1D("oldpriorsPtPrM","Proton (-) priors;p_{T} (GeV/#it{c});N",100,0,10);
    priorsPt[1]->Add(priorsPt[0]);
    priorsPt[2]->Add(priorsPt[0]);
    priorsPt[3]->Add(priorsPt[0]);
    priorsPt[4]->Add(priorsPt[0]);
    priorsPt[5]->Add(priorsPt[0]);

    // Ks and phi priors
    for(Int_t i=0; i< 3;i++){
      for(Int_t j=0; j< 3;j++){
	priorsKs[i][j] =  new TH3D(Form("oldpriorsKs%s%s",spec[i],spec[j]),Form("K^{0*} priors for %s-%s;m_{#piK} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N",spec[i],spec[j]),200,0.4,1.4,40,0,10,nbinpol,-1.001,1.001);
	priorsPhi[i][j] =  new TH2D(Form("oldpriorsPhi%s%s",spec[i],spec[j]),Form("#phi priors for %s-%s;m_{KK} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N",spec[i],spec[j]),100,0.98,1.05,40,0,10);


	if(i==0 && j==0){
	  for(Int_t ibx=1;ibx<=200;ibx++)
	    for(Int_t iby=1;iby<=40;iby++){
	      for(Int_t ibz=1;ibz <= nbinpol;ibz++)
		priorsKs[i][j]->SetBinContent(ibx,iby,ibz,1);
	      priorsPhi[i][j]->SetBinContent(ibx,iby,1);
	    }
	}
	else{
	  priorsKs[i][j]->Add(priorsKs[0][0]);
	  priorsPhi[i][j]->Add(priorsPhi[0][0]);
	}

	for(Int_t k=0; k< 3;k++){
	  priorsLc[i][j][k] =  new TH3D(Form("oldpriorsLc%s%s%s",spec[i],spec[j],spec[k]),Form("#Lambda_{c}^{+} priors for %s-%s-%s;m_{#piKp} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N",spec[i],spec[j],spec[k]),nbinmlc,2.1,2.5,nbinptlc,7,27,nbinpol,0,1.);
	  priorsLcbar[i][j][k] =  new TH3D(Form("oldpriorsLcbar%s%s%s",spec[i],spec[j],spec[k]),Form("#overline{#Lambda}_{c}^{-} priors for %s-%s-%s;m_{#piKp} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N",spec[i],spec[j],spec[k]),nbinmlc,2.1,2.5,nbinptlc,7,27,nbinpol,0,1.);
	  if(i==0 && j==0 && k==0){
	    for(Int_t ibx=1;ibx<=nbinmlc;ibx++)
	      for(Int_t iby=1;iby<=nbinptlc;iby++){
		for(Int_t ibz=1;ibz <= nbinpol;ibz++){
		  priorsLc[i][j][k]->SetBinContent(ibx,iby,ibz,1);
		  priorsLcbar[i][j][k]->SetBinContent(ibx,iby,ibz,1);
		}
	      }
	  }
	  else{
	    priorsLc[i][j][k]->Add(priorsLc[0][0][0]);
	    priorsLcbar[i][j][k]->Add(priorsLc[0][0][0]);
	  }
	}
      }
    }
  }
  else{
    TFile *fin = new TFile(Form("step%i.root",step));
    priorsPt[0] = (TH1D *) fin->Get("priorsPtPiP"); 
    priorsPt[0]->SetName("oldpriorsPtPiP");
    priorsPt[1] = (TH1D *) fin->Get("priorsPtKaP"); 
    priorsPt[1]->SetName("oldpriorsPtPiP");
    priorsPt[2] = (TH1D *) fin->Get("priorsPtPrP"); 
    priorsPt[2]->SetName("oldpriorsPtPiP");
    priorsPt[3] = (TH1D *) fin->Get("priorsPtPiM"); 
    priorsPt[3]->SetName("oldpriorsPtPiM");
    priorsPt[4] = (TH1D *) fin->Get("priorsPtKaM"); 
    priorsPt[4]->SetName("oldpriorsPtKaM");
    priorsPt[5] = (TH1D *) fin->Get("priorsPtPrM"); 
    priorsPt[5]->SetName("oldpriorsPtPrM");

    // Ks and phi priors
    for(Int_t i=0; i< 3;i++){
      for(Int_t j=0; j< 3;j++){
	priorsKs[i][j] =  (TH3D *) fin->Get(Form("priorsKs%s%s",spec[i],spec[j]));
	priorsKs[i][j]->SetName(Form("oldpriorsKs%s%s",spec[i],spec[j]));
	priorsPhi[i][j] =  (TH2D *) fin->Get(Form("priorsPhi%s%s",spec[i],spec[j]));
	priorsPhi[i][j]->SetName(Form("oldpriorsPhi%s%s",spec[i],spec[j]));
	for(Int_t k=0; k< 3;k++){
	  priorsLc[i][j][k] =  (TH3D *) fin->Get(Form("priorsLc%s%s%s",spec[i],spec[j],spec[k]));
	  priorsLc[i][j][k]->SetName(Form("oldpriorsLc%s%s%s",spec[i],spec[j],spec[k]));
	  priorsLcbar[i][j][k] =  (TH3D *) fin->Get(Form("priorsLcbar%s%s%s",spec[i],spec[j],spec[k]));
	  priorsLcbar[i][j][k]->SetName(Form("oldpriorsLcbar%s%s%s",spec[i],spec[j],spec[k]));
	}
      }
    }
  }
  
  newpriorsPt[0] = new TH1D("priorsPtPiP","Pion (+) priors;p_{T} (GeV/#it{c});N",100,0,10);
  newpriorsPt[1] = new TH1D("priorsPtKaP","Kaon (+) priors;p_{T} (GeV/#it{c});N",100,0,10);
  newpriorsPt[2] = new TH1D("priorsPtPrP","Proton (+) priors;p_{T} (GeV/#it{c});N",100,0,10);
  newpriorsPt[3] = new TH1D("priorsPtPiM","Pion (-) priors;p_{T} (GeV/#it{c});N",100,0,10);
  newpriorsPt[4] = new TH1D("priorsPtKaM","Kaon (-) priors;p_{T} (GeV/#it{c});N",100,0,10);
  newpriorsPt[5] = new TH1D("priorsPtPrM","Proton (-) priors;p_{T} (GeV/#it{c});N",100,0,10);

  // Ks and phi priors distributions
  for(Int_t i=0; i< 3;i++){
    for(Int_t j=0; j< 3;j++){
      newpriorsKs[i][j] =  new TH3D(Form("priorsKs%s%s",spec[i],spec[j]),Form("K^{0*} priors for %s-%s;m_{#piK} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N",spec[i],spec[j]),200,0.4,1.4,40,0,10,nbinpol,-1.001,1.001);
      newpriorsPhi[i][j] =  new TH2D(Form("priorsPhi%s%s",spec[i],spec[j]),Form("#phi priors for %s-%s;m_{KK} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N",spec[i],spec[j]),100,0.98,1.05,40,0,10);
      for(Int_t k=0; k< 3;k++){
	newpriorsLc[i][j][k] =  new TH3D(Form("priorsLc%s%s%s",spec[i],spec[j],spec[k]),Form("#Lambda_{c}^{+} priors for %s-%s-%s;m_{#piKp} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N",spec[i],spec[j],spec[k]),nbinmlc,2.1,2.5,nbinptlc,7,27,nbinpol,0,1.);
	newpriorsLcbar[i][j][k] =  new TH3D(Form("priorsLcbar%s%s%s",spec[i],spec[j],spec[k]),Form("#overline{#Lambda}_{c}^{-} priors for %s-%s-%s;m_{#piKp} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N",spec[i],spec[j],spec[k]),nbinmlc,2.1,2.5,nbinptlc,7,27,nbinpol,0,1.);
      }
    }
  }
  
  truePt[0]  = new TH1D("truePtPiP","Pion (+) truth;p_{T} (GeV/#it{c});N",100,0,10);
  truePt[1]  = new TH1D("truePtKaP","Kaon (+) truth;p_{T} (GeV/#it{c});N",100,0,10);
  truePt[2]  = new TH1D("truePtPrP","Proton (+) truth;p_{T} (GeV/#it{c});N",100,0,10);
  truePt[3]  = new TH1D("truePtPiM","Pion (-) truth;p_{T} (GeV/#it{c});N",100,0,10);
  truePt[4]  = new TH1D("truePtKaM","Kaon (-) truth;p_{T} (GeV/#it{c});N",100,0,10);
  truePt[5]  = new TH1D("truePtPrM","Proton (-) truth;p_{T} (GeV/#it{c});N",100,0,10);

  // Ks and phi truePid distributions
  for(Int_t i=0; i< 3;i++){
    for(Int_t j=0; j< 3;j++){
      truePidKs[i][j] =  new TH3D(Form("truePidKs%s%s",spec[i],spec[j]),Form("K^{0*} truePid for %s-%s;m_{#piK} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N",spec[i],spec[j]),200,0.4,1.4,40,0,10,nbinpol,-1.001,1.001);
      truePidPhi[i][j] =  new TH2D(Form("truePidPhi%s%s",spec[i],spec[j]),Form("#phi truePid for %s-%s;m_{KK} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N",spec[i],spec[j]),100,0.98,1.05,40,0,10);

      for(Int_t k=0; k< 3;k++){
	truePidLc[i][j][k] =  new TH3D(Form("truePidLc%s%s%s",spec[i],spec[j],spec[k]),Form("#Lambda_{c}^{+} truePid for %s-%s-%s;m_{#piKp} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N",spec[i],spec[j],spec[k]),nbinmlc,2.1,2.5,nbinptlc,7,27,nbinpol,0,1.);
	truePidLcbar[i][j][k] =  new TH3D(Form("truePidLcbar%s%s%s",spec[i],spec[j],spec[k]),Form("#overline{#Lambda}_{c}^{-} truePid for %s-%s-%s;m_{#piKp} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N",spec[i],spec[j],spec[k]),nbinmlc,2.1,2.5,nbinptlc,7,27,nbinpol,0,1.);
      }

    }
  }

  trueKs =  new TH3D(Form("trueKs"),Form("K^{0*} true;m_{#piK} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N"),200,0.4,1.4,40,0,10,nbinpol,-1.001,1.001);
  truePhi =  new TH2D(Form("truePhi"),Form("#phi true;m_{KK} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N"),100,0.98,1.05,40,0,10);

  trueLc =  new TH3D(Form("trueLc"),Form("#Lambda_{c}^{+} true;m_{#piKp} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N"),nbinmlc,2.1,2.5,nbinptlc,7,27,nbinpol,0,1.);
  trueLcbar =  new TH3D(Form("trueLcbar"),Form("#overline{#Lambda}_{c}^{-} true;m_{#piKp} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N"),nbinmlc,2.1,2.5,nbinptlc,7,27,nbinpol,0,1);

  mypidLc =  new TH3D(Form("mypidLc"),Form("#Lambda_{c}^{+} true;m_{#piKp} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N"),nbinmlc,2.1,2.5,nbinptlc,7,27,nbinpol,0,1.);
  mypidLcbar =  new TH3D(Form("mypidLcbar"),Form("#Lambda_{c}^{+} true;m_{#piKp} (GeV/#it{c}^2);p_{T} (GeV/#it{c});N"),nbinmlc,2.1,2.5,nbinptlc,7,27,nbinpol,0,1.);

  // define particle types (particle type array)
  particle::AddParticleType("pi+",0.139,1); // 0
  particle::AddParticleType("pi-",0.139,-1); // 1
  particle::AddParticleType("K+",0.493,1); // 2 
  particle::AddParticleType("K-",0.493,-1); // 3
  particle::AddParticleType("p+",0.938,1); // 4 
  particle::AddParticleType("p-",0.938,-1); // 5
  particle::AddParticleType("K0*",0.896,0,5.05e-02); // 6
  particle::AddParticleType("K0bar*",0.896,0,5.05e-02); // 7
  particle::AddParticleType("Phi",1.02,0,0.00426); // 8
  particle::AddParticleType("Delta++",1.232,2,0.118); // 9 
  particle::AddParticleType("Delta--",1.232,-2,0.118);  // 10
  particle::AddParticleType("Lambdac+",2.28646,1,0.008); // 11
  particle::AddParticleType("Lambdacbar-",2.28646,-1,0.008); // 12
  particle::AddParticleType("Lambda1520",1.5195,-1,0.0000156); // 12

  particle d1("pi+");
  particle d2("K+");
  particle d3("p+");
  particle d4("pi-");
  particle d5("K-");
  particle d6("p-");

  particle prong1;
  particle prong2;
  particle prong3;

  particle polarKs("K0*");
  particle polarLc("Lambdac+");

  Int_t charge[] = {1,-1,1,-1,1,-1,0,0,0,2,-2,1,-1};

  particle ppos[20000];
  particle pneg[20000];

  Float_t weightsPos[20000][3];
  Float_t weightsNeg[20000][3];
  Int_t passMyPIDPos[20000][3];
  Int_t passMyPIDNeg[20000][3];

  Int_t npos=0;
  Int_t nneg=0;

  Float_t signal,signalTOF,signalTPC,pt,pz,phi,ptComb,ptComb3prong,invmass;
  Float_t ptd,pzd,phid;

  Float_t priors[3],prob[3];
  Float_t priors2[3][3],prob2[3][3];
  Float_t priors3[3][3][3],prob3[3][3][3];
      
  Int_t iev=-1,id,mother;
  Int_t cev;
  
  TFile *fout = new TFile(Form("step%i.root",step+1),"RECREATE");
  // TTree *treeKs = new TTree("treeKs","treeKs");
  // Float_t ptPair,massPair,ptD1,ptD2,weightD1[3],weightD2[3],weightFill;
  // Int_t isTrue,isTruePid;
  // treeKs->Branch("ptPair",&ptPair,"ptPair/F");
  // treeKs->Branch("massPair",&massPair,"massPair/F");
  // treeKs->Branch("ptPi",&ptD1,"ptPi/F");
  // treeKs->Branch("ptKa",&ptD2,"ptKa/F");
  // treeKs->Branch("weightPi",weightD1,"wightPi[3]/F");
  // treeKs->Branch("weightKa",weightD2,"wightKa[3]/F");
  // treeKs->Branch("weightFill",&weightFill,"wightFill/F");
  // treeKs->Branch("isTruePid",&isTruePid,"isTruePid/I");
  // treeKs->Branch("isTrue",&isTrue,"isTrue/I");
  TH1F *hcentr = new TH1F("hcentr","",100,0,100);

  FILE *flist = fopen("lista","r");
  char namefile[100];
  Float_t weight1[3],weight2[3],weight3[3];
  Float_t ptPi,ptKa,ptPr;

  TH1F *htemp;

  while(fscanf(flist,"%s",namefile)==1){
    TFile *fin = new TFile(namefile);
    printf("file = %s\n",namefile);
    TList *l = (TList *) fin->Get("TOFpid");
    htemp = (TH1F *) l->At(0);
    if(!hcentr) hcentr = new TH1F(*htemp);
    else hcentr->Add(htemp);
    TTree *t = (TTree *) l->At(1);
    Int_t n = t->GetEntries();
    
    for(Int_t i=0;i < n;i++){
      t->GetEvent(i);

      ptPi = t->GetLeaf("ptPi")->GetValue();
      ptKa = t->GetLeaf("ptPi")->GetValue();
      ptPr = t->GetLeaf("ptPi")->GetValue();
      pt = t->GetLeaf("pt")->GetValue();
      invmass = t->GetLeaf("mass")->GetValue();
      weight1[0] = t->GetLeaf("weightPi")->GetValue(0);
      weight1[1] = t->GetLeaf("weightPi")->GetValue(1);
      weight1[2] = t->GetLeaf("weightPi")->GetValue(2);
      weight2[0] = t->GetLeaf("weightKa")->GetValue(0);
      weight2[1] = t->GetLeaf("weightKa")->GetValue(1);
      weight2[2] = t->GetLeaf("weightKa")->GetValue(2);
      weight3[0] = t->GetLeaf("weightPr")->GetValue(0);
      weight3[1] = t->GetLeaf("weightPr")->GetValue(1);
      weight3[2] = t->GetLeaf("weightPr")->GetValue(2);

      Float_t pt1 = Int_t(ptPi/(ptPi+ptKa+ptPr)*nbinPtFrPi);
      Float_t pt2 = Int_t(ptKa/(ptPi+ptKa+ptPr)*nbinPtFrKa);
      Float_t polar = 0;//TMath::Abs(polarLc.GetY());//ptComb3prong/ptot;//(pt2*nbinpol + pt1)*invpollc;
      polar = ((pt1*nbinPtFrKa + pt2 + polar)*nbinY)*normbin;

      Int_t ibinx = priorsLc[0][0][0]->GetXaxis()->FindBin(invmass);
      Int_t ibiny = priorsLc[0][0][0]->GetYaxis()->FindBin(pt);
      Int_t ibinz = priorsLc[0][0][0]->GetZaxis()->FindBin(polar);
      
      for(Int_t ipr=0;ipr<3;ipr++)
	for(Int_t jpr=0;jpr<3;jpr++)
	  for(Int_t kpr=0;kpr<3;kpr++)
	    priors3[ipr][jpr][kpr] = priorsLc[ipr][jpr][kpr]->GetBinContent(ibinx,ibiny,ibinz);
      
      GetProb3(weight1,weight2,weight3,priors3,prob3);

      for(Int_t ipr=0;ipr<3;ipr++)
	for(Int_t jpr=0;jpr<3;jpr++)
	  for(Int_t kpr=0;kpr<3;kpr++){
	    newpriorsLc[ipr][jpr][kpr]->Fill(invmass,pt,polar,prob3[ipr][jpr][kpr]);
	  }
    }
    t->Delete();
    fin->Close();

  }



  printf("Write output\n");
  fout->cd();
  hcentr->Write();
  //if(step==0) treeKs->Write();
  for(Int_t i=0;i<6;i++){
    newpriorsPt[i]->Write();
    truePt[i]->Write();
  }
  for(Int_t i=0;i<3;i++){
    for(Int_t j=0;j<3;j++){
      priorsPhi[i][j]->Write();
      newpriorsKs[i][j]->Write();
      newpriorsPhi[i][j]->Write();
      truePidKs[i][j]->Write();
      truePidPhi[i][j]->Write();
      for(Int_t k=0;k<3;k++){
       	newpriorsLc[i][j][k]->Write();
	truePidLc[i][j][k]->Write();
	newpriorsLcbar[i][j][k]->Write();
	truePidLcbar[i][j][k]->Write();
      }
    }
  }
  trueKs->Write();
  truePhi->Write();
  trueLc->Write();
  trueLcbar->Write();
  mypidLc->Write();
  mypidLcbar->Write();
  fout->Close();
}
Example #5
0
inline void
TrdtrmmUVar1( Orientation orientation, DistMatrix<F>& U )
{
#ifndef RELEASE
    PushCallStack("internal::TrdtrmmUVar1");
    if( U.Height() != U.Width() )
        throw std::logic_error("U must be square");
    if( orientation == NORMAL )
        throw std::logic_error("Orientation must be (conjugate-)transpose");
#endif
    const Grid& g = U.Grid();

    // Matrix views
    DistMatrix<F>
        UTL(g), UTR(g),  U00(g), U01(g), U02(g),
        UBL(g), UBR(g),  U10(g), U11(g), U12(g),
                         U20(g), U21(g), U22(g);
    DistMatrix<F,MD,STAR> d1(g);

    // Temporary distributions
    DistMatrix<F,MC,  STAR> S01_MC_STAR(g);
    DistMatrix<F,VC,  STAR> S01_VC_STAR(g);
    DistMatrix<F,VR,  STAR> U01_VR_STAR(g);
    DistMatrix<F,STAR,MR  > U01AdjOrTrans_STAR_MR(g);
    DistMatrix<F,STAR,STAR> U11_STAR_STAR(g);

    S01_MC_STAR.AlignWith( U );
    S01_VC_STAR.AlignWith( U );
    U01_VR_STAR.AlignWith( U );
    U01AdjOrTrans_STAR_MR.AlignWith( U );

    PartitionDownDiagonal
    ( U, UTL, UTR,
         UBL, UBR, 0 );
    while( UTL.Height() < U.Height() && UTL.Width() < U.Height() )
    {
        RepartitionDownDiagonal 
        ( UTL, /**/ UTR,  U00, /**/ U01, U02,
         /*************/ /******************/
               /**/       U10, /**/ U11, U12,
          UBL, /**/ UBR,  U20, /**/ U21, U22 );

        //--------------------------------------------------------------------//
        U11.GetDiagonal( d1 );
        S01_MC_STAR = U01;
        S01_VC_STAR = S01_MC_STAR;
        U01_VR_STAR = S01_VC_STAR;
        if( orientation == TRANSPOSE )
        {
            DiagonalSolve( RIGHT, NORMAL, d1, U01_VR_STAR );
            U01AdjOrTrans_STAR_MR.TransposeFrom( U01_VR_STAR );
        }
        else
        {
            DiagonalSolve( RIGHT, ADJOINT, d1, U01_VR_STAR );
            U01AdjOrTrans_STAR_MR.AdjointFrom( U01_VR_STAR );
        }
        LocalTrrk( UPPER, F(1), S01_MC_STAR, U01AdjOrTrans_STAR_MR, F(1), U00 );

        U11_STAR_STAR = U11;
        LocalTrmm
        ( RIGHT, UPPER, ADJOINT, UNIT, F(1), U11_STAR_STAR, U01_VR_STAR );
        U01 = U01_VR_STAR;

        LocalTrdtrmm( orientation, UPPER, U11_STAR_STAR );
        U11 = U11_STAR_STAR;
        //--------------------------------------------------------------------//
        d1.FreeAlignments();

        SlidePartitionDownDiagonal
        ( UTL, /**/ UTR,  U00, U01, /**/ U02,
               /**/       U10, U11, /**/ U12,
         /*************/ /******************/
          UBL, /**/ UBR,  U20, U21, /**/ U22 );
    }
#ifndef RELEASE
    PopCallStack();
#endif
}
void CameraCalibrator::calulateAxis(const std::vector<std::string>& filelist)
{
	std::cout << "Processing Axis Calulation" << std::endl << std::endl;

	std::vector<cv::Point3f> objectPs;
	objectPs.push_back(cv::Point3f(0, 0, 0));
	objectPs.push_back(cv::Point3f(0, 2, 2));
	objectPs.push_back(cv::Point3f(2, 0, 2));
	objectPs.push_back(cv::Point3f(2, 2, 0));
	objectPs.push_back(cv::Point3f(2, 0, 0));
	objectPs.push_back(cv::Point3f(0, 0, 2));
	objectPs.push_back(cv::Point3f(0, 2, 0));
	objectPs.push_back(cv::Point3f(2, 2, 2));
	objectPs.push_back(cv::Point3f(4, 0, 0));
	objectPs.push_back(cv::Point3f(0, 4, 0));
	objectPs.push_back(cv::Point3f(0, 0, 4));
	

	for (int i=0; i<filelist.size(); i++) 
	{
		std::cout << "Calculation of Axis for:" << filelist[i] << std::endl;

		//With Function Call
		cv::Mat rvecs33;
		cv::Rodrigues(rvecs[i],rvecs33);
		std::vector<cv::Point2f> imagePs;

		cv::projectPoints(objectPs, rvecs33, tvecs[i], cameraMatrix, distCoeffs, imagePs);

		cv::Point2d a(imagePs[0].x,imagePs[0].y);
		cv::Point2d b(imagePs[1].x,imagePs[1].y);
		cv::Point2d c(imagePs[2].x,imagePs[2].y);
		cv::Point2d d(imagePs[3].x,imagePs[3].y);
		cv::Point2d e(imagePs[4].x,imagePs[4].y);
		cv::Point2d f(imagePs[5].x,imagePs[5].y);
		cv::Point2d g(imagePs[6].x,imagePs[6].y);
		cv::Point2d h(imagePs[7].x,imagePs[7].y);
		cv::Point2d x(imagePs[8].x,imagePs[8].y);
		cv::Point2d y(imagePs[9].x,imagePs[9].y);
		cv::Point2d z(imagePs[10].x,imagePs[10].y);
								
		cv::Mat udImUsingFn = cv::imread(filelist[i]);

		//Drwaing Axis
		cv::line(udImUsingFn, a, x, CV_RGB(0, 0, 255), 3, 8, 0);
		cv::line(udImUsingFn, a, y, CV_RGB(0, 255, 0), 3, 8, 0);
		cv::line(udImUsingFn, a, z, CV_RGB(255, 0, 0), 3, 8, 0);

		//Drwaing Rectangle
		cv::line(udImUsingFn, a, e, CV_RGB(0, 255, 255), 1, 8, 0);
		cv::line(udImUsingFn, a, f, CV_RGB(0, 255, 255), 1, 8, 0);
		cv::line(udImUsingFn, a, g, CV_RGB(0, 255, 255), 1, 8, 0);
		cv::line(udImUsingFn, e, c, CV_RGB(0, 255, 255), 1, 8, 0);
		cv::line(udImUsingFn, e, d, CV_RGB(0, 255, 255), 1, 8, 0);
		cv::line(udImUsingFn, g, b, CV_RGB(0, 255, 255), 1, 8, 0);
		cv::line(udImUsingFn, g, d, CV_RGB(0, 255, 255), 1, 8, 0);
		cv::line(udImUsingFn, f, b, CV_RGB(0, 255, 255), 1, 8, 0);
		cv::line(udImUsingFn, f, c, CV_RGB(0, 255, 255), 1, 8, 0);
		cv::line(udImUsingFn, h, b, CV_RGB(0, 255, 255), 1, 8, 0);
		cv::line(udImUsingFn, h, c, CV_RGB(0, 255, 255), 1, 8, 0);
		cv::line(udImUsingFn, h, d, CV_RGB(0, 255, 255), 1, 8, 0);

				
		//Store the Axis in Undistorted Images in Folder
		std::stringstream fileNameAxisUnDistortUsingFnOutput;
		fileNameAxisUnDistortUsingFnOutput << IMG_OUT_AXIS_DRAWING << "savasci_doshi_Undistort_WithFn" << i << ".jpg";
		cv::imwrite(fileNameAxisUnDistortUsingFnOutput.str(),udImUsingFn);

		 
		//Without Function Call	
		cv::Mat tvecs31= tvecs[i];

		//cv::Mat rvecs33;
		cv::Rodrigues(rvecs[i],rvecs33);
		
		cv::Mat extrinsic = (cv::Mat_<double>(3, 4) <<	rvecs33.at<double>(0,0), rvecs33.at<double>(0,1), rvecs33.at<double>(0,2), tvecs31.at<double>(0),
														rvecs33.at<double>(1,0), rvecs33.at<double>(1,1), rvecs33.at<double>(1,2), tvecs31.at<double>(1),
														rvecs33.at<double>(2,0), rvecs33.at<double>(2,1), rvecs33.at<double>(2,2), tvecs31.at<double>(2));
		
		cv::Mat instrinsic=cameraMatrix;

		cv::Mat P=instrinsic*extrinsic;

		//Drawing the 3 coordinate axis
		cv::Mat p1 = (cv::Mat_<double>(4, 1) << 0,0,0,1);
		cv::Mat imagep1=P*p1;

		cv::Mat p2 = (cv::Mat_<double>(4, 1) << 4,0,0,1);
		cv::Mat imagep2=P*p2;

		cv::Mat p3 = (cv::Mat_<double>(4, 1) << 0,4,0,1);
		cv::Mat imagep3=P*p3;
				
		cv::Mat p4 = (cv::Mat_<double>(4, 1) << 0,0,4,1);
		cv::Mat imagep4=P*p4;

		cv::Mat im = cv::imread(filelist[i]);

		cv::Point2d o1(imagep1.at<double>(0)/imagep1.at<double>(2),imagep1.at<double>(1)/imagep1.at<double>(2));
		cv::Point2d x1(imagep2.at<double>(0)/imagep2.at<double>(2),imagep2.at<double>(1)/imagep2.at<double>(2));
		cv::Point2d y1(imagep3.at<double>(0)/imagep3.at<double>(2),imagep3.at<double>(1)/imagep3.at<double>(2));
		cv::Point2d z1(imagep4.at<double>(0)/imagep4.at<double>(2),imagep4.at<double>(1)/imagep4.at<double>(2));


		cv::line(im, o1, x1, CV_RGB(0, 0, 255), 3, 8, 0);
		cv::line(im, o1, y1, CV_RGB(0, 255, 0), 3, 8, 0);
		cv::line(im, o1, z1, CV_RGB(255, 0, 0), 3, 8, 0);
		
		//Drawing the cube
		cv::Mat rectp1 = P*(cv::Mat_<double>(4, 1) << 0,0,0,1);
		cv::Mat rectp2 = P*(cv::Mat_<double>(4, 1) << 0,2,2,1);
		cv::Mat rectp3 = P*(cv::Mat_<double>(4, 1) << 2,0,2,1);
		cv::Mat rectp4 = P*(cv::Mat_<double>(4, 1) << 2,2,0,1);

		cv::Mat rectp5 = P*(cv::Mat_<double>(4, 1) << 2,0,0,1);
		cv::Mat rectp6 = P*(cv::Mat_<double>(4, 1) << 0,0,2,1);
		cv::Mat rectp7 = P*(cv::Mat_<double>(4, 1) << 0,2,0,1);
		cv::Mat rectp8 = P*(cv::Mat_<double>(4, 1) << 2,2,2,1);
		
		cv::Point2d a1(rectp1.at<double>(0)/rectp1.at<double>(2),rectp1.at<double>(1)/rectp1.at<double>(2));
		cv::Point2d b1(rectp2.at<double>(0)/rectp2.at<double>(2),rectp2.at<double>(1)/rectp2.at<double>(2));
		cv::Point2d c1(rectp3.at<double>(0)/rectp3.at<double>(2),rectp3.at<double>(1)/rectp3.at<double>(2));
		cv::Point2d d1(rectp4.at<double>(0)/rectp4.at<double>(2),rectp4.at<double>(1)/rectp4.at<double>(2));
		cv::Point2d e1(rectp5.at<double>(0)/rectp5.at<double>(2),rectp5.at<double>(1)/rectp5.at<double>(2));
		cv::Point2d f1(rectp6.at<double>(0)/rectp6.at<double>(2),rectp6.at<double>(1)/rectp6.at<double>(2));
		cv::Point2d g1(rectp7.at<double>(0)/rectp7.at<double>(2),rectp7.at<double>(1)/rectp7.at<double>(2));
		cv::Point2d h1(rectp8.at<double>(0)/rectp8.at<double>(2),rectp8.at<double>(1)/rectp8.at<double>(2));
				
		cv::line(im, a1, e1, CV_RGB(0, 255, 255), 1, 8, 0);
		cv::line(im, a1, f1, CV_RGB(0, 255, 255), 1, 8, 0);
		cv::line(im, a1, g1, CV_RGB(0, 255, 255), 1, 8, 0);
		cv::line(im, e1, c1, CV_RGB(0, 255, 255), 1, 8, 0);
		cv::line(im, e1, d1, CV_RGB(0, 255, 255), 1, 8, 0);
		cv::line(im, g1, b1, CV_RGB(0, 255, 255), 1, 8, 0);
		cv::line(im, g1, d1, CV_RGB(0, 255, 255), 1, 8, 0);
		cv::line(im, f1, b1, CV_RGB(0, 255, 255), 1, 8, 0);
		cv::line(im, f1, c1, CV_RGB(0, 255, 255), 1, 8, 0);
		cv::line(im, h1, b1, CV_RGB(0, 255, 255), 1, 8, 0);
		cv::line(im, h1, c1, CV_RGB(0, 255, 255), 1, 8, 0);
		cv::line(im, h1, d1, CV_RGB(0, 255, 255), 1, 8, 0);

		//cv::rectangle(im, a1, b1, CV_RGB(0, 255, 255), 1, 8, 0);
		//cv::rectangle(im, a1, c1, CV_RGB(0, 255, 255), 1, 8, 0);
		//cv::rectangle(im, a1, d1, CV_RGB(0, 255, 255), 1, 8, 0);
		//cv::rectangle(im, b1, c1, CV_RGB(0, 255, 255), 1, 8, 0);
		//cv::rectangle(im, b1, d1, CV_RGB(0, 255, 255), 1, 8, 0);
		//cv::rectangle(im, c1, d1, CV_RGB(0, 255, 255), 1, 8, 0);

		//cv::rectangle(udIm, a1, b1, CV_RGB(0, 255, 255), 1, 8, 0);
		//cv::rectangle(udIm, a1, c1, CV_RGB(0, 255, 255), 1, 8, 0);
		//cv::rectangle(udIm, a1, d1, CV_RGB(0, 255, 255), 1, 8, 0);
		//cv::rectangle(udIm, b1, c1, CV_RGB(0, 255, 255), 1, 8, 0);
		//cv::rectangle(udIm, b1, d1, CV_RGB(0, 255, 255), 1, 8, 0);
		//cv::rectangle(udIm, c1, d1, CV_RGB(0, 255, 255), 1, 8, 0);
		
		//Store the Axis in Original Images in Folder
		std::stringstream fileNameAxisOriginalOutput;
		fileNameAxisOriginalOutput << IMG_OUT_AXIS_DRAWING << "savasci_doshi_Original_WithoutFn" << i << ".jpg";
		cv::imwrite(fileNameAxisOriginalOutput.str(),im);
	}
}
Example #7
0
int  main( int  argc, char ** argv )
{
    // 1. Angle brackets handling bug
    // As of now a2, a3 and a4 will be skipped

    int  a1 = i < 7 ? i : 7;
    int  a2 = 8;
    int  a3 = 9;
    int  a4 = p->data;
    int  a5 = 8;


    // 2. Function pointer decl bug
    // As of now a6 will be skipped

    int ( *a6 )( int, char ** ) = &main;


    // 3. Wrong prototype will be written
    // As of now prototype will be ( SomeType ( p )( int ) )

    int  a7( short ( *p )( int ) );


    // 4. DECL_IGNORE bug
    // As of now a8 will be skipped

    if ( argc > 0 )
        return 0;

    short a8 = i;


    // 5. Local variables support
	// As of now all the identifiers below are either reported as prototypes,
	// or not recognized at all
	// The comments on the right specify which kind of tag should be generated

    const char *b1( "uuu" );                //variable
    int b2( int ooo, const char* o );       //prototype
    int b3( int( 7 ) );                     //variable
    int c1( a >> ooo );                     //variable
    int c2( int * h );                      //prototype
    int c3( std::map<int>( 9 ) );           //variable
    int c4( std::map<int> a );              //prototype
    int c5( map<int>  & a );                //prototype
    int c6( ooo & a );                      //prototype
    int c7( int & a );                      //prototype
    int c8( map<int> a );                   //prototype
    int c9( int a );                        //prototype
    ind d1( a * 2 );                        //variable
    ind d2( "a" * 2 );                      //variable
    int d3( *j );                           //variable
    int f1( SomeType (*p)( int ) );         //prototype
    SomeType (*f2)( int o );                //variable
    int f3( std::map<int> & a );            //prototype
    int g1( SomeType a );                   //prototype
	// As of now, the signature of h1 will be "( int a = R )",
	// 'R' is to be replaced by something clearer to denote a
	// string literal
    char h1( const char *a = "a" );         //prototype
    int h2();                               //prototype
    char h3( double );                      //prototype
    int h4( h u );                          //prototype
    int (*p1)( int o );                     //variable
    int v4( iii( 'o' ) );                   //variable
    int v5( iii( o ) );                     //variable
    int v6( int (*p)( int ) );              //prototype
    int v7( 89 );                           //variable
    int v8( ooo );                          //variable
    // __ARGS(x) is a compatibility macro which optionally
	// expands to x when prototypes are supported, so
	// w1 should be parsed as a prototype
    int w1 __ARGS (( int a ));              //prototype
    int w2 (( a - 5 ) / 6 );                //variable
    int x1( a.b );                          //variable
    int x2( a->b );                         //variable
    int x3( NS::a  b );                     //prototype
    int x4( a ^ b );                        //variable 
    int x5( a ^ 6 );                        //variable
    int x6( a | b );                        //variable
	// As of now, x7 is not recognized at all; it should
	// give a variable tag but it's tricky to get it
	// right because of '&' which suggests a prototype,
	// so for now let's just ignore it
    //int x7( a & b & c );                  //variable
    int x8( a & b & 2 );                    //variable
    int x9( a && b );                       //variable
}
Example #8
0
int main()
{
	// test if two ints are equal or not
	cout << "***  Integers Tests  ***" << endl;

	int leftInts[4] = { 1, 2, -1, -1 }; // lhs integers used for testing equality
	int rightInts[4] = { 1, 4, 1, -1 }; // rhs integers used for testing equality
	for (int a = 0; a < 4; a++)
	{
		cout << "Integers: " << leftInts[a] << " and " << rightInts[a] << " are "
			<< (isEqualTo(leftInts[a], rightInts[a]) ? "equal" : "\"NOT\" equal") << '\n';
	}

	// test if two chars are equal or not
	cout << "\n\n***  Chars Tests  ***" << endl;
	char leftChars[4] = { 'a', 'a', 'c', 'c' }; // lhs chars used for testing equality
	char rightChars[4] = { 'a', 'c', 'a', 'c' }; // rhs chars used for testing equality
	for (int a = 0; a < 4; a++)
	{
		cout << "Characters: " << leftChars[a] << " and " << rightChars[a] << " are "
			<< (isEqualTo(leftChars[a], rightChars[a]) ? "equal" : "\"NOT\" equal") << '\n';
	}

	// test if two doubles are equal or not
	cout << "\n\n***  Double Tests  ***" << endl;
	double leftDoubles[4] = { 2.2, 2.2, -2.2, -2.2 }; // lhs integers used for testing equality
	double rightDoubles[4] = { 2.2, 2.3, 2.2, -2.2 }; // rhs integers used for testing equality
	for (int a = 0; a < 4; a++)
	{
		cout << "Double numbers: " << leftDoubles[a] << " and " << rightDoubles[a] << " are "
			<< (isEqualTo(leftDoubles[a], rightDoubles[a]) ? "equal" : "\"NOT\" equal") << '\n';
	}

	// test if two Complex objects are equal
	cout << "\n\n***  Complex Tests  ***" << endl;
	Complex a(10, 5); // Complex objects used
	Complex a1(10, 5); // for testing equality
	cout << "Class objects: " << a << " and " << a1 << " are "
		<< (isEqualTo(a, a1) ? "equal" : "\"NOT\" equal");

	Complex b(10, 5); // Complex objects used
	Complex b1(10, 54); // for testing equality
	cout << "\nClass objects: " << b << " and " << b1 << " are "
		<< (isEqualTo(b, b1) ? "equal" : "\"NOT\" equal");

	Complex c(10, -5); // Complex objects used
	Complex c1(10, 5); // for testing equality
	cout << "\nClass objects: " << c << " and " << c1 << " are "
		<< (isEqualTo(c, c1) ? "equal" : "\"NOT\" equal");

	Complex d(-10, -5); // Complex objects used
	Complex d1(-10, -5); // for testing equality
	cout << "\nClass objects: " << d << " and " << d1 << " are "
		<< (isEqualTo(d, d1) ? "equal" : "\"NOT\" equal");

	//test if two strings are equal or not
	cout << "\n\n\n***  String Tests  ***" << endl;
	string leftStrings[4] = { "abcdefg", "abcdefg", "-abcdefg", "-abcdefg" }; // lhs chars used for testing equality
	string rightStrings[4] = { "abcdefg", "abcdefh", "abcdefg", "-abcdefg" }; // rhs chars used for testing equality
	for (int a = 0; a < 4; a++)
	{
		cout << "String objects: " << leftStrings[a] << " and " << rightStrings[a] << " are "
			<< (isEqualTo(leftStrings[a], rightStrings[a]) ? "equal" : "\"NOT\" equal") << '\n';
	}

	//test if two dates are equal or not
	cout << "\n\n***  Date Tests  ***";
	Date dayA(2, 31, 2016); // create date object
	Date dayB(2, 31, 2016); // create date object
	cout << "\nDate objects: " << dayA << " and " << dayB << " are "
		<< (isEqualTo(dayA, dayB) ? "equal" : "\"NOT\" equal");

	Date dayC(-2, 13, 2016); // create date object
	Date dayD(2, 14, 2016); // create date object
	cout << "\nDate objects: " << dayC << " and " << dayD << " are "
		<< (isEqualTo(dayC, dayD) ? "equal" : "\"NOT\" equal");

	Date dayE(-2, 13, 2016); // create date object
	Date dayF(2, 13, 2016); // create date object
	cout << "\nDate objects: " << dayE << " and " << dayF << " are "
		<< (isEqualTo(dayE, dayF) ? "equal" : "\"NOT\" equal");

	Date dayG(-2, 13, 2016); // create date object
	Date dayH(2, 31, 2016); // create date object
	cout << "\nDate objects: " << dayG << " and " << dayH << " are "
		<< (isEqualTo(dayG, dayH) ? "equal" : "\"NOT\" equal") << '\n';

	cout << endl << endl;
	return 0;
} // end main
Example #9
0
int
tDateTime6( void )
{
    // void setTm( void ) - NO TEST (tested by other test)

  {   
    // int compare( const DateTime & two ) 

    DateTime	d1( "2/17/95 11:30:30" );
    DateTime	d2( "2/17/95 11:30:30" );

    if( d1.compare( d2 ) ) ERROR;

    d1.setTimeZone();

    if( ! (d1.compare( d2 ) < 0 ) ) ERROR;

    d2.setTimeZone();

    if( d1.compare( d2 ) ) ERROR;

    d1.addMin();

    if( ! ( d1.compare( d2 ) > 0 ) ) ERROR;
    
  }

  {   
    // operator time_t()

    DateTime	dt( "2/17/95 11:30:30" );

    if( (time_t)dt != dt.getTimeT() ) ERROR;

  }

  {   
    // operator const char *()

    DateTime	dt( "2/17/95 11:30:30" );

    char    dtBuf[50];

    dt.getString( dtBuf );

    if( strcmp( (const char *)dt, dtBuf ) ) ERROR;
    
  }

  {   
    // operator ==( const DateTime & two )

    DateTime	d1( "2/17/95 11:30:30" );
    DateTime	d2( "2/17/95 11:30:30" );

    if( ! (d1 == d2) ) ERROR;
    d2.addSec();
    if( d1 == d2 ) ERROR;
    
  }

  {   
    // operator !=( const DateTime & two )
    DateTime	d1( "2/17/95 11:30:30" );
    DateTime	d2( "2/17/95 11:30:30" );

    if( d1 != d2 ) ERROR;
    d2.addSec();
    if( ! (d1 != d2) ) ERROR;
    
  }

  {   
    // const char * getClassName(void) - NO TEST NEEDED

  }

  {   
    // Bool 	     good( void ) - NO TEST (tested by setValid());

  }

  {   
    // const char * error( void ) - NO TEST NEEDED
    
  }
  return( 0 );
}
Example #10
0
int main (int argc, char** argv)
{

int lives=3;

  int width = 1400;
  int height = 715;
  int numBlocks;

  points=10;
  /*float v[][6] = {
    2.5, -8.6, 3, 0.5,0,1,
    4, -7, 1, 4,0,1,
    5.5, -8.6, 3, 0.5,0,1,
    2.5, -5.5, 2, 1,1,1,
    4, -5.5, 2, 1,1,1,

    5.5, -5.5, 2, 1,1,1,
    4, -9.5, 2.5, 1.5, 2,2,
    4, -10.5, 1, 4, 0, 3,
    9, -9, 4, 4, 0, 3
  };*/


  GLFWwindow* window = initGLFW(width, height);

 initGL (window, width, height);
 float tm=glfwGetTime();
  elements e;
  while (glfwGetTime()-tm<=5 and mode==0)
  {
    e.menu();
    glfwSwapBuffers(window);
    glfwPollEvents();
  //  cout<<mode;  
  }

if(mode==0)
  mode=1;

if(mode==1){
  numBlocks= 12;
  groundLevel=-15;
}

dummy d1(0-2,12);

dummy d2(4-2,12);

dummy d3(8-2,12);
float v1[][6] = {
    2, -9.5-3, 3, 0.5,0,3,
    5, -9-3, 4, 0.5,0,3,

    8, -8.5-3, 5, 0.5,0,3,
    11, -8-3, 6, 0.5,0,3,
    
    2, -8-3, 1, 2,0,1,
    5, -7.0-3, 1, 2,0,1,
    
    8, -6.0-3, 1, 2,0,1,
    11, -5-3, 1, 2,0,1,
    
    2, -7-3, 1, 1,0,2,
    5, -6.0-3, 1, 1,0,2,
    
    8, -5.0, 1, 1,0,2,
    11, -4, 1, 1,0,2,
    
   // 2, -8+6, 1, 2,0,1,
    //5, -7+6, 1, 2,0,1,
    
   // 2,-8+9,1,1,0,2,
    //5, -7+9, 1, 1,0,2
};

if(mode==2)
{
  numBlocks=14;
  groundLevel=-15;
  
}


    float v2[][6] = {
    //0,-14.5,5,3,0,3,//hill
    //0,-11,1,1,1,4,//ball
    //7.5,groundLevel+4*2,1,5,0,1,
    2+4, -9.5-3, 3, 0.5,0,3,
    5+4, -9-3, 4, 0.5,0,3,
    8+4, -8.5-3, 5, 0.5,0,3,
    11+4, -8-3, 6, 0.5,0,3,
    
    2+4, -8-3, 1, 2,0,1,
    5+4, -7.0-3, 1, 2,0,1,
    
    8+4, -6.0-3, 1, 2,0,1,
    11+4, -5-3, 1, 2,0,1,

    2+4, -7-3, 1, 1,0,2,
    5+4, -6.0-3, 1, 1,0,2,
    
    2+4, -7-3, 1, 1,0,2,
    5+4, -6.0-3, 1, 1,0,2,
    
      
    8+4, -5.0, 1, 1,0,2,
    11+4, -4, 1, 1,0,2
   
};




 
  double last_update_time = glfwGetTime(), current_time;
  canon c;
  bird b(c.x-2, c.y-2);

  speedy speedo;
  vector<block> arr;

  for(int i=0; i<numBlocks;++i){
    if(mode==1){
    block a(v1[i][0], v1[i][1], v1[i][2], v1[i][3], v1[i][4], v1[i][5]);
   arr.push_back(a);
 }
    
    if(mode==2){
    block a(v2[i][0], v2[i][1], v2[i][2], v2[i][3], v2[i][4], v2[i][5]);
    arr.push_back(a);
  }

  }
  e.modeupdate();

  arr[1].fire(scale*2);
  while (!glfwWindowShouldClose(window) or glfwGetTime()-tm>=0.08 ) {

    // OpenGL Draw commands

  tm=glfwGetTime(); 


    e.draw();

    if(shoot == 1) {
      b.fire(boost, rectangle_rotation);
      shoot = 0;
    }

     c.draw();
     b.draw();
    

    for(int i=0; i<numBlocks;++i){
      bool flag=false;
     // if(i==1)
    //  cout<<i<<" "<<arr[i].vy<<" "<<arr[i].fall<<endl;
      for(int j=0; j<numBlocks;++j) {
        //if(i==1 and j==4)
        //cout<<arr[i].checkBelow(arr[j])<<" "<<;
        if(arr[i].checkBelow(arr[j])==true and i!=j){
          flag=true;
          
           //cout<<i<<" "<<j<<endl;

          //  if(arr[j].t==2 && arr[i].t==1) arr[j].lives--;
        }
        else if(arr[i].checkBelow(arr[j])==false and i!=j)
            {
                         }

      }
      if(flag==false)
        arr[i].fall=1;
      else arr[i].fall = 0,arr[i].vy=0;
      if(i==0)
        arr[i].fall = 0,arr[i].vy=0;
      arr[i].draw();
        

    }

    for(int i=4; i<numBlocks;++i) {
      for(int j=0; j<numBlocks;++j) {
        if(arr[i].checkCollision(arr[j]) && i!=j) {
         if(arr[j].type==1 && arr[i].type==4)
          arr[i].vx = arr[j].vx = (arr[i].vx+arr[j].vx)/2;

         if(arr[j].type==4&& arr[i].type==1)
          arr[i].vx = arr[j].vx = (arr[i].vx+arr[j].vx)/2;
          if(arr[j].type==1 && arr[i].type==1) {
          arr[i].vx = arr[j].vx = (arr[i].vx+arr[j].vx)/2;
         // arr[i].vy = arr[j].vy = (arr[i].vy+arr[j].vy)/2;
        }
   //     else if(arr[j].type == 3) {
          //cout<<"hi"<<endl;
    //      arr[i].vx = -coeff*arr[i].vx;
     // }
    }
    }
  }


    int hit,diff;

    for(int i=0; i<numBlocks;++i) {
      if(b.checkCollision(arr[i].x, arr[i].y, arr[i].h, arr[i].w, arr[i].alive))
      {
        if(arr[i].type == 2) {
          points+=10;
          arr[i].alive = false;
        }
        if(arr[i].type == 1 or arr[i].type==4) {
          arr[i].fire(scale*2);
        }
        if(arr[i].type==3)
          lives--;
        break;
      }
    }

    /*if(arr[i].t==2) {

      arr[i].lives=0;
      points+=arr[i].score;

      }*/
    /*  hit=arr[i].getLayer();
    //arr[i].fire(1);
    for(int j=0; j<numBlocks;++j){
    diff=(arr[j].getLayer()-hit);
    if(diff==0)
    arr[j].fire(scale*1.0);
    else if (diff==1) 
    arr[j].fire(scale*0.5);
    else if (diff==2) 
    arr[j].fire(scale*0.2);
    }
    break;  */
      //cout<<c.x<<" "<<c.y<<" "<<b.x<<" "<<b.y<<endl;  


    speedo.draw();

    if(lives==0)
      break;
    if(lives==1)
      d1.draw();
    if(lives==2){
      d1.draw();
      d2.draw();
    }
    if(lives==3){
    d1.draw();
    d2.draw();
    d3.draw();  
    }

    // Swap Frame Buffer in double buffering
    glfwSwapBuffers(window);

    // Poll for Keyboard and mouse events
    glfwPollEvents();

    // Control based on time (Time based transformation like 5 degrees rotation every 0.5s)
    current_time = glfwGetTime(); // Time in seconds
    if ((current_time - last_update_time) >= 0.5) { // atleast 0.5s elapsed since last frame
      // do something every 0.5 seconds ..
      last_update_time = current_time;
    }


  }
  cout<<"Score="<<points<<endl;;
    
  glfwTerminate();
  exit(EXIT_SUCCESS);
}
 Real AnalyticTwoAssetBarrierEngine::put() const {
     CumulativeNormalDistribution nd;
     return strike()*std::exp(-riskFreeRate()*residualTime())*nd(-d2())-underlying1()*nd(-d1());
 }
 Real AnalyticTwoAssetBarrierEngine::d3() const {
     return d1()+ (2*rho()*std::log(barrier()/underlying2()))/(volatility2()*std::sqrt(residualTime()));
 }
 Real AnalyticTwoAssetBarrierEngine::d2() const {
     return d1() - volatility1()*std::sqrt(residualTime());
 }
Example #14
0
// Collision detection for rotated rectangles
k3d::vec2 collide(k3d::vec2 pos1, const k3d::vec2 & hw1, const k3d::vec2 & v1,
                  const k3d::vec2 & pos2, const k3d::vec2 & hw2, const k3d::vec2 & v2, bool & collided)
{
    k3d::vec2 vn1(-v1.y, v1.x);
    k3d::vec2 a1((pos1 + (hw1.x*v1)) - (hw1.y*vn1));
    k3d::vec2 b1((pos1 + (hw1.x*v1)) + (hw1.y*vn1));
    k3d::vec2 c1((pos1 - (hw1.x*v1)) + (hw1.y*vn1));
    k3d::vec2 d1((pos1 - (hw1.x*v1)) - (hw1.y*vn1));

    k3d::vec2 vn2(-v2.y, v2.x);
    k3d::vec2 a2((pos2 + (hw2.x*v2)) - (hw2.y*vn2));
    k3d::vec2 b2((pos2 + (hw2.x*v2)) + (hw2.y*vn2));
    k3d::vec2 c2((pos2 - (hw2.x*v2)) + (hw2.y*vn2));
    k3d::vec2 d2((pos2 - (hw2.x*v2)) - (hw2.y*vn2));

    collided = true;

    if (intersect(a1, b1, a2, b2)) {
        // TODO check if it is enough to go back that distance for the 1st 2 cases (corners) here
        if (intersect(a1, b1, b2, c2)) { //corner
            return pos1 + dist_point_to_line(b2, a1, b1)*((v2 + vn2).normalize());
        }
        if (intersect(a1, b1, a2, d2)) { //corner
            return pos1 + dist_point_to_line(a2, a1, b1)*((v2 - vn2).normalize());
        }
        if (intersect(b1, c1, a2, b2)) {
            return pos1 + dist_point_to_line(b1, a2, b2)*v2;
        }
        if (intersect(a1, d1, a2, b2)) {
            return pos1 + dist_point_to_line(a1, a2, b2)*v2;
        }
        if (intersect(b1, c1, a2, d2)) {
            //return pos1 + a2 - b1; // MAYBE THIS IS BETTER ?
            // FIXME max is actually incorrect here, it should be a weighted sum based on where a2b2 intersects a1b1
            return pos1 - max(dist_point_to_line(a1, a2, d2), dist_point_to_line(b1, a2, d2))*vn2;
        }
        if (intersect(a1, d1, b2, c2)) {
            // FIXME max is actually incorrect here, it should be a weighted sum based on where a2b2 intersects a1b1
            return pos1 + max(dist_point_to_line(a1, b2, c2), dist_point_to_line(b1, b2, c2))*vn2;
        }
    }

    if (intersect(a1, b1, b2, c2)) {
        // a1,b1 and a2,b2 already covered
        // TODO check if it is enough to go back that distance for the 1st case here (corner)
        if (intersect(a1, b1, c2, d2)) { //corner
            return pos1 + dist_point_to_line(c2, a1, b1)*((vn2-v2).normalize());
        }
        if (intersect(b1, c1, b2, c2)) {
            return pos1 + dist_point_to_line(b1, b2, c2)*vn2;
        }
        if (intersect(a1, d1, b2, c2)) {
            return pos1 + dist_point_to_line(a1, b2, c2)*vn2;
        }
        if (intersect(b1, c1, a2, b2)) {
            // FIXME max is actually incorrect here, it should be a weighted sum based on where b2c2 intersects a1b1
            return pos1 + max(dist_point_to_line(b1, a2, b2), dist_point_to_line(a1, a2, b2))*v2;
        }
        if (intersect(a1, d1, c2, d2)) {
            // FIXME max is actually incorrect here, it should be a weighted sum based on where b2c2 intersects a1b1
            return pos1 - max(dist_point_to_line(b1, c2, d2), dist_point_to_line(a1, c2, d2))*v2;
        }
    }

    if (intersect(a1, b1, c2, d2)) {
        // a1,b1 and b2,c2 already covered
        // TODO check if it is enough to go back that distance for the 1st case here (corner)
        if (intersect(a1, b1, a2, d2)) {
            return pos1 + dist_point_to_line(d2, a1, b1)*((-1.0*v2)-vn2);
        }
        if (intersect(b1, c1, c2, d2)) {
            return pos1 - dist_point_to_line(b1, c2, d2)*v2;
        }
        if (intersect(a1, d1, c2, d2)) {
            return pos1 - dist_point_to_line(a1, c2, d2)*v2;
        }
        if (intersect(b1, c1, b2, c2)) {
            // FIXME see above fixme's
            return pos1 + max(dist_point_to_line(b1, b2, c2), dist_point_to_line(a1, b2, c2))*vn2;
        }
        if (intersect(a1, d1, a2, d2)) {
            // FIXME see above fixme's
            return pos1 - max(dist_point_to_line(a1, d2, a2), dist_point_to_line(b1, d2, a2))*vn2;
        }
    }

    if (intersect(a1, b1, d2, a2)) {
        // a1,b1 and c2,d2 already covered and a1,b1 and a2,b2 also already covered
        if (intersect(b1, c1, d2, a2)) {
            return pos1 - dist_point_to_line(b1, d2, a2)*vn2;
        }
        if (intersect(a1, d1, d2, a2)) {
            return pos1 - dist_point_to_line(a1, d2, a2)*vn2;
        }
        if (intersect(b1, c1, c2, d2)) {
            // FIXME see above fixme's
            return pos1 - max(dist_point_to_line(b1, c2, d2), dist_point_to_line(a1, c2, d2))*v2;
        }
        if (intersect(a1, d1, a2, b2)) {
            // FIXME see above fixme's
            return pos1 + max(dist_point_to_line(a1, a2, b2), dist_point_to_line(b1, a2, b2))*v2;
        }
    }

    if (intersect(b1, c1, a2, b2)) {
        return pos1 + dist_point_to_line(b1, a2, b2)*v2;
    }
    if (intersect(b1, c1, b2, c2)) {
        return pos1 + dist_point_to_line(b1, b2, c2)*vn2;
    }
    if (intersect(b1, c1, c2, d2)) {
        return pos1 - dist_point_to_line(b1, c2, d2)*v2;
    }
    if (intersect(b1, c1, d2, a2)) {
        return pos1 - dist_point_to_line(b1, d2, a2)*vn2;
    }

    if (intersect(a1, d1, a2, b2)) {
        return pos1 + dist_point_to_line(a1, a2, b2)*v2;
    }
    if (intersect(a1, d1, b2, c2)) {
        return pos1 + dist_point_to_line(a1, b2, c2)*vn2;
    }
    if (intersect(a1, d1, c2, d2)) {
        return pos1 - dist_point_to_line(a1, c2, d2)*v2;
    }
    if (intersect(a1, d1, d2, a2)) {
        return pos1 - dist_point_to_line(a1, d2, a2)*vn2;
    }

    collided = false;
    return pos1;
}
Example #15
0
	void test_objects()
	{
		std::cout << "- Data Object" << std::endl;
		set_context(false);

		{
			std::cout << "-- With Triggers Full API" << std::endl;
			{
				cache().reset();
				cppcms::triggers_recorder tr(cache());
				mydata d(1,2);
				std::set<std::string> t1,t2;
				t1.insert("k1");
				t2.insert("k2");
				cache().store_frame("foo","bar",t1);
				cache().store_data("dat",d,t2);
				TEST(tr.detach().size()==4);
			}
			{
				cache().reset();
				cppcms::triggers_recorder tr(cache());
				mydata d;
				std::string tmp;
				TEST(cache().fetch_frame("foo",tmp));
				TEST(cache().fetch_data("dat",d));
				TEST(d.x==1  && d.y==2);
				TEST(tmp=="bar");
				std::set<std::string> tg=tr.detach();
				TEST(tg.size()==4);
				TEST(tg.count("foo")==1);
				TEST(tg.count("dat")==1);
				TEST(tg.count("k1")==1);
				TEST(tg.count("k2")==1);
			}
			{
				cache().reset();
				cppcms::triggers_recorder tr(cache());
				mydata d;
				std::string tmp;
				TEST(cache().fetch_frame("foo",tmp,true));
				TEST(cache().fetch_data("dat",d,true));
				TEST(d.x==1  && d.y==2);
				TEST(tmp=="bar");
				TEST(tr.detach().size()==0);
			}
			{
				cache().reset();
				cppcms::triggers_recorder tr(cache());
				mydata d(4,5);
				cache().store_frame("foo","baz",-1);
				cache().store_data("dat",d,-1);
				TEST(tr.detach().size()==2);
			}
			{
				cache().reset();
				cppcms::triggers_recorder tr(cache());
				mydata d;
				std::string tmp;
				TEST(cache().fetch_frame("foo",tmp));
				TEST(cache().fetch_data("dat",d));
				TEST(d.x==4  && d.y==5);
				TEST(tmp=="baz");
				std::set<std::string> tg=tr.detach();
				TEST(tg.size()==2);
				TEST(tg.count("foo")==1);
				TEST(tg.count("dat")==1);
			}
		}
		cache().clear();
		{
			std::cout << "-- Without Triggers" << std::endl;
			{
				cache().reset();
				cppcms::triggers_recorder tr(cache());
				mydata d(1,2);
				cache().store_frame("foo","bar",std::set<std::string>(),-1,true);
				cache().store_data("dat",d,std::set<std::string>(),-1,true);
				TEST(tr.detach().size()==0);
			}
			{
				cache().reset();
				cppcms::triggers_recorder tr(cache());
				mydata d;
				std::string tmp;
				TEST(cache().fetch_frame("foo",tmp,true));
				TEST(cache().fetch_data("dat",d,true));
				TEST(d.x==1  && d.y==2);
				TEST(tmp=="bar");
				TEST(tr.detach().size()==0);
			}
			{
				cache().reset();
				cppcms::triggers_recorder tr(cache());
				mydata d;
				std::string tmp;
				TEST(cache().fetch_frame("foo",tmp));
				TEST(cache().fetch_data("dat",d));
				TEST(d.x==1  && d.y==2);
				TEST(tmp=="bar");
				TEST(tr.detach().size()==2);
			}
			{
				cache().reset();
				cppcms::triggers_recorder tr(cache());
				mydata d(4,5);
				cache().store_frame("foo","baz",-1,true);
				cache().store_data("dat",d,-1,true);
				TEST(tr.detach().size()==0);
			}
			{
				cache().reset();
				cppcms::triggers_recorder tr(cache());
				mydata d;
				std::string tmp;
				TEST(cache().fetch_frame("foo",tmp,true));
				TEST(cache().fetch_data("dat",d,true));
				TEST(d.x==4  && d.y==5);
				TEST(tmp=="baz");
				TEST(tr.detach().size()==0);
			}
		}
		cache().clear();
		{
			std::cout << "-- Timeouts" << std::endl;
			{
				cache().reset();
				mydata d1(1,2);
				mydata d2(4,5);
				cache().store_frame("foo1","baz1",std::set<std::string>(),2,true);
				cache().store_data("dat1",d1,std::set<std::string>(),2,true);
				cache().store_frame("foo2","baz2",2,true);
				cache().store_data("dat2",d2,2,true);
			}
			{
				cache().reset();
				mydata d1,d2;
				std::string t1,t2;
				TEST(cache().fetch_frame("foo1",t1,true));
				TEST(cache().fetch_frame("foo2",t2,true));
				TEST(cache().fetch_data("dat1",d1,true));
				TEST(cache().fetch_data("dat2",d2,true));
				TEST(d1.x==1  && d1.y==2);
				TEST(d2.x==4  && d2.y==5);
				TEST(t1=="baz1");
				TEST(t2=="baz2");
			}
			booster::ptime::millisleep(3000);
			{
				cache().reset();
				mydata d1,d2;
				std::string t1,t2;
				TEST(!cache().fetch_frame("foo1",t1,true));
				TEST(!cache().fetch_frame("foo2",t2,true));
				TEST(!cache().fetch_data("dat1",d1,true));
				TEST(!cache().fetch_data("dat2",d2,true));
			}
		}


	}
Example #16
0
/// The top three entries on the stack are two digits to add and their
/// proported sum mod 10. Transmit Y/N to indicate whether or not the
/// sum is correct. If the sum is not correct, transmit the correct
/// sum. Update the weights to bias future random number selection.
void gradeSum(MorseToken) {
  if (2 < symbolStackSize()) {
    uint8_t s1(s(1).m2i());
    uint8_t s2(s(2).m2i());
    uint8_t s0(s(0).toChar());
    uint8_t sum((s1 + s2) % 10);
    Serial.print(s2);
    Serial.print(" ");
    Serial.print(s1);
    Serial.print(" ");
    Serial.print(s0);
    Serial.print(" sum: ");
    Serial.println(sum);
    bool correct(s(0).m2i() == sum);
    if (correct) {
      txString("Y");
      // Decrease the error counts associated with the digits the user
      // just added incorrectly, taking care not to underflow.
      uint8_t d1(!!digitErr[s1]);
      uint8_t d2(!!digitErr[s2]);
      digitErr[s1] -= d1; 
      digitErr[s2] -= d2;
      digitErrCount -= (d1 + d2);
      Serial.print("Decrementing ");
      Serial.print(s1);
      Serial.print(". New weight is: ");
      Serial.println(digitErr[s1]);
      Serial.print("Decrementing ");
      Serial.print(s2);
      Serial.print(". New weight is: ");
      Serial.println(digitErr[s2]);
    } else {
      //            012345678901
      char buffer[] = "N  a + b = c";
      buffer[3] = s2 + '0';
      buffer[7] = s1 + '0';
      buffer[11] = sum + '0';
      txString(buffer);
      // Increase the error counts associated with the digits the user
      // just added incorrectly, taking care not to overflow.
      uint8_t d1(3 * (digitErr[s1] - 3 < 255));
      uint8_t d2(3 * (digitErr[s2] - 3 < 255));
      digitErr[s1] += d1;
      digitErr[s2] += d2;
      digitErrCount += d1 + d2;
      Serial.print("Incrementing ");
      Serial.print(s1);
      Serial.print(". New weight is: ");
      Serial.println(digitErr[s1]);
      Serial.print("Incrementing ");
      Serial.print(s2);
      Serial.print(". New weight is: ");
      Serial.println(digitErr[s2]);
    }
    // If the user plays long enough without a reset to saturate two
    // of the digits chosen at random, divide all the error counts
    // by 2.
    if (digitErr[s1] == 255 && digitErr[s2] == 255) {
      for (uint8_t i(0); i < 10; ++i) {
	digitErr[i] <<= 1;
      }
      digitErrCount <<= 1;
      Serial.println("Halving all weights.");
    }
    Serial.print("Digit error count is: ");
    Serial.println(digitErrCount);
    popN(3);
  } else {
    txError();
  }
}
Example #17
0
bool
tDateTime06( LibTest & tester )
{
    // void setTm( void ) - NO TEST (tested by other test)

  {   
    // compare( const DateTime & ) 

    DateTime	d1( "2/17/95 11:30:30" );
    DateTime	d2( d1 );

    TEST( d1 == d2 );
    TEST( ! d1.compare( d2 ) );
    TEST( ! compare( d1, d2 ) );

    d1.setTimeZone();

    TEST( d1 == d2 );
    TEST( ! d1.compare( d2 ) );
    TEST( ! compare( d1, d2 ) );

    d2.setTimeZone();

    TEST( d1 == d2 );
    TEST( ! d1.compare( d2 ) );
    TEST( ! compare( d1, d2 ) );

    d1.addMin();

    TEST( d1.compare( d2 ) > 0 );
    TEST( d1 > d2 );
    TEST( compare( d1, d2 ) > 0 );
    
  }

  {   
    // operator time_t ( void ) const

    DateTime	dt( "2/17/95 11:30:30" );

    TEST( (time_t)dt == dt.getTimeT() );

  }

  {   
    // operator const char * ( void ) const

    DateTime	dt( "2/17/95 11:30:30" );

    char    dtBuf[50];

    dt.getString( dtBuf );

    TEST( ! strcmp( (const char *)dt, dtBuf ) );
    
  }

  {   
    // operator == ( const DateTime & ) const

    DateTime	d1( "2/17/95 11:30:30" );
    DateTime	d2( "2/17/95 11:30:30" );

    TEST( d1 == d2 );
    d2.addSec();
    TEST( d1 != d2 );
    
  }

  {   
    // operator !=( const DateTime & ) const
    
    DateTime	d1( "2/17/95 11:30:30" );
    DateTime	d2( "2/17/95 11:30:30" );

    TEST( d1 == d2 );
    d2.addSec();
    TEST( d1 != d2 );
    
  }

  {   
    // const char * getClassName(void) - NO TEST NEEDED

  }

  {   
    // Bool 	     good( void ) - NO TEST (tested by setValid());

  }

  {   
    // const char * error( void ) - NO TEST NEEDED
    
  }
  return( true );
}
Example #18
0
Node *OutlineVectorizer::findOtherSide(Node *node)
{
	DataPixel *pix = node->m_pixel;

	TPoint dir = -computeGradient(pix);
	if (dir == TPoint(0, 0))
		return 0;
	TPoint d1(tsign(dir.x), 0), d2(0, tsign(dir.y));
	int num = abs(dir.y), den = abs(dir.x);
	if (num > den) {
		tswap(d1, d2);
		tswap(num, den);
	}
	TPoint pos = pix->m_pos;
	int i;
	for (i = 0;; i++) {
		TPoint q(pos.x + d1.x * i + d2.x * num * i / den, pos.y + d1.y * i + d2.y * num * i / den);
		DataPixel *nextPix = m_dataRaster->pixels(q.y) + q.x;
		if (nextPix->m_ink == false)
			break;
		pix = nextPix;
	}
	assert(pix);
	if (!pix->m_node) {
		const int wrap = m_dataRaster->getWrap();
		if (pix[-1].m_node)
			pix--;
		else if (pix[1].m_node)
			pix++;
		else if (pix[wrap].m_node)
			pix += wrap;
		else if (pix[-wrap].m_node)
			pix -= wrap;
		else {
			assert(0);
		}
	}
	if (!pix->m_node)
		return 0;
	Node *q = pix->m_node;
	while (q->m_pixel == 0 && q->m_other)
		q = q->m_other;
	assert(q && q->m_pixel == pix);

	for (i = 0; i < 5; i++) {
		if (!q->m_prev)
			break;
		q = q->m_prev;
	}

	Node *best = q;
	double bestDist2 = computeDistance2(q, node);
	for (i = 0; i < 10; i++) {
		q = q->m_next;
		if (!q)
			break;
		double dist2 = computeDistance2(q, node);
		if (dist2 < bestDist2) {
			bestDist2 = dist2;
			best = q;
		}
	}

	return best;
}
Example #19
0
/* Function that returns the ID of the most dangerous neighboring plane and its ZEM */
AU_UAV_ROS::threatContainer AU_UAV_ROS::findGreatestThreat(PlaneObject &plane1, std::map<int, PlaneObject> &planes){
	/* Set reference for origin (Northwest corner of the course)*/
	AU_UAV_ROS::coordinate origin;
	origin.latitude = 32.606573;
	origin.longitude = -85.490356;
	origin.altitude = 400;
	/* Set preliminary plane to avoid as non-existent and most dangerous 
	ZEM as negative*/
	int planeToAvoid = -1;
	double mostDangerousZEM = -1;
	
	/* Set the preliminary time-to-go to infinity*/
	double minimumTimeToGo = std::numeric_limits<double>::infinity();
	/* Declare second plane and ID variable */
	PlaneObject plane2;
	int ID;
	/* Make a position vector representation of the current plane*/
	double magnitude2, direction2;
	double magnitude = findDistance(origin.latitude, origin.longitude, 
		plane1.getCurrentLoc().latitude, plane1.getCurrentLoc().longitude);
	double direction = findAngle(origin.latitude, origin.longitude, 
		plane1.getCurrentLoc().latitude, plane1.getCurrentLoc().longitude);
	AU_UAV_ROS::mathVector p1(magnitude,direction);

	/* Make a heading vector representation of the current plane*/
	AU_UAV_ROS::mathVector d1(1.0,toCartesian(plane1.getCurrentBearing()));
	
	/* Declare variables needed for this loop*/
	AU_UAV_ROS::mathVector pDiff;
	AU_UAV_ROS::mathVector dDiff;
	double timeToGo, zeroEffortMiss, distanceBetween, timeToDest;
	std::map<int,AU_UAV_ROS::PlaneObject>::iterator it;
	for ( it=planes.begin() ; it!= planes.end(); it++ ){
		/* Unpacking plane to check*/		
		ID = (*it).first;
		plane2 = (*it).second;
		
		/* If it's not in the Check Zone, check the other plane*/
		distanceBetween = plane1.findDistance(plane2);
		if (distanceBetween > CHECK_ZONE || plane1.getID() == ID) continue;

		else if (distanceBetween < MPS_SPEED) {
			planeToAvoid = ID;
			mostDangerousZEM = 0;
			minimumTimeToGo = 0.1;
			break;
		}	

		/* Making a position vector representation of plane2*/
		magnitude2 = findDistance(origin.latitude, origin.longitude, 
			plane2.getCurrentLoc().latitude, plane2.getCurrentLoc().longitude);
		direction2 = findAngle(origin.latitude, origin.longitude, 
			plane2.getCurrentLoc().latitude, plane2.getCurrentLoc().longitude);
		AU_UAV_ROS::mathVector p2(magnitude2,direction2);

		/* Make a heading vector representation of the current plane*/
		AU_UAV_ROS::mathVector d2(1.0,toCartesian(plane2.getCurrentBearing()));

		/* Compute Time To Go*/
		pDiff = p1-p2;
		dDiff = d1-d2;
		timeToGo = -1*pDiff.dotProduct(dDiff)/(MPS_SPEED*dDiff.dotProduct(dDiff));

		/* Compute Zero Effort Miss*/
		zeroEffortMiss = sqrt(pDiff.dotProduct(pDiff) + 
			2*(MPS_SPEED*timeToGo)*pDiff.dotProduct(dDiff) + 
			pow(MPS_SPEED*timeToGo,2)*dDiff.dotProduct(dDiff));
		
		/* If the Zero Effort Miss is less than the minimum required 
		separation, and the time to go is the least so far, then avoid this plane*/
		if(zeroEffortMiss <= DANGER_ZEM && timeToGo < minimumTimeToGo && timeToGo > 0){
			// If the plane is behind you, don't avoid it
			if ( fabs(plane2.findAngle(plane1)*180/PI - toCartesian(plane1.getCurrentBearing())) > 35.0) {
				timeToDest = plane1.findDistance(plane1.getDestination().latitude, 
					plane1.getDestination().longitude) / MPS_SPEED;
				/* If you're close to your destination and the other plane isn't
				much of a threat, then don't avoid it */ 
				if ( timeToDest < 5.0 && zeroEffortMiss > 3.0*MPS_SPEED ) continue;
				planeToAvoid = ID;
				mostDangerousZEM = zeroEffortMiss;
				minimumTimeToGo = timeToGo;			
			}
		}
	}

	AU_UAV_ROS::threatContainer greatestThreat;
	greatestThreat.planeID = planeToAvoid;
	greatestThreat.ZEM = mostDangerousZEM;
	greatestThreat.timeToGo = minimumTimeToGo;

	return greatestThreat;
}
Example #20
0
void drive_operation()
{

    // Uint64 tests

    CQLValue a1(Uint64(10));
    CQLValue a2(Uint64(15));
    CQLValue a3(Uint64(25));
    CQLValue a4(Uint64(30));
    CQLValue a5(Uint64(150));

    PEGASUS_TEST_ASSERT(a1 != a2);
    PEGASUS_TEST_ASSERT(a5 == a5);
    PEGASUS_TEST_ASSERT(a1 < a2);
    PEGASUS_TEST_ASSERT(a2 >= a1);
    PEGASUS_TEST_ASSERT(a1 <= a2);
    PEGASUS_TEST_ASSERT(a2 > a1);

    // Sint64 tests

    CQLValue b1(Sint64(10));
    CQLValue b2(Sint64(15));
    CQLValue b3(Sint64(25));
    CQLValue b4(Sint64(30));
    CQLValue b5(Sint64(150));

    PEGASUS_TEST_ASSERT(b1 != b2);
    PEGASUS_TEST_ASSERT(b5 == b5);
    PEGASUS_TEST_ASSERT(b1 < b2);
    PEGASUS_TEST_ASSERT(b2 >= b1);
    PEGASUS_TEST_ASSERT(b1 <= b2);
    PEGASUS_TEST_ASSERT(b2 > b1);

    // Real64 tests

    CQLValue c1(Real64(10.00));
    CQLValue c2(Real64(15.00));
    CQLValue c3(Real64(25.00));
    CQLValue c4(Real64(30.00));
    CQLValue c5(Real64(150.00));

    PEGASUS_TEST_ASSERT(c1 != c2);
    PEGASUS_TEST_ASSERT(c5 == c5);
    PEGASUS_TEST_ASSERT(c1 < c2);
    PEGASUS_TEST_ASSERT(c2 >= c1);
    PEGASUS_TEST_ASSERT(c1 <= c2);
    PEGASUS_TEST_ASSERT(c2 > c1);

    // Misc
    PEGASUS_TEST_ASSERT(a1 == b1);
    PEGASUS_TEST_ASSERT(a1 == c1);
    PEGASUS_TEST_ASSERT(b1 == a1);
    PEGASUS_TEST_ASSERT(b1 == c1);
    PEGASUS_TEST_ASSERT(c1 == a1);
    PEGASUS_TEST_ASSERT(c1 == b1);

    PEGASUS_TEST_ASSERT(a2 != b1);
    PEGASUS_TEST_ASSERT(a2 != c1);
    PEGASUS_TEST_ASSERT(b2 != a1);
    PEGASUS_TEST_ASSERT(b2 != c1);
    PEGASUS_TEST_ASSERT(c2 != a1);
    PEGASUS_TEST_ASSERT(c2 != b1);

    PEGASUS_TEST_ASSERT(a2 >= b1);
    PEGASUS_TEST_ASSERT(a2 >= c1);
    PEGASUS_TEST_ASSERT(b2 >= a1);
    PEGASUS_TEST_ASSERT(b2 >= c1);
    PEGASUS_TEST_ASSERT(c2 >= a1);
    PEGASUS_TEST_ASSERT(c2 >= b1);

    PEGASUS_TEST_ASSERT(a2 <= b3);
    PEGASUS_TEST_ASSERT(a2 <= c3);
    PEGASUS_TEST_ASSERT(b2 <= a3);
    PEGASUS_TEST_ASSERT(b2 <= c3);
    PEGASUS_TEST_ASSERT(c2 <= a3);
    PEGASUS_TEST_ASSERT(c2 <= b3);

    PEGASUS_TEST_ASSERT(a2 > b1);
    PEGASUS_TEST_ASSERT(a2 > c1);
    PEGASUS_TEST_ASSERT(b2 > a1);
    PEGASUS_TEST_ASSERT(b2 > c1);
    PEGASUS_TEST_ASSERT(c2 > a1);
    PEGASUS_TEST_ASSERT(c2 > b1);

    PEGASUS_TEST_ASSERT(a2 < b3);
    PEGASUS_TEST_ASSERT(a2 < c3);
    PEGASUS_TEST_ASSERT(b2 < a3);
    PEGASUS_TEST_ASSERT(b2 < c3);
    PEGASUS_TEST_ASSERT(c2 < a3);
    PEGASUS_TEST_ASSERT(c2 < b3);

    //Overflow testing
    CQLValue real1(Real64(0.00000001));
    CQLValue sint1(Sint64(-1));
    CQLValue uint1(Sint64(1));
    CQLValue uint2(Uint64(0));

    PEGASUS_TEST_ASSERT(uint1 > sint1);
    PEGASUS_TEST_ASSERT(real1 > sint1);
    PEGASUS_TEST_ASSERT(uint2 > sint1);
    PEGASUS_TEST_ASSERT(real1 > uint2);

    CQLValue real2(Real64(25.00000000000001));
    CQLValue real3(Real64(24.99999999999999));
    CQLValue sint2(Sint64(25));
    CQLValue uint3(Uint64(25));

    PEGASUS_TEST_ASSERT(real2 > real3);
    PEGASUS_TEST_ASSERT(real2 > sint2);
    PEGASUS_TEST_ASSERT(real2 > uint3);
    PEGASUS_TEST_ASSERT(real3 < sint2);
    PEGASUS_TEST_ASSERT(real3 < uint3);

    // String tests

    CQLValue d1(String("HELLO"));
    CQLValue d2(String("HEL"));
    CQLValue d3(String("LO"));
    CQLValue d4(String("AHELLO"));
    CQLValue d5(String("ZHELLO"));

    PEGASUS_TEST_ASSERT(d1 == d2 + d3);
    PEGASUS_TEST_ASSERT(d1 != d2 + d4);

    PEGASUS_TEST_ASSERT(d1 <= d5);
    PEGASUS_TEST_ASSERT(d1 <  d5);

    PEGASUS_TEST_ASSERT(d1 >= d4);
    PEGASUS_TEST_ASSERT(d1 >  d4);

    String str1("0x10");
    String str2("10");
    String str3("10B");
    String str4("10.10");


    CQLValue e1( str1, CQLValue::Hex);
    CQLValue e2( str2, CQLValue::Decimal);
    CQLValue e3( str3, CQLValue::Binary);
    CQLValue e4( str4, CQLValue::Real);

    CQLValue e5(Uint64(16));
    CQLValue e6(Uint64(10));
    CQLValue e7(Uint64(2));
    CQLValue e8(Real64(10.10));

    PEGASUS_TEST_ASSERT(e1 == e5);
    PEGASUS_TEST_ASSERT(e2 == e6);
    PEGASUS_TEST_ASSERT(e3 == e7);
    PEGASUS_TEST_ASSERT(e4 == e8);

    Array<Uint64> array1;

    array1.append(1);
    array1.append(2);
    array1.append(3);
    array1.append(4);
    array1.append(5);
    array1.append(6);
    array1.append(7);
    array1.append(8);
    array1.append(9);
    array1.append(10);

    Array<Sint64> array2;

    array2.append(1);
    array2.append(2);
    array2.append(3);
    array2.append(4);
    array2.append(5);
    array2.append(6);
    array2.append(7);
    array2.append(8);
    array2.append(9);
    array2.append(10);
    array2.append(3);

    Array<Real64> array3;

    array3.append(1.00);
    array3.append(2.00);
    array3.append(3.00);
    array3.append(9.00);
    array3.append(10.00);
    array3.append(3.00);
    array3.append(4.00);
    array3.append(5.00);
    array3.append(6.00);
    array3.append(7.00);
    array3.append(8.00);

    Array<Uint64> array4;

    array4.append(1);
    array4.append(23);
    array4.append(3);
    array4.append(4);
    array4.append(5);
    array4.append(6);
    array4.append(7);
    array4.append(88);
    array4.append(9);
    array4.append(10);

    Array<Sint64> array5;

    array5.append(-1);
    array5.append(2);
    array5.append(3);
    array5.append(4);
    array5.append(5);
    array5.append(-6);
    array5.append(7);
    array5.append(8);
    array5.append(9);
    array5.append(10);
    array5.append(-3);

    Array<Real64> array6;

    array6.append(1.23);
    array6.append(2.00);
    array6.append(3.00);
    array6.append(9.00);
    array6.append(10.00);
    array6.append(3.00);
    array6.append(4.14);
    array6.append(5.00);
    array6.append(6.00);
    array6.append(7.00);
    array6.append(8.00);

    CIMValue cv1(array1);
    CIMValue cv2(array2);
    CIMValue cv3(array3);
    CIMValue cv4(array4);
    CIMValue cv5(array5);
    CIMValue cv6(array6);

    CQLValue vr1(cv1);
    CQLValue vr2(cv1);
    CQLValue vr3(cv2);
    CQLValue vr4(cv3);
    CQLValue vr5(cv4);
    CQLValue vr6(cv5);
    CQLValue vr7(cv6);

    PEGASUS_TEST_ASSERT(vr1 == vr2);
    PEGASUS_TEST_ASSERT(vr1 == vr3);
    PEGASUS_TEST_ASSERT(vr1 == vr4);
    PEGASUS_TEST_ASSERT(vr4 == vr3);

    PEGASUS_TEST_ASSERT(vr1 != vr5);
    PEGASUS_TEST_ASSERT(vr3 != vr6);
    PEGASUS_TEST_ASSERT(vr4 != vr7);

    const CIMName _cimName(String("CIM_OperatingSystem"));

    CIMInstance _i1(_cimName);
    CIMProperty _p1(CIMName("Description"),CIMValue(String("Dave Rules")));
    CIMProperty _p2(CIMName("EnabledState"),CIMValue(Uint16(2)));
    CIMProperty _p3(CIMName("CurrentTimeZone"),CIMValue(Sint16(-600)));
    CIMProperty _p4(CIMName("TimeOfLastStateChange"),
                    CIMValue(CIMDateTime(String("20040811105625.000000-360"))));

    _i1.addProperty(_p1);
    _i1.addProperty(_p2);
    _i1.addProperty(_p3);
    _i1.addProperty(_p4);

    CIMInstance _i2(_cimName);
    CIMProperty _p5(CIMName("Description"),
                    CIMValue(String("Dave Rules Everything")));
    CIMProperty _p6(CIMName("EnabledState"),CIMValue(Uint16(2)));
    CIMProperty _p7(CIMName("CurrentTimeZone"),CIMValue(Sint16(-600)));
    CIMProperty _p8(CIMName("TimeOfLastStateChange"),
                    CIMValue(CIMDateTime(String("20040811105625.000000-360"))));

    _i2.addProperty(_p5);
    _i2.addProperty(_p6);
    _i2.addProperty(_p7);
    _i2.addProperty(_p8);

    CQLValue cql1(_i1);
    CQLValue cql2(_i1);
    CQLValue cql3(_i2);
    CQLValue cql4(_i2);

    //PEGASUS_TEST_ASSERT(cql1 == cql1);

    return;
}
Example #21
0
void dpps::Pattern_random::generate () {
    // We have do declare them all. We cannot do a switch of if,
    // because distributions would get out of scope.
    // The only other possibility would be to place the switch inside
    // the loop, but it would be very inefficient to call the constructor
    // everytime.
    // So we have to pay for overhead and initialize them all in te beginning.
    // It's probably a negligible amount of time and memory as compared to the
    // loop.

    // signification of parametres depends on the engine. Some engines
    // need only one parametre.
    // For all user-changeable values (p1 and p2), 1.0 would have been the
    // default if we had not specified it, so it is an acceptable value for the
    // user as well.
    const double p1 {pattern_settings. p1} ;
    const double p2 {pattern_settings. p2} ;

    std::uniform_real_distribution<double> d0 (-p1, p1) ; // min, max
    // Normal-type
    std::normal_distribution<double> d1 (0.0, p1) ;    // average = 0, sigma
    std::lognormal_distribution<double> d2 (0.0, p1) ; // average = 0, m
    std::chi_squared_distribution<double> d3 (p1) ;    // n
    std::cauchy_distribution<double> d4 (p1, p2) ;     // a, b
    std::fisher_f_distribution<double> d5 (p1, p2) ;   // m, n
    std::student_t_distribution<double> d6 (p1) ;      // n
    // Poisson-type
    std::exponential_distribution<double> d7 (p1) ;    // lambda
    std::gamma_distribution<double> d8 (p1, p2) ;      // alpha, beta
    std::weibull_distribution<double> d9 (p1, p2) ;    // a, b

    Polyline p ;
    p. closed = true ;
    double x {0.0}, y {0.0} ;
    long_unsigned_int i {0}, attempts {0} ;
    //const double s {pattern_settings. side / 2.0} ;
    if (pattern_settings. max_attempts < pattern_settings. number)
        pattern_settings. max_attempts =
            std::numeric_limits<long_unsigned_int>::max () ;
    //std::cout << "hello" << i << " " << pattern_settings. number << " " <<  attempts << " " << pattern_settings. max_attempts << std::endl ;
    while ((i < pattern_settings. number) &&
           (attempts < pattern_settings. max_attempts)) {
        bool overlap = false ;
        switch (pattern_settings. type) {
            case type_uniform_real_distribution: // 0
                x = d0 (pseudorandom_generator) ;
                y = d0 (pseudorandom_generator) ;
                //std::cout << "alea 0 : " << x << " " << y << std::endl ;
                break ;
            case type_normal_distribution: // 1
                x = d1 (pseudorandom_generator) ;
                y = d1 (pseudorandom_generator) ;
                break ;
            case type_lognormal_distribution: // 2
                x = d2 (pseudorandom_generator) ;
                y = d2 (pseudorandom_generator) ;
                break ;
            case type_chi_squared_distribution: // 3
                x = d3 (pseudorandom_generator) ;
                y = d3 (pseudorandom_generator) ;
                break ;
            case type_cauchy_distribution: // 4
                x = d4 (pseudorandom_generator) ;
                y = d4 (pseudorandom_generator) ;
                break ;
            case type_fisher_f_distribution: // 5
                x = d5 (pseudorandom_generator) ;
                y = d5 (pseudorandom_generator) ;
                break ;
            case type_student_t_distribution: // 6
                x = d6 (pseudorandom_generator) ;
                y = d6 (pseudorandom_generator) ;
                break ;
            case type_exponential_distribution: // 7
                x = d7 (pseudorandom_generator) ;
                y = d7 (pseudorandom_generator) ;
                break ;
            case type_gamma_distribution: // 8
                x = d8 (pseudorandom_generator) ;
                y = d8 (pseudorandom_generator) ;
                break ;
            case type_weibull_distribution: // 9
                x = d9 (pseudorandom_generator) ;
                y = d9 (pseudorandom_generator) ;
                break ;
            default:
                break ;
        }
        if (pattern_settings. avoid_overlap) {
            for (long_unsigned_int j = 0 ; j < polylines. size () ; j++) {
                if ((polylines[j]. vertices[0] - Vertex(x, y)).norm2_square() <
                    pattern_settings. diametre*pattern_settings. diametre) {
                    overlap = true ;
                    break ;
                 }
            }
        }

        bool within_limits =
            (((fabs (x - pattern_settings. x0) < pattern_settings. lx / 2.0) ||
             (pattern_settings. lx <= 0)) &&
            ((fabs (y - pattern_settings. y0) < pattern_settings. ly / 2.0) ||
             (pattern_settings. ly <= 0))) ;

        // Either we are inside lx, or user set it to negative to disable it.
        if  (within_limits && !overlap) {
            p. push_back (Vertex (x, y)) ;
            p. dose = pattern_settings. diametre ;
            polylines. push_back (p) ;
            p. vertices. clear () ; // does not change that p. closed == true ;
            i++ ;
        }
        attempts++ ;
    }
}
Example #22
0
void next(int c[], int d[], int size)
{
	if (DEBUGDECIDE==1)
		printf("Making decision next at %d %d %d\n", c[ROW],c[COL],c[FLOOR]);
  // special local arrays 
  int NW[2][2] = { {4, 12},{12, 4}};
  int SW[2][2] = {{ 4,  4},{12,12}};
  int SE[2][2] = {{12,  4},{ 4,12}};
  int NE[2][2] = {{12, 12},{ 4, 4}};

  // default is no find
  bool find = false;

  // case when store is on the other floor
  if (c[FLOOR] != d[FLOOR])
  {
    d1(c, size);
    return;
  } 
  else
  {
	if (DEBUGDECIDE==1)
		printf("Step value at %d %d %d is %d", c[ROW], c[COL], c[FLOOR], (Mall[c[ROW]][c[COL]][c[FLOOR]]).getStep());
    switch ((Mall[c[ROW]][c[COL]][c[FLOOR]]).getStep())
    {
     case NorthWest:
          if((NW[c[FLOOR]][ROW] == d[ROW]) &&
             (NW[c[FLOOR]][COL] == d[COL]) )
	    find = true;
	  break;
      case SouthWest:
	  if((SW[c[FLOOR]][ROW] == d[ROW]) &&
             (SW[c[FLOOR]][COL] == d[COL]) )
	    find = true;
          break;
      case SouthEast:
	  if((SE[c[FLOOR]][ROW] == d[ROW]) &&
             (SE[c[FLOOR]][COL] == d[COL]) )
	    find = true;
          break;
      case NorthEast: 
          if((NE[c[FLOOR]][ROW] == d[ROW]) &&
             (NE[c[FLOOR]][COL] == d[COL]) )
	    find = true;
          break;
      case INVALID:
      default:
         printloc(c);
	 printf("Next: Lost in Mall at");
         exit(EXIT_FAILURE);
    } //end switch
  } //end else

  /* if store is next to current location,
     move robot into store.             */
  if (find)
  {
     c[ROW] = d[ROW];
     c[COL] = d[COL]; 
  }
  else
    // otherwise call d1!
    d1(c, size);
  return;
}
Example #23
0
//---------------------------------------------------------------------------
//用于生成高斯点序列
int Gauss::Generate_gauss_array(vector<double> &gauss, vector<double> &weight)const
{
	//开始计算
	int n = precision;
	int iter = 10;   //迭代次数
	int m=int((n+1)/2); 
	int e1=n*(n+1);
	int mm=4*m-1;
	vector<long double> t;
	for(int i=3; i<=mm; i=i+4)
	{
		t.push_back((PI/(4*n+2))*i);
	}
	int nn=(1-(1-1/n)/(8*n*n));
	vector<long double> xo;
	for(int i=0; i<m; i++)
	{
		xo.push_back(nn*cos(t[i]));
	}
	vector<long double> pk;
	vector<long double> den(m);
	vector<long double> d1(m);
	vector<long double> dpn(m);
	vector<long double> d2pn(m);
	vector<long double> d3pn(m);
	vector<long double> d4pn(m);
	vector<long double> u(m);
	vector<long double> v(m);
	vector<long double> h(m);
	vector<long double> p(m);
	vector<long double> dp(m);

	for(int j=1; j<=iter; j++)
	{
		vector<long double> pkm1(m, 1.0);
		pk=xo;
		for(int k=2; k<=n; k++)
		{
			vector<long double> t1(m);
			vector<long double> pkp1(m);
			for(int i=0; i<m; i++)
			{
				t1[i]=xo[i]*pk[i];
				pkp1[i]=t1[i]-pkm1[i]-(t1[i]-pkm1[i])/k+t1[i];
			}
			pkm1=pk;
			pk=pkp1;
		}
		for(int i=0; i<m; i++)
		{
			den[i]=1.0-xo[i]*xo[i];
			d1[i]=n*(pkm1[i]-xo[i]*pk[i]);
			dpn[i]=d1[i]/den[i];
			d2pn[i]=(2.0*xo[i]*dpn[i]-e1*pk[i])/den[i];
			d3pn[i]=(4*xo[i]*d2pn[i]+(2-e1)*dpn[i])/den[i];
			d4pn[i]=(6*xo[i]*d3pn[i]+(6-e1)*d2pn[i])/den[i];
			u[i]=pk[i]/dpn[i]; 
			v[i]=d2pn[i]/dpn[i];
			h[i]=-u[i]*(1+(0.5*u[i])*(v[i]+u[i]*(v[i]*v[i]-u[i]*d3pn[i]/(3*dpn[i]))));
			p[i]=pk[i]+h[i]*(dpn[i]+(0.5*h[i])*(d2pn[i]+(h[i]/3)*(d3pn[i]+0.25*h[i]*d4pn[i])));
			dp[i]=dpn[i]+h[i]*(d2pn[i]+(0.5*h[i])*(d3pn[i]+h[i]*d4pn[i]/3));
			h[i]=h[i]-p[i]/dp[i]; 
			xo[i]=xo[i]+h[i];
		}
	}
	vector<long double> bp(m);
	vector<long double> fx(m);
	vector<long double> wf(m);
	for(int i=0; i<m; i++)
	{
		bp[i]=-xo[i]-h[i];
		fx[i]=d1[i]-h[i]*e1*(pk[i]+(h[i]/2)*(dpn[i]+(h[i]/3)*(d2pn[i]+(h[i]/4)*(d3pn[i]+(0.2*h[i])*d4pn[i]))));
		wf[i]=2*(1-bp[i]*bp[i])/(fx[i]*fx[i]);
	}

	if((m+m)>n) bp[m-1]=0;
	if((m+m) != n) m=m-1;
	for(int i=m-1; i>=0; i--)
	{
		bp.push_back(-bp[i]);
		wf.push_back(wf[i]);
	}
 	for(int i=0; i<n; i++)
	{
		gauss.push_back(bp[i]);
		weight.push_back(wf[i]);
	}

	//cout << "bp=" << endl;
	//for(int i=0; i<n; i++)
	//{
	//	cout << setprecision(20) << bp[i] << endl;
	//}
	//cout << "wf=" << endl;
	//long double sum=0.0;
	//for(int i=0; i<n; i++)
	//{
	//	sum += wf[i];
	//	cout << setprecision(20) << wf[i] << endl;
	//}
	//cout << setprecision(20) << "sum=" << sum << endl;

	return 1;
}
Example #24
0
void d2(int c[], int d[], int size)
{
	if (DEBUGDECIDE==1)
		printf("Making decision 2 at %d %d %d\n", c[ROW],c[COL],c[FLOOR]);
  int i,j;

  /* d2 decides whether the robot needs to turn or not.
     The default is to turn because this has higher
     likelihood given one-way restrictions.          */

  bool turn = true;

    switch ((Mall[c[ROW]][c[COL]][c[FLOOR]]).getStep())
    {
      case West: 

	if (c[FLOOR])
	{
	   if((d[ROW] == 12) &&
	      (d[COL]   == 4) &&
	      (d[FLOOR] == c[FLOOR]))
	      turn = false;
	}
	else
	{
	  for(j = 0;  j <=  6; j = j+6)
	  {
	    for(i = 4; i <= 6; i = i+2)
            {
              {
	      if((d[ROW]   == i+j) &&
	         (d[COL]   == 4) &&
	         (d[FLOOR] == c[FLOOR]))
	        turn = false;
	      }
	    }
	  }
	}
	// This is adjustment when turning.
	if(turn)
        {
          if (c[FLOOR])
	    c[ROW]--;
          else
	    c[ROW]++;
        }
        break;

      case South:
	for(j = 0;  j <=  6; j = j+6)
	{
	  for(i = 4; i <= 6; i = i+2)
          {
            if((d[ROW]   == 12) &&
	       (d[COL]   == i+j) &&
	       (d[FLOOR] == c[FLOOR]))
	        turn = false;
	  }
	}
	// This is adjustment when turning.
	if(turn)
        {
          if (c[FLOOR])
	    c[COL]--;
          else
	    c[COL]++;
        }
        break;
    case INVALID:
    default:
         printloc(c);
	 printf("d2: lost in Mall!!");
         exit(EXIT_FAILURE);
  }
  // When not turning, simply call d1!
  if (!turn) d1(c,SIZE);
  return;
}
Example #25
0
 /*!\ingroup date_format
  */
 inline std::string to_simple_string(const date_period& d) {
   std::string s("[");
   std::string d1(date_time::date_formatter<date,date_time::simple_format<char> >::date_to_string(d.begin()));
   std::string d2(date_time::date_formatter<date,date_time::simple_format<char> >::date_to_string(d.last()));
   return std::string("[" + d1 + "/" + d2 + "]");
 }
void test()
{
   //Single unique_ptr
   reset_counters();
   {
   A* p1 = new A(1);
   move_constr_deleter<A> d1(1);
   bml::unique_ptr<A, move_constr_deleter<A> > s1(p1, ::boost::move(d1));
   A* p2 = new A(2);
   move_constr_deleter<A> d2(2);
   bml::unique_ptr<A, move_constr_deleter<A> > s2(p2, ::boost::move(d2));
   BOOST_TEST(s1.get() == p1);
   BOOST_TEST(*s1 == A(1));
   BOOST_TEST(s1.get_deleter().state() == 1);
   BOOST_TEST(s2.get() == p2);
   BOOST_TEST(*s2 == A(2));
   BOOST_TEST(s2.get_deleter().state() == 2);
   boost::adl_move_swap(s1, s2);
   BOOST_TEST(s1.get() == p2);
   BOOST_TEST(*s1 == A(2));
   BOOST_TEST(s1.get_deleter().state() == 2);
   BOOST_TEST(s2.get() == p1);
   BOOST_TEST(*s2 == A(1));
   BOOST_TEST(s2.get_deleter().state() == 1);
   }
   //Unbounded array unique_ptr
   reset_counters();
   {
   A* p1 = new A[2];
   p1[0].set(1);
   p1[1].set(2);
   move_constr_deleter<A[]> d1(1);
   bml::unique_ptr<A[], move_constr_deleter<A[]> > s1(p1, ::boost::move(d1));
   A* p2 = new A[2];
   p2[0].set(3);
   p2[1].set(4);
   move_constr_deleter<A[]> d2(2);
   bml::unique_ptr<A[], move_constr_deleter<A[]> > s2(p2, ::boost::move(d2));
   BOOST_TEST(s1.get() == p1);
   BOOST_TEST(s1[0] == A(1));
   BOOST_TEST(s1[1] == A(2));
   BOOST_TEST(s1.get_deleter().state() == 1);
   BOOST_TEST(s2.get() == p2);
   BOOST_TEST(s2[0] == A(3));
   BOOST_TEST(s2[1] == A(4));
   BOOST_TEST(s2.get_deleter().state() == 2);
   swap(s1, s2);
   BOOST_TEST(s1.get() == p2);
   BOOST_TEST(s1[0] == A(3));
   BOOST_TEST(s1[1] == A(4));
   BOOST_TEST(s1.get_deleter().state() == 2);
   BOOST_TEST(s2.get() == p1);
   BOOST_TEST(s2[0] == A(1));
   BOOST_TEST(s2[1] == A(2));
   BOOST_TEST(s2.get_deleter().state() == 1);
   }
   //Bounded array unique_ptr
   reset_counters();
   {
   A* p1 = new A[2];
   p1[0].set(1);
   p1[1].set(2);
   move_constr_deleter<A[2]> d1(1);
   bml::unique_ptr<A[2], move_constr_deleter<A[2]> > s1(p1, ::boost::move(d1));
   A* p2 = new A[2];
   p2[0].set(3);
   p2[1].set(4);
   move_constr_deleter<A[2]> d2(2);
   bml::unique_ptr<A[2], move_constr_deleter<A[2]> > s2(p2, ::boost::move(d2));
   BOOST_TEST(s1.get() == p1);
   BOOST_TEST(s1[0] == A(1));
   BOOST_TEST(s1[1] == A(2));
   BOOST_TEST(s1.get_deleter().state() == 1);
   BOOST_TEST(s2.get() == p2);
   BOOST_TEST(s2[0] == A(3));
   BOOST_TEST(s2[1] == A(4));
   BOOST_TEST(s2.get_deleter().state() == 2);
   swap(s1, s2);
   BOOST_TEST(s1.get() == p2);
   BOOST_TEST(s1[0] == A(3));
   BOOST_TEST(s1[1] == A(4));
   BOOST_TEST(s1.get_deleter().state() == 2);
   BOOST_TEST(s2.get() == p1);
   BOOST_TEST(s2[0] == A(1));
   BOOST_TEST(s2[1] == A(2));
   BOOST_TEST(s2.get_deleter().state() == 1);
   }
}
Example #27
0
int
TFP_Bearing::update()
{
  //  opserr << "UPDATE: " << this->getTag() << endln;

  static Vector delU(4);
  static Vector delP(4);

  const Vector &v1 = theNodes[0]->getIncrDisp();
  const Vector &v2 = theNodes[1]->getIncrDisp();	

  double vpi[8];

  delU(0)=v1(0);
  delU(1)=v1(1);
  delU(2)=v2(0);
  delU(3)=v2(1);

  int contC = kt3Drma(vCommit, vpCommit, FrCommit, Ac, PCommit, vpi);

  //  Vector vpiF (vpi,8);  
  //  opserr << "delU: " << delU;
  //  opserr << "vpiF: " << vpiF;

  static Matrix stiffCommit(8,8);
  stiffCommit = ks;
  stiffCommit += ksrest;

  Vector PC(PCommit,4);
  Vector PT(PTrial, 4);

  //  opserr << "PTrial 1:" << PTrial;

  delP = kthat*delU;

  PT = PC;
  PT += delP;

  for (int i=0; i<4; i++)
    UTrial[i] = UCommit[i] + delU(i);

  static Vector delU58(4);
  static Vector tmp1(4);
  
  tmp1.addMatrixVector(0.0, kei, delU, 1.0);
  delU58.addMatrixVector(0.0, kee, tmp1, -1.0);

  static double dvData[8];
  static Vector dv(dvData,8);
  static Vector dFr(8);
  static Vector tmp2(8);

  for (int i=0; i<4; i++) {
    tmp2(i)=delU(i);
    tmp2(i+4)=delU58(i);
  }

  dv = Af * tmp2;

  //  opserr << "dv: " << dv;
  //  Vector vC(vCommit, 8); opserr << "vCommit: " << vC;

  for (int i=0; i<8; i++) {
    vTrial[i] = vCommit[i] + dvData[i];
    FrTrial[i] = FrCommit[i] + dFr(i);
  }

  //  Vector vT(vTrial, 8); opserr << "vTrial: " << vT;

  HTrial = H0 + dh;
  double vpit[8];

  int contT = kt3Drma(vTrial, vpCommit, FrTrial, Ac, PTrial, vpit);

  //  opserr << "vTrial: " << vT;
  // Vector FT(FrTrial, 8); opserr << "FrTrial: " << FT;

  // opserr << "Ptrial 2:" << PT;
  // opserr << "kthat: " << kthat;

  //   Vector vpiO(vpi, 8); opserr << "VPI 0: " << vpiO;

  static Matrix stiffTrial(8,8);

  stiffTrial = ks;
  stiffTrial += ksrest;
  
  int subDiv = 0;
  for (int j=0; j<8; j++) { // j=1:8
    int f=(stiffCommit(j,j)*2<stiffTrial(j,j) || stiffCommit(j,j)>2*stiffTrial(j,j));
    if (f==1 || contT==1 || contC==1)
      subDiv=1;
  }

  //  opserr << "subDIV: " << subDiv << " contT: " << contT << " contC: " << contC << endln;

  if (subDiv==1) {

    double dumax = 0.0001; 
    //double dumax = 0.001; 
    double maxDelU = 0.0;

    for (int i=0; i<4; i++) {
      double delUi = fabs(delU(i));
      //      opserr << "delUi: " << delUi << " maxDelU: " << maxDelU << endln;

      if (delUi > maxDelU)
	maxDelU = delUi;
    }

    int n=ceil(maxDelU/dumax);
    //    opserr << "n: " << n << "maxDelU: " << maxDelU << " dumax: " << dumax << endln;

    static Vector delu(4);
    delu =  delU;
    delu /= 1.0*n;

    //    opserr << "delu: " << delu;

    static double padd[4];
    static double uadd[4];
    static double Ptemp[4];

    static double vadd[8];
    static double vpTemp[8];
    static double FrTemp[8];

    for (int i=0; i<4; i++) {
      padd[i] = 0.0; 
      uadd[i]=0.0; 
    }
    for (int i=0; i<8; i++) {
      vadd[i]=0.0;
      FrTemp[i]=FrCommit[i];
      vpTemp[i] = vpCommit[i];
    }
    
    for (int j=0; j<n; j++) {

      for (int i=0; i<4; i++) {
	vTrial[i] = vCommit[i] + vadd[i];
	Ptemp[i] = PCommit[i] + padd[i];
      }

      contT = kt3Drma(vTrial, vpTemp, FrTemp, Ac, Ptemp, vpi);    

      //      Vector vpiJ(vpi, 8); opserr << "vpiJ: " << vpiJ;
      
      static Vector delp(4);

      delp.addMatrixVector(0.0, kthat, delu, 1.0);

      //      opserr << "delp: " << delp;
      
      for (int i=0; i<4; i++) {
	padd[i] += delp(i);
	uadd[i] += delu[i];
      }

      // delu58=-kt(5:8,5:8)^-1*kt(5:8,1:4)*delu;

      tmp1.addMatrixVector(0.0, kei, delu, 1.0);
      delU58.addMatrixVector(0.0, kee, tmp1, -1.0);

      //      opserr << "delU58: " << delU58;
      
      // dv=Af*[delu;delu58];
      static Vector tmp2(8);
      for (int i=0; i<4; i++) {
	tmp2(i)=delu[i];
	tmp2(i+4)=delU58(i);
      }
      
      dv.addMatrixVector(0.0, Af, tmp2, 1.0);

      ///      opserr << "tmp2: " << tmp2;
      // opserr << "dv: " << dv;

      dFr.addMatrixVector(0.0, ksrest, dv, 1.0);

      for (int i=0; i<8; i++) {
	vadd[i] += dv(i); 
	vpTemp[i]=vpi[i];
	FrTemp[i] = FrTemp[i] + dFr(i);
      }
    }
    
    for (int i=0; i<8; i++) {
      FrTrial[i] = FrTemp[i];
      vTrial[i] = vCommit[i] + vadd[i];
    }
  
    for (int i=0; i<4; i++) {
      PTrial[i] = PCommit[i]+padd[i];
      UTrial[i] = UCommit[i]+uadd[i];
      vTrial[i] = vCommit[i]+vadd[i];
    }
  }




  for (int i=0; i<8; i++) {
    vpTrial[i] = vpi[i];
  }
  HTrial=H0+dh;

  theMatrix->Zero();
  theVector->Zero();

  int numD = numDOF/2;

  for (int i=0; i<2; i++) {
    (*theVector)(i) = PTrial[i];
    (*theVector)(i+numD) = PTrial[i+2];

    for (int j=0; j<2; j++) {
      (*theMatrix)(i,j) = kthat(i,j);
      (*theMatrix)(i+numD,j+numD) = kthat(i+2,j+2);
      (*theMatrix)(i+numD,j) = kthat(i+2,j);
      (*theMatrix)(i,j+numD) = kthat(i,j+2);
    }
  }

  const Vector &d1 = theNodes[0]->getTrialDisp();
  const Vector &d2 = theNodes[1]->getTrialDisp();	

  double axialDefo = d1(2)-d2(2);

  if (axialDefo >= 0) {
    (*theMatrix)(2,2) = K;
    (*theMatrix)(2,2+numD) = -K;
    (*theMatrix)(2+numD,2) = -K;
    (*theMatrix)(2+numD,2+numD) = K;
    

    double force = axialDefo*K;
    (*theVector)(2) = force;
    (*theVector)(2+numD) = -force;
    Ap = force;
  } else {
    double Kmin = K*DBL_EPSILON;
    (*theMatrix)(2,2) = Kmin; // uisng Kmin to keep system stable
    (*theMatrix)(2,2+numD) = -Kmin;
    (*theMatrix)(2+numD,2) = -Kmin;
    (*theMatrix)(2+numD,2+numD) = Kmin;
    
    double force = 0.0;
    (*theVector)(2) = force;
    (*theVector)(2+numD) = -force;
    Ap = force;
  }

  return 0;
}
Example #28
0
int main(){
	
	Scalar a("a",STRING,"Hello");
	Scalar b("b",STRING,"World");
	std::cout << " a                      : " << a << std::endl;
	std::cout << " b                      : " << b << std::endl; 
	Scalar c("c",STRING,"Hello");
	std::cout << " c                      : " << c << std::endl;
	std::cout << " a == b                 : " << (a == b) << std::endl;
	std::cout << " a == c                 : " << (a == c) << std::endl;
	std::cout << " a  < b                 : " << (a < b) << std::endl;
	std::cout << " c  < a                 : " << (c < a) << std::endl;
	std::cout << " b  < a                 : " << (b < a) << std::endl; 
	Scalar ga("ga",BOOLEAN,"M");
	Scalar gb("gb",BOOLEAN,"F");
	Scalar gc("gc",BOOLEAN,"F");
	Scalar d("d",STRING,"M");
	std::cout << " ga                     : " << ga << std::endl;
	std::cout << " gb                     : " << gb << std::endl;
	std::cout << " gc                     : " << gc << std::endl;
	std::cout << " d                      : " << d << std::endl;
	std::cout << " (ga == gb)             : " << (ga == gb) << std::endl;
	std::cout << " (gb == gc)             : " << (gb == gc) << std::endl;
	std::cout << " (ga == d)              : " << (ga == d) << std::endl;
	std::cout << " (gb < gc)              : " << (gb < gc) << std::endl;
	std::cout << " (ga < gc)              : " << (ga < gc) << std::endl;
	std::cout << " (gc < ga)              : " << (gc < ga) << std::endl;
	std::cout << " (ga < a)               : " << (ga < a) << std::endl;
	std::cout << " (b < gb)               : " << (b < gb) << std::endl;
	std::cout << "Testing Assignment and Copy operators" << std::endl;
	Scalar copy1(ga);
	std::cout << " copy1 of ga            : " << copy1 << std::endl;  
	std::cout << " name and type          : " << copy1.getName() << " = " << copy1.getValueType() << std::endl;
	Scalar e("e",STRING,"Namaste");
	std::cout << " e                      : " << e << std::endl;
	e=ga;
	std::cout << " e=ga                   : " << e << std::endl;
	std::cout << " name and type          : " << e.getName() << " = " << e.getValueType() << std::endl;
	e=a;
	std::cout << " e=a                    : " << e << std::endl;
	std::cout << " name and type          : " << e.getName() << " = " << e.getValueType() << std::endl;
	ga=a;
	std::cout << " ga=a                   : " << ga << std::endl;
	std::cout << " name and type          : " << ga.getName() << " = " << ga.getValueType() << std::endl;
	std::cout << "Testing Scalar variables of type ANY" << std::endl;
	Scalar anyVar("anyVar");
	std::cout << " name and type          : " << anyVar.getName() << " = " << anyVar.getValueType() << std::endl;
	std::cout << " anyVar                 : " << anyVar << std::endl;
	std::cout << " anyVar < ga            : " << (anyVar < ga) << std::endl;
	std::cout << " a < anyVar             : " << (a < anyVar) << std::endl;
	std::cout << " a == anyVar            : " << (a == anyVar) << std::endl;
	anyVar.set(STRING,"Wow");
	std::cout << " anyVar=Wow             : " << anyVar << std::endl;
	Scalar anyVar1("anyVar1");
	std::cout << " anyVar1                : " << anyVar1 << std::endl;
	std::cout << " name and type          : " << anyVar1.getName() << " = " << anyVar1.getValueType() << std::endl;
	anyVar1 = anyVar;
	std::cout << " anyVar1=anyVar         : " << anyVar1 << std::endl;
	std::cout << " name and type          : " << anyVar1.getName() << " = " << anyVar1.getValueType() << std::endl;
	Scalar anyVar2("anyVar2");
	std::cout << " anyVar2                : " << anyVar2 << std::endl;
	std::cout << " name and type          : " << anyVar2.getName() << " = " << anyVar2.getValueType() << std::endl;
	anyVar = anyVar2;
	std::cout << " anyVar=anyVar2         : " << anyVar << std::endl;
	std::cout << " anyVar name and type   : " << anyVar.getName() << " = " << anyVar.getValueType() << std::endl;
	std::cout << " anyVar2 name and type  : " << anyVar2.getName() << " = " << anyVar2.getValueType() << std::endl;
	Scalar anyType("anyType",ANY,"Testing Any");
	std::cout << " anyType                : " << anyType << std::endl;
	std::cout << " name and type          : " << anyType.getName() << " = " << anyType.getValueType() << std::endl;
	std::cout << " anyVar2 < anyType      : " << (anyVar2 < anyType) << std::endl;
	std::cout << " anyVar2 == anyType     : " << (anyVar2 == anyType) << std::endl;
	Scalar g1("g1",GENOTYPE,"120/120");
	Scalar g2("g2",GENOTYPE,"120/120");
	Scalar g3("g3",GENOTYPE,"112/118");
	Scalar g4("g4",GENOTYPE,"C/T");
	Scalar g5("g5",GENOTYPE,"A/A");
	std::cout << " g1                     : " << g1 << std::endl;
	std::cout << " name and type          : " << g1.getName() << " = " << g1.getValueType() << std::endl;
	anyVar2 = g1;
	std::cout << " anyVar2=g1             : " << anyVar2 << std::endl;
	std::cout << " name and type          : " << anyVar2.getName() << " = " << anyVar2.getValueType() << std::endl;
	std::cout << " g2                     : " << g2 << std::endl;
	std::cout << " g3                     : " << g3 << std::endl;
	std::cout << " g4                     : " << g4 << std::endl;
	std::cout << " g5                     : " << g5 << std::endl;
	std::cout << " name and type          : " << g5.getName() << " = " << g5.getValueType() << std::endl;
	std::cout << " g1 < g2                : " << (g1 < g2) << std::endl;
	std::cout << " g2 == g1               : " << (g2 == g1) << std::endl;
	std::cout << " g5 < g4                : " << (g5 < g4) << std::endl;
	std::cout << " g2 < g4                : " << (g2 < g4) << std::endl;
	std::cout << " g2 < e                 : " << (g2 < e) << std::endl;
	std::cout << " ga == g2               : " << (ga == g2) << std::endl;
	Scalar f("f",STRING,"123/125");
	Scalar g6Any("g6Any");
	std::cout << " g6Any                  : " << g6Any << std::endl;
	std::cout << " name and type          : " << g6Any.getName() << " = " << g6Any.getValueType() << std::endl;
	g6Any = f;
	std::cout << " g6Any=f                : " << g6Any << std::endl;
	std::cout << " name and type          : " << g6Any.getName() << " = " << g6Any.getValueType() << std::endl;
	g3 = g6Any;
	std::cout << " g3=g6Any               : " << g3 << std::endl;
	std::cout << " name and type          : " << g3.getName() << " = " << g3.getValueType() << std::endl;
	Scalar g7Inv("g7Inv");
	g7Inv.set(GENOTYPE,"0/0");
	std::cout << " g7Inv                  : " << g7Inv << std::endl;
	std::cout << " name and type          : " << g7Inv.getName() << " = " << g7Inv.getValueType() << std::endl;
	Scalar d1("d1",DATE,"1987-08-23");
	Scalar d2("d2",DATE,"1987-08");
	Scalar d3("d3",DATE,"[1987-1990]");
	Scalar d4("d4",DATE,"~2000-02-13");
	Scalar d5("d5",DATE,"1948");
	Scalar d6Any("d6Any");
	std::cout << " d1                     : " << d1 << std::endl;
	std::cout << " name and type          : " << d1.getName() << " = " << d1.getValueType() << std::endl;
	std::cout << " d6Any                  : " << d6Any << std::endl;
	std::cout << " name and type          : " << d6Any.getName() << " = " << d6Any.getValueType() << std::endl;
	d6Any = d1;
	std::cout << " d6Any=d1               : " << d6Any << std::endl;
	std::cout << " name and type          : " << d6Any.getName() << " = " << d6Any.getValueType() << std::endl;
	std::cout << " d2                     : " << d2 << std::endl;
	std::cout << " d3                     : " << d3 << std::endl;
	std::cout << " d4                     : " << d4 << std::endl;
	std::cout << " d5                     : " << d5 << std::endl;
	Scalar d7Inv("d7Inv");
	d7Inv.set(DATE,"2003-[03-04-12");
	std::cout << " d7Inv                  : " << d7Inv << std::endl;
	std::cout << " name and type          : " << d7Inv.getName() << " = " << d7Inv.getValueType() << std::endl;
	std::cout << " d1 < d2                : " << (d1 < d2) << std::endl;
	std::cout << " d2 == d1               : " << (d2 == d1) << std::endl;
	std::cout << " d2 == d3               : " << (d2 == d3) << std::endl;
	std::cout << " d3 < d2                : " << (d3 < d2) << std::endl;
	std::cout << " d5 < d4                : " << (d5 < d4) << std::endl;
	std::cout << " d2 < d4                : " << (d2 < d4) << std::endl;
	std::cout << " d2 < e                 : " << (d2 < e) << std::endl;
	std::cout << " ga == d2               : " << (ga == d2) << std::endl;
	Scalar d8Copy(d4);
	std::cout << " Copy of d4             : " << d8Copy << std::endl;
	std::cout << " name and type          : " << d8Copy.getName() << " = " << d8Copy.getValueType() << std::endl;
	std::cout << " d4 == d8Copy           : " << (d4 == d8Copy) << std::endl;
	
	Scalar n1("n1",NUMBER,"19-23");
	Scalar n2("n2",NUMBER,"18-38");
	Scalar n3("n3",NUMBER,"17");
	Scalar n4("n4",NUMBER,"~20");
	Scalar n5("n5",NUMBER,"48");
	Scalar n6Any("n6Any");
	std::cout << " n1                     : " << n1 << std::endl;
	std::cout << " name and type          : " << n1.getName() << " = " << n1.getValueType() << std::endl;
	std::cout << " n6Any                  : " << n6Any << std::endl;
	std::cout << " name and type          : " << n6Any.getName() << " = " << n6Any.getValueType() << std::endl;
	n6Any = n1;
	std::cout << " n6Any=n1               : " << n6Any << std::endl;
	std::cout << " name and type          : " << n6Any.getName() << " = " << n6Any.getValueType() << std::endl;
	std::cout << " n2                     : " << n2 << std::endl;
	std::cout << " n3                     : " << n3 << std::endl;
	std::cout << " n4                     : " << n4 << std::endl;
	std::cout << " n5                     : " << n5 << std::endl;
	Scalar n7Inv("n7Inv");
	n7Inv.set(NUMBER,"2003-[");
	std::cout << " n7Inv                  : " << n7Inv << std::endl;
	std::cout << " name and type          : " << n7Inv.getName() << " = " << n7Inv.getValueType() << std::endl;
	std::cout << " n1 < n2                : " << (n1 < n2) << std::endl;
	std::cout << " n2 == n1               : " << (n2 == n1) << std::endl;
	std::cout << " n2 == n3               : " << (n2 == n3) << std::endl;
	std::cout << " n3 < n2                : " << (n3 < n2) << std::endl;
	std::cout << " n5 < n4                : " << (n5 < n4) << std::endl;
	std::cout << " n2 < n4                : " << (n2 < n4) << std::endl;
	std::cout << " n2 < e                 : " << (n2 < e) << std::endl;
	std::cout << " ga == n2               : " << (ga == n2) << std::endl;
	Scalar n8Copy(n4);
	std::cout << " Copy of n4             : " << n8Copy << std::endl;
	std::cout << " name and type          : " << n8Copy.getName() << " = " << n8Copy.getValueType() << std::endl;
	std::cout << " n4 == n8Copy           : " << (n4 == n8Copy) << std::endl;
	Number::addNumberMissingValue("99");
	std::cout << "Added 99 as Number missing value" << std::endl;
	Scalar n8("n8",NUMBER,"99");
	std::cout << " n8=99                  : " << n8 << std::endl;
	return 0;
	
} 
int main()
{











//        E X T E N D I D O . . .



assert (        mtk::fnExt(mtk::fnDec(5), mtk::fnInc(5)   )
                !=
                mtk::fnExt(mtk::fnDec(2), mtk::fnInc(5)    )
    );

assert (        mtk::fnExt(mtk::fnDec(2), mtk::fnInc(10)   )
                !=
                mtk::fnExt(mtk::fnDec(1), mtk::fnInc(1)    )
    );




//---------------------------------------------------------------------------

//              f n D o u b l e

//---------------------------------------------------------------------------

//  the same..
mtk::fnDouble d1 (3.4);
mtk::fnDouble d2 (3.4, mtk::fnRoundArithmetic   );

mtk::fnDouble d3 (3.4, mtk::fnRoundFloor        );
mtk::fnDouble d4 (3.4, mtk::fnRoundCeil         );
mtk::fnDouble d5 (3.4, mtk::fnRoundNotAllowed   );








//---------------------------------------------------------------------------

//              F i x e d N u m b e r

//---------------------------------------------------------------------------


    //  CONSTRUCTORES   ____________________________________________________


//  double
assert  (
            mtk::FixedNumber(
                mtk::fnDouble   (3.1415926535          ),
                mtk::fnDec      (4                     ),
                mtk::fnInc      (1                     )
            )
            ==
            mtk::FixedNumber(
                mtk::fnDouble   (3.1415926535            ,
                                 mtk::fnRoundArithmetic ),
                mtk::fnDec      (4                      ),
                mtk::fnInc      (1                      )
            )
    );

assert  (
            mtk::FixedNumber(
                mtk::fnDouble   (3.1415926535        ,
                                 mtk::fnRoundCeil   ),
                mtk::fnDec      (4                  ),
                mtk::fnInc      (1                  )
            )
            ==
            mtk::FixedNumber(
                mtk::fnDouble   (3.1415926535        ,
                                 mtk::fnRoundCeil   ),
                mtk::fnDec      (4                  ),
                mtk::fnInc      (1                  )
            )

        );

//  integer
assert  (
            mtk::FixedNumber(
                mtk::fnIntCode  (31416                 ),
                mtk::fnDec      (4                     ),
                mtk::fnInc      (1                     )
            )
            ==
            mtk::FixedNumber(
                mtk::fnDouble   (3.1415926535            ,
                                 mtk::fnRoundArithmetic ),
                mtk::fnDec      (4                      ),
                mtk::fnInc      (1                      )
            )

        );



        //  error en tiempo de ejecución
        //  redondeo por defecto para enteros...   notallowed
        /*
            mtk::FixedNumber(
                mtk::fnIntCode  (31416              ),
                mtk::fnDec      (4                  ),
                mtk::fnInc      (5                  )
            );
      */

assert  (
            mtk::FixedNumber(
                mtk::fnIntCode  (31415                 ),
                mtk::fnDec      (4                     ),
                mtk::fnInc      (5                     )
            )
            ==
            mtk::FixedNumber(
                mtk::fnIntCode   (31416                  ,
                                 mtk::fnRoundArithmetic ),
                mtk::fnDec      (4                      ),
                mtk::fnInc      (5                      )
            )

        );






//  fnExt
assert  (
            mtk::FixedNumber(
                mtk::fnIntCode  (31416                 ),
                mtk::fnExt (
                            mtk::fnDec      (4         ),
                            mtk::fnInc      (1         )
                           )
            )
            ==
            mtk::FixedNumber(
                mtk::fnDouble   (3.1415926535            ,
                                 mtk::fnRoundArithmetic ),
                mtk::fnExt (
                            mtk::fnDec      (4          ),
                            mtk::fnInc      (1          )
                           )
            )

        );






    //  Métodos de acceso  ________________________________________________

    //  lectura
    assert  (
                mtk::FixedNumber(mtk::fnDouble(3.14), mtk::fnDec(2), mtk::fnInc(5))
                .GetDouble()
                > 3.14
                //  == 3.15
            );


    {
    mtk::FixedNumber fn1 (mtk::fnDouble(3.14), mtk::fnDec(2), mtk::fnInc(5));

    assert (    fn1.GetExt().GetDec()       ==  2              );
    assert (    fn1.GetDouble()             >   3.14           );
    assert (    fn1.d()                     >   3.14           );
    assert (    fn1.GetExt().GetFormat()    ==  mtk::fnFNormal );



        //  escritura
    fn1.SetDouble(3.11);
    assert (    fn1.GetIntCode()            ==  310 );
    assert (    fn1.GetDouble ()            <   3.11);

    fn1.SetIntCode(39);
    assert (    fn1.GetIntCode()            ==  40 );
    assert (    fn1.GetDouble ()            >   0.39);


    mtk::FixedNumber  fn2 =  fn1;
    assert (    fn1.SetDouble(3.10)         ==  fn2.SetIntCode(310)  );


    assert  (
                mtk::FixedNumber(
                    mtk::fnIntCode  (0                      ),
                    mtk::fnDec      (4                      ),
                    mtk::fnInc      (5                      )
                ).SetIntCode (31415)
                ==
                mtk::FixedNumber(
                    mtk::fnIntCode  (0                      ),
                    mtk::fnDec      (4                      ),
                    mtk::fnInc      (5                      )
                ).SetIntCode (31416, mtk::fnRoundArithmetic )

            );


            //  error en tiempo de ejecución,
            //  default round for integers, not allowed
        /*
                mtk::FixedNumber fnp = mtk::FixedNumber(
                            mtk::fnIntCode  (0                  ),
                            mtk::fnDec      (4                  ),
                            mtk::fnInc      (5                  )
                    ).SetIntCode (31416);

                mtk::FixedNumber fnp2(
                            mtk::fnIntCode  (0                  ),
                            mtk::fnDec      (4                  ),
                            mtk::fnInc      (5                  )
                    );
                fnp2.SetIntCode (31416);
          */
    }









    //  OPERADORES      ____________________________________________________

        //  relacionales
assert  (
            mtk::FixedNumber(mtk::fnDouble(3.14), mtk::fnDec(2), mtk::fnInc(5))
            >=
            mtk::FixedNumber(mtk::fnDouble(3.14), mtk::fnDec(2), mtk::fnInc(5))
            &&
            mtk::FixedNumber(mtk::fnDouble(3.14), mtk::fnDec(2), mtk::fnInc(5))
            >
            mtk::FixedNumber(mtk::fnDouble(3.0) , mtk::fnDec(2), mtk::fnInc(5))
            &&
            mtk::FixedNumber(mtk::fnDouble(3.0) , mtk::fnDec(2), mtk::fnInc(5))
            !=
            mtk::FixedNumber(mtk::fnDouble(3.14) , mtk::fnDec(2), mtk::fnInc(5))
            &&
            mtk::FixedNumber(mtk::fnDouble(3.14) , mtk::fnDec(2), mtk::fnInc(5))
            <
            mtk::FixedNumber(mtk::fnDouble(20.0) , mtk::fnDec(2), mtk::fnInc(5))
        );


            //  error en tiempo de ejecución, no son comparables
/*
assert  (
            mtk::FixedNumber(mtk::fnDouble(3.14), mtk::fnDec(2), mtk::fnInc(1))
            >=
            mtk::FixedNumber(mtk::fnDouble(3.14), mtk::fnDec(2), mtk::fnInc(5))
        );
assert  (
            mtk::FixedNumber(mtk::fnDouble(3.14), mtk::fnDec(1), mtk::fnInc(5))
            >=
            mtk::FixedNumber(mtk::fnDouble(3.14), mtk::fnDec(2), mtk::fnInc(5))
        );
*/





        //  aritméticos

mtk::FixedNumber fna (mtk::fnDouble(3.20), mtk::fnDec(2), mtk::fnInc(1));
assert  (
            ++mtk::FixedNumber(mtk::fnDouble(3.14), mtk::fnDec(2), mtk::fnInc(1))
            ==
            mtk::FixedNumber  (mtk::fnDouble(3.15), mtk::fnDec(2), mtk::fnInc(1))

            &&

            mtk::FixedNumber  (mtk::fnDouble(3.15), mtk::fnDec(2), mtk::fnInc(1))
            ==
            --mtk::FixedNumber(mtk::fnDouble(3.16), mtk::fnDec(2), mtk::fnInc(1))

            &&

            --mtk::FixedNumber(mtk::fnDouble(3.16), mtk::fnDec(2), mtk::fnInc(1))
            ==
            mtk::FixedNumber  (mtk::fnDouble(3.10), mtk::fnDec(2), mtk::fnInc(1))
            +mtk::fnTicks(5)

            &&

            mtk::FixedNumber  (mtk::fnDouble(3.10), mtk::fnDec(2), mtk::fnInc(1))
            +mtk::fnTicks(5)
            ==
            (fna-=mtk::fnTicks(5))
        );






{
    mtk::FixedNumber         fn1(mtk::fnIntCode(0),   mtk::fnDec(3), mtk::fnInc(5) );
    fn1.SetDouble(3.14);
    mtk::FixedNumber         fn2(mtk::fnDouble(3.14), mtk::fnDec(3), mtk::fnInc(5) );
    mtk::FixedNumber         fn3(mtk::fnIntCode(0),   mtk::fnDec(3), mtk::fnInc(5) );
    fn3.SetIntCode(3140);

    assert          (fn1 == fn2    &&    fn2 == fn3);
    assert          (   fn3
                        ==
                        mtk::FixedNumber(
                                mtk::fnIntCode(0),
                                mtk::fnDec(3),
                                mtk::fnInc(5)
                               ).SetIntCode(3140)
                    );
}





    #include "support/release_on_exit.hpp"
    return 0;
}
Example #30
0
int main()
{
    Samoyed::Scheduler scheduler(8);

    AlarmDriver d1(scheduler, 1, 1, 1),
                d2(scheduler, 2, 2, 2),
                d3(scheduler, 3, 3, 3),
                d4(scheduler, 4, 4, 4),
                d5(scheduler, 5, 5, 5);
    boost::system_time t = boost::get_system_time();
    printf("Alarm 1 runs 10 times\n");
    d1.run(10, false);
    printf("Scheduler starts 3 threads\n");
    scheduler.size_controller().resize(3);
    printf("Alarm 2 runs 1 more time\n");
    d2.run(1, true);
    t += boost::posix_time::seconds(5);
    boost::thread::sleep(t);
    printf("Alarm 1 runs 1 time\n");
    d1.run(1, false);
    printf("Alarm 2 runs 2 more times\n");
    d2.run(2, true);
    printf("Alarm 3 runs 1 more time\n");
    d3.run(1, true);
    printf("Alarm 4 runs 7 more times\n");
    d4.run(7, true);
    printf("Alarm 5 runs 5 more times\n");
    d5.run(5, true);
    t += boost::posix_time::seconds(7);
    boost::thread::sleep(t);
    printf("Scheduler resizes to 2 threads\n");
    scheduler.size_controller().resize(2);
    printf("Alarm 1 runs 1 time\n");
    d1.run(1, false);
    printf("Alarm 2 runs 7 more times\n");
    d2.run(7, true);
    printf("Alarm 3 runs 11 more times\n");
    d3.run(11, true);
    printf("Alarm 4 runs 5 more times\n");
    d4.run(5, true);
    printf("Alarm 5 runs 7 times\n");
    d5.run(7, false);

    scheduler.wait();

    GMainContext *ctx = g_main_context_default();
    while (g_main_context_pending(ctx))
        g_main_context_iteration(ctx, TRUE);

    boost::shared_ptr<Alarm> a1(new Alarm(scheduler, 1, 1, 1, 1)),
                             a2(new Alarm(scheduler, 2, 2, 2, 2)),
                             a3(new Alarm(scheduler, 3, 3, 3, 3)),
                             a4(new Alarm(scheduler, 4, 4, 4, 4)),
                             a5(new Alarm(scheduler, 5, 5, 5, 5));
    a2->addDependency(a1);
    a3->addDependency(a1);
    a4->addDependency(a2);
    a4->addDependency(a3);
    a5->addDependency(a1);
    a5->addDependency(a2);
    a5->addDependency(a3);

    printf("Submit all\n");
    a5->submit(a5);
    a4->submit(a4);
    a3->submit(a3);
    a2->submit(a2);
    a1->submit(a1);

    a1.reset();
    a2.reset();
    a3.reset();
    a4.reset();

    t = boost::get_system_time() + boost::posix_time::seconds(5);
    boost::thread::sleep(t);
    printf("Cancel alarm 5\n");
    a5->cancel(a5);
    a5.reset();

    scheduler.wait();

    while (g_main_context_pending(ctx))
        g_main_context_iteration(ctx, TRUE);
    return 0;
}