| 615 | } |
| 616 | |
| 617 | void RegionMaker::constructRegions() |
| 618 | { |
| 619 | // Construct potential regions per area (not assigned) |
| 620 | std::map<int, std::set<int> >::iterator it; |
| 621 | std::set<int>::iterator rit, ait; |
| 622 | |
| 623 | // Process the most feasible area that has shortest distance to a region |
| 624 | |
| 625 | for (it=potentialRegions4Area.begin(); it != potentialRegions4Area.end(); ++it) { |
| 626 | int areaID = it->first; |
| 627 | const std::set<int>& regionIDs = it->second; |
| 628 | |
| 629 | for (rit = regionIDs.begin(); rit != regionIDs.end(); ++rit) { |
| 630 | int region = *rit; |
| 631 | std::pair<int, int> a_r = std::make_pair(areaID, region); |
| 632 | double regionDistance = am.getDistance2Region(areaID, region, region2Area); |
| 633 | // (areaID, region): distance |
| 634 | candidateInfo[a_r] = regionDistance; |
| 635 | } |
| 636 | } |
| 637 | |
| 638 | if (candidateInfo.empty() == false) { |
| 639 | |
| 640 | // Select and assign the nearest area to a region |
| 641 | // minimumSelection(RegionMaker) |
| 642 | // if there are more than one (area, region) pair |
| 643 | // random select from cands |
| 644 | |
| 645 | std::vector<std::pair<int, int> > cands; |
| 646 | std::map<std::pair<int, int>, double>::iterator cit; |
| 647 | |
| 648 | // get min dist |
| 649 | double min_region_distance = std::numeric_limits<double>::max(); |
| 650 | for (cit = candidateInfo.begin(); cit != candidateInfo.end(); ++cit) { |
| 651 | if (cit->second < min_region_distance) { |
| 652 | min_region_distance = cit->second; |
| 653 | } |
| 654 | } |
| 655 | // get all pairs with min dist |
| 656 | for (cit = candidateInfo.begin(); cit != candidateInfo.end(); ++cit) { |
| 657 | if (cit->second == min_region_distance) { |
| 658 | cands.push_back(cit->first); |
| 659 | } |
| 660 | } |
| 661 | |
| 662 | // if random select candidate from pairs is needed |
| 663 | int rnd_sel = cands.size() == 1? 0 : rng.nextInt((int)cands.size()); |
| 664 | std::pair<int, int>& sel_area_region = cands[rnd_sel]; |
| 665 | int aid = sel_area_region.first; |
| 666 | int rid = sel_area_region.second; |
| 667 | |
| 668 | // assign select areaID to regionID, and process the neighbors of areaID |
| 669 | // update the centroid of the regionID |
| 670 | if (this->assignArea(aid, rid)) { |
| 671 | |
| 672 | // remove from candidateInfo with areaID=aid |
| 673 | std::vector<std::pair<int, int> > removed_cands; |
| 674 | for (cit = candidateInfo.begin(); cit != candidateInfo.end(); ++cit) { |
no test coverage detected