190 // |
190 // |
191 bool RingFinder::Solution::isSuperiorTo (const Solution* other) const |
191 bool RingFinder::Solution::isSuperiorTo (const Solution* other) const |
192 { |
192 { |
193 // If one solution has less components than the other one, it is definitely |
193 // If one solution has less components than the other one, it is definitely |
194 // better. |
194 // better. |
195 if (getComponents().size() != other->getComponents().size()) |
195 if (length(getComponents()) != length(other->getComponents())) |
196 return getComponents().size() < other->getComponents().size(); |
196 return length(getComponents()) < length(other->getComponents()); |
197 |
197 |
198 // Calculate the maximum ring number. Since the solutions have equal |
198 // Calculate the maximum ring number. Since the solutions have equal |
199 // ring counts, the solutions with lesser maximum rings should result |
199 // ring counts, the solutions with lesser maximum rings should result |
200 // in cleaner code and less new primitives, right? |
200 // in cleaner code and less new primitives, right? |
201 int maxA = 0, |
201 int maxA = 0, |
202 maxB = 0; |
202 maxB = 0; |
203 |
203 |
204 for (int i = 0; i < getComponents().size(); ++i) |
204 for (const Component& component : getComponents()) |
205 { |
205 { |
206 maxA = qMax (getComponents()[i].num, maxA); |
206 maxA = qMax (component.num, maxA); |
207 maxB = qMax (other->getComponents()[i].num, maxB); |
207 maxB = qMax (component.num, maxB); |
208 } |
208 } |
209 |
209 |
210 if (maxA != maxB) |
210 if (maxA != maxB) |
211 return maxA < maxB; |
211 return maxA < maxB; |
212 |
212 |