Exemplo n.º 1
0
void DrawDetectedPoints(const vector<Point2f>* initPts, const vector<Point2f>* updPts,
	const vector<FatoStatus>* ptsStatus, const vector<int>* ptsIds, Mat&out)
{
	int imgOffset = out.cols / 2;
	
	random_device rd;
	default_random_engine dre(rd());
	uniform_int_distribution<unsigned int> uniform_dist(0, 255);

	for (size_t i = 0; i < updPts->size(); i++)
	{
		const int id = ptsIds->at(i);
		if (ptsStatus->at(i) == FatoStatus::MATCH)
		{
			Scalar color(uniform_dist(dre), uniform_dist(dre), uniform_dist(dre));

			const Point2f& src = initPts->at(id);
			Point2f dst = updPts->at(i);
			dst.x += imgOffset;

			circle(out, src, 3, color, 1);
			circle(out, dst, 3, color, 1);
			line(out, src, dst, color, 1);
			
		}
	}
}
Exemplo n.º 2
0
int Enemy::randomNumber(int min, int max)
{
	random_device dev;
	default_random_engine dre(dev());
	uniform_int_distribution<int> dist(min, max);
	return dist(dre);
}
Exemplo n.º 3
0
void
RilConsumer::ReceiveSocketData(nsAutoPtr<UnixSocketRawData>& aMessage)
{
    MOZ_ASSERT(NS_IsMainThread());

    nsRefPtr<DispatchRILEvent> dre(new DispatchRILEvent(aMessage.forget()));
    mDispatcher->PostTask(dre);
}
Exemplo n.º 4
0
void Graph::teleportRabbit() {
	Vertex* destination = nullptr;
	while(destination == nullptr || destination == getCowVertex() || destination == getRabbitVertex()) {
		std::random_device dev;
		std::default_random_engine dre(dev());
		std::uniform_int_distribution<int> dist1(0, this->getVertices()->size() - 1);

		int index = dist1(dre);
		destination = this->getVertices()->at(index);
	}
	this->rabbit->setDestination(destination);
	while(this->rabbit->getRoute()->size() > 0) {
		this->rabbit->getRoute()->pop_back();
	}
	this->setRabbitVertex(destination);
}
Exemplo n.º 5
0
void
Tester::run(const unsigned int highpower) {	

	unsigned int seed = 12345;
    std::default_random_engine dre(seed);
    std::uniform_int_distribution<> dis(1, 10000);
 
	for (int n = 0; n < (REPS * 2) + pow(2, highpower); ++n) {
		
		RAN_NUMS.push_back(dis(dre));
	}

	TestFHeap(highpower);
	TestBHeap(highpower);
    //TestDijkstra(highpower);
}
Exemplo n.º 6
0
		void MainMenuState::loadAdvertisement()
		{
			if (_advertisementIndex >= 0)
				_game->getEngine()->getDrawEngine()->unload("advertisement");

			std::random_device dev;
			std::default_random_engine dre(dev());
			std::uniform_int_distribution<int> randomAdvertisement(0, _advertismentList->size() - 1);

			int advertisementIndex = 0;
			do
				advertisementIndex = randomAdvertisement(dre);
			while (advertisementIndex == _advertisementIndex);

			_advertisementIndex = advertisementIndex;
			_game->getEngine()->getDrawEngine()->load("advertisement", "assets\\advertisements\\" + _advertismentList->at(advertisementIndex));

			const std::array<int, 2> size = _game->getEngine()->getDrawEngine()->getImageSize("advertisement");
			_advertisementX = _advertisementStartX + (size[0] / 2);
			_advertisementY = _advertisementStartY + (size[1] / 2);
		}
	individual combine(individual i1, individual i2){
		std::cerr<<"Warning: for sex aware objective function set the sexAware \n "
				 <<"boolean flag of the combination strategy to true! Otherwise\n"
				 <<" the sex of the individual has no effect."<<std::endl;
		std::vector<std::pair<float, float> > newGenotype(i2.getNdim());

		/* the get chromosome method gives a random selection of allele genes
		  * which is not neccesarrily the gene sequence that has been represented in the
		  * phenotype of the individual!
		  *
		  * This simulates the process of meiosis - an integral part of
		  * sexual reproduction.
		  *
		  * Possible improvements could inlcude gene methylation simulation and other
		  * acquired genetic traits other than simple mutation.
		  *
		  * When the strategy is sex aware the returned individual is returned with the objective function
		  * already calculated in order to reduce the number of objective function calculations.
		  *
		  * The objective function value of the male individual is estimated as
		  * the best objective function of his mother. That allows for possible hidden beneficial traits to
		  * pass to next generations and not wiped out by evolutionary pressure.
		  *
		  */

		std::vector<float > v1 = i1.getChromosome();
		std::vector<float > v2 = i2.getChromosome();
		
		std::uniform_real_distribution<float> dre(0.0,1.0);

		assert(REset == true);

		for(unsigned int i=0;i<i1.getNdim();i++){
			float rn = dre(re);
			std::pair<float, float> newGene;
			newGene.first = rn>0.5?v1.at(i):v2.at(i);
			newGene.second = rn>0.5?v2.at(i):v1.at(i); // saving the non expressed genes in the non expressed chromosome

			//Mutation in reality is most probable to happen during meiosis - here it goes:
			if(MRSet){
				//std::cout<<"mutating gene gene after recombination"<<std::endl;
				float rn2 = dre(re);
				newGene.first += (0.5-rn2)*mutRates.at(i);
				newGene.second += (0.5-rn2)*mutRates.at(i);
			}
			newGenotype.at(i) = newGene;
		}

		individual indd(newGenotype);
		indd.setSex(dre(re)>0.5?MALE:FEMALE);
		if(sexAware){
			if(indd.getSex()==MALE){
				/*
				 * If the created individual is a Male (objective function should not be calculated) then
				 * he inherits the objective function of his mother in order to reduce the objective function calcu
				 * lations and increase population variability. Hopefully beneficial genes are surviving generations
				 * when they are part of less fit individuals that way.
				 */
				indd.setEstimatedObjectiveFunction(i1.getSex()==FEMALE?i1.getObjectiveFunction():i2.getObjectiveFunction());
			}
		}
		return indd;
	}
Exemplo n.º 8
0
void background_Thread() {
    std::default_random_engine dre(static_cast<int>(time(0)));
    std::this_thread::sleep_for(std::chrono::seconds(dre()%2));
    std::lock_guard<std::mutex> lock(m);
    std::cout << "Woke up" << "\n";
}