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


C++ Mutator类代码示例

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


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

示例1: add

 void ControlDevice::add(std::string const& name, Mutator value_ref) 
 { 
   if(required_flag == all_required_flag)
     value_ref.make_required();
   else if(required_flag == all_optional_flag)
     value_ref.make_optional();
   impl->add(name,value_ref);
 }
开发者ID:BackupTheBerlios,项目名称:gral,代码行数:8,代码来源:control-device.C

示例2: switch

inline void
Value::accept(Mutator& v)
{
  switch (k) {
    case error_value: return v.visit(r.err_);
    case integer_value: return v.visit(r.int_);
    case function_value: return v.visit(r.fn_);
    case reference_value: return v.visit(r.ref_);
    case array_value: return v.visit(r.arr_);
    case tuple_value: return v.visit(r.tup_);
  }
}
开发者ID:thehexia,项目名称:steve,代码行数:12,代码来源:value.hpp

示例3: dprintf

HRESULT MutationEngine::addMutator(PCHAR scriptFileName, PCHAR filter)
{
	if(_mutators.size() >= this->_maxMutatorsNum)
	{
		dprintf("[windbgshark] MutationEngine::addMutator: sorry, mutators number reached _maxMutatorsNum = %d\n", this->_maxMutatorsNum);
		return E_FAIL;
	}

	Mutator *pMutator = new Mutator();
	if(pMutator == NULL)
	{
		dprintf("[windbgshark] MutationEngine::addMutator: error! could not allocate memory for a new mutator\n");
		return E_FAIL;
	}

	ULONG mutatorId;
	for(mutatorId = 0; mutatorId < this->_maxMutatorsNum; mutatorId++)
	{
		if(_mutators.find(mutatorId) == _mutators.end())
		{
			break;
		}
	}

	if(mutatorId >= this->_maxMutatorsNum)
	{
		dprintf("[windbgshark] MutationEngine::addMutator: error! could not find suitable Id for mutator\n");
		return E_FAIL;
	}

	pMutator->setMutator(mutatorId, scriptFileName, filter);

	_mutators[mutatorId] = pMutator;

	return S_OK;
}
开发者ID:Rootkitsmm,项目名称:windbgshark,代码行数:36,代码来源:mutate.cpp

示例4: accept

 void accept(Mutator& v)       { v.visit(*this); }
开发者ID:asutton,项目名称:banjo,代码行数:1,代码来源:ast-stmt.hpp

示例5: main


//.........这里部分代码省略.........
        f.reset(WIDTH, HEIGHT);
        food.push_back(f);
    }

    sf::Clock frame_clock;
    sf::Clock gen_clock;
    int frame_count = 0;

    while (window.isOpen()) {
        sf::Event event;
        while (window.pollEvent(event)) {
            switch (event.type) {

                case sf::Event::Closed:
                    window.close();
                    break;

                case sf::Event::KeyPressed:
                    if (event.key.code == sf::Keyboard::W) {
                        creature.moveForward();
                    } else if (event.key.code == sf::Keyboard::S) {
                        printf("%s\n", "S PRESSED");
                    } else if (event.key.code == sf::Keyboard::A) {
                        creature.setRotation(creature.getRotation() + 5);
                    } else if (event.key.code == sf::Keyboard::D) {
                        creature.setRotation(creature.getRotation() - 5);
                    } else if (event.key.code == sf::Keyboard::P) {
                        launchConsole();
                        frame_clock.restart();
                    }
                    break;

                case sf::Event::MouseButtonPressed:
                    if (event.mouseButton.button == sf::Mouse::Right) {
                        sf::Vector2f position = static_cast<sf::Vector2f>(sf::Mouse::getPosition(window));
                    }
                    break;

                default:
                    break;
            }
        }

        window.clear();

        for (int i = 0; i < NUM_FOOD; ++i) {
            if (!food[i].isConsumed()) window.draw(food[i]);
        }

        // Debug creature
        creature.draw(&window);
        for (int i = 0; i < NUM_FOOD; ++i) {
            if (creature.isPointInFOV(food[i].getPosition())) {
                // printf("%f\n", creature.distanceToPoint(food[i].getPosition()));
            }
        }

        for (int i = 0; i < NUM_CREATURES; ++i) {
            creatures[i].process(&food);
            creatures[i].draw(&window);
        }

        // Handle generations
        if (gen_clock.getElapsedTime().asSeconds() > GENERATION_LENGTH_SECONDS) {
            std::cout << "Generation: " << ++gen_count << std::endl;
            writeOutData();
            // Reset food
            for (int i = 0; i < NUM_FOOD; ++i) {
                food[i].reset(WIDTH, HEIGHT);
            }

            // Sort by energy level
            std::sort(creatures, creatures + NUM_CREATURES, compareCreatures);

            // Select and mutate the top 50% of creatures
            Mutator mutator = Mutator();
            for (int i = 0; i < NUM_CREATURES/2; ++i) {
                printf("Creature %d  %f\n", i, creatures[i].getEnergy());
                mutator.setTarget(&creatures[i]);
                creatures[i].resetEnergy();
                creatures[i].position[0] = WIDTH / 2;
                creatures[i].position[1] = HEIGHT / 2;

                mutator.mutate(&creatures[NUM_CREATURES - 1 - i]);
                creatures[NUM_CREATURES - 1 - i].resetEnergy();
                creatures[NUM_CREATURES - 1 - i].position[0] = WIDTH / 2;
                creatures[NUM_CREATURES - 1 - i].position[1] = HEIGHT / 2;
            }

            gen_clock.restart();
        }

        window.display();

        sf::Time elapsed = frame_clock.restart();
        env.step(elapsed.asSeconds());
    }

    return 0;
}
开发者ID:alobo,项目名称:ev,代码行数:101,代码来源:main.cpp

