Path::Path(Path* mother, Path* father) { unsigned int size=mother->path.size(); this->path.resize(size,-1); LARGE_INTEGER time; QueryPerformanceCounter(&time); randomGenerator.seed((unsigned)time.QuadPart); int from=randomGenerator()%size,to=randomGenerator()%size; for(int i=0;i<size;i++){ if(from <= to && i>= from && i<=to){ path[i]=mother->path[i]; } else if(from > to && (i>=from || i<=to )) { path[i]=mother->path[i]; } } int j=(to+1)%size; for(int i=j;i!=from;i=(i+1)%size){ while(contains(father->path[j]) && j!=to){ j++; j%=size; } path[i]=father->path[j++]; j%=size; } this->graph=mother->graph; countLength(); }
void Ant::updatePheromone(EdgePheromone *pheromoneDelta) { float pheromoneDisposed = 1.f / countLength(); for(int i=0;i<path.size()-1;i++) pheromoneDelta->addPheromone(path[i],path[i+1],pheromoneDisposed); pheromoneDelta->addPheromone(path.front(),path.back(),pheromoneDisposed); }
/** * @param headA: the first list * @param headB: the second list * @return: a ListNode */ ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) { int la, lb; ListNode *pa, *pb; la = countLength(headA); lb = countLength(headB); pa = headA; pb = headB; if (la < lb) { moveForward(pb, lb - la); } else { moveForward(pa, la - lb); } while (pa != pb) { pa = pa->next; pb = pb->next; } return pa; }
Path::Path(unsigned int size, Graph* graph) { LARGE_INTEGER time; QueryPerformanceCounter(&time); randomGenerator.seed((unsigned) time.QuadPart); this->graph=graph; path.resize(size); for(int i=0;i< path.size();i++) path[i]=i; for(int i=0;i<path.size();i++) swap(path[i],path[randomGenerator()%path.size()]); countLength(); }
Path::Path(Path *source,Graph* graph) { this->graph = graph; for(int i=0;i<source->path.size();i++) this->path.push_back(source->path[i]); countLength(); }
for (; i < 1000000; i++) { if (i % 2 == 0) length[i] = 1 + length[i >> 1];// i >> 1 = i / 2 else if (i % 8 == 5) length[i] = 4 + length[3 * ((i - 5) >> 3) + 2];// n >> 3 = n / 8 /* if i = 8j + 5 -> i is odd follow the pattern: 8j + 5 -> 24j + 16 -> 12j + 8 -> 6j + 4 -> 3j + 2 1 odd 2 even 3 even 4 even length[i]=4 + length[3 * j + 2] (j = (i - 5)/8) */ else length[i] = countLength(i); } int a, b; while (scanf("%d%d", &a, &b) != EOF) { int small = a, big = b; if (a > b) { small = b; big = a; } int max = 0; for (; small <= big; small++)