当前位置: 首页>>代码示例>>C++>>正文


C++ Simplex类代码示例

本文整理汇总了C++中Simplex的典型用法代码示例。如果您正苦于以下问题:C++ Simplex类的具体用法?C++ Simplex怎么用?C++ Simplex使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Simplex类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main() {
  init();
  // read input
  cin >> n >> m;
  for (int i=0;i<m;i++) {
    for (int j=0;j<3;j++) cin >> e[i][j];
    nextE[e[i][0]].push_back(i);
    nextE[e[i][1]].push_back(i);
    next[e[i][0]].push_back(e[i][1]);
    next[e[i][1]].push_back(e[i][0]);
  }
  // set up linear program
  nA=0;
  for (int i=0;i<n;i++) cycles(i);
  for (int i=0;i<m;i++) {
    A[nA][2*i+1]=1; b[nA]=e[i][2];
    nA++;
    c[2*i]=-1; c[2*i+1]=1;
  }
  // solve
  Simplex s = Simplex(A, b, c, nA, 2*m);
  Fraction f = s.solve();
  f = f.neg();
  for (int i=0;i<m;i++) f = f.add(Fraction(e[i][2]));
  cout << f.str() << endl;
  return 0;
}
开发者ID:kodingmach12,项目名称:MyCodes,代码行数:27,代码来源:FLYDIST.cpp

示例2: errif

Point OjaData::oja_rank(const Point& x) const
{
	errif(x.dim() != dim(), "OjaData::oja_rank: Illegal dimension on point " << x);

	if (plane)
		return plane->oja_rank(x);

	Point Gr(dim());
	Simplex S;
	double sgn;
	double k = 0;

	for (Index I(dim(), size()); I; I++, k++)
	{
		S.get(*this, I, x);
		sgn = S.sign();
		for (int j = 0; j<dim(); j++)
			Gr[j] += S.row_cof(j + 1) * sgn;
	}

	for (int i = 0; i < dim(); i++)
		Gr[i] /= k;

	return Gr;
}
开发者ID:cran,项目名称:OjaNP,代码行数:25,代码来源:oja_data.cpp

示例3: interpolateValue

  //! Retourne la valeur interpolée d'un point dans le pavage
  float interpolateValue(const Point<N> &Q) {
    bool found = false;
    float value = 0;
    float rapport = 0;
    size_t iSimplex;
    for (iSimplex = 0; iSimplex < multiplex.size(); iSimplex++) {
      if (isInside(Q, multiplex[iSimplex])) {
        found = true;
        break;
      }
    }
    if (!found) {
      cout << "Le point n'est dans aucun simplex" << endl;
      return 0;
    }

    //  le rapport entre le volume du N-simplexe {Q,Fbj} et le volume du
    //  N-simplexe D={Pbj,Fbj}.
    for (int i = 0; i < multiplex[iSimplex].getSize(); i++) {
      Simplex<N> temp;
      temp.pushPoint(Q);
      for (int j = 0; j < multiplex[iSimplex].getSize(); j++) {
        if (i != j)
          temp.pushPoint((multiplex[iSimplex])[j]);
      }
      // temp le simplex {Q,Fbj}
      // <multiplex[iSimplex] le simplex {Pbj,Fbj}
      rapport = temp.calculateVol() / multiplex[iSimplex].calculateVol();
      value += rapport * (multiplex[iSimplex][i]).getValeur();
    }
    return value;
  }
开发者ID:Ananasr,项目名称:Interpol,代码行数:33,代码来源:Paving.hpp

