本文整理汇总了C++中Solution::alignment方法的典型用法代码示例。如果您正苦于以下问题:C++ Solution::alignment方法的具体用法?C++ Solution::alignment怎么用?C++ Solution::alignment使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Solution
的用法示例。
在下文中一共展示了Solution::alignment方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: perturbate
void Pheromone::perturbate(
const Solution ¤t,
const Solution &best,
Solution &out
) {
size_t m = current.alignment.size1();
// Create unused lists
std::vector<std::vector<vertex_descriptor>> unused(n);
for(size_t i = 0; i < n; ++i) {
unused[i].resize(num_vertices((*graphs)[i]));
std::iota(unused[i].begin(), unused[i].end(), 0);
}
// Fill first column of alignment randomly
std::iota(out.alignment.begin1(), out.alignment.end1(), 0);
std::shuffle(out.alignment.begin1(), out.alignment.end1(), rand_gen[0]);
// Align remaining networks
size_t start_node;
for(size_t i = 0; i < m; ++i) {
start_node = out.alignment(i, 0);
for(size_t g = 1; g < n; ++g) {
size_t best_index = 0;
float best_prob = 0.0f;
#pragma omp parallel
{
int tid = omp_get_thread_num();
size_t prv_best_index = 0;
float prv_best_prob = 0.0f;
#pragma omp for schedule(static)
for(size_t index = 0; index < unused[g].size(); ++index) {
size_t node = unused[g][index];
float prob = real_dist[tid](rand_gen[tid]) * pheromones[g-1](start_node, node);
if(prob > prv_best_prob) {
prv_best_index = index;
prv_best_prob = prob;
}
}
#pragma omp critical
{
if(prv_best_prob > best_prob) {
best_index = prv_best_index;
best_prob = prv_best_prob;
}
}
}
size_t node = unused[g][best_index];
unused[g].erase(unused[g].begin()+best_index);
out.alignment(i, g) = node;
}
}
}
示例2: update
void Pheromone::update(
const Solution ¤t,
const Solution &best
) {
size_t m = current.alignment.size1();
// Evaporate pheromones
for(auto &m : pheromones) {
for(auto it1 = m.begin1(); it1 != m.end1(); ++it1) {
for(auto it = it1.begin(); it != it1.end(); ++it) {
*it = std::max(*it * (1.0f - evaporation), min_pheromone);
}
}
}
// Add pheromones for current solution
float quality = static_cast<float>(current.quality);
float best_quality = static_cast<float>(best.quality);
for(size_t i = 0; i < n-1; ++i) {
for(size_t j = 0; j < m; ++j) {
int u = current.alignment(j, 0);
int v = current.alignment(j, i+1);
pheromones[i](u, v) = std::min(pheromones[i](u,v) + quality, best_quality);
}
}
}