| 56 | /// Formatted for dot: http://www.graphviz.org/content/dot-language |
| 57 | |
| 58 | static void CLI_DoRL_print_trace(std::ostream& os, const agent::RL_Trace& rl_trace) |
| 59 | { |
| 60 | os << "digraph RL_Trace {" << std::endl; |
| 61 | |
| 62 | std::ostringstream label; |
| 63 | std::queue<std::pair<const agent::RL_Trace*, std::string> > trace_queue; |
| 64 | trace_queue.push(std::make_pair(&rl_trace, "0")); |
| 65 | size_t c = 1; |
| 66 | |
| 67 | do |
| 68 | { |
| 69 | const agent::RL_Trace* const current_trace = trace_queue.front().first; |
| 70 | const std::string prev_label = trace_queue.front().second; |
| 71 | |
| 72 | trace_queue.pop(); |
| 73 | |
| 74 | for (std::map<std::vector<std::string>, agent::RL_Trace::Entry>::const_iterator tt = current_trace->split.begin(), tend = current_trace->split.end(); tt != tend; ++tt) |
| 75 | { |
| 76 | label << c++; |
| 77 | |
| 78 | os << " " << label.str(); |
| 79 | |
| 80 | // os << " [label=\""; |
| 81 | // bool sfirst = true; |
| 82 | // for(std::vector<std::string>::const_iterator ss = tt->first.begin(), send = tt->first.end(); ss != send; ++ss) { |
| 83 | // if(sfirst) |
| 84 | // sfirst = false; |
| 85 | // else |
| 86 | // os << "\\n"; |
| 87 | // |
| 88 | // os << *ss; |
| 89 | // } |
| 90 | // os << "\"];"; |
| 91 | |
| 92 | os << std::endl; |
| 93 | |
| 94 | os << " " << prev_label << " -> " << label.str() << " [label=\""; |
| 95 | |
| 96 | for (std::vector<std::string>::const_iterator ss = tt->first.begin(), send = tt->first.end(); ss != send; ++ss) |
| 97 | { |
| 98 | os << *ss << "\\n"; |
| 99 | } |
| 100 | |
| 101 | if (tt->second.probability == tt->second.probability) |
| 102 | { |
| 103 | os << tt->second.probability; |
| 104 | } |
| 105 | else //< NaN |
| 106 | { |
| 107 | os << '-'; |
| 108 | } |
| 109 | |
| 110 | os << " (" << tt->second.init << ")\"];" << std::endl; |
| 111 | |
| 112 | if (tt->second.next) |
| 113 | { |
| 114 | trace_queue.push(std::make_pair(tt->second.next, label.str())); |
| 115 | } |