本文整理汇总了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);
}
示例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_);
}
}
示例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;
}
示例4: accept
void accept(Mutator& v) { v.visit(*this); }
示例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;
}
示例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();
//.........这里部分代码省略.........
示例7: accept
void accept(Mutator& v) { return v.visit(this); }