Example #1
0
FloatType route_evaluation(GlobalGiftData g_data, const Route & r){
    FloatType res = 0.0;
    int test_counter = 0;

    FloatType w = sleigh_base_weight;
    for (int i = 0; i < r.size(); ++i) {
        const auto & gift = g_data[r[i]];
        w += gift.Weight();
        ++test_counter;
    }

    auto w_limit = sleigh_weight_limit + sleigh_base_weight;

    // weight > then limit
    assert(w <= w_limit);

    res += w*Dist(north_pole, g_data[r[0]].Loc() );

    test_counter = 0;
    int __size = r.size();
    for (int i = 0; i < __size-1; ++i) {
        const auto & gift = g_data[r[i]];
        const auto & gift_next = g_data[r[i+1]];

        w -= gift.Weight();

        res += w*Dist(gift.Loc(), gift_next.Loc());
        ++test_counter;
    }

    w = sleigh_base_weight;
    res += w*Dist(north_pole, g_data[r[r.size()-1]].Loc() );

    return res;
}
Example #2
0
File: Graph.cpp Project: cran/SGCS
void Graph::sg_knn()
{

	int i,j,l, k;
	k = (int) par;
	std::vector<int> *node;

	if(prepR==0)// if not preprocessed
	{
		if(dbg) Rprintf("%i-nn: ", k);
		int n = pp->size();
		double *dists2_i, *dists2_i2;
		dists2_i = new double[n];
		dists2_i2 = new double[n];
		for(i=0;i<pp->size();i++) //for each point
		{
			for(j=0;j<pp->size();j++) dists2_i2[j]=dists2_i[j]= Dist(&i,&j); //gather the distances to others
			qsort( dists2_i, pp->size(), sizeof(double), compare_doubles); // sort distances, rising
			for(j=1;j <= k;j++) // find the k nearest
				for(l=0;l<pp->size();l++)
					if( dists2_i[j] == dists2_i2[l] ) //with distance comparison
					{
						nodelist[i].push_back(l+1);
						break;
					}

		}
	}
	else{ //preprocessed
		if(dbg) Rprintf("%i-nn (shrinking):", k);
		double *dists2_i, *dists2_i2;
		for(i=0;i<pp->size();i++) //for each point
		{
			node = new std::vector<int>;
			dists2_i = new double [nodelist[i].size()];
			dists2_i2 = new double [nodelist[i].size()];
			if((int)nodelist[i].size()<k){ Rprintf("\n preprocessing R too small, not enough neighbours (point #%i)!!\n",i+1); return;}
			for(l=	0;l< (int)nodelist[i].size();l++)
			{
				j = nodelist[i][l]-1;
				dists2_i2[l]=Dist(&i,&j); //gather the distances to others, given preprocessing
				dists2_i[l]=dists2_i2[l];
			}
			qsort( dists2_i, nodelist[i].size() , sizeof(double),compare_doubles); // sort distances, rising
			for(j=0;j<k;j++) // find the k nearest
				for(l=0;l<(int)nodelist[i].size();l++)
					if( dists2_i[j] == dists2_i2[l] ) //with distance comparison
					{
						node->push_back(nodelist[i][l]);
						break;
					}
			nodelist[i].clear();nodelist[i].resize(0);
			for(j=0;j < (int)node->size();j++) nodelist[i].push_back( (*node)[j] );
			delete node;
			delete[] dists2_i;
			delete[] dists2_i2;
		}
	}
	 if(dbg) Rprintf(" Ok.");
}
Example #3
0
double Adjust(){
  int i = 0;
  while (i < n && s[i] == 'T')
    ++i;
  if (i == n)
    return -0.5;
  if (i == 0){
    if (s[i] == 'S')
      return 0;
    else
      return -2 + M_PI / 2;
  }
  double x1 = 0.5;
  double y1 = sqrt(3) / 2;
  if (s[i] == 'S'){
    double x2 = i;
    double y2 = 1.0;
    return -x2 - 1 + Dist(0, 0, x1, y1) + Dist(x1, y1, x2, y2); 
  }
  else{
    double xc    = i + 0.5;
    double yc    = 0.5;
    double h     = Dist(x1, y1, xc, yc);
    double alpha = atan2(y1 - yc, x1 - xc);
    double fi    = acos(0.5 / h);
    double x2    = xc + 0.5 * cos(alpha - fi);
    double y2    = yc + 0.5 * sin(alpha - fi);
    return -xc - 1 + Dist(0, 0, x1, y1) + Dist(x1, y1, x2, y2) + 0.5 * (alpha - fi - M_PI / 2);
  }
}
Example #4
0
void  cDistorBilin::Diff(ElMatrix<REAL> & aM,Pt2dr aP) const
{
    // InitEtatFromCorner(ToCoordGrid(aP));

    Pt2dr aPds;
    GetParamCorner(mCurCorner,aPds,ToCoordGrid(aP)); 
    const Pt2dr & aP00 =  Dist(mCurCorner+CamBilinCorn[0] ) ;
    const Pt2dr & aP10 =  Dist(mCurCorner+CamBilinCorn[1] ) ;
    const Pt2dr & aP01 =  Dist(mCurCorner+CamBilinCorn[2] ) ;
    const Pt2dr & aP11 =  Dist(mCurCorner+CamBilinCorn[3] ) ;


    Pt2dr aGx =    ((aP10-aP00)*aPds.y + (aP11-aP01)*(1-aPds.y))  / mStep.x;
    Pt2dr aGy =    ((aP01-aP00)*aPds.x + (aP11-aP10)*(1-aPds.x))  / mStep.y;

    aM.ResizeInside(2,2);
    SetCol(aM,0,aGx);
    SetCol(aM,1,aGy);

    // A conserver, verification par diff std
    if (0)
    {
        ElMatrix<REAL> aM2(2,2);
        DiffByDiffFinies(aM2,aP,euclid(mStep)/1e4);
        static double aDMax = 0;
        double aD = aM.L2(aM2);
        if (aD>aDMax)
        {
            aDMax = aD;
            std::cout << "DDDD " << aD << "\n";
        }
    }
    // InitEtatFromCorner(ToCoordGrid(aP));

}
Example #5
0
void * LogMem::alloc(ulen len)
 {
  if( !TryAlign(len) ) return 0;
  
  if( ptr<lim )
    {
     ulen s=Dist(lim,mem_lim);
     
     if( len<=s )
       {
        void *ret=lim;
        
        lim+=len;
        
        return ret;
       }
       
     s=Dist(mem,ptr);  
     
     if( len<s )
       {
        cut=lim;
        lim=mem+len;
        
        return mem;
       }
       
     return 0;  
    }
    
  if( ptr>lim )  
    {
     ulen s=Dist(lim,ptr);
     
     if( len<s )
       {
        void *ret=lim;
        
        lim+=len;
        
        return ret;
       }
       
     return 0;  
    }
    
  ulen s=Dist(lim,mem_lim);
     
  if( len<s )
    {
     void *ret=lim;
        
     lim+=len;
        
     return ret;
    }
       
  return 0;  
 }
