add parallel
This commit is contained in:
parent
c1d79ac699
commit
215ca2a9c0
@ -1,4 +1,5 @@
|
||||
#include <bits/stdc++.h>
|
||||
#include <omp.h>
|
||||
#include "pushbox.h"
|
||||
#include "box-solver.h"
|
||||
|
||||
@ -10,7 +11,7 @@ std::mt19937 rng(std::random_device{}());
|
||||
__builtin_unreachable(); \
|
||||
} while (false); \
|
||||
|
||||
const int species_limit = 5;
|
||||
const int species_limit = 8;
|
||||
const int population_limit = 10;
|
||||
const int SPECIES_NAME_LEN = 4;
|
||||
|
||||
@ -102,7 +103,7 @@ inline void randomName(int n, char res[]) {
|
||||
}
|
||||
}
|
||||
|
||||
static std::uniform_int_distribution<int> rng0N(0, N - 1);
|
||||
thread_local std::uniform_int_distribution<int> rng0N(0, N - 1);
|
||||
|
||||
inline void mutationRandomHole(Species &res, const Gene &sc, int clear_cnt) {
|
||||
Gene ac = sc;
|
||||
@ -299,14 +300,19 @@ int main() {
|
||||
std::uniform_real_distribution<float> d01(0, 1);
|
||||
for (int iter_id = 1; ; ++iter_id) {
|
||||
int best_w = 0;
|
||||
for (auto &s : biosphere) {
|
||||
|
||||
# pragma omp parallel for num_threads(8)
|
||||
for (auto &s : biosphere)
|
||||
inherit(s);
|
||||
|
||||
for (auto &s : biosphere)
|
||||
best_w = std::max(best_w, s.best_w);
|
||||
}
|
||||
|
||||
std::vector<Species> Hnxt, Lnxt;
|
||||
for (auto &s : biosphere) {
|
||||
if (s.stable_age <= 15 * s.best_w / best_w || s.best_w == best_w) {
|
||||
if (s.stable_age <= std::max(5, 15 * s.best_w / best_w)
|
||||
|| s.best_w == best_w)
|
||||
{
|
||||
if (s.best_w < best_w || s.age <= 35)
|
||||
Hnxt.push_back(std::move(s));
|
||||
else
|
||||
|
@ -6,9 +6,9 @@
|
||||
#include "pushbox.h"
|
||||
|
||||
namespace Solve {
|
||||
std::bitset<N> mp[N];
|
||||
int dis[N][N][N][N];
|
||||
std::queue<std::tuple<int, int, int, int>> qu;
|
||||
thread_local std::bitset<N> mp[N];
|
||||
thread_local int dis[N][N][N][N];
|
||||
thread_local std::queue<std::tuple<int, int, int, int>> qu;
|
||||
|
||||
inline int bfs(int px, int py, int bx, int by, int tx, int ty) {
|
||||
std::memset(dis, 127, sizeof(dis));
|
||||
@ -64,7 +64,7 @@ inline int bfs(int px, int py, int bx, int by, int tx, int ty) {
|
||||
}
|
||||
|
||||
inline int solve(Maze q) {
|
||||
for (int i = 0; i < 20; ++i)
|
||||
for (int i = 0; i < N; ++i)
|
||||
mp[i] = q.M[i];
|
||||
return bfs(q.poi[POI_PERSON][0], q.poi[POI_PERSON][1]
|
||||
, q.poi[POI_BOX][0], q.poi[POI_BOX][1], q.poi[POI_TARGET][0], q.poi[POI_TARGET][1]);
|
||||
|
Loading…
x
Reference in New Issue
Block a user