Quantum Fog  0.9.3
QB_NET.h
1 #pragma once
2 
3 #include "QFog_constants.h"
4 
5 #ifdef _mac_gui_app //''''''''''''''''''''''''''''''''''''''''''''\\.
6 
7  class C_DOC;
8  class C_MAIN_VIEW;
9  #include "C_ARROW.h"
10  #include "C_ANTHOLOGY_ITEM.h"
11  // a run is composed of one or more go_forward()'s
12  enum RUN_STATE{bef_run, dur_run, aft_run}; //dur= during
13 #endif //_mac_gui_app \\............................................//
14 
15 
16 
17 #include <stdlib.h>
18 #include <typeinfo.h>
19 
20 
21 #include "NODE.h"
22 #include "VECTOR.h"
23 #include "STRINGY.h"
24 #include "L_LIST.h"
25 
26 
27 #include "UI_MAP.h"
28 
29 #include "BI_NODE.h"
30 #include "MY_FSTREAMS.h"
31 
32 //QB_NET = quantum bayesian net
33 //******************************************
34 class QB_NET
35 {
36 private:
37  NODE * * its_nds_p_p; // nds = nodes
38  // a NODE object X will have id-number nd_id if its_nds_p_p[nd_id] points to X
39  // num = number, ptrs = pointers
40  USHORT its_num_of_nd_ptrs;
41  USHORT its_num_of_nds;
42 
43  L_LIST<BI_NODE> its_bi_nds;
44 
45  const STRINGY * * its_nd_names_p_p;
46  DICTIONARY * its_nd_name_dict_p;
47 
48  VECTOR<USHORT> its_nd_chronology;
49  USHORT its_final_era_len;
50  //dynamic
51  COMPLEX its_dyn_amp;
52  VECTOR<USHORT> its_dyn_story;
53 
54 #ifdef _mac_gui_app //''''''''''''''''''''''''''''''''''''''''''''\\.
55 
56  C_DOC * its_doc_p;
57  C_MAIN_VIEW * its_mview_p;
58  L_LIST<C_ARROW> its_arrows;
59 
60 
61  L_LIST<C_ANTHOLOGY_ITEM> its_anthology;
62 
63  RUN_STATE its_run_state;
64 #endif //_mac_gui_app \\............................................//
65 
66 
67 
68 public:
69  VOID clear_nds();
70  VOID clear();
71  VOID init();
72  QB_NET();
73  virtual ~QB_NET();
74 
75  NODE * get_nd_ptr(USHORT nd_id);
76  USHORT get_num_of_nds() const;
77 
78  const STRINGY & get_nd_name(USHORT nd_id) const;
79  VOID set_nd_name(USHORT nd_id, const STRINGY & name);
80  USHORT get_len_of_longest_nd_name();
81 
82  USHORT get_len_of_longest_st_name(USHORT nd_id);
83  VOID set_state_name(USHORT nd_id, USHORT row_num, const STRINGY & new_name);
84 
85  const USHORT get_cur_finesse_of_amps() const;
86  VOID filter_out_small_amps(USHORT finesse );
87 
88  VOID set_act_sts_of_a_nd(USHORT nd_id, const SET & act_sts);
89  VOID activate_a_nd_state(USHORT nd_id, USHORT st_id);
90  VOID empty_act_st_sets_of_all_nds();
91  VOID fill_act_st_sets_of_all_nds();
92  VOID preserve_act_st_sets_of_all_nds();
93  VOID restore_act_st_sets_of_all_nds();
94 
95  BOOLEAN sort_into_layers_of_external_nds(VECTOR<USHORT> & era_of, USHORT & num_of_eras);
96 // BOOLEAN sort_into_layers_of_parents(VECTOR<USHORT> & era_of, USHORT & num_of_eras);
97  BOOLEAN chrono_sort();
98  VOID grow_num_of_nd_ptrs();
99  VOID warn_user_about_cycle();
100  BOOLEAN add_int_arrow(USHORT s, USHORT d, BOOLEAN try_to_sort);
101  USHORT add_nd(const STRINGY & nd_class_str, BOOLEAN try_to_sort);
102 
103  VOID set_degen_of_a_nd(USHORT nd_id, USHORT degen);
104  USHORT get_degen_of_a_nd(USHORT nd_id);
105  USHORT get_max_degen();
106 
107  USHORT get_num_of_bi_nds();
108  BI_NODE * get_bi_nd_ptr(USHORT loc);
109  STRINGY get_bi_nd_name(USHORT loc);
110  VOID get_bi_nd(USHORT loc, USHORT & nd1, USHORT & nd2);
111  BOOLEAN add_bi_nd(USHORT nd1, USHORT nd2);
112  VOID warn_user_about_repeated_bi_nd();
113  VOID warn_user_about_degenerate_bi_nd();
114 
115  const DICTIONARY & get_dict() const;
116  VOID create_nd_name_dictionary();
117  VOID create_nd_st_dictionaries();
118  VOID create_dictionaries();
119  VOID kill_nd_name_dictionary();
120  VOID kill_nd_st_dictionaries();
121  VOID kill_dictionaries();
122 
123  VOID read_topology_file(MY_IFSTREAM & istream);
124  BOOLEAN good_nd_sts_file(MY_IFSTREAM & istream);
125  BOOLEAN read_nd_sts_file(MY_IFSTREAM & istream);
126  BOOLEAN good_amps_file(MY_IFSTREAM & istream);
127  BOOLEAN read_amps_file(MY_IFSTREAM & istream);
128 
129  BOOLEAN good_ecases_file(MY_IFSTREAM & istream);
130  VOID write_one_story_into_file(
131  MY_OFSTREAM * fstream_p,
132  USHORT net_story_count,
133  USHORT ending);
134  VOID write_header_of_nd_probs_file( MY_OFSTREAM * nd_probs_stream_p);
135  VOID write_nd_probs_into_file(
136  const CHAR * ecase_name_cstr,
137  MY_OFSTREAM * nd_probs_stream_p);
138  VOID write_bi_nd_probs_into_file(
139  const CHAR * ecase_name_cstr,
140  MY_OFSTREAM * bi_nd_probs_stream_p);
141 
142  VOID set_cum_info_to_default();
143  VOID fill_final_era_degens(VECTOR<USHORT> & final_era_degens);
144  VOID set_all_dyn_sts_to_max_ushort();
145  BOOLEAN external_nds_accept_ending(const VECTOR<USHORT> & ending_vec);
146  BOOLEAN dyn_in_st_is_consistent(USHORT nd_id);
147  VOID send_dyn_in_st_to_nds(USHORT nd_id);
148  VOID use_dyn_in_sts_to_reconstruct_dyn_sts_for_times_larger_than(USHORT limit_time);
149  VOID set_dyn_net_story_and_amp();
150  VOID add_story_to_cum_amps();
151  VOID prepare_cum_info_for_next_ending();
152  VOID normalize_cum_probs();
153  VOID add_story_to_anthology( USHORT ending);
154  VOID multi_mode_go(
155  BOOLEAN is_mini_run,
156  const CHAR * ecase_name_cstr,
157  MY_OFSTREAM * nd_probs_stream_p,
158  MY_OFSTREAM * bi_nd_probs_stream_p,
159  MY_OFSTREAM * stories_stream_p,
160  BOOLEAN illustrate_stories,
161  DOUBLE & out_prob,
162  USHORT & num_of_stories);
163  VOID go_forward(
164  const CHAR * ecase_name_cstr,
165  MY_OFSTREAM * nd_probs_stream_p,
166  MY_OFSTREAM * bi_nd_probs_stream_p,
167  MY_OFSTREAM * stories_stream_p,
168  BOOLEAN illustrate_stories);
169  VOID do_mini_run(DOUBLE & out_prob, USHORT & num_of_stories);
170 
171 
172 #ifdef _mac_gui_app //''''''''''''''''''''''''''''''''''''''''''''\\.
173 
174  ND_CLASS_ID get_nd_class_id(USHORT nd_id) const;
175  STRINGY get_nd_class_str(USHORT nd_id) const;
176 
177  VOID set_doc_and_mview_ptrs(C_DOC * doc_p, C_MAIN_VIEW * view_p);
178 
179  DIR_DATA<C_ARROW> * get_arrows_first_p();
180  USHORT get_num_of_arrows();
181 
182  VOID reorder_nds(const UI_MAP & map);
183  VOID reorder_nd_sts(USHORT nd_id, const UI_MAP & map);
184 
185  VOID del_int_arrow(USHORT s, USHORT d, BOOLEAN try_to_sort);
186  VOID del_nd(USHORT nd_id, BOOLEAN try_to_sort);
187  VOID del_bi_nd(USHORT xed_position);
188  VOID del_all_bi_nds_with_this_nd(USHORT nd_id);
189 
190  BOOLEAN calc_closest_pts(
191  const C_CIRCLE & cir1,
192  const C_CIRCLE & cir2,
193  Point & pt1,
194  Point & pt2);
195  C_ARROW * mac_add_int_arrow(
196  const C_PORT_NAME & s_port_name,
197  const C_PORT_NAME & d_port_name,
198  BOOLEAN try_to_sort);
199  USHORT mac_add_nd(
200  ND_CLASS_ID nd_class_id,
201  const Point & m_down_pt,
202  BOOLEAN try_to_sort);
203 
204  BOOLEAN nodes_have_same_state_set(USHORT nd1, USHORT nd2);
205  BOOLEAN change_source_nd_of_ar(C_ARROW * ar_p, const C_PORT_NAME & new_s_port_name);
206 
207  const RUN_STATE get_run_state() const;
208  VOID set_run_state( RUN_STATE state);
209 
210  DIR_DATA<C_ANTHOLOGY_ITEM> * get_anthology_first_p();
211  USHORT get_anthology_len();
212 
213  VOID write_net_stream(LStream & net_stream, NET_STREAM_TYPE stream_type);
214  VOID read_net_stream(LStream & net_stream, NET_STREAM_TYPE stream_type);
215 
216  VOID write_topology_file(MY_OFSTREAM & strm);
217  VOID write_nd_sts_file(MY_OFSTREAM & strm);
218  VOID write_amps_file(MY_OFSTREAM & strm);
219 
220 #endif //_mac_gui_app \\............................................//
221 
222 
223 };
224 #pragma mark -
225 
226 
227 //******************************************
228 inline
229 NODE * QB_NET::get_nd_ptr(
230 USHORT nd_id) //in
231 {
232  return its_nds_p_p[nd_id];
233 }
234 //******************************************
235 inline
236 USHORT QB_NET::get_num_of_nds() const
237 {
238  return its_num_of_nds;
239 }
240 //******************************************
241 inline
242 const STRINGY & QB_NET::get_nd_name(
243 USHORT nd_id) //in
244 const
245 {
246  return its_nds_p_p[nd_id]->get_name();
247 }
248 //******************************************
249 inline
250 VOID QB_NET::set_nd_name(
251 USHORT nd_id, //in
252 const STRINGY & name) //in
253 {
254  its_nds_p_p[nd_id]->set_name(name);
255 }
256 //******************************************
257 inline
258 VOID QB_NET::set_state_name(
259 USHORT nd_id, //in
260 USHORT row_num, //in
261 const STRINGY & new_name) //in
262 {
263  its_nds_p_p[nd_id]->set_st_name(row_num, new_name);
264 }
265 //******************************************
266 inline
267 VOID QB_NET::set_act_sts_of_a_nd(
268 USHORT nd_id, //in
269 const SET & act_sts) //in
270 {
271  its_nds_p_p[nd_id]->set_active_states(act_sts);
272 }
273 //******************************************
274 inline
275 VOID QB_NET::activate_a_nd_state(
276 USHORT nd_id, //in
277 USHORT st_id) //in
278 {
279  its_nds_p_p[nd_id]->activate_state(st_id);
280 }
281 //******************************************
282 inline
283 USHORT QB_NET::get_degen_of_a_nd(
284 USHORT nd_id) //in
285 {
286  return its_nds_p_p[nd_id]->get_degen();
287 }
288 //******************************************
289 inline
290 USHORT QB_NET::get_num_of_bi_nds()
291 {
292  return its_bi_nds.get_len();
293 }
294 //******************************************
295 inline
296 BI_NODE * QB_NET::get_bi_nd_ptr(USHORT loc)
297 {
298  return &(its_bi_nds[loc]);
299 }
300 //******************************************
301 inline
302 const DICTIONARY & QB_NET::get_dict() const
303 {
304  return *its_nd_name_dict_p;
305 }
306 
307 //******************************************
308 inline
309 VOID QB_NET::do_mini_run(
310 DOUBLE & out_prob, //out
311 USHORT & num_of_stories) //out
312 {
313  //Calculates total probability of all stories and
314  //number of stories, assuming all states are active.
315  multi_mode_go(
316  true,//is_mini_run
317  0,//ecase_name_cstr
318  0,//nd_probs_stream_p
319  0,//bi_nd_probs_stream_p
320  0,//stories_stream_p
321  false,//illustrate_stories
322  out_prob,
323  num_of_stories);
324 }
325 
326 
327 #ifdef _mac_gui_app //''''''''''''''''''''''''''''''''''''''''''''\\.
328 
329 //******************************************
330 inline
331 ND_CLASS_ID QB_NET::get_nd_class_id(
332 USHORT nd_id) //in
333 const
334 {
335  return its_nds_p_p[nd_id]->get_class_id();
336 }
337 //******************************************
338 inline
339 STRINGY QB_NET::get_nd_class_str(
340 USHORT nd_id) //in
341 const
342 {
343  return its_nds_p_p[nd_id]->get_class_str();
344 }
345 //******************************************
346 inline
347 DIR_DATA<C_ARROW> * QB_NET::get_arrows_first_p()
348 {
349  return its_arrows.get_first_p();
350 }
351 //******************************************
352 inline
353 USHORT QB_NET::get_num_of_arrows()
354 {
355  return its_arrows.get_len();
356 }
357 //******************************************
358 inline
359 const RUN_STATE QB_NET::get_run_state() const
360 {
361  return its_run_state;
362 }
363 //******************************************
364 inline
365 VOID QB_NET::set_run_state( RUN_STATE state)
366 { // used by C_DOC
367  its_run_state = state;
368 }
369 //******************************************
370 inline
371 DIR_DATA<C_ANTHOLOGY_ITEM> * QB_NET::get_anthology_first_p()
372 {
373  return its_anthology.get_first_p();
374 }
375 //******************************************
376 inline
377 USHORT QB_NET::get_anthology_len()
378 {
379  return its_anthology.get_len();
380 }
381 #endif //_mac_gui_app \\............................................//
382 
383 
384 
385 
Definition: C_MAIN_VIEW.h:24
Definition: STRINGY.h:22
Definition: MY_FSTREAMS.h:35
Definition: QB_NET.h:34
Definition: C_DOC.h:12
Definition: DICTIONARY.h:15
Definition: C_PORT_RELATED.h:54
Definition: NODE.h:52
Definition: BI_NODE.h:10
Definition: L_LIST.h:10
Definition: SET.h:4
Definition: MY_FSTREAMS.h:14
Definition: UI_MAP.h:7
Definition: C_PORT_RELATED.h:6
Definition: C_ARROW.h:14