mCRL2
Loading...
Searching...
No Matches
SmallProgressMeasures.h
Go to the documentation of this file.
1// Copyright (c) 2009-2013 University of Twente
2// Copyright (c) 2009-2013 Michael Weber <michaelw@cs.utwente.nl>
3// Copyright (c) 2009-2013 Maks Verver <maksverver@geocities.com>
4// Copyright (c) 2009-2013 Eindhoven University of Technology
5//
6// Distributed under the Boost Software License, Version 1.0.
7// (See accompanying file LICENSE_1_0.txt or copy at
8// http://www.boost.org/LICENSE_1_0.txt)
9
10#ifndef MCRL2_PG_SMALL_PROGRESS_MEASURES_H
11#define MCRL2_PG_SMALL_PROGRESS_MEASURES_H
12
16
26{
27public:
29 LiftingStatistics(const ParityGame &game, long long max_lifts = -1);
30
31#if 0
35 void merge(const LiftingStatistics &other, const verti *mapping = NULL);
36#endif
37
38 long long lifts_attempted() const { return lifts_attempted_; }
39 long long lifts_succeeded() const { return lifts_succeeded_; }
40 long long lifts_attempted(verti v) const { return vertex_stats_[v].first; }
41 long long lifts_succeeded(verti v) const { return vertex_stats_[v].second; }
42
43 void add_lifts_attempted(long long count) { lifts_attempted_ += count; }
44 void add_lifts_succeeded(long long count) { lifts_succeeded_ += count; }
45 void add_lifts_attempted(verti v, long long count)
46 {
47 vertex_stats_[v].first += count;
48 }
49 void add_lifts_succeeded(verti v, long long count)
50 {
51 vertex_stats_[v].second += count;
52 }
53
54private:
55 void record_lift(verti v, bool success);
57
58private:
60 std::vector<std::pair<long long, long long> > vertex_stats_;
61 long long max_lifts_;
62};
63
85{
86public:
88 static const int work_size = 10000;
89
92 LiftingStatistics *stats = 0,
93 const verti *vmap = 0, verti vmap_size = 0 );
94
95 virtual ~SmallProgressMeasures();
96
105 long long solve_some( LiftingStrategy &ls,
106 long long attempts = work_size );
107 long long solve_some( LiftingStrategy2 &ls,
108 long long attempts = work_size );
109
113 std::pair<verti, bool> solve_one(LiftingStrategy &ls);
115
120 verti get_strategy(verti v) const;
121
124 void get_strategy(ParityGame::Strategy &strat) const;
125
129 template<class OutputIterator>
130 void get_winning_set(ParityGame::Player player, OutputIterator result);
131
134 inline bool lift_to_top(verti v);
135
140 bool lift_to(verti v, const verti vec2[], bool carry = 0);
141
144 bool less_than(verti v, const verti vec2[], bool carry = 0);
145
147 void debug_print() const;
148 void debug_print_vertex(int v) const;
149
152
154 const ParityGame &game() const { return game_; }
155
158
160 int len() const { return len_; }
161
163 const verti *M() const { return M_; }
164
167 void set_M(const verti *new_M) { std::copy(new_M, new_M + len_, M_); }
168
170 void decr_M(int i) { assert(M_[i] > 1); --M_[i]; }
171
174 int len(verti v) const { return (game_.priority(v) + 1 + p_)/2; }
175
177 bool is_top(const verti vec[]) const { return vec[0] == NO_VERTEX; }
178
180 bool is_top(verti v) const { return is_top(vec(v)); }
181
182 // The following functions are implemented in derived classes that
183 // implement the actual storage of progress measure vectors:
184
188 // virtual verti *vec(verti v) = 0;
189 virtual const verti *vec(verti v) const = 0;
190
193 virtual void set_vec(verti v, const verti src[], bool carry) = 0;
194
196 virtual void set_vec_to_top(verti v) = 0;
197
201
202protected:
205 void initialize_loops();
206
210 inline void set_top(verti v);
211
212private:
215
216private:
220 inline int vector_cmp(const verti vec1[], const verti vec2[], int N) const;
221
223 inline int vector_cmp(verti v, verti w, int N) const;
224
228 inline bool take_max(verti v) const { return game_.player(v) != p_; }
229
233 inline bool compare_strict(verti v) const { return game_.priority(v)%2 != p_; }
234
237 inline verti get_ext_succ(verti v, bool take_max) const;
238
241 inline verti get_ext_succ(verti v) const;
242
244 inline verti get_min_succ(verti v) const { return get_ext_succ(v, false); }
245
247 inline verti get_max_succ(verti v) const { return get_ext_succ(v, true); }
248
252 inline verti get_successor(verti v) const { return strategy_[v]; }
253
257 inline bool is_dirty(verti v) const { return dirty_[v]; }
258
259 // Allow selected lifting strategies to access the SPM internals:
263
264protected:
266 const std::size_t p_;
268 const verti *vmap_;
270 std::size_t len_;
273 bool *dirty_;
274};
275
286{
287public:
288 DenseSPM(
290 LiftingStatistics *stats = 0,
291 const verti *vertex_map = 0, verti vertex_map_size = 0 );
292 ~DenseSPM();
293
294 // verti *vec(verti v) { return &spm_[(std::size_t)len_*v]; }
295 const verti *vec(verti v) const { return &spm_[(std::size_t)len_*v]; }
296 void set_vec(verti v, const verti src[], bool carry) ;
297 void set_vec_to_top(verti v);
298
299protected:
301};
302
303
309 : public ParityGameSolver
310{
311protected:
316 {
317 public:
319 SetToTopIterator& operator++() { return *this; }
320 SetToTopIterator& operator++(int) { return *this; }
321 SetToTopIterator& operator*() { return *this; }
323 {
324 spm.lift_to_top(v);
325 return *this;
326 }
327
328 private:
330 };
331
332public:
334 std::shared_ptr<LiftingStrategyFactory> lsf,
335 bool alternate = false,
336 LiftingStatistics *stats = 0,
337 const verti *vmap = 0,
338 verti vmap_size = 0 );
339
341
347
353
361 static void preprocess_game(ParityGame &game);
362
363private:
366
367protected:
368 std::shared_ptr<LiftingStrategyFactory> lsf_;
371 const verti *vmap_;
373};
374
379{
380public:
382 std::shared_ptr<LiftingStrategyFactory> lsf,
383 bool alternate = false,
384 LiftingStatistics *stats = 0,
385 const verti *vmap = 0,
386 verti vmap_size = 0 );
387
390
391private:
394};
395
400{
401public:
402 SmallProgressMeasuresSolverFactory(std::shared_ptr<LiftingStrategyFactory> lsf,
403 int version = 1, bool alt = false, LiftingStatistics *stats = 0 );
404
405 ParityGameSolver *create( const ParityGame &game,
406 const verti *vmap,
407 verti vmap_size );
408
409private:
410 std::shared_ptr<LiftingStrategyFactory> lsf_;
412 bool alt_;
414};
415
417
418#endif /* ndef MCRL2_PG_SMALL_PROGRESS_MEASURES_H */
std::size_t verti
type used to number vertices
Definition Graph.h:24
#define NO_VERTEX
Definition Graph.h:27
player_t
Definition ParityGame.h:35
const verti * vec(verti v) const
verti * spm_
array storing the SPM vector data
void set_vec_to_top(verti v)
void set_vec(verti v, const verti src[], bool carry)
long long lifts_attempted() const
void add_lifts_succeeded(long long count)
void add_lifts_attempted(long long count)
void add_lifts_succeeded(verti v, long long count)
std::vector< std::pair< long long, long long > > vertex_stats_
long long lifts_attempted(verti v) const
void record_lift(verti v, bool success)
long long lifts_succeeded() const
long long lifts_succeeded(verti v) const
void add_lifts_attempted(verti v, long long count)
const ParityGame & game() const
priority_t priority(verti v) const
Definition ParityGame.h:259
Player player(verti v) const
Definition ParityGame.h:262
std::vector< verti > Strategy
Definition ParityGame.h:97
SmallProgressMeasuresSolver2 & operator=(const SmallProgressMeasuresSolver2 &)
SmallProgressMeasuresSolver2(const SmallProgressMeasuresSolver2 &)
ParityGameSolver * create(const ParityGame &game, const verti *vmap, verti vmap_size)
std::shared_ptr< LiftingStrategyFactory > lsf_
bool alternate_
whether to use the alternate algorithm
const verti vmap_size_
size of vertex map
virtual ParityGame::Strategy solve_normal()
std::shared_ptr< LiftingStrategyFactory > lsf_
factory used to create lifting strategy
virtual ParityGame::Strategy solve_alternate()
SmallProgressMeasuresSolver & operator=(const SmallProgressMeasuresSolver &)
LiftingStatistics * stats_
object to record lifting statistics
const verti * vmap_
current vertex map
static void preprocess_game(ParityGame &game)
SmallProgressMeasuresSolver(const SmallProgressMeasuresSolver &)
void debug_print_vertex(int v) const
long long solve_some(LiftingStrategy &ls, long long attempts=work_size)
const verti * vmap_
active vertex map (if any)
LiftingStatistics * stats_
statistics object to record lifts
const std::size_t p_
the player to solve for
SmallProgressMeasures & operator=(const SmallProgressMeasures &)
verti * M_
bounds on the SPM vector components
bool take_max(verti v) const
verti get_max_succ(verti v) const
void set_M(const verti *new_M)
std::size_t len_
length of SPM vectors
virtual void set_vec_to_top(verti v)=0
bool is_top(const verti vec[]) const
verti get_min_succ(verti v) const
const verti * M() const
SmallProgressMeasures(const SmallProgressMeasures &)
void debug_print() const
bool less_than(verti v, const verti vec2[], bool carry=0)
bool compare_strict(verti v) const
verti get_ext_succ(verti v) const
bool is_dirty(verti v) const
bool lift_to(verti v, const verti vec2[], bool carry=0)
void get_winning_set(ParityGame::Player player, OutputIterator result)
const ParityGame & game() const
bool * dirty_
marks unstable vertices
ParityGame::Player player() const
std::pair< verti, bool > solve_one(LiftingStrategy &ls)
verti vmap_size_
size of vertex map
static const int work_size
Maximum number of lifting attempts in a row before checking timer.
verti get_successor(verti v) const
verti get_strategy(verti v) const
int vector_cmp(const verti vec1[], const verti vec2[], int N) const
void initialize_lifting_strategy(LiftingStrategy2 &ls)
const ParityGame & game_
the game being solved
verti get_ext_succ(verti v, bool take_max) const
virtual void set_vec(verti v, const verti src[], bool carry)=0
ParityGame::Strategy strategy_
current strategy
virtual const verti * vec(verti v) const =0