示例4: isInside

 //! return true if p is in the simplex s
 static bool isInside(const Point<N> &p, Simplex<N> &s) {
   bool inside = true;
   std::vector<Point<N> > opposed;
   float m1[N][N]; // x par rapport a l'arrete
   float m2[N][N]; // R par rapport a l'arrete
   for (int k = 0; k < s.getSize(); k++) {
     opposed.clear();
     for (int i = 0; i < s.getSize(); i++) {
       if (i != k)
         opposed.push_back(s[i]);
     }
     // creation of matrix N*N
     for (size_t i = 0; i < N; i++) {
       for (size_t j = 0; j < N; j++) {
         m1[i][j] = p[i] - (opposed[j])[i];      // x par rapport a Fbi
         m2[i][j] = (s[k])[i] - (opposed[j])[i]; // R par rapport a Fbi
       }
     }
     if (Simplex<N>::determinant(m1, N) * Simplex<N>::determinant(m2, N) <
         0) { // determinants de signes different
       inside = false;
       break;
     }
   }
   return inside;
 }
开发者ID:Ananasr,项目名称:Interpol,代码行数:27,代码来源:Paving.hpp

示例5: add_simplices

void add_simplices(SimplexVector& sv, int d, const PointContainer& points)
{
	PointIndex indices[d+1];
	for (int i = 0; i < d+1; ++i) 
		indices[i] = d - i;

	while(indices[d] < points.size() - d)
	{
		// Add simplex
		Miniball mb(points[indices[0]].dim());
		Simplex s;
		for (int i = 0; i < d+1; ++i)
		{
			s.add(indices[i]);
			mb.check_in(points[indices[i]]);
		}
		mb.build();
		s.set_value(mb.squared_radius());
		sv.push_back(s);

		
		// Advance indices
		for (int i = 0; i < d+1; ++i)
		{
			++indices[i];
			if (indices[i] < points.size() - i)
			{
				for (int j = i-1; j >= 0; --j)
					indices[j] = indices[j+1] + 1;
				break;
			}
		}
	}
}
开发者ID:veldanie,项目名称:Dionysus-python3,代码行数:34,代码来源:cech-complex.cpp

示例6: optimise_single

double Handler::optimise_single(vector<double> &parameters, vector<vector<double> > &results, vector<vector<vector<double> > > &allResults, int& itr){
  double SSE = 99999999999999.9;
  double tempSSE;
  vector<double> tempPar, seedParams;
  Simplex simplex;

  parameters.clear();
  allResults.clear();
  parameters = generate_seed_parameters();
  for(int index = 0;index<20;index++){
    seedParams.clear();
    seedParams = generate_seed_parameters();
    //printcon(seedParams);
    if(this->useMLE == false) tempPar = simplex.neldermead(&Handler::fitEpidemicsMLE, *this,  seedParams, itr);
    else tempPar = simplex.neldermead(&Handler::fitEpidemics, *this,  seedParams, itr);
    // Store the SSE value for this
    tempSSE = fitEpidemics(tempPar);
    if(tempSSE < SSE){
      SSE = tempSSE;
      parameters=tempPar;
    }
    cout << "." << flush;
  }
  results = ode_solve(parameters);
  allResults = ode_solve_separate(parameters);
  //allResults.clear();
  cout << endl;
  return SSE;
}
开发者ID:jameshay218,项目名称:epidemics,代码行数:29,代码来源:datahandler.cpp

示例7: SetToSimplex

	void SetToSimplex(Simplex& s){
		data.clear();
		for(unsigned int i = 0; i< s.GetSize(); i++){
			data.push_back(s[i]);
			dataA.push_back(s.atA(i));
			dataB.push_back(s.atB(i));
		}
	}
开发者ID:scottc52,项目名称:SpaceGame,代码行数:8,代码来源:CollisionDetection.cpp

示例8: PrintSimplex

 static void PrintSimplex(std::ostream &str, const Simplex &simplex)
 {
     for (typename Simplex::const_iterator i = simplex.begin(); i != simplex.end(); i++)
     {
         str<<(*i)<<" ";
     }
     str<<std::endl;
 }
开发者ID:pbrendel,项目名称:AccSub,代码行数:8,代码来源:Utils.hpp

示例9: main

int main()
{
	Simplex s;
	s.getInput();
	cout << "\n\n";
	s.simplexMethod();
	return 0;
}
开发者ID:tusharwalzade216,项目名称:numerical_methods2,代码行数:8,代码来源:simplex_method_main.cpp

示例10: optimiseEpidemics

