void interval_set_contains_4_bicremental_types()
{
    typedef IntervalSet<T> IntervalSetT;
    typedef typename IntervalSetT::interval_type IntervalT;
    //LAW: x.add(e).contains(e);
    //LAW: z = x + y => contains(z, x) && contains(z, y);
    T v1 = make<T>(1);
    T v3 = make<T>(3);
    T v5 = make<T>(5);
    T v7 = make<T>(7);
    T v8 = make<T>(8);
    T v9 = make<T>(9);
    T v11 = make<T>(11);
    IntervalSet<T> is(v1);    
    BOOST_CHECK_EQUAL( icl::contains(is, v1), true );

    BOOST_CHECK_EQUAL( icl::contains(IntervalSet<T>().add(make<T>(2)), make<T>(2)), true );
    BOOST_CHECK_EQUAL( icl::contains(IntervalSet<T>().insert(make<T>(2)), make<T>(2)), true );
    BOOST_CHECK_EQUAL( icl::contains((is += IntervalT(v3,v7)), IntervalT(v3,v7)), true );

    IntervalSet<T> is0 = is;    

    IntervalSet<T> is2(IntervalT::closed(v5,v8));
    is2.add(v9).add(v11);
    is += is2;
    BOOST_CHECK_EQUAL( contains(is, is2), true );    

    is = is0;
    IntervalSet<T> is3(IntervalT::closed(v5,v8));
    is3.insert(v9).insert(v11);
    is += is3;
    BOOST_CHECK_EQUAL( contains(is, is3), true );    
}
Beispiel #2
0
void ClansManager::load(Settings& args)
{
	try{
		m_maxId = args.getS32("clans-maxId");
		
		std::string s = args.get("clans-names");
		std::istringstream is(s);
		while(is.good() && !is.eof()){
			u16 id;
			std::string name;
			is >> id >> name;
			if(id == 0 || name.length() == 0) continue;
			setClan(id,name,false);
		}

		if(args.exists("clans-spawn")){
			s = args.get("clans-spawn");
			std::istringstream is3(s);
			while(is3.good() && !is3.eof()){
				u16 id;
				v3f spawn;
				is3 >> id >> spawn.X >> spawn.Y >> spawn.Z;
				if(id == 0) continue;
				Clan* clan = getClan(id);
				if(!clan) continue;
				clan->hasSpawnPoint = true;
				clan->spawnPoint = spawn;
			}
		}

		s = args.get("clans-deleted");
		std::istringstream is2(s);
		while(is2.good() && !is2.eof()){
			u16 id;
			is2 >> id;
			if(id == 0 ) continue;
			deleteClan(id);
			m_deleted.insert(id);
		}

	}catch(...){
Beispiel #3
0
int
main()
{
  std::cout.setf(std::ios_base::boolalpha);

  std::polynomial<double> P({0.0, 1.0, 2.0, 3.0});
  std::cout << "P = " << P << std::endl;
  std::cout << "+P = " << +P << std::endl;
  std::cout << "-P = " << -P << std::endl;
  std::cout << "P = " << P << std::endl;
  std::cout << "degree(P) = " << P.degree() << std::endl;
  std::polynomial<double> Q({2.0, 1.0});
  std::cout << "Q = " << Q << std::endl;
  std::cout << "degree(Q) = " << Q.degree() << std::endl;
  std::cout << "P + Q = " << P + Q << std::endl;
  std::cout << "P - Q = " << P - Q << std::endl;
  std::cout << "P * Q = " << P * Q << std::endl;
  std::cout << "P / Q = " << P / Q << std::endl;
  std::cout << "P % Q = " << P % Q << std::endl;
  double b = 5.0;
  std::cout << "b = " << b << std::endl;
  std::cout << "P + b = " << P + b << std::endl;
  std::cout << "P - b = " << P - b << std::endl;
  std::cout << "P * b = " << P * b << std::endl;
  std::cout << "P / b = " << P / b << std::endl;
  std::cout << "P % b = " << P % b << std::endl;
  double a = 2.0;
  std::cout << "a = " << a << std::endl;
  std::cout << "a + Q = " << a + Q << std::endl;
  std::cout << "a - Q = " << a - Q << std::endl;
  std::cout << "a * Q = " << a * Q << std::endl;
  std::cout << "a / Q = " << a / Q << std::endl;
  std::cout << "a % Q = " << a % Q << std::endl;

  std::polynomial<double> B;// = b;
  B = b;
  std::cout << "B = " << B << std::endl;
  std::cout << "P % B = " << P % B << std::endl;

  Q = {0.0, -2.0, 4.0, -6.0, 8.0, -12.0};
  std::cout << "Q = " << Q << std::endl;

  std::polynomial<double> P2;
  P2 = P;
  std::cout << "P2 = " << P2 << std::endl;
  std::cout << "P2 == P = " << (P2 == P) << std::endl;

  for (int i = 0; i <= 100; ++i)
  {
    double x = i * 0.1;
    std::cout << "P(" << x << ") = " << P(x) << std::endl;
  }

  std::polynomial<std::complex<double>>
  CP({std::complex<double>(0.0, -1.0),
      std::complex<double>(1.0, -2.0), 
      std::complex<double>(2.0, -3.0), 
      std::complex<double>(3.0, -4.0)});
  std::cout << "CP = " << CP << std::endl;
  std::cout << "CP * CP = " << CP * CP << std::endl;

  std::polynomial<int> IP({0, 1, 2, 3});
  std::cout << "IP = " << IP << std::endl;
  std::cout << "IP * IP = " << IP * IP << std::endl;

  std::array<double, 10> arr;
  P.eval(1.0, arr);
  std::cout << "P(" << 1.0 << ") =";
  for (int i = 0; i < arr.size(); ++i)
    std::cout << " " << arr[i];
  std::cout << std::endl;

  P.eval(1.0, arr.begin(), arr.end());
  std::cout << "P(" << 1.0 << ") =";
  for (auto iarr = arr.cbegin(); iarr != arr.cend(); ++iarr)
    std::cout << " " << *iarr;
  std::cout << std::endl;

  std::istringstream is("(-2.0, -1.0, 0.0)");
  std::polynomial<double> R;
  is >> R;
  std::cout << "R = " << R << std::endl;

  std::istringstream is2("(5.0)");
  std::polynomial<double> S;
  is2 >> S;
  std::cout << "S = " << S << std::endl;

  std::istringstream is3("42.0");
  std::polynomial<double> T;
  is3 >> T;
  std::cout << "T = " << T << std::endl;

  std::polynomial<double> u({1.0, 3.0, 3.0, 1.0});
  std::polynomial<double> v({1.0, 1.0});
  std::polynomial<double> q, r;
  std::divmod(u, v, q, r);
  std::cout << "u = " << u << std::endl;
  std::cout << "v = " << v << std::endl;
  std::cout << "q = " << q << std::endl;
  std::cout << "r = " << r << std::endl;

  std::polynomial<double> u1({1.0, -3.0, 3.0, -1.0});
  std::polynomial<double> v1({1.0, -2.0, 1.0});
  std::polynomial<double> q1, r1;
  std::divmod(u1, v1, q1, r1);
  std::cout << "u1 = " << u1 << std::endl;
  std::cout << "v1 = " << v1 << std::endl;
  std::cout << "q1 = " << q1 << std::endl;
  std::cout << "r1 = " << r1 << std::endl;

  std::polynomial<double> u2({1.0, 1.0});
  std::polynomial<double> v2({1.0, 3.0, 3.0, 1.0});
  std::polynomial<double> q2, r2;
  std::divmod(u2, v2, q2, r2);
  std::cout << "u2 = " << u2 << std::endl;
  std::cout << "v2 = " << v2 << std::endl;
  std::cout << "q2 = " << q2 << std::endl;
  std::cout << "r2 = " << r2 << std::endl;

  std::polynomial<double> u3({1.0, 0.0, 0.0, 1.0});
  std::polynomial<double> v3({1.0, 3.0, 3.0, 1.0});
  std::polynomial<double> q3, r3;
  std::divmod(u3, v3, q3, r3);
  std::cout << "u3 = " << u3 << std::endl;
  std::cout << "v3 = " << v3 << std::endl;
  std::cout << "q3 = " << q3 << std::endl;
  std::cout << "r3 = " << r3 << std::endl;

  std::cout << "P = " << P << std::endl;
  std::cout << "P' = " << P.derivative() << std::endl;
  std::cout << "I = " << P.integral(42.0) << std::endl;

  //std::array<double, 5> aaa{{1.1, 2.2, 3.3, 4.4, 5.5}};
  //std::cout << "aaa = " << std::polynomial_eval(aaa, 3.13149) << std::endl;
}
Beispiel #4
0
int main()
{
   //---
   // Test ossiIpt::operator>>
   //---
   std::string is1(" ( 0, 1 )");
   std::string is2(" (2,3)");
   std::string is3(" ( 4, 5 )");
   std::string is4_5_6_7(" ( 6, 7 )(8, 9) ( 10, 11 ) ( 12, 13) 9876");

   ossimIpt ip1;
   ossimIpt ip2;
   ossimIpt ip3;
   ossimIpt ip4;
   ossimIpt ip5;
   ossimIpt ip6;
   ossimIpt ip7;
   

   ip1.toPoint(is1);
   ip2.toPoint(is2);
   ip3.toPoint(is3);
   int i;

   std::istringstream istr(is4_5_6_7);
   istr >> ip4 >> ip5 >> ip6 >> ip7 >> i;

   //---
   // Test ossiDpt::operator>>
   //---
   std::string ds1(" ( 0.0, 1.1 )");
   std::string ds2(" (2.2,3.3)");
   std::string ds3(" ( 4.4, 5.5 )");
   std::string ds4_5_6_7(" ( 6.6, 7.7 )(8.8, 9.9) ( 10.0, 11.0 ) ( 12.0, 13.0) 9876.12345678");
   std::string ds8("12 20");

   ossimDpt dp1;
   ossimDpt dp2;
   ossimDpt dp3;
   ossimDpt dp4;
   ossimDpt dp5;
   ossimDpt dp6;
   ossimDpt dp7;
   ossimDpt dp8;

   dp1.toPoint(ds1);
   dp2.toPoint(ds2);
   dp3.toPoint(ds3);
   double d;

   std::istringstream istr2(ds4_5_6_7);
   istr2 >> dp4 >> dp5 >> dp6 >> dp7 >> d;

   dp8.toPoint(ds8); // Test an invalid string "12 20"

    //---
   // Test ossiDpt3d
   //---
   std::string ds3d1  = " ( 0.0, 1.1, 2.2 )";
   std::string ds3d2 = "(1.0,2.0,3.0)";
   
   ossimDpt3d dp3d1;
   ossimDpt3d dp3d2;
   dp3d1.toPoint(ds3d1);
   dp3d2.toPoint(ds3d2);


   //---
   // Test ossiGpt::operator>>
   //---
   std::string gs1("(0.0,0.0,0.0,WGE)");
   std::string gs2("(1.1,2.2,3.3,NAR-C)");
   std::string gs3(" (4.4,5.5,6.6,NAS-C )");
   std::string gs4_5_6_7(" (4.4,5.5,6.6,NAS-C )( 10.0, 10.0 ,5.0, TOY-C ) (17, -89, 50.0, xxx) (28.2, -44.5, 10000.0, NAS-B) 12345.6789");

   ossimGpt gp1;
   ossimGpt gp2;
   ossimGpt gp3;
   ossimGpt gp4;
   ossimGpt gp5;
   ossimGpt gp6;
   ossimGpt gp7;
   double d2;

   gp1.toPoint(gs1);
   gp2.toPoint(gs2);
   gp3.toPoint(gs3);

   std::istringstream istr4(gs4_5_6_7);
   istr4 >> gp4 >> gp5 >> gp6 >> gp7 >> d2;


   //---
   // Test ossimEcefPoint toString and toPoint methods.
   //---
   std::string es1("(1.0,2.0,3.0)");
   ossimEcefPoint ep1;
   ep1.toPoint(es1);
   std::string es2 = ep1.toString(10).string();

   //---
   // Test ossimEcefPoint toString and toPoint methods.
   //---
   ossimEcefVector ev1;
   ev1.toPoint(es1);
   std::string es3 = ev1.toString(10).string();
  
   std::cout
      << "\nis1:       " << is1
      << "\nip1:       " << ip1
      << "\nis2:       " << is2
      << "\nip2:       " << ip2
      << "\nis3:       " << is3
      << "\nip3:       " << ip3
      << "\nis4_5_6_7: " << is4_5_6_7
      << "\nip4:       " << ip4
      << "\nip5:       " << ip5
      << "\nip6:       " << ip6
      << "\nip7:       " << ip7
      << "\ni:         " << i

      << "\n\n\nds1:       " << ds1
      << "\ndp1:       " << dp1
      << "\nds2:       " << ds2
      << "\ndp2:       " << dp2
      << "\nds3:       " << ds3
      << "\ndp3:       " << dp3
      << "\nds4_5_6_7: " << ds4_5_6_7
      << "\ndp4:       " << dp4
      << "\ndp5:       " << dp5
      << "\ndp6:       " << dp6
      << "\ndp7:       " << dp7
      << "\nds8:       " << ds8
      << "\ndp8:       " << dp8
      << "\nd:         " << d

      << "\n\nds3d1:       " << ds3d1
      << "\nds3d2:     " << ds3d2
      << "\ndp3d1:     " << dp3d1
      << "\ndp3d2:     " << dp3d2

      << "\n\n\ngs1:       " << gs1
      << "\ngp1:       " << gp1
      << "\ngs2:       " << gs2
      << "\ngp2:       " << gp2
      << "\ngs3:       " << gs3
      << "\ngp3:       " << gp3
      << "\ngs4_5_6_7: " << gs4_5_6_7
      << "\ngp4:       " << gp4
      << "\ngp5:       " << gp5
      << "\ngp6:       " << gp6
      << "\ngp7:       " << gp7
      << "\nd2:         " << d2

      << "\n\n\nes1:       " << es1
      << "\nep1:       " << ep1
      << "\nes2:       " << es2
      << "\nev1:       " << ev1
      << "\nes3:       " << es3

      << std::endl;

   return 0;
}
Beispiel #5
0
double lfun (double x[], int np)
{
  GaussLegendreRule(&xI, &wI, com.npoints);
  for (Gtree=0; Gtree<com.nGtree;Gtree++){
    for(igrid=0; igrid<K*K; igrid++){
      if(Gtree==G1a||Gtree==G1b || Gtree==G1c){
	if(com.model==M2SIM3s){
	  xtoy(Q,Q1,DIM*DIM);
	  complexroots (Q1, Pt1, t[0]*t[1]);
	  if(0 && igrid==0){
	    debug_print(Pt1, DIM);
	  }
	  xtoy(Q,Q1,DIM*DIM);
	  complexroots (Q1, Pt0, t[0]-t[0]*t[1]);
	  if(0 && igrid==0){
	    debug_print(Pt0, DIM);
	  }
	  if (Gtree==G1c){
	  }
	  else if (Gtree==G1b){
	  }
	  else if (Gtree==G1a){
	  }
	}
	b[1]=t[0]*t[1];	
	b[0]=t[0]-t[0]*t[1];
      }
      else if(Gtree==G2a || Gtree==G2b || Gtree==G2c || Gtree== G3a || Gtree ==G3b || Gtree ==G3c){
	if(com.model==M2SIM3s){
	  xtoy(Q,Q1,DIM*DIM);
	  complexroots (Q1, Pt0, tau1-t[1]); /*ÔÚpt.cÀֱ½ÓÓÿÉÄÜÓÐÎÊÌâ*/
	  xtoy(Q,Q1,DIM*DIM);
	  complexroots (Q1, Pt1, t[1]);
	  //printf("\n In lfun after end2\n");
	  for(s=1;s<=8;s++){ //problems about s-1
	    if (Gtree==G2c || Gtree==G3c)
	      f[s-1]=(Pt1[get_ij(s,1,DIM)] * is2(11,Pt0,DIM) + Pt1[s,2,DIM]*is2(20,Pt0,DIM)) * 2/theta1
		+      (Pt1[get_ij(s,7,DIM)] * is2(17,Pt0,DIM) + Pt1[s,8,DIM]*is2(14,Pt0,DIM)) * 2/theta2;
	    else if (Gtree==G2b || Gtree==G3b)
	      f[s-1]=(Pt1[get_ij(s,1,DIM)] * is2(10,Pt0,DIM) + Pt1[s,3,DIM]*is2(19,Pt0,DIM))*2/theta1
		+(Pt1[get_ij(s,6,DIM)] * is2(16,Pt0,DIM) + Pt1[s,8,DIM]*is2(13,Pt0,DIM))*2/theta2;
	    else if (Gtree==G2a || Gtree==G3a)
	      f[s-1]=(Pt1[get_ij(s,1,DIM)] * is2( 9,Pt0,DIM) + Pt1[s,5,DIM]*is2(18,Pt0,DIM)) *2/theta1
		+(Pt1[get_ij(s,4,DIM)] * is2(15,Pt0,DIM) + Pt1[s,8,DIM]*is2(12,Pt0,DIM)) *2/theta2;
	  } 
	}
	if(Gtree==G2a || Gtree==G2b || Gtree==G2c){
	  g=exp(-t[0]);
	  for(s=1;s<=8;s++)
	    f[s-1]*=g;
	  b[1]=t[1];
	  b[0]= 2.0*t[0]/theta5+tau1-t[1];
	}
	else if(Gtree==G3a || Gtree==G3b || Gtree==G3c){
	  g= exp(-t[0])*exp(-2*(tau0-tau1)/theta5);
	  for(s=1;s<=8;s++)
	    f[s-1]*=g;
	  b[1]=t[1];
	  b[0]= 2.0*t[0]/theta4+tau0-t[1];
	}
      }

      else{
	//printf("\n In lfun after end3\n");
	if (Gtree==G4a || Gtree==G4b || Gtree==G4c){
	  g= exp(-3*t[0]*t[1]-t[0]*(1-t[1]));
	  b[1]=theta5/2*t[0]*t[1]+tau1;
	  b[0]=theta5/2*t[0]+tau1-b[1];
	}//above checked
	else if (Gtree==G5a || Gtree==G5b || Gtree==G5c){
	  g=exp(-2*t[1]-t[0])* exp(-2.0*(tau0-tau1)/theta5);
	  b[1]=theta5/2*t[1]+tau1;
	  b[0]=theta4/2*t[0]+tau0-b[1];
	}
	else if (Gtree==G6a || Gtree==G6b || Gtree==G6c){
	  g= exp(-3*t[1]-t[0])* exp(-6.0*(tau0-tau1)/theta5);
	  b[1]=theta4/2*t[1]+tau0;
	  b[0]=theta4/2*(t[0]+t[1])+tau0-b[1];
	} /*end else if*/
	if(com.model==M2SIM3s){
	  xtoy(Q,Q1,DIM*DIM);
	  complexroots (Q1, Ptau1, tau1);	
	  for(s=1;s<=8;s++)
	    f[s-1]= is3(s,Ptau1,DIM)*g; 
	}
      }
    
      for(s=0;s<8;s++)
	{
	  com.wwprior[Gtree][igrid][s] = f[s] * com.wwprior[Gtree][igrid][0];
	  //printf("wwprior[%d][%d][%d]=%f  ",Gtree, igrid,s,com.wwprior[Gtree][igrid][s]);
	}
      //printf("\n"); //hhh
      if(!com.fix_locusrate)
	p0124Fromb0b1(com.bp0124[Gtree]+igrid*5, b);
      else {
	com.bp0124[Gtree][igrid*2+0] = b[0];
	com.bp0124[Gtree][igrid*2+1] = b[1];
      }
      /* printf("%-3s %5d y%9.5f%9.5f t%9.5f%9.5f b%9.5f%9.5f\n",
	 GtreeStr[Gtree], igrid+1, y[0],y[1], t[0],t[1], b[0],b[1]); */
      //printf("In lfun after igrid loop !!!!\n"); zzz
    }
	
    for(locus=0; locus<com.ndata; locus++) {
      Li = lnpD_locus(locus,com.state[locus]);
      if(com.model==M1DiscreteBeta)
	com.pDclass[itau1*com.ndata+locus] = Li;
      else
	lnL += Li;
      n = com.Nij + locus*5;
      if(debug) printf("%d\t%d\t%d\t%d\t%d\t%.6f\n", n[0],n[1],n[2],n[3],n[4], Li);
    }
	
    return(-lnL);
  }