20
20
#include < path-symex/path_symex.h>
21
21
#include < path-symex/build_goto_trace.h>
22
22
23
+ #include " shortest_path_graph.h"
24
+
23
25
#include < random>
24
26
27
+
28
+ void path_searcht::sort_queue ()
29
+ {
30
+ debug ()<< " get shortest path, queue.size = " <<queue.size () <<eom;
31
+ if (queue.size ()==1 )
32
+ {
33
+ current_distance = queue.front ().get_shortest_path ();
34
+ return ;
35
+ }
36
+
37
+ unsigned shortest_path = std::numeric_limits<unsigned >::max ();
38
+
39
+ std::list<statet>::iterator it;
40
+ std::list<statet>::iterator closest_state;
41
+
42
+ for (it=queue.begin (); it!=queue.end (); ++it)
43
+ {
44
+ if (it->get_shortest_path () < shortest_path)
45
+ {
46
+ shortest_path = it->get_shortest_path ();
47
+ closest_state = it;
48
+ }
49
+ }
50
+
51
+ if (shortest_path != std::numeric_limits<unsigned >::max ())
52
+ {
53
+ current_distance = shortest_path;
54
+ statet tmp = *closest_state;
55
+ queue.erase (closest_state);
56
+ queue.push_front (tmp);
57
+ }
58
+ else
59
+ {
60
+ error () << " all states have shortest path length = MAX_UNSIGNED_INT, "
61
+ << " try removing function pointers with goto-instrument next time."
62
+ << " randomly picking state instead"
63
+ << eom;
64
+ shuffle_queue (queue);
65
+ }
66
+ }
67
+
25
68
void path_searcht::shuffle_queue (queuet &queue)
26
69
{
27
70
if (queue.size ()<=1 )
@@ -54,9 +97,8 @@ path_searcht::resultt path_searcht::operator()(
54
97
// this is the container for the history-forest
55
98
path_symex_historyt history;
56
99
57
- queue.push_back (initial_state (var_map, locs, history));
58
-
59
100
// set up the statistics
101
+ current_distance = std::numeric_limits<unsigned >::max ();
60
102
number_of_dropped_states=0 ;
61
103
number_of_paths=0 ;
62
104
number_of_VCCs=0 ;
@@ -72,6 +114,15 @@ path_searcht::resultt path_searcht::operator()(
72
114
absolute_timet last_reported_time=start_time;
73
115
74
116
initialize_property_map (goto_functions);
117
+ if (search_heuristic == search_heuristict::SHORTEST_PATH ||
118
+ search_heuristic == search_heuristict::RAN_SHORTEST_PATH )
119
+ {
120
+ status ()<<" Building shortest path graph" << eom;
121
+ shortest_path_grapht shortest_path_graph (goto_functions, locs);
122
+ }
123
+ statet init_state = initial_state (var_map, locs, history);
124
+ queue.push_back (init_state);
125
+ initial_distance_to_property=init_state.get_shortest_path ();
75
126
76
127
while (!queue.empty ())
77
128
{
@@ -135,8 +186,13 @@ path_searcht::resultt path_searcht::operator()(
135
186
<< " thread " << state.get_current_thread ()+1
136
187
<< ' /' << state.threads .size ()
137
188
<< " PC " << state.pc ()
138
- << " depth " << state.get_depth ()
139
- << " [" << number_of_steps << " steps, "
189
+ << " depth " << state.get_depth ();
190
+
191
+ if (search_heuristic == search_heuristict::SHORTEST_PATH
192
+ || search_heuristic == search_heuristict::RAN_SHORTEST_PATH)
193
+ status () << " distance to property " << state.get_shortest_path ();
194
+
195
+ status () << " [" << number_of_steps << " steps, "
140
196
<< running_time << " s]" << messaget::eom;
141
197
}
142
198
}
@@ -243,6 +299,15 @@ void path_searcht::pick_state()
243
299
queue.splice (queue.begin (), queue, --queue.end (), queue.end ());
244
300
return ;
245
301
302
+ case search_heuristict::RAN_SHORTEST_PATH:
303
+ if (number_of_steps%1000 ==0 )
304
+ shuffle_queue (queue);
305
+ else
306
+ sort_queue ();
307
+ return ;
308
+ case search_heuristict::SHORTEST_PATH:
309
+ sort_queue ();
310
+ return ;
246
311
case search_heuristict::LOCS:
247
312
return ;
248
313
}
0 commit comments