MCPcopy Create free account
hub / github.com/OriginQ/QPanda-2 / genGraph

Function genGraph

Applications/NodeSort/NodeSort.cpp:146–233  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

144}
145
146vector<vector<double>> genGraph(const string& grid, int &real_size)
147{
148 vector<vector<double>> graph;
149 QString str_grid(grid);
150 auto strs = str_grid.split(";", QString::SkipEmptyParts);
151
152 real_size = 0;
153 map<int, vector<int>> node_neighbors;
154 for (auto& item : strs)
155 {
156 auto items = item.split("-", QString::SkipEmptyParts);
157 if (items.size() > 2)
158 {
159 cerr << "grid format error! error item: " << item << endl;
160 return graph;
161 }
162
163 bool ok = false;
164 auto node = items[0].toInt(&ok);
165 if (!ok)
166 {
167 cerr << "node must be digital! error node: " << item[0] << endl;
168 return graph;
169 }
170 if (node > real_size)
171 {
172 real_size = node;
173 }
174 if (node_neighbors.find(node) == node_neighbors.end())
175 {
176 node_neighbors.insert(make_pair(node, vector<int>()));
177 }
178
179 if (items.size() == 2)
180 {
181 auto neighbor = items[1].toInt(&ok);
182 if (!ok)
183 {
184 cerr << "node must be digital! error node: " << item[1] << endl;
185 return graph;
186 }
187
188 if (neighbor > real_size)
189 {
190 real_size = neighbor;
191 }
192 node_neighbors[node].push_back(neighbor);
193 }
194 }
195 auto size = node_neighbors.size();
196 if (size == 0)
197 {
198 cerr << "no node found! error grid: " << grid << endl;
199 return graph;
200 }
201 real_size++;
202
203 int tmp_log = ceil(std::log2(real_size));

Callers 1

mainFunction · 0.85

Calls 12

toIntMethod · 0.80
ceilFunction · 0.50
log2Function · 0.50
powFunction · 0.50
splitMethod · 0.45
sizeMethod · 0.45
findMethod · 0.45
endMethod · 0.45
insertMethod · 0.45
push_backMethod · 0.45
resizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected