MCPcopy Create free account
hub / github.com/GeoDaCenter/geoda / CheckAdd

Method CheckAdd

Algorithms/azp.cpp:84–142  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

82}
83
84bool ZoneControl::CheckAdd(int area, boost::unordered_map<int, bool>& candidates)
85{
86 bool is_valid = true; // default true since no check will yield good cands
87 boost::unordered_map<int, bool>::iterator it;
88 for (size_t i=0; i< comparators.size(); ++i) {
89 if (comparators[i] != LESS_THAN) {
90 continue;
91 }
92
93 // get zone value for comparison
94 double zone_val = 0;
95 if (operations[i] == SUM) {
96 double sum = 0;
97 for (it=candidates.begin(); it!=candidates.end(); ++it) {
98 sum += data[ it->first ];
99 }
100 sum += data[area];
101 zone_val = sum;
102 } else if (operations[i] == MEAN) {
103 double sum = 0;
104 for (it=candidates.begin(); it!=candidates.end(); ++it) {
105 sum += data[it->first];
106 }
107 sum += data[area];
108 double mean = sum / (double) (candidates.size() + 1);
109 zone_val = mean;
110 } else if (operations[i] == MAX) {
111 double max = data[candidates[0]];
112 for (it=candidates.begin(); it!=candidates.end(); ++it) {
113 if (max < data[it->first]) {
114 max = data[it->first];
115 }
116 }
117 if (max < data[area]) {
118 max = data[area];
119 }
120 zone_val = max;
121 } else if (operations[i] == MIN) {
122 double min = data[candidates[0]];
123 for (it=candidates.begin(); it!=candidates.end(); ++it) {
124 if (min > data[it->first]) {
125 min = data[it->first];
126 }
127 }
128 if (min > data[area]) {
129 min = data[area];
130 }
131 zone_val = min;
132 }
133
134 // compare zone value
135 if (comparators[i] == LESS_THAN) {
136 if (zone_val >= comp_values[i]) {
137 return false;
138 }
139 }
140 }
141 return is_valid;

Callers 3

assignAreaMethod · 0.80
getPossibleMoveMethod · 0.80
InitSolutionMethod · 0.80

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected