src/misc/ringFinder.cc

changeset 604
01bdac75994a
parent 603
47e7773c7841
equal deleted inserted replaced
603:47e7773c7841 604:01bdac75994a
131 131
132 for (QVector<Solution>::iterator solp = m_solutions.begin(); solp != m_solutions.end(); ++solp) 132 for (QVector<Solution>::iterator solp = m_solutions.begin(); solp != m_solutions.end(); ++solp)
133 { 133 {
134 const Solution& sol = *solp; 134 const Solution& sol = *solp;
135 135
136 if (m_bestSolution == null || sol > *m_bestSolution) 136 if (m_bestSolution == null || sol.isBetterThan (m_bestSolution))
137 m_bestSolution = &sol; 137 m_bestSolution = &sol;
138 } 138 }
139 139
140 return (m_bestSolution != null); 140 return (m_bestSolution != null);
141 } 141 }
142 142
143 // ============================================================================= 143 // =============================================================================
144 // ----------------------------------------------------------------------------- 144 // -----------------------------------------------------------------------------
145 bool RingFinder::Solution::operator> (const RingFinder::Solution& other) const 145 bool RingFinder::Solution::isBetterThan (const Solution* other) const
146 { 146 {
147 // If this solution has less components than the other one, this one 147 // If this solution has less components than the other one, this one
148 // is definitely better. 148 // is definitely better.
149 if (getComponents().size() < other.getComponents().size()) 149 if (getComponents().size() < other->getComponents().size())
150 return true; 150 return true;
151 151
152 // vice versa 152 // vice versa
153 if (other.getComponents().size() < getComponents().size()) 153 if (other->getComponents().size() < getComponents().size())
154 return false; 154 return false;
155 155
156 // Calculate the maximum ring number. Since the solutions have equal 156 // Calculate the maximum ring number. Since the solutions have equal
157 // ring counts, the solutions with lesser maximum rings should result 157 // ring counts, the solutions with lesser maximum rings should result
158 // in cleaner code and less new primitives, right? 158 // in cleaner code and less new primitives, right?
160 maxB = 0; 160 maxB = 0;
161 161
162 for (int i = 0; i < getComponents().size(); ++i) 162 for (int i = 0; i < getComponents().size(); ++i)
163 { 163 {
164 maxA = max (getComponents()[i].num, maxA); 164 maxA = max (getComponents()[i].num, maxA);
165 maxB = max (other.getComponents()[i].num, maxB); 165 maxB = max (other->getComponents()[i].num, maxB);
166 } 166 }
167 167
168 if (maxA < maxB) 168 if (maxA < maxB)
169 return true; 169 return true;
170 170

mercurial