mCRL2
Loading...
Searching...
No Matches
FocusListLiftingStrategy.cpp
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
11
13static const unsigned initial_credit = 2;
14
16static const unsigned credit_increase = 2;
17
18
20 bool alternate, verti max_size, std::size_t max_lifts )
21 : LiftingStrategy(), V_(game.graph().V()), max_lift_attempts_(max_lifts),
22 phase_(1), num_lift_attempts_(0), lls_(game, alternate)
23{
24 focus_list_.reserve(max_size);
25}
26
28{
29 if (phase_ == 1)
30 {
31 lls_.lifted(vertex);
32 if (focus_list_.size() < focus_list_.capacity())
33 {
34 focus_list_.push_back(std::make_pair(vertex, initial_credit));
35 }
36 }
37 else /* phase_ == 2 */
38 {
39 if (vertex == read_pos_->first) prev_lifted_ = true;
40 }
41}
42
44{
45 verti res = phase_ == 1 ? phase1() : phase2();
47 return res;
48}
49
51{
52 if (focus_list_.size() == focus_list_.capacity() ||
54 {
55 if (focus_list_.empty())
56 {
57 /* This can only happen if lls_.num_failed >= V too */
58 assert(lls_.next() == NO_VERTEX);
59 return NO_VERTEX;
60 }
61
62 /* Switch to phase 2: */
63 phase_ = 2;
66 mCRL2log(mcrl2::log::verbose) << "Switching to focus list of size " << focus_list_.size() << std::endl;
67 return phase2();
68 }
69
70 return lls_.next();
71}
72
74{
75 if (num_lift_attempts_ > 0)
76 {
77 // Adjust previous vertex credit and move to next position
78 focus_list::value_type prev = *read_pos_++;
79 if (prev_lifted_)
80 {
81 prev.second += credit_increase;
82 *write_pos_++ = prev;
83 }
84 else
85 if (prev.second > 0)
86 {
87 prev.second /= 2;
88 *write_pos_++ = prev;
89 }
90 // else, drop from list.
91 }
92
93 // Check if we've reached the end of the focus list; if so, restart:
94 if (read_pos_ == focus_list_.end())
95 {
98 }
99
101 {
102 if (focus_list_.empty())
103 {
104 mCRL2log(mcrl2::log::verbose) << "Focus list exhausted." << std::endl;
105 }
106 else
107 {
108 mCRL2log(mcrl2::log::verbose) << "Maximum lift attempts (" << max_lift_attempts_ << ") on focus list reached." << std::endl;
109 focus_list_.clear();
110 }
111
112 /* Switch to phase 1 */
113 phase_ = 1;
115 return phase1();
116 }
117
118 // Return current item on the focus list
119 prev_lifted_ = false;
120 return read_pos_->first;
121}
122
124 const ParityGame &game, const SmallProgressMeasures &spm )
125{
126 (void)spm; // unused
127
128 /* Ratio is absolute value if >1, or a fraction of the size of the game's
129 vertex set if <= 1. */
130 verti V = game.graph().V();
131 verti max_size = (size_ratio_ > 1) ? static_cast<verti>(size_ratio_) : static_cast<verti>(size_ratio_*V); // XXX Ugly casting here
132 if (max_size == 0) max_size = 1;
133 if (max_size > V) max_size = V;
134 verti max_lifts = (verti)(lift_ratio_ * max_size);
135 return new FocusListLiftingStrategy(
136 game, alternate_, max_size, max_lifts );
137}
static const unsigned initial_credit
static const unsigned credit_increase
std::size_t verti
type used to number vertices
Definition Graph.h:24
#define NO_VERTEX
Definition Graph.h:27
LiftingStrategy * create(const ParityGame &game, const SmallProgressMeasures &spm)
Return a new FocusListLiftingStrategy instance.
bool prev_lifted_
whether previous vertex was lifted
focus_list::iterator read_pos_
current position in the focus list
std::size_t max_lift_attempts_
maximum lift attempts per list
LinearLiftingStrategy lls_
strategy for phase 1
focus_list::iterator write_pos_
current position in the focus list
std::size_t num_lift_attempts_
number of consecutive lift attempts
const verti V_
game graph vertex count
focus_list focus_list_
nodes on the focus list
FocusListLiftingStrategy(const ParityGame &game, bool alternate, verti max_size, std::size_t max_lifts)
const StaticGraph & graph() const
Definition ParityGame.h:256
verti V() const
Definition Graph.h:179
#define mCRL2log(LEVEL)
mCRL2log(LEVEL) provides the stream used to log.
Definition logger.h:391
@ verbose
Definition logger.h:37