GainType LKH::LKHAlg::PatchCycles(int k, GainType Gain) { Node *s1, *s2, *sStart, *sStop; GainType NewGain; int M, i; if(!CurrentCycle.get()) { CurrentCycle.reset(new int(0)); Patchwork.reset(new int(0)); RecLevel.reset(new int(0)); } FindPermutation(k,this); M = Cycles(k); if (M == 1 && Gain > 0) { MakeKOptMove(k); return Gain; } if (M == 1 || M > PatchingC || k + M > NonsequentialMoveType) return 0; if (*RecLevel == 0) *Patchwork = 0; *CurrentCycle = ShortestCycle(M, k,this); for (i = 0; i < k; i++) { if ((*cycle.get())[(*p.get())[2 * i]] != *CurrentCycle) continue; sStart = (*t.get())[(*p.get())[2 * i]]; sStop = (*t.get())[(*p.get())[2 * i + 1]]; for (s1 = sStart; s1 != sStop; s1 = s2) { s2 = SUC(s1); if (FixedOrCommon(s1, s2)) continue; if (++(*Patchwork) > Dimension) return 0; (*t.get())[2 * k + 1] = s1; (*t.get())[2 * k + 2] = s2; MarkDeleted(s1, s2); /* Find a set of gainful alternating cycles */ NewGain = PatchCyclesRec(k, 2, M, Gain + (this->*C)(s1, s2),this); UnmarkDeleted(s1, s2); if (NewGain > 0) return NewGain; } } return 0; }
virtual unsigned int CpuCycles(void) { return Cycles(); }
// ================================================================================================ // Take a timing sample // ================================================================================================ void Timer::Sample() { last = curr; curr = Cycles(); }
// ================================================================================================ // Constructor // ================================================================================================ Timer::Timer() { curr = last = Cycles(); }