2020#include < path-symex/path_symex.h>
2121#include < path-symex/build_goto_trace.h>
2222
23+ #include " shortest_path_graph.h"
24+
2325#include < random>
2426
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+
2568void path_searcht::shuffle_queue (queuet &queue)
2669{
2770 if (queue.size ()<=1 )
@@ -54,9 +97,8 @@ path_searcht::resultt path_searcht::operator()(
5497 // this is the container for the history-forest
5598 path_symex_historyt history;
5699
57- queue.push_back (initial_state (var_map, locs, history));
58-
59100 // set up the statistics
101+ current_distance = std::numeric_limits<unsigned >::max ();
60102 number_of_dropped_states=0 ;
61103 number_of_paths=0 ;
62104 number_of_VCCs=0 ;
@@ -72,6 +114,15 @@ path_searcht::resultt path_searcht::operator()(
72114 absolute_timet last_reported_time=start_time;
73115
74116 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 ();
75126
76127 while (!queue.empty ())
77128 {
@@ -135,8 +186,13 @@ path_searcht::resultt path_searcht::operator()(
135186 << " thread " << state.get_current_thread ()+1
136187 << ' /' << state.threads .size ()
137188 << " 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, "
140196 << running_time << " s]" << messaget::eom;
141197 }
142198 }
@@ -243,6 +299,15 @@ void path_searcht::pick_state()
243299 queue.splice (queue.begin (), queue, --queue.end (), queue.end ());
244300 return ;
245301
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 ;
246311 case search_heuristict::LOCS:
247312 return ;
248313 }
0 commit comments