Exemplo n.º 1
0
void crossing2() {
  GlobalPoint startingPos(-8.12604,-50.829,9.82116);   
  GlobalVector startingDir(-0.517536,-5.09581,1.02212);

  GlobalPoint  pos(-2.96723,-51.4573,14.8322);
  
  Surface::RotationType rot(0.995041,0.0994701,0.000124443,
			    0.000108324,-0.00233467,0.999997,
			    0.0994701,-0.995038,-0.00233387);
  std::cout << rot << std::endl;
  
  Plane plane(pos,rot);
  
  double rho = 0.00223254;
  
  HelixBarrelPlaneCrossingByCircle precise(startingPos, startingDir, rho,alongMomentum);
  bool cross; double s;
  std::tie(cross,s) = precise.pathLength(plane);

  HelixBarrelPlaneCrossing2OrderLocal crossing(startingPos, startingDir, rho, plane);

  std::cout << plane.toLocal(GlobalPoint(precise.position(s))) << " " <<  plane.toLocal(GlobalVector(precise.direction(s))) << std::endl;
  std::cout << HelixBarrelPlaneCrossing2OrderLocal::positionOnly(startingPos, startingDir, rho, plane) << ' ';
  std::cout << crossing.position() << ' ' << crossing.direction() << std::endl;

  LocalPoint thePos; LocalVector theDir;
  std::tie(thePos,theDir) = secondOrderAccurate(startingPos, startingDir, rho, plane);

  std::cout << thePos << ' ' << theDir << std::endl;



}
Exemplo n.º 2
0
void crossing1() {
  GlobalPoint startingPos(-7.79082,-47.6418,9.18163);
  GlobalVector startingDir(-0.553982,-5.09198,1.02212);

  GlobalPoint  pos(-2.95456,-48.2127,3.1033);
  
  double rho = 0.00223254;
  
  Surface::RotationType rot(0.995292,0.0969201,0.000255868,
			    8.57131e-06,0.00255196,-0.999997,
			    -0.0969205,0.995289,0.00253912);
  
  std::cout << rot << std::endl;

  Plane plane(pos,rot);

  HelixBarrelPlaneCrossingByCircle precise(startingPos, startingDir, rho,alongMomentum);
  bool cross; double s;
  std::tie(cross,s) = precise.pathLength(plane);

  HelixBarrelPlaneCrossing2OrderLocal crossing(startingPos, startingDir, rho, plane);


  std::cout << plane.toLocal(GlobalPoint(precise.position(s))) << " " <<  plane.toLocal(GlobalVector(precise.direction(s))) << std::endl;
  std::cout << HelixBarrelPlaneCrossing2OrderLocal::positionOnly(startingPos, startingDir, rho, plane) << ' ';
  std::cout << crossing.position() << ' ' << crossing.direction() << std::endl;

  LocalPoint thePos; LocalVector theDir;
  std::tie(thePos,theDir) = secondOrderAccurate(startingPos, startingDir, rho, plane);

  std::cout << thePos << ' ' << theDir << std::endl;
}
Exemplo n.º 3
0
Coords OneDRootFinder::retZeros() {
    std::vector<double> signs,coords;
    Coords r(3,0);
    r[0] = -100000.;
    signs.push_back(pots_->operator()(r,t0_));
    coords.push_back(r[0]);
    for (int i=0; i<100; ++i) {
        r[0]=-50. + i;
        signs.push_back(ip_+pots_->operator()(r,t0_));
        coords.push_back(r[0]);
    }
    r[0] = 100000;
    signs.push_back(ip_+pots_->operator()(r,t0_));
    coords.push_back(r[0]);
    zeroPts crossPts;
    crossing(signs, coords, crossPts);

    double zero=0.;
    PotDouble f(pots_, ip_, t0_);
    foreach(dPair d, crossPts) {
        double retZero = findZero(d, f);
        if (std::abs(retZero) >= std::abs(zero))
            zero = retZero;
    }
Exemplo n.º 4
0
void DotlikeOptimizer::Reorder(Layout &nodes,Layout &edges) {
	vector<int> affectedRanks;
	{
		NodeV optimVec;
		getCrossoptModelNodes(nodes,edges,optimVec);
		if(optimVec.empty())
			return;
		sort(optimVec.begin(),optimVec.end(),RankLess());
		NodeV::iterator wot = optimVec.begin();
		for(Config::Ranks::iterator ri = config.ranking.begin(); ri!=config.ranking.end(); ++ri)
			for(NodeV::iterator ni = (*ri)->order.begin(); ni!=(*ri)->order.end(); ++ni)
				if(wot!=optimVec.end() && *ni==*wot) {
					DDd(*ni).orderConstraint = -1;
					++wot;
				}
				else
					DDd(*ni).orderConstraint = DDd(*ni).order;
		assert(wot==optimVec.end());
		loops.Field(r_crossopt,"model nodes for crossopt",optimVec.size());
		loops.Field(r_crossopt,"total model nodes",optimVec.front()->g->nodes().size());

		for(NodeV::iterator ni = optimVec.begin(); ni!=optimVec.end(); ++ni)
			if(affectedRanks.empty() || affectedRanks.back()!=DDd(*ni).rank)
				affectedRanks.push_back(DDd(*ni).rank);
		loops.Field(r_crossopt,"ranks for crossopt",affectedRanks.size());
		loops.Field(r_crossopt,"total ranks",config.ranking.size());
	}
	SiftMatrix matrix(config),backupM(config);
	MedianCompare median(DOWN,false);
	CrossingCompare crossing(config,matrix,false);
	OrderConstraintSwitchable switchable;

	Config::Ranks backup = config.ranking;
	// optimize once ignoring node crossings (they can scare the sifting alg) 
	// in a sec we'll sift using the node penalty to clean up
	matrix.m_light = true;
	matrix.recompute();
	backupM = matrix;
	unsigned best = matrix.sumCrossings(),bestPass=0;
	loops.Field(r_crossopt,"crossings before crossopt",best);
	unsigned passes = 32,pass=0,score=0;
	while(pass<passes && best) {
		int tired = 0;
		while(pass<passes && tired<TIRE) {
				assert(matrix.m_light);
			median.m_allowEqual = pass%8>4;
			crossing.m_allowEqual = !median.m_allowEqual;
			LeftRight way = (pass%2) ? RIGHT : LEFT;
			UpDown dir;
				assert(matrix.m_light);
			if(pass%4<2) {
				median.m_dir = UP;
				dir = DOWN;
			}
			else {
				median.m_dir = DOWN;
				dir = UP;
			}
			bubblePass(config,matrix,affectedRanks,dir,way,switchable,median);
				assert(matrix.m_light);

			// something in the next dozen lines crashes MS Visual C++ .NET
			// if run-time checks are enabled so i've disabled them for this file - ?
			unsigned score2 = matrix.sumCrossings();
			do {
				score = score2;
				assert(matrix.m_light);
				bubblePass(config,matrix,affectedRanks,dir,way,switchable,crossing);
				score2 = matrix.sumCrossings();
				assert(score2<=score);
			}
			while(score2<score);
			score = score2;

			if(reportEnabled(r_crossopt)) {
				char buf[10];
				sprintf(buf,"crossings pass %d",pass);
				loops.Field(r_crossopt,buf,score);
			}

			if(score<best) {
				backup = config.ranking;
				backupM = matrix;
				best = score;
				bestPass = pass;
				tired = 0;
			}
			else 
				tired++;
			pass++;
		}
		if(score>best || tired==TIRE) {
			config.Restore(backup);
			//matrix.recompute();
			matrix = backupM;
			tired = 0;
		}
	}
	if(reportEnabled(r_crossopt))
		for(;pass<passes;++pass) {
			char buf[10];
			sprintf(buf,"crossings pass %d",pass);
			loops.Field(r_crossopt,buf,0);
		}

	if(score>=best) {
		config.Restore(backup);
	}
	loops.Field(r_crossopt,"model edge crossings",best);

	// sift out node crossings
	matrix.m_light = false;
	matrix.recompute();
	score = matrix.sumCrossings();
	loops.Field(r_crossopt,"weighted crossings before heavy pass",score);
	/*
	report(r_crossopt,"%d node-node crossings; %d node-edge crossings; %d edge-edge crossings\n",score/(NODECROSS_PENALTY*NODECROSS_PENALTY),
		(score/NODECROSS_PENALTY)%NODECROSS_PENALTY,score%NODECROSS_PENALTY);
	*/
	if(score<NODECROSS_PENALTY) {
		loops.Field(r_crossopt,"weighted crossings after heavy pass",-1);
		return;
	}
	pass = 0;
	passes = 4;
	crossing.m_allowEqual = true;
	// sifting out upward or downward may be better - try both.
	bool improved;
	do {
		improved = false;
		backup = config.ranking;
		bubblePass(config,matrix,affectedRanks,DOWN,RIGHT,switchable,crossing);
		unsigned down = matrix.sumCrossings();
		Config::Ranks backup2 = config.ranking;
		config.Restore(backup);
		matrix.recompute();
		bubblePass(config,matrix,affectedRanks,UP,RIGHT,switchable,crossing);
		unsigned up = matrix.sumCrossings();
		if(down<score && down<up) {
			config.Restore(backup2);
			matrix.recompute();
			score = down;
			improved = true;
		}
		else if(up<score) {
			score = up;
			improved = true;
		}
	}
	while(improved);
	loops.Field(r_crossopt,"weighted crossings after heavy pass",score);
	// absolutely must not leave here with nodes crossing nodes!!
	assert(score<NODECROSS_PENALTY*NODECROSS_PENALTY);
}