/* Optimisation procedure. Takes a reference to parameters, combined results, component results and number of iterations taken. The function updates these
   arguments with the results of the Nelder-Mead optimisation procedure. */
double Handler::optimiseEpidemics(vector<double> &parameters, vector<vector<double> > &results, vector<vector<vector<double> > > &allResults, int& itr){
  double SSE = 99999999999999999.9;
  double tempSSE;
  vector<double> tempPar, seedParams;
  Simplex simplex;
  int iterations = 10001;

  // If no epidemics have yet been detected, use the mean of the current data as the 
  // current model and return the corresponding SSE.
  if(epidemics.size() == 0){
    //baseModel = base_model(temp_data);
    results = base_model(temp_data);
    SSE = calculate_SSE(results, temp_data);
    parameters.clear();
    allResults.clear();
    allResults.push_back(baseModel);
    return(SSE);
  }
  srand(time(NULL));
  parameters = generate_seed_parameters();

  // If there are epidemics to be fitted, perform X random fits and keep best fitting model
  for(int index=0;index<10;index++){
    // Create random seed parameters
    seedParams.clear();      
    seedParams = generate_seed_parameters();
    
    while(fitEpidemics(seedParams) != fitEpidemics(seedParams)){
      seedParams.clear();            
      seedParams = generate_seed_parameters();
    }
    
    // Get the optimised parameters from nelder mead algorithm
    tempPar = simplex.neldermead(&Handler::fitEpidemics, *this,  seedParams, iterations);
    // Store the SSE value for this
 
    tempSSE = fitEpidemics(tempPar);
    //if(tempSSE == tempSSE) cout << "Temp RSquare: " << (1-tempSSE/(SStot(temp_data,1))) << endl;
 
    // If this SSE value is better than the previous, store it and the corresponding parameters
    if(tempSSE < SSE){
      itr = iterations;
      SSE = tempSSE;
      parameters=tempPar;
    }
    cout << "." << flush;
  }

  // Get the combined values from these parameters, as well as a vector of 
  // each sub-epidemic
  results = ode_solve(parameters);
   
  allResults.clear();
  allResults = ode_solve_separate(parameters);
  cout << endl;
  return(SSE);

}
开发者ID:jameshay218,项目名称:epidemics,代码行数:60,代码来源:datahandler.cpp

示例11: main

int main()
{
	struct user_data::_userdata ud;
	user_data::get_data_from_user(&ud);
	

	Simplex s;
	s.generate_plane(&ud);
	s.run();

	return 0;
}
开发者ID:MOZGIII,项目名称:Simplex-Method,代码行数:12,代码来源:main.cpp

示例12:

	/**
	* @param includeMargin Indicate whether algorithm operates on objects with margin
	*/
	template<class T> std::unique_ptr<GJKResult<T>> GJKAlgorithm<T>::processGJK(const CollisionConvexObject3D &convexObject1,
			const CollisionConvexObject3D &convexObject2, bool includeMargin) const
	{
		//get point which belongs to the outline of the shape (Minkowski difference)
		Vector3<T> initialDirection = Vector3<T>(1.0, 0.0, 0.0);
		Point3<T> initialSupportPointA = convexObject1.getSupportPoint(initialDirection.template cast<float>(), includeMargin).template cast<T>();
		Point3<T> initialSupportPointB = convexObject2.getSupportPoint((-initialDirection).template cast<float>(), includeMargin).template cast<T>();
		Point3<T> initialPoint = initialSupportPointA - initialSupportPointB;

		Vector3<T> direction = (-initialPoint).toVector();

		Simplex<T> simplex;
		simplex.addPoint(initialSupportPointA, initialSupportPointB);

		T minimumToleranceMultiplicator = (T)1.0;

		for(unsigned int iterationNumber=0; iterationNumber<maxIteration; ++iterationNumber)
		{
			Point3<T> supportPointA = convexObject1.getSupportPoint(direction.template cast<float>(), includeMargin).template cast<T>();
			Point3<T> supportPointB = convexObject2.getSupportPoint((-direction).template cast<float>(), includeMargin).template cast<T>();
			Point3<T> newPoint = supportPointA - supportPointB;

			const Vector3<T> &vClosestPoint = -direction; //vector from origin to closest point of simplex
			T closestPointSquareDistance = vClosestPoint.dotProduct(vClosestPoint);
			T closestPointDotNewPoint = vClosestPoint.dotProduct(newPoint.toVector());

			//check termination conditions: new point is not more extreme that existing ones OR new point already exist in simplex
			T distanceTolerance = std::max(minimumTerminationTolerance*minimumToleranceMultiplicator, relativeTerminationTolerance*closestPointSquareDistance);
			if((closestPointSquareDistance-closestPointDotNewPoint) <= distanceTolerance || simplex.isPointInSimplex(newPoint))
			{
				if(closestPointDotNewPoint <= 0.0)
				{ //collision detected
					return std::make_unique<GJKResultCollide<T>>(simplex);
				}else
				{
					return std::make_unique<GJKResultNoCollide<T>>(std::sqrt(closestPointSquareDistance), simplex);
				}
			}

			simplex.addPoint(supportPointA, supportPointB);

			direction = (-simplex.getClosestPointToOrigin()).toVector();

			minimumToleranceMultiplicator += percentageIncreaseOfMinimumTolerance;
		}

		#ifdef _DEBUG
			logMaximumIterationReach();
		#endif

		return std::make_unique<GJKResultInvalid<T>>();
	}
