24 #include <spot/mc/reachability.hh> 25 #include <spot/misc/timer.hh> 28 #include <bricks/brick-hashset> 33 template<
typename State,
typename SuccIterator,
34 typename StateHash,
typename StateEqual>
36 StateHash, StateEqual,
37 count_valid<State, SuccIterator,
38 StateHash, StateEqual>>
43 std::function<
bool(
const State)> count_valid_fun,
44 std::function<
int(State)> get_depth,
45 std::function<
int(State)> get_pos,
47 unsigned tid,
bool& stop, std::string algoname)
50 StateHash, StateEqual>>(sys, tid, stop),
51 new_initial_(new_initial), count_valid_fun_(count_valid_fun),
52 get_depth_(get_depth), get_pos_(get_pos), id_(
id), algoname_(algoname)
65 bool push(State st,
unsigned int dfsnum)
70 this->visited.erase(st);
71 this->sys_.recycle(this->todo.back().it, this->tid_);
72 this->todo.pop_back();
73 this->todo.push_back({new_initial_,
74 this->sys_.succ(new_initial_, this->tid_)});
75 this->visited[new_initial_] = this->dfs_number;
77 if (count_valid_fun_(new_initial_))
82 if (count_valid_fun_(st))
85 if (first_depth_ == -1)
87 first_depth_ = get_depth_(st);
88 first_pos_ = get_pos_(st);
99 void edge(
unsigned int,
unsigned int)
105 float x = (float) counter_ / this->states();
106 std::cout <<
'@' << id_
108 <<
',' << first_depth_
111 <<
',' << this->states()
112 <<
',' << this->trans()
114 << (this->stop_?
",ABORTED" :
",FINISHED");
120 std::function<bool(const State)> count_valid_fun_;
121 std::function<int(State)> get_depth_;
122 std::function<int(State)> get_pos_;
123 unsigned int counter_ = 0;
124 int first_depth_ = -1;
127 std::string algoname_;
130 template<
typename State,
typename SuccIterator,
131 typename StateHash,
typename StateEqual>
133 StateHash, StateEqual,
134 interpolate<State, SuccIterator,
135 StateHash, StateEqual>>
139 std::function<
void(State,
unsigned int)> display,
140 std::function<std::vector<State>*(std::vector<State>&)> interpolate_fun,
141 unsigned tid,
bool& stop, std::string algoname)
144 StateHash, StateEqual>>(sys, tid, stop),
145 display_(display), interpolate_fun_(interpolate_fun), algoname_(algoname)
157 tm_.start(
"original DFS");
160 bool push(State st,
unsigned int dfsnum)
163 sample_.push_back(st);
165 depth.insert({st, (int) this->todo.size()});
166 dfspos.insert({st, (int) this->dfs_number});
176 void edge(
unsigned int,
unsigned int)
182 using namespace std::literals::chrono_literals;
183 tm_.stop(
"original DFS");
185 std::cout <<
"STATES : " << this->states() << std::endl;
186 std::cout <<
"TRANSITIONS : " << this->trans() << std::endl;
187 std::cout <<
"TIME : " << tm_.timer(
"original DFS").walltime()
189 tm_.start(
"Generation of states");
190 auto* gen = interpolate_fun_(sample_);
191 tm_.stop(
"Generation of states");
193 std::cout <<
"GenPop : " << tm_.timer(
"Generation of states").walltime()
196 for (
unsigned i = 0; i < gen->size(); ++i)
201 cv(this->sys_, (*gen)[i], [
this](State s) ->
bool 203 return this->visited.find(s) != this->visited.end();
205 [
this](State s) ->
int 209 [
this](State s) ->
int 221 for (
unsigned t = 0; t < 600 && !stop; ++t)
222 std::this_thread::sleep_for(1s);
225 std::cout << std::endl;
231 std::function<void(State, unsigned int)> display_;
232 std::function<std::vector<State>*(std::vector<State>&)> interpolate_fun_;
233 std::vector<State> sample_;
235 typedef std::unordered_map<
const State, int,
236 StateHash, StateEqual> visited_map;
239 std::string algoname_;
244 template<
typename State,
typename SuccIterator,
245 typename StateHash,
typename StateEqual>
248 StateHash, StateEqual,
249 swarmed_dfs<State, SuccIterator,
250 StateHash, StateEqual>>
254 my_pair(): color(0){}
255 my_pair(
const my_pair& p): st(p.st), color(p.color.load()){}
256 my_pair(
const State st,
int bar): st(st), color(bar) { }
257 my_pair& operator=(my_pair& other)
262 color = other.color.load();
266 std::atomic<int> color;
269 struct inner_pair_hasher
271 inner_pair_hasher(
const my_pair&)
274 inner_pair_hasher() =
default;
276 brick::hash::hash128_t
277 hash(
const my_pair& lhs)
const 280 auto u = hash(lhs.st);
284 bool equal(
const my_pair& lhs,
285 const my_pair& rhs)
const 288 return equal(lhs.st, rhs.st);
299 using shared_map = brick::hashset::FastConcurrent <my_pair,
304 unsigned tid,
bool& stop)
307 StateHash, StateEqual>>(sys, tid, stop),
317 tm_.start(
"DFS thread " + std::to_string(this->tid_));
320 bool push(State s,
unsigned int)
323 auto it = map_.insert({s, OPEN});
329 if (!b && it->color.load(std::memory_order_relaxed) == CLOSED)
340 auto it = map_.insert({s, CLOSED});
341 it->color.store(CLOSED, std::memory_order_relaxed);
345 void edge(
unsigned int,
unsigned int)
353 tm_.stop(
"DFS thread " + std::to_string(this->tid_));
358 return tm_.timer(
"DFS thread " + std::to_string(this->tid_))
377 unsigned how_many_generations()
385 unsigned inserted_ = 0;
386 unsigned nb_gens_ = 0;
387 unsigned states_ = 0;
393 template<
typename State,
typename SuccIterator,
394 typename StateHash,
typename StateEqual>
397 StateHash, StateEqual,
398 swarmed_gp<State, SuccIterator,
399 StateHash, StateEqual>>
403 my_pair(): color(0){}
404 my_pair(
const my_pair& p): st(p.st), color(p.color.load()){}
405 my_pair(
const State st,
int bar): st(st), color(bar) { }
406 my_pair& operator=(my_pair& other)
411 color = other.color.load();
415 std::atomic<int> color;
418 struct inner_pair_hasher
420 inner_pair_hasher(
const my_pair&)
423 inner_pair_hasher() =
default;
425 brick::hash::hash128_t
426 hash(
const my_pair& lhs)
const 429 auto u = hash(lhs.st);
433 bool equal(
const my_pair& lhs,
434 const my_pair& rhs)
const 437 return equal(lhs.st, rhs.st);
450 using shared_map = brick::hashset::FastConcurrent <my_pair,
454 std::function<std::vector<State>*(std::vector<State>&)>
457 unsigned tid,
bool& stop)
460 StateHash, StateEqual>>(sys, tid, stop),
461 interpolate_fun_(interpolate_fun), map_(map)
473 tm_.start(
"DFS GP thread " + std::to_string(this->tid_));
476 bool push(State s,
unsigned int dfsnum)
479 if (SPOT_UNLIKELY(dfsnum <= 1000 && phase1))
481 sample_.push_back(s);
488 insert_status_ = UNKNOWN;
489 new_gen = interpolate_fun_(sample_);
492 for (
auto& e: this->todo)
493 this->sys_.recycle(e.it, this->tid_);
497 this->dfs_number = 0;
498 this->visited.clear();
501 this->todo.push_back({new_gen->at(new_gen_idx),
502 this->sys_.succ(new_gen->at(new_gen_idx), this->tid_)});
503 this->visited[new_gen->at(new_gen_idx)] = this->dfs_number;
504 this->dfs_number = 1;
505 s = new_gen->at(new_gen_idx);
510 auto it = map_.insert({s, insert_status_});
514 st_status status = (st_status) it->color.load(std::memory_order_relaxed);
517 if (!b && status == CLOSED)
527 auto it = map_.insert({s, CLOSED});
531 it->color.store(CLOSED, std::memory_order_relaxed);
538 if (SPOT_UNLIKELY(insert_status_ != OPEN && this->todo.size() == 1))
541 for (
auto& e: this->todo)
542 this->sys_.recycle(e.it, this->tid_);
546 this->dfs_number = 0;
547 this->visited.clear();
555 if (SPOT_UNLIKELY(new_gen_idx == new_gen->size()))
559 new_gen->push_back(this->sys_.initial(this->tid_));
560 insert_status_ = OPEN;
564 this->todo.push_back({new_gen->at(new_gen_idx),
565 this->sys_.succ(new_gen->at(new_gen_idx), this->tid_)});
566 this->visited[new_gen->at(new_gen_idx)] = this->dfs_number;
567 this->dfs_number = 1;
575 void edge(
unsigned int,
unsigned int)
582 if (insert_status_ == OPEN)
584 tm_.stop(
"DFS GP thread " + std::to_string(this->tid_));
589 return tm_.timer(
"DFS GP thread " + std::to_string(this->tid_))
608 unsigned how_many_generations()
615 std::function<std::vector<State>*(std::vector<State>&)> interpolate_fun_;
617 std::vector<State> sample_;
619 std::vector<State>* new_gen =
nullptr;
620 unsigned new_gen_idx = 0;
621 st_status insert_status_ = OPEN;
622 unsigned inserted_ = 0;
623 unsigned nb_gens_ = 0;
624 unsigned states_ = 0;
Definition: interpolate.hh:246
This class is a template representation of a Kripke structure. It is composed of two template paramet...
Definition: kripke.hh:37
A map of timer, where each timer has a name.
Definition: timer.hh:227
Definition: interpolate.hh:395
Definition: interpolate.hh:35
Definition: interpolate.hh:132
This template class provide a sequential reachability of a kripkecube. The algorithm uses a single DF...
Definition: reachability.hh:33