示例6: process

	void process(const WorkUnit *workUnit, WorkResult *workResult, const bool &stop) {
		ImageBlock *result = static_cast<ImageBlock *>(workResult);
		const SeedWorkUnit *wu = static_cast<const SeedWorkUnit *>(workUnit);
		Path *current = new Path(), *proposed = new Path();
		Spectrum relWeight(0.0f);

		result->clear();

		/// Reconstruct the seed path
		m_pathSampler->reconstructPath(wu->getSeed(), m_config.importanceMap, *current);
		relWeight = current->getRelativeWeight();
		BDAssert(!relWeight.isZero());

		DiscreteDistribution suitabilities(m_mutators.size());
		MutationRecord muRec, currentMuRec(Mutator::EMutationTypeCount,0,0,0,Spectrum(0.f));
		ref<Timer> timer = new Timer();

		size_t consecRejections = 0;
		Float accumulatedWeight = 0;

		#if defined(MTS_DEBUG_FP)
			enableFPExceptions();
		#endif

		#if defined(MTS_BD_DEBUG_HEAVY)
			std::ostringstream oss;
			Path backup;
		#endif
		for (size_t mutationCtr=0; mutationCtr < m_config.nMutations
				&& !stop; ++mutationCtr) {
			if (wu->getTimeout() > 0 && (mutationCtr % 8192) == 0 &&
					(int) timer->getMilliseconds() > wu->getTimeout())
				break;

			/* Query all mutators for their suitability */
			suitabilities.clear();
			for (size_t j=0; j<m_mutators.size(); ++j)
				suitabilities.append(m_mutators[j]->suitability(*current));
			#if defined(MTS_BD_DEBUG_HEAVY)
				current->clone(backup, *m_pool);
			#endif

			size_t mutatorIdx = 0;
			bool success = false;
			Mutator *mutator = NULL;

			if (suitabilities.normalize() == 0) {
				/* No mutator can handle this path -- give up */
				size_t skip = m_config.nMutations - mutationCtr;
				accumulatedWeight += skip;
				consecRejections += skip;
				break;
			}

			mutatorIdx = suitabilities.sample(m_sampler->next1D());
			mutator = m_mutators[mutatorIdx].get();

			/* Sample a mutated path */
			success = mutator->sampleMutation(*current, *proposed, muRec, currentMuRec);

			#if defined(MTS_BD_DEBUG_HEAVY)
				if (backup != *current)
					Log(EError, "Detected an unexpected path modification after a "
						"mutation of type %s (k=%i)!", muRec.toString().c_str(),
						current->length());
				if (success) {
					bool fail = false;
					for (int i=0; i<muRec.l; ++i)
						if (*backup.vertex(i) != *proposed->vertex(i))
							fail = true;

					for (int i=1; i <= backup.length() - muRec.m; ++i)
						if (*backup.vertex(muRec.m+i) != *proposed->vertex(muRec.l+muRec.ka+i))
							fail = true;
					if (fail)
						Log(EError, "Detected an unexpected path modification outside of the "
							"specified range after a mutation of type %s (k=%i)!",
							muRec.toString().c_str(), current->length());
				}
				backup.release(*m_pool);
			#endif

			statsAccepted.incrementBase(1);
			if (success) {
				Float Qxy = mutator->Q(*current, *proposed, muRec) * suitabilities[mutatorIdx];
				suitabilities.clear();
				for (size_t j=0; j<m_mutators.size(); ++j)
					suitabilities.append(m_mutators[j]->suitability(*proposed));
				suitabilities.normalize();
				Float Qyx = mutator->Q(*proposed, *current, muRec.reverse()) * suitabilities[mutatorIdx];

				Float a;
				if (!m_config.importanceMap) {
					if(Qxy > RCPOVERFLOW)
					a = std::min((Float) 1, Qyx / Qxy);
					else
						a = 0.f;
				} else {
					const Float *luminanceValues = m_config.importanceMap->getFloatData();
					const Point2 &curPos = current->getSamplePosition();
//.........这里部分代码省略.........
开发者ID:AdrianJohnston,项目名称:ShapeNetRender,代码行数:101,代码来源:mlt_proc.cpp

示例7: accept

 void accept(Mutator& v)       { return v.visit(this); }
开发者ID:thehexia,项目名称:steve,代码行数:1,代码来源:actions.hpp


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