开发者ID:xuxiaowei007,项目名称:UrchinEngine,代码行数:55,代码来源:GJKAlgorithm.cpp

示例13: GetConvexHullPenetration

D3DXVECTOR3 CollisionSolver::GetConvexHullPenetration(const CollisionMesh& particle, 
                                                      const CollisionMesh& hull, 
                                                      Simplex& simplex)
{
    D3DXVECTOR3 furthestPoint;
    D3DXVECTOR3 penetrationDirection;
    float penetrationDistance = 0.0f;
    bool penetrationFound = false;
    const float minDistance = 0.1f;
    const int maxIterations = 10;
    int iteration = 0;

    while(!penetrationFound && iteration < maxIterations)
    {
        ++iteration;
        const Face& face = simplex.GetClosestFaceToOrigin();
        penetrationDirection = face.normal;
        penetrationDistance = face.distanceToOrigin;
        penetrationFound = penetrationDistance == 0.0f;

        if(!penetrationFound)
        {
            // Check if there are any edge points beyond the closest face
            furthestPoint = GetMinkowskiSumEdgePoint(face.normal, particle, hull);
            const D3DXVECTOR3 faceToPoint = furthestPoint - simplex.GetPoint(face.indices[0]);
            const float distance = fabs(D3DXVec3Dot(&faceToPoint, &face.normal));
            penetrationFound = distance < minDistance;

            if(!penetrationFound)
            {
                // Add the new point and extend the convex hull
                simplex.ExtendFace(furthestPoint);
            }
        }
    }

    if(!penetrationFound)
    {
        // Fallback on the initial closest face
        const Face& face = simplex.GetClosestFaceToOrigin();
        penetrationDirection = face.normal;
        penetrationDistance = face.distanceToOrigin;
    }

    if(particle.RenderSolverDiagnostics())
    {
        UpdateDiagnostics(simplex, furthestPoint);
    }

    return -(penetrationDirection * penetrationDistance);
}
开发者ID:huaminglee,项目名称:cloth-simulator,代码行数:51,代码来源:collisionsolver.cpp

示例14: D3DXVec3Cross

