| 909 | } |
| 910 | |
| 911 | void MaxpRegionMaker::InitSolution() |
| 912 | { |
| 913 | // init unassigned areas |
| 914 | for (int i=0; i<n; ++i) { |
| 915 | unassignedAreas[i] = true; |
| 916 | } |
| 917 | |
| 918 | // mark neighborless areas |
| 919 | AssignAreasNoNeighs(); |
| 920 | |
| 921 | // get max-p regions |
| 922 | // get starting position: either from init_areas or randomly selected |
| 923 | std::set<int> start_areas; |
| 924 | for (int i=0; i<init_areas.size(); ++i) { |
| 925 | start_areas.insert(init_areas[i]); |
| 926 | } |
| 927 | std::vector<int> _candidates; |
| 928 | for (int i=0; i < n; i++) { |
| 929 | if (start_areas.empty() || start_areas.find(i) == start_areas.end()) { |
| 930 | _candidates.push_back(i); |
| 931 | } |
| 932 | } |
| 933 | DataUtils::Shuffle(_candidates, rng); |
| 934 | for (int i=0; i<init_areas.size(); ++i) { |
| 935 | _candidates.insert(_candidates.begin(), init_areas[i]); |
| 936 | } |
| 937 | std::list<int> candidates; |
| 938 | boost::unordered_map<int, bool> candidates_dict; |
| 939 | for (int i=0; i<n;i++) { |
| 940 | candidates.push_back( _candidates[i] ); |
| 941 | candidates_dict[ _candidates[i] ] = false; |
| 942 | } |
| 943 | |
| 944 | // grow p regions using the starting positions above |
| 945 | int r = 0; |
| 946 | bool satisfy_lower_bound = false; |
| 947 | |
| 948 | while (!candidates.empty()) { |
| 949 | int seed = candidates.front(); |
| 950 | candidates.pop_front(); |
| 951 | |
| 952 | // try to grow it till threshold constraint is satisfied |
| 953 | bool is_growing = true; |
| 954 | bool reach_ub = false; |
| 955 | bool reach_lb = false; |
| 956 | std::set<int>::iterator it; |
| 957 | |
| 958 | // assign this seed with a new region |
| 959 | boost::unordered_map<int, bool> region; |
| 960 | region[seed] = true; |
| 961 | candidates_dict[seed] = true; |
| 962 | |
| 963 | while (is_growing && !reach_ub && !reach_lb) { |
| 964 | // each time, grow just one area, to avoid dominant grow |
| 965 | // if two seeds are next to each other |
| 966 | bool has_assign = false; |
| 967 | std::set<int> buffer_areas = getBufferingAreas(region); |
| 968 | for (it = buffer_areas.begin(); !has_assign && it != buffer_areas.end(); ++it) { |
nothing calls this directly
no test coverage detected