| 512 | } |
| 513 | |
| 514 | void AbstractClusterFactory::init() |
| 515 | { |
| 516 | ssd_utils = new SSDUtils(raw_data, rows, cols); |
| 517 | |
| 518 | // create nodes and edges |
| 519 | nodes.resize(rows); |
| 520 | for (int i=0; i<rows; i++) { |
| 521 | Node* node = djset.MakeSet(i); |
| 522 | nodes[i] = node; |
| 523 | } |
| 524 | |
| 525 | this->dist_dict.resize(rows); |
| 526 | |
| 527 | Node* orig; |
| 528 | Node* dest; |
| 529 | double length; |
| 530 | boost::unordered_map<std::pair<int, int>, bool> access_dict; |
| 531 | |
| 532 | for (int i=0; i<rows; i++) { |
| 533 | orig = nodes[i]; |
| 534 | const std::vector<long>& nbrs = w[i].GetNbrs(); |
| 535 | for (int j=0; j<w[i].Size(); j++) { |
| 536 | int nbr = (int)nbrs[j]; |
| 537 | dest = nodes[nbr]; |
| 538 | length = dist_matrix[orig->id][dest->id]; |
| 539 | |
| 540 | if (access_dict.find(std::make_pair(i, nbr)) == access_dict.end()) { |
| 541 | edges.push_back(new Edge(orig, dest, length)); |
| 542 | access_dict[std::make_pair(i, nbr)] = true; |
| 543 | access_dict[std::make_pair(nbr, i)] = true; |
| 544 | } |
| 545 | this->dist_dict[i][nbr] = length; |
| 546 | } |
| 547 | } |
| 548 | |
| 549 | Clustering(); |
| 550 | |
| 551 | } |
| 552 | |
| 553 | std::vector<std::vector<int> >& AbstractClusterFactory::GetRegions() |
| 554 | { |