bool CollisionSolver::SolveTetrahedronSimplex(Simplex& simplex, D3DXVECTOR3& direction)
{
    const D3DXVECTOR3& pointA = simplex.GetPoint(3);
    const D3DXVECTOR3& pointB = simplex.GetPoint(0);
    const D3DXVECTOR3& pointC = simplex.GetPoint(1);
    const D3DXVECTOR3& pointD = simplex.GetPoint(2);

    const D3DXVECTOR3 AB = pointB - pointA;
    const D3DXVECTOR3 AC = pointC - pointA;
    const D3DXVECTOR3 AD = pointD - pointA;
    const D3DXVECTOR3 AO = -pointA;

    // Check if within the three surrounding planes
    // The forth plane has been previously tested with the plane simplex
    // All normals will point to the center of the tetrahedron
    D3DXVECTOR3 CBnormal, BDnormal, DCnormal;
    D3DXVec3Cross(&CBnormal, &AC, &AB);
    D3DXVec3Cross(&BDnormal, &AB, &AD);
    D3DXVec3Cross(&DCnormal, &AD, &AC);

    const float CBdistance = D3DXVec3Dot(&CBnormal, &AO);
    const float BDdistance = D3DXVec3Dot(&BDnormal, &AO);
    const float DCdistance = D3DXVec3Dot(&DCnormal, &AO);

    bool originInsideSimplex = true;
    if(CBdistance < 0.0f)
    {
        // Origin is outside of the CB plane
        // D is furthest point, remove it and search towards the origin
        simplex.RemovePoint(pointD);
        direction = -CBnormal;
        originInsideSimplex = false;
    }
    else if(BDdistance < 0.0f)
    {
        // Origin is outside of the BD plane
        // C is furthest point, remove it and search towards the origin
        simplex.RemovePoint(pointC);
        direction = -BDnormal;
        originInsideSimplex = false;
    }
    else if(DCdistance < 0.0f)
    {
        // Origin is outside of the DC plane
        // C is furthest point, remove it and search towards the origin
        simplex.RemovePoint(pointB);
        direction = -DCnormal;
        originInsideSimplex = false;
    }
    return originInsideSimplex;
}
开发者ID:huaminglee,项目名称:cloth-simulator,代码行数:51,代码来源:collisionsolver.cpp

示例15: GetMinkowskiSumEdgePoint

bool CollisionSolver::AreConvexHullsColliding(const CollisionMesh& particle, 
                                              const CollisionMesh& hull, 
                                              Simplex& simplex)
{
    // If two convex hulls have collided, the Minkowski Sum A + (-B) of both 
    // hulls will contain the origin. Reference from 'Proximity Queries and 
    // Penetration Depth Computation on 3D Game Objects' by Gino van den Bergen
    // http://graphics.stanford.edu/courses/cs468-01-fall/Papers/van-den-bergen.pdf

    const std::vector<D3DXVECTOR3>& particleVertices = particle.GetVertices();
    const std::vector<D3DXVECTOR3>& hullVertices = hull.GetVertices();

    // Determine an initial point for the simplex
    const int initialIndex = 0;
    D3DXVECTOR3 direction = particleVertices[initialIndex] - hullVertices[initialIndex];
    D3DXVECTOR3 lastEdgePoint = GetMinkowskiSumEdgePoint(direction, particle, hull);
    simplex.AddPoint(lastEdgePoint);
        
    direction = -direction;
    int iteration = 0;
    bool collisionFound = false;
    bool collisionPossible = true;
    const int maxIterations = 20;

    // Iteratively create a simplex within the Minkowski Sum Hull
    while(iteration < maxIterations && !collisionFound && collisionPossible)
    {
        ++iteration;
        lastEdgePoint = GetMinkowskiSumEdgePoint(direction, particle, hull);
        simplex.AddPoint(lastEdgePoint);

        if(D3DXVec3Dot(&lastEdgePoint, &direction) <= 0)
        {
            // New edge point of simplex is not past the origin.
            collisionPossible = false;
        }
        else if(simplex.IsLine())
        {
            SolveLineSimplex(simplex, direction);
        }
        else if(simplex.IsTriPlane())
        {
            SolvePlaneSimplex(simplex, direction);
        }
        else if(simplex.IsTetrahedron())
        {
            collisionFound = SolveTetrahedronSimplex(simplex, direction);
        }
    }
    return collisionFound;
}
开发者ID:huaminglee,项目名称:cloth-simulator,代码行数:51,代码来源:collisionsolver.cpp


注:本文中的Simplex类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。