Example #6
0
void FillRandomImg(CSimpleImage& Image, int ImageNo)
{
   static bool Initialized = false;
   const static int NbImages = 2;
   static CSimpleImage Images[NbImages];
   static CImage<float> FloatImages[NbImages];

   //assert(ImageNo >= 0 && ImageNo < NbImages);

   if (!Initialized)
   {
      // Random image generation is time consuming
      // So we do it only once

      std::mt19937 Rand;   // Mersenne twister pseudo random number generator

      // Uniform distribution that can set all but the leftmost bit
      std::uniform_int_distribution<int> Dist(0, 0xFF);

      SSize Big = GetBiggestImage();

      for (int i = 0; i < NbImages; i++)
      {
         Images[i].Create(Big.Width, Big.Height, 1, SImage::S32);
         uint uByteWidth = Images[i].BytesWidth();
         for (uint y = 0; y < Images[i].Height; y++)
            for (uint b = 0; b < uByteWidth; b++)
               Images[i].Data(y)[b] = Dist(Rand);
      }


      std::normal_distribution<float> FloatDist(0, 1);

      for (int i = 0; i < NbImages; i++)
      {
         FloatImages[i].Create(Big.Width, Big.Height, 1, SImage::F32);
         for (uint y = 0; y < FloatImages[i].Height; y++)
            for (uint x = 0; x < FloatImages[i].Width; x++)
               FloatImages[i](x, y) = FloatDist(Rand);
      }

      Initialized = true;
   }

   uint uByteWidth = Image.BytesWidth();
   
   if (Image.Type == Image.F32)
   {
      for (uint y = 0; y < Image.Height; y++)
         memcpy(Image.Data(y), FloatImages[ImageNo].Data(y), uByteWidth);

      return;
   }

   for (uint y = 0; y < Image.Height; y++)
      memcpy(Image.Data(y), Images[ImageNo].Data(y), uByteWidth);
}
Example #7
0
Pt2dr cDistorBilin::Direct(Pt2dr aP) const
{
    InitEtatFromCorner(ToCoordGrid(aP));

    return   
             Dist(mCurCorner +CamBilinCorn[0] ) * mPds[0]
           + Dist(mCurCorner +CamBilinCorn[1] ) * mPds[1]
           + Dist(mCurCorner +CamBilinCorn[2] ) * mPds[2]
           + Dist(mCurCorner +CamBilinCorn[3] ) * mPds[3];
}
Example #8
0
void CBasePoly::Flip()
{
	for(uint32 i=0; i < m_Indices/2; i++ )
	{
		uint32 temp = m_Indices[i];
		m_Indices[i] = m_Indices[m_Indices-i-1];
		m_Indices[m_Indices-i-1] = temp;
	}

	Normal() = -Normal();
	Dist() = -Dist();
}
Example #9
0
void cDistorBilin::V_SetScalingTranslate(const double & aF,const Pt2dr & aPP)
{
   for (int aKY=0 ; aKY<= mNb.y ; aKY++)
   {
       for (int aKX=0 ; aKX<= mNb.x ; aKX++)
       {
           Dist(Pt2di(aKX,aKY)) = ( Dist(Pt2di(aKX,aKY))- aPP) / aF;
       }
   }
   mP0 = (mP0-aPP) / aF;
   mP1 = (mP1-aPP) / aF;
   mStep = mStep / aF;
}
Example #10
0
void CEditPoly::Flip()
{
	uint32		i, temp;

	for( i=0; i < m_Indices/2; i++ )
	{
		temp = m_Indices[i];
		m_Indices[i] = m_Indices[m_Indices-i-1];
		m_Indices[m_Indices-i-1] = temp;
	}

	Normal() = -Normal();
	Dist() = -Dist();
}
Example #11
0
//extern int spp_send(char* buf, int count);
static uint16_t gesture_caculate(int index, const int8_t* point)
{
  const int8_t *currentGesture = GestureData[index + gestureoffset];
  uint8_t gestureLength = GestureDataLength[index + gestureoffset];
  uint16_t *distance = distances + (MAX_GESTURES * index);
  // caculate with template
  uint16_t lastvalue = Dist(&currentGesture[0], point);
  
  if (count == MOVE_WINDOW)
  {
    distance[0] = lastvalue;
    for(int tindex = 1; tindex < gestureLength; tindex++)
    {
      distance[tindex] = distance[tindex - 1] + Dist(&currentGesture[tindex * 3], point);
    }
  }
  else
  {
    if (lastvalue > distance[0])
      lastvalue = distance[0];
    for(int tindex = 1; tindex < gestureLength; tindex++)
    {
      uint16_t local = Dist(&currentGesture[tindex * 3], point);
      uint16_t min = lastvalue;
      if (min > distance[tindex])
        min = distance[tindex];
      if (min > distance[tindex - 1])
        min = distance[tindex - 1];
      if (min > lastvalue)
        min = lastvalue;
      distance[tindex - 1] = lastvalue;
      lastvalue = local + min;
    }
    distance[gestureLength - 1] = lastvalue;
  }
#if 0
  for(int i = 0; i < gestureLength; i++)
  {
    PRINTF("%d ",distance[i]);
  }
  PRINTF("\n  ");
  for(int i = 1; i < gestureLength; i++)
  {
    PRINTF("%d ",distance[i] - distance[i-1]);
  }
  PRINTF("\n");
#endif
  return distance[gestureLength - 1]/(gestureLength + count/MOVE_STEP - 1);
}
Example #12
0
bool CBasePoly::LoadBasePolyTBW( CAbstractIO& InFile )
{
	//load up all the vertices
	uint32 nNumVerts;
	InFile >> nNumVerts;

	m_Indices.SetSize( nNumVerts );

	for(uint32 nCurrVert = 0; nCurrVert < nNumVerts; nCurrVert++)
	{
		uint32 nIndex;
		InFile >> nIndex;

		Index(nCurrVert) = nIndex;
	}

	//now read in the plane data
	InFile >> Normal().x;
	InFile >> Normal().y;
	InFile >> Normal().z;

	InFile >> Dist();

	return true;
}
Example #13
0
 void PathPlanner::disconnectNodes(Node * path) {
     SearchSpaceNode * S;
     Node * temp;
     double distance;
     if (!path)
         return;
     S = searchspace;
     int numConnections = this->MAXNODES;
     while (S != NULL) {
         temp = path;
         while (temp != NULL) {
             distance = Dist(S->location, temp->pose.p);
             if (distance == 0)//S == temp->pose.p.position.x)// && distance !=0)
             {
                 S->children.pop_back();
                 bool t = removeNode(S->location);
                 numConnections--;
                 delete S;
             }
             temp = temp->next;
         }
         S = S->next;
     }
     searchspace = S;
     std::cout << "\n	--->>> NODES CONNECTED <<<---	" << numConnections;
     this->MAXNODES = numConnections; //searchspace->id;
 }
Example #14
0
    void PathPlanner::connectNodes() {
        SearchSpaceNode * S;
        SearchSpaceNode *temp;
        double distance;
        if (!searchspace)
            return;
        temp = searchspace;
        int numConnections = 0;
        while (temp != NULL) {
            S = searchspace;
            while (S != NULL) {
                distance = Dist(S->location, temp->location);
                if (distance <= regGridConRadius && S != temp)// && distance !=0)
                {
                    //check if parent and child are in the same position
                    if (S->location.position.x != temp->location.position.x || S->location.position.y != temp->location.position.y || S->location.position.z != temp->location.position.z) {
                        if (heuristic->isConnectionConditionSatisfied(temp, S)) {
                            temp->children.push_back(S);
                            numConnections++;
                        }
                    }//child and parent are in the same position.
                        // TODO: check this logic
                    else {
                        temp->children.push_back(S);
                    }

                }
                S = S->next;
            }
            temp = temp->next;
        }
        std::cout << "\n	--->>> NODES CONNECTED <<<---	" << numConnections;
        this->MAXNODES = numConnections; //searchspace->id;
    }
Example #15
0
void cEqHomogFormelle::StdRepondere(ElPackHomologue & aPack,REAL aCoeff)
{
    cElHomographie H1 = HF1().HomCur();
    cElHomographie H2 = HF2().HomCur();
    ElDistRadiale_PolynImpair Dist(1e5,Pt2dr(0,0));
    if (DRF()) 
       Dist = DRF()->DistCur();

    for
    (
         ElPackHomologue::iterator it=aPack.begin();
         it!=aPack.end();
         it++
    )
    {
          Pt2dr aP1 = it->P1();
          Pt2dr aP2 = it->P2();
          if (mDRF)
          {
              aP1 = Dist.Direct(aP1);
              aP2 = Dist.Direct(aP2);
          }
          Pt2dr Ec = H1.Direct(Dist.Direct(it->P1())) - H2.Direct(Dist.Direct(it->P2()));

          REAL D = euclid(Ec);
         
          REAL Pds = 1 / (1 + ElSquare(D/aCoeff));
          it->Pds() = Pds;
    }
}
Example #16
0
GeomPerfectMatching::REAL GeomPerfectMatching::SolveComplete()
{
	if (node_num != node_num_max) { printf("ComputeCost() cannot be called before all points have been added!\n"); exit(1); }

	PointId p, q;
	int e = 0, E = node_num*(node_num-1)/2;
	PerfectMatching* pm = new PerfectMatching(node_num, E);
	for (p=0; p<node_num; p++)
	{
		for (q=p+1; q<node_num; q++)
		{
			pm->AddEdge(p, q, Dist(p, q));
		}
	}
	pm->options = options;
	pm->Solve();
	for (p=0; p<node_num; p++)
	{
		for (q=p+1; q<node_num; q++)
		{
			if (pm->GetSolution(e++))
			{
				matching[p] = q;
				matching[q] = p;
			}
		}
	}
	delete pm;
	return ComputeCost(matching);
}
int ReferenceFrame2D::GetNode(Vector2D p_loc) const
{
	double tol = 1e-8*GetMBS()->CharacteristicLength();
/*
	for (int i = 1; i <=nodes.Length(); i++)
	{
		if (Dist(p_loc,nodes(i)->Pos2D()) <= tol) return i;
	}
	GetMBS()->UO() << "ERROR: node not found:" << p_loc << " !!!\n";
	return 0;
*/

	IVector items;
	Vector3D p(p_loc.X(),p_loc.Y(),0.);

	Box3D box(p, p);
	box.Increase(tol);
	searchtree.GetItemsInBox(box,items);
	for (int i = 1; i <= items.Length(); i++)
	{
		Vector3D p2(nodes(items(i))->Pos().X(), nodes(items(i))->Pos().Y(), 0.);
		if (Dist(p,p2) <= tol) return items(i);
	}
	GetMBS()->UO() << "ERROR: node not found:" << p_loc << " !!!\n";
	return 0;
}
Example #18
0
int main()
{
	int i,n;
	double drray[9];

	for(i=0;i<10;i++){
		printf("Enter point p%d:\n",i);
		scanf("%lf%lf",&point[i].x,&point[i].y);
	}

	for(n=0;n<9;n++)
		drray[n]=Dist(point[0],point[n]);


	double max;
	int m;
	max=drray[0];

	for(m=1;m<9;m++){
		if(drray[m]>max)
			max=drray[m];
	}

	printf("Max disance=%lf\n",max);

return 0;
}
Example #19
0
void CreateTopology(struct atom_s *a, int n, int **top, double thresh, int debug)
{
	int i,j,c=0;

	fprintf(stderr,"Create topology of bonded interactions\n");
	if (debug>2) fprintf(stderr,"Bonded topology:\n");

	for(i=0;i<n;i++)
		for(j=i+1;j<n;j++)
			if ( (a+i)->chain == (a+j)->chain )					// must be the same chain
			 if (Dist((a+i)->pos,(a+j)->pos)<thresh)			// bonded if dist<thresh
				 if ( !(!strcmp((a+i)->aa,"PRO") && !strcmp((a+i)->atom,"N") && !strcmp((a+j)->atom,"CD")) &&
						  !(!strcmp((a+i)->aa,"PRO") && !strcmp((a+j)->atom,"N") && !strcmp((a+i)->atom,"CD")) &&	// if PRO, assign backbone to CA even if it comes later
						  !(!strcmp((a+i)->aa,"TRP") && !strcmp((a+i)->atom,"CD2") && !strcmp((a+j)->atom,"CE3")) &&
						  !(!strcmp((a+i)->aa,"TRP") && !strcmp((a+j)->atom,"CD2") && !strcmp((a+i)->atom,"CE3"))  ) 	// if TRP, turn from the side of CE3 (like rotamers.lib)
				 {
					top[i][j]=1;
					top[j][i]=1;
					c++;

					if (debug>2) fprintf(stderr,"\t%d%s(%d%s) - %d%s(%d%s)\n",i,(a+i)->atom,(a+i)->iaa,(a+i)->aa,j,(a+j)->atom,(a+j)->iaa,(a+j)->aa);
				 }

	fprintf(stderr,"Found %d covalent bond to define the molecule topology\n",c);
}
int main() {
  struct Ponto v[1000];
  FILE* f;
  int n;
  // Leitura dos dados.
  f = fopen("pontos.txt", "r");
  fscanf(f, "%d", &n);

  int i;
  for (i = 0; i < n; ++i) {
    fscanf(f, "%f", &v[i].x);
    fscanf(f, "%f", &v[i].y);
  }
  // Iteração do algoritmo.
  while (1) {
    struct Ponto p;
    float r;
    printf("Digite as coordenadas X e Y do ponto de origem:\n");
    scanf("%f", &p.x);
    scanf("%f", &p.y);
    printf("Digite o raio de interesse:\n");
    scanf("%f", &r);
    printf("Os pontos mais proximos sao:\n");

    int i;
    for (i = 0; i < n; ++i) {
      if (Dist(p, v[i]) <= r) {
        printf("(%.1f, %.1f)\n", v[i].x, v[i].y);
      }
    }
  }
  return 0;
}
Example #21
0
  int GeneralizedCylinder ::BoxInSolid (const BoxSphere<3> & box) const
  {
    Point<3> p3d;
    Point<2> p2d, projp;
    double t;
    Vec<2> tan, n;

    p3d = box.Center();

    p2d = Point<2> (planee1 * (p3d - planep), planee2 * (p3d - planep));
    t = crosssection.ProjectParam (p2d);

    projp = crosssection.Eval (t);
    tan = crosssection.EvalPrime (t);
    n(0) = tan(1);
    n(1) = -tan(0);

    if (Dist (p2d, projp) < box.Diam()/2)
      return 2;

    if (n * (p2d - projp) > 0)
      {
        return 0;
      }

    return 1;
  }
Example #22
0
int Dist(char* a,char *b)
{
    int i,j,len1,len2,res=0;
    len1=strlen(a);
    len2=strlen(b);
    if (len1<len2)
    {
        i=0;j=0;
        while (i<len1 && j<len2)
        {
            if (a[i]==b[j])
            {
                i++;
                j++;
            }
            else
            {
                res++;
                j++;
            }
        }
        res+=len1-i+len2-j;
    }
    else if (len1==len2)
    {
        for (i=0;i<len1;i++) if (a[i]!=b[i]) res++;
    }
    else res=Dist(b,a);
    return res;
}
Example #23
0
int CalcTriangleCenter (const Point3d ** pts, Point3d & c)
{
  static DenseMatrix a(2), inva(2);
  static Vector rs(2), sol(2);
  double h = Dist(*pts[0], *pts[1]);

  Vec3d v1(*pts[0], *pts[1]);
  Vec3d v2(*pts[0], *pts[2]);

  rs.Elem(1) = v1 * v1;
  rs.Elem(2) = v2 * v2;

  a.Elem(1,1) = 2 * rs.Get(1);
  a.Elem(1,2) = a.Elem(2,1) = 2 * (v1 * v2);
  a.Elem(2,2) = 2 * rs.Get(2);

  if (fabs (a.Det()) <= 1e-12 * h * h)
    {
      (*testout) << "CalcTriangleCenter: degenerated" << endl;
      return 1;
    }

  CalcInverse (a, inva);
  inva.Mult (rs, sol);

  c = *pts[0];
  v1 *= sol.Get(1);
  v2 *= sol.Get(2);

  c += v1;
  c += v2;

  return 0;
}
Example #24
0
Point<3> STLLine ::
GetPointInDist(const Array<Point<3> >& ap, double dist, int& index) const
{
    if (dist <= 0)
    {
        index = 1;
        return ap.Get(StartP());
    }

    double len = 0;
    int i;
    for (i = 1; i < pts.Size(); i++)
    {
        double seglen = Dist (ap.Get(pts.Get(i)),
                              ap.Get(pts.Get(i+1)));

        if (len + seglen > dist)
        {
            index = i;
            double relval = (dist - len) / (seglen + 1e-16);
            Vec3d v (ap.Get(pts.Get(i)), ap.Get(pts.Get(i+1)));
            return ap.Get(pts.Get(i)) + relval * v;
        }

        len += seglen;
    }

    index = pts.Size() - 1;
    return ap.Get(EndP());
}
Example #25
0
void resolve_derived_copies(CommPtr comm, Read<GO> verts2globs, Int deg,
    LOs* p_ent_verts2verts, Remotes* p_ents2owners) {
  auto ev2v = *p_ent_verts2verts;
  auto ev2vg = unmap(ev2v, verts2globs, 1);
  auto canon_codes = get_codes_to_canonical(deg, ev2vg);
  auto ev2v_canon = align_ev2v(deg, ev2v, canon_codes);
  *p_ent_verts2verts = ev2v_canon;
  auto ev2vg_canon = align_ev2v(deg, ev2vg, canon_codes);
  auto e2fv = get_component(ev2v_canon, deg, 0);
  auto total_verts = find_total_globals(comm, verts2globs);
  auto v2ov = globals_to_linear_owners(comm, verts2globs, total_verts);
  auto e2ov = unmap(e2fv, v2ov);
  auto linsize = linear_partition_size(comm, total_verts);
  auto in_dist = Dist(comm, e2ov, linsize);
  auto sev2vg = in_dist.exch(ev2vg_canon, deg);
  auto out_dist = in_dist.invert();
  auto sv2svse = out_dist.roots2items();
  auto nse = out_dist.nitems();
  auto svse2se = LOs(nse, 0, 1);
  auto sv2se_codes = Read<I8>(nse, make_code(false, 0, 0));
  auto sv2se = Adj(sv2svse, svse2se, sv2se_codes);
  auto se2fsv = invert_fan(sv2svse);
  LOs se2ose;
  Read<I8> se2ose_codes;
  find_matches_ex(deg, se2fsv, sev2vg, sev2vg, sv2se, &se2ose, &se2ose_codes);
  auto ose2oe = out_dist.items2dests();
  auto se2oe = unmap(se2ose, ose2oe);
  out_dist.set_roots2items(LOs());
  auto e2oe = out_dist.exch(se2oe, 1);
  *p_ents2owners = e2oe;
}
Example #26
0
void dijkstra(int src)
{
    set< pair<int, int> > setds;
    vector<int> Dist(N+1, INF);
    setds.insert(make_pair(0, src));
    Dist[src] = 0;
    while (!setds.empty())
    {
        pair<int, int> tmp = *(setds.begin());
        setds.erase(setds.begin());
        int u = tmp.second;
        //pf("@%d\n", u);
        for (int i = 0; i < adj[u].size(); i++)
        {
            int v = adj[u][i];
            //pf("-%d\n", v);
            int weight = dist[u][v];
            if (Dist[v] > Dist[u] + weight)
            {
                if (Dist[v] != INF)
                    setds.erase(setds.find(make_pair(Dist[v], v)));
                Dist[v] = Dist[u] + weight;
                setds.insert(make_pair(Dist[v], v));
            }
        }
    }
    for (int i = 1; i <= N; i++)
    {
        m_time[src][i] = Dist[i];
    }
}
    inline typename Dist::value_type find_location( // Default policy.
      complemented3_type<Real1, Real2, Real3> const& c)
    {
      static const char* function = "lslboost::math::find_location<Dist, Policy>&, %1%)";

      typename Dist::value_type p = c.param1;
      if(!(lslboost::math::isfinite)(p) || (p < 0) || (p > 1))
      {
       return policies::raise_domain_error<typename Dist::value_type>(
           function, "Probability parameter was %1%, but must be >= 0 and <= 1!", p, policies::policy<>());
      }
      typename Dist::value_type z = c.dist;
      if(!(lslboost::math::isfinite)(z))
      {
       return policies::raise_domain_error<typename Dist::value_type>(
           function, "z parameter was %1%, but must be finite!", z, policies::policy<>());
      }
      typename Dist::value_type scale = c.param2;
      if(!(lslboost::math::isfinite)(scale))
      {
       return policies::raise_domain_error<typename Dist::value_type>(
           function, "scale parameter was %1%, but must be finite!", scale, policies::policy<>());
      }
       // cout << "z " << c.dist << ", quantile (Dist(), " << c.param1 << ") * scale " << c.param2 << endl;
       return z - quantile(Dist(), p) * scale;
    } // find_location complement
Example #28
0
Dist bi_partition(CommPtr comm, Read<I8> marks) {
  CHECK(comm->size() % 2 == 0);
  Write<I32> dest_ranks(marks.size());
  Write<LO> dest_idxs(marks.size());
  LO linsize = -1;
  auto halfsize = comm->size() / 2;
  I32 rank_start = 0;
  for (Int half = 0; half < 2; ++half) {
    marks = invert_marks(marks);
    auto marked = collect_marked(marks);
    auto total = comm->allreduce(GO(marked.size()), OMEGA_H_SUM);
    auto start = comm->exscan(GO(marked.size()), OMEGA_H_SUM);
    Read<GO> globals(marked.size(), start, 1);
    auto owners = globals_to_linear_owners(globals, total, halfsize);
    map_into(add_to_each(owners.ranks, rank_start), marked, dest_ranks, 1);
    map_into(owners.idxs, marked, dest_idxs, 1);
    if (rank_start <= comm->rank() && comm->rank() < (rank_start + halfsize)) {
      linsize =
          linear_partition_size(total, halfsize, comm->rank() - rank_start);
    }
    rank_start += halfsize;
  }
  auto dests = Remotes(Read<I32>(dest_ranks), Read<LO>(dest_idxs));
  return Dist(comm, dests, linsize);
}
Example #29
0
void CheckLen(char* word,int len)
{
    int i;
    
    for (i=startpos[len];dict[i].len==len;i++)
        if (Dist(word,dict[i].word)==1) ans[cnt++]=dict[i];
}
Example #30
0
double dssyn( double r, void * params ){

	double dist_z = Dist() / (1+c.z);

	double ssynIntegrand = 4 *pi /pow(dist_z , 2) *pow(r,2)  *  pow(c.DM_profile(r) , 2)*gslInt_jsyn(r);	
	
	return ssynIntegrand;
}