Quantum Fog  0.9.3
TRANS_MAT.h
1 //******************************************
2 // Purpose: To define a sparse transition matrix.
3 // The matrix will be stored as an array of pointers to linked-lists.
4 // The matrix dwell in the heap.
5 //******************************************
6 #pragma once
7 
8 #include "VECTOR.h"
9 //#include "COL_LABEL_TRANSLATOR.h"
10 #include "UI_MAP.h"
11 class STRETCH_OR_FOLD;
12 
13 typedef long TM_COL_NUM;
14 //IMP: For the transition matrix,
15 //We assume
16 //num_of_cols<=max_ushort and
17 //num_of_cols<=max_long.
18 //However, we assume that
19 //the number of non-zero elements in any row is <= max_ushort
20 //******************************************
21 class DIR_NZ_ELE // dir_nz_ele = directed non-zero element
22 {
23 public:
24  // data
25  TM_COL_NUM its_col_num; // col = column, num = number
26  COMPLEX its_ele;
27  DIR_NZ_ELE * its_next_p;
28 
29  DIR_NZ_ELE();
30  DIR_NZ_ELE (TM_COL_NUM col_num, const COMPLEX & ele, DIR_NZ_ELE * next_p);
31  DIR_NZ_ELE (const DIR_NZ_ELE & s);
32 
33  const TM_COL_NUM get_col_num() const;
34  const COMPLEX & get_ele() const;
35  const DIR_NZ_ELE * get_next_p() const;
36 };
37 
38 // Except for the gets, the class DIR_NZ_ELE
39 // will be used only by the class TRANS_MAT. Thus, it
40 // has only those four horsemen that will be used
41 // by the class TRANS_MAT. In particular, the assigner not will be used.
42 // Also, there is no need for an explicit destructor as
43 // DIR_NZ_ELE never calls "new".
44 
45 //******************************************
46 class TRANS_MAT //trans_mat = transition matrix
47 {
48 private:
49  USHORT its_num_of_rows;
50  TM_COL_NUM its_num_of_cols; // cols = columns
51  DIR_NZ_ELE * * its_elements_p_p;
52 public:
53  VOID clear_row(USHORT r);
54  VOID clear_row(DIR_NZ_ELE * x_p);
55  VOID clear();
56  VOID copy(const TRANS_MAT & mat);
57  VOID set_to_zero_mat(USHORT num_of_rows, TM_COL_NUM num_of_cols);
58  VOID resize(USHORT new_nr, TM_COL_NUM new_nc);
59  VOID set_num_of_rows(USHORT nr);
60  VOID set_num_of_cols(TM_COL_NUM nc);
61  TRANS_MAT();
62  TRANS_MAT(USHORT num_of_rows, TM_COL_NUM num_of_cols);
63  TRANS_MAT(const TRANS_MAT & mat);
64  TRANS_MAT & operator=(const TRANS_MAT & rhs);
65  virtual ~TRANS_MAT();
66 
67  VOID set_ele(USHORT row, TM_COL_NUM col, const COMPLEX & ele);
68  COMPLEX read_ele(USHORT row, TM_COL_NUM col) const;
69 
70  BOOLEAN is_col_valid(TM_COL_NUM c) const;
71  DOUBLE get_col_prob(TM_COL_NUM col);
72  VECTOR<COMPLEX> get_col(TM_COL_NUM col);
73 
74  BOOLEAN is_row_valid(USHORT r) const;
75  USHORT get_num_of_nz_elems(USHORT row);
76  const DIR_NZ_ELE * get_row_ptr(USHORT row) const;
77 
78 
79  TM_COL_NUM get_num_of_cols() const;
80  USHORT get_num_of_rows() const;
81 // VOID relabel_cols( const COL_LABEL_TRANSLATOR & ator);
82 
83  const USHORT get_cur_finesse_of_amps() const;
84  VOID filter_out_small_amps(USHORT finesse );
85 
86  VOID reorder_rows(const UI_MAP & map);
87  VOID reorder_cols_as_part_of_reordering_in_nds(
88  const STRETCH_OR_FOLD & old_sof,
89  const STRETCH_OR_FOLD & new_sof,
90  const UI_MAP & map);
91  VOID reorder_cols_as_part_of_reordering_nd_sts_of_a_pa(
92  USHORT pa_pos,
93  const STRETCH_OR_FOLD & sof,
94  const UI_MAP & map);
95  VOID order_row_elems_by_increasing_col_num();
96 #ifdef _mac_gui_app //''''''''''''''''''''''''''''''''''''''''''''\\.
97 
98 
99  VOID write_net_stream(LStream & net_stream);
100  VOID read_net_stream(LStream & net_stream);
101 #endif //_mac_gui_app \\............................................//
102 
103 
104 };
105 #pragma mark -
106 
107 #pragma mark ----DIR_NZ_ELE----
108 //******************************************
109 inline
110 const TM_COL_NUM DIR_NZ_ELE::get_col_num() const
111 {
112  return its_col_num;
113 }
114 //******************************************
115 inline
116 const COMPLEX & DIR_NZ_ELE::get_ele() const
117 {
118  return its_ele;
119 }
120 //******************************************
121 inline
122 const DIR_NZ_ELE * DIR_NZ_ELE::get_next_p() const
123 {
124  return its_next_p;
125 }
126 #pragma mark ----TRANS_MAT----
127 //******************************************
128 inline
129 VOID TRANS_MAT::set_num_of_cols(
130 TM_COL_NUM nc) //in
131 {
132  resize(its_num_of_rows, nc);
133 }
134 //******************************************
135 inline
136 VOID TRANS_MAT::set_num_of_rows(
137 USHORT nr) //in
138 {
139  resize(nr, its_num_of_cols);
140 }
141 //******************************************
142 inline
143 BOOLEAN TRANS_MAT::is_col_valid(
144 TM_COL_NUM c) //in
145 const
146 {
147  return ( (0<=c)&&(c<=its_num_of_cols) );
148 }
149 //******************************************
150 inline
151 BOOLEAN TRANS_MAT::is_row_valid(
152 USHORT r) //in
153 const
154 {
155  return ( (0<=r)&&(r<=its_num_of_rows) );
156 }
157 //******************************************
158 inline
159 const DIR_NZ_ELE * TRANS_MAT::get_row_ptr(
160 USHORT row)
161 const
162 {
163  return its_elements_p_p[row];
164 }
165 //******************************************
166 inline
167 TM_COL_NUM TRANS_MAT::get_num_of_cols() const
168 {
169  return its_num_of_cols;
170 }
171 //******************************************
172 inline
173 USHORT TRANS_MAT::get_num_of_rows() const
174 {
175  return its_num_of_rows;
176 }
177 
Definition: TRANS_MAT.h:21
Definition: STRETCH_OR_FOLD.h:12
Definition: TRANS_MAT.h:46
Definition: UI_MAP.h:7