void TwoBitFile::readRegions(std::vector<TwoBitSequenceMeta::Region>& out) { uint32_t count; std::vector<uint32_t> starts; std::vector<uint32_t> lengths; count = nextInt(); for (uint32_t i = 0; i < count; ++i) { // read starts of regions starts.emplace_back(nextInt()); } for (uint32_t i = 0; i < count; ++i) { // read lengths of regions lengths.emplace_back(nextInt()); } // transform into a usable structure. // {(0, 0), (start, 1), (end, -1), (start, 1), (end, -1), ...} out.clear(); out.reserve(count * 2); out.emplace_back(0, 0); // filler, makes logic a little easier for (uint32_t i = 0; i < count; ++i) { out.emplace_back(starts[i], 1); out.emplace_back(starts[i] + lengths[i], -1); } std::sort(out.begin() + 1, out.end(), [](const TwoBitSequenceMeta::Region& a, const TwoBitSequenceMeta::Region& b) { return a.pos_ < b.pos_; }); }
int main() { while((n = nextInt()) && (m = nextInt())) { for(int i = 1; i <= n; i++) a[i] = nextInt(); std::sort(a+1, a+1+n); L = 1; R = 0; // [L, R) for(int i = 1; i <= n; i++) { if(i == 1 || a[i] != a[i-1]) { hei[++R] = a[i]; val[R] = 0; } val[R]++; } for(int i = 1; i <= m; i++) { int x = nextInt(); int k = find(x); if(hei[k] == x) { printf("%d\n", val[k]); val[k] = 0; } else printf("%d\n", 0); } } return 0; }
uint mutateHim( uint statesCount, uint stateSize, __local char* automatPtr, uint random_value ) { random_value = nextInt( random_value ); if ( random_value%100 < mutation_probability ) { random_value = nextInt( random_value ); uint pos = random_value%statesCount; __local char* ptrStates = automatPtr + 1 + 2*stateSize*pos; __local char* ptrActions = ptrStates + stateSize; for ( size_t j=0; j<stateSize; ++j ) { random_value = nextInt( random_value ); *(ptrStates + j) = random_value % statesCount; random_value = nextInt( random_value ); *(ptrActions + j) = random_value % actions_count; } random_value = nextInt( random_value ); if ( random_value % 100 > 15 ) *(automatPtr) = (char)(random_value % statesCount); } return random_value; }
void TwoBitFile::readTwoBitHeader() { // Read first 16 bytes of 2-bit file to get things going if (file_.read(reinterpret_cast<char*>(&magic_), 4)) { if (magic_ == MAGIC_NUMBER) { swapped_ = false; } else if (magic_ == REVERSE_MAGIC_NUMBER) { swapped_ = true; } else { throw Exception(__PRETTY_FUNCTION__, "Invalid magic number. Bad 2-bit file."); } } else { throw Exception(__PRETTY_FUNCTION__, "Error reading file."); } version_ = nextInt(); // always zero sequenceCount_ = nextInt(); // number of sequences reserved_ = nextInt(); // always zero // integrity check if (VERSION != version_) { throw Exception(__PRETTY_FUNCTION__, "Unexpected version number. Bad 2-bit file."); } if (RESERVED != reserved_) { throw Exception(__PRETTY_FUNCTION__, "Unexpected data. Bad 2-bit file."); } }
task main() { initReadMode("log.txt", 1024); for(int i = 0; i < 1000; i++) { writeDebugStream("%i\t", nextInt()); writeDebugStream("%f\n", (((nextInt())/1000.0))); nxtDisplayBigTextLine(1, "%i", nextInt()); nxtDisplayBigTextLine(3, "%f", (((nextInt())/1000.0))); wait1Msec(40); } closeActiveFile(); }
void MeetingSetting::initPermittedSteps(const bool* const permitted) { // THIS WORKS CAUSE WE KNOW THAT PERMITTED STEPS CONTAINS EGO! if (lpPermittedSteps == 0) { lpSetting->initPermittedSteps(permitted); if (lpSetting->getPermittedSize() > 1) { ITieIterator* iter = lpSetting->getPermittedSteps(); if(iter->actor() == ego()) { iter->next(); } int pos = nextInt(lpSetting->getPermittedSize() - 1); while (pos != 0) { iter->next(); if (iter->actor() != ego()) { --pos; } } SingleIterator iter1(ego()); SingleIterator iter2(iter->actor()); lpPermittedSteps = new UnionTieIterator(iter1, iter2); delete iter; } else { lpPermittedSteps = new SingleIterator(ego()); } } else { LOGS(Priority::ERROR)<<"setting has not been terminated\n"; throw "setting has not been terminated"; } }
int main(int argc, char **argv) { long seed = 1234567890L; random(seed); int expected[] = { 782593066, 746941499, 577072204, 541420637, 639986798, 604335231, 1004891264, 969239697, 1067805858, 1032154291 }; int i; printf("Validating nextInt() against known results from DTFRandom.\n"); for (i = 0; i < 10; i++) { int result = nextInt(); if ( result != expected[i] ) { printf("nextInt() with seed %ld, did not return %d, got %d instead", seed, expected[i], result); return -1; } } return 0; }
void Random::shuffle(vector<T>& array) { size_t lastIndex = array.size(); for (size_t i = 0; i < array.size(); ++i, --lastIndex) { size_t nextIndex = nextInt() % lastIndex; std::swap(array[nextIndex], array[lastIndex - 1]); } }
int* getNextStep() { // note that initReadMode() must have been called before this function is called int stp[8]; for(int i = 0; i < 8; i++) { stp[i] = nextInt(); } return stp; }
int main() { int test, k, n, dx, dy, x1, y1, x2, y2, g; fread(buff, BUFF, 1, stdin); ptr = buff; test = nextInt(); while (test--) { k = nextInt(); n = nextInt(); x1 = nextInt(); y1 = nextInt(); x2 = nextInt(); y2 = nextInt(); g = gcd(k, n); dx = x1 > x2 ? x1 - x2 : x2 - x1; dy = y1 > y2 ? y1 - y2 : y2 - y1; if(g > 1) { if(dx % g || dy % g) { puts("NIE"); continue; } k /= g, n /= g, dx /= g, dy /= g; } if(!(k & 1) || !(n & 1)) puts("TAK"); else if((dx & 1) + (dy & 1) == 1) puts("NIE"); else puts("TAK"); } return 0; }
uint crossThem( uint bufSize, uint myBuf, __local char* tempBuffer, uint hisBuf, __global char* inBuffer, uint random_value ) { for ( uint i=0; i < bufSize; ++i ) { random_value = nextInt( random_value ); uint res = select( myBuf, hisBuf, (random_value & 512) ); tempBuffer[ myBuf + i ] = inBuffer[ res + i ]; } return random_value; }
void TwoBitFile::populateSequenceMeta(TwoBitSequenceMeta& meta) { // seek to offset and read actual sequence meta data. file_.seekg(meta.offset_); meta.dnaSize_ = nextInt(); // length of sequence meta.dnaBytes_ = meta.dnaSize_ / 4 + (meta.dnaSize_ % 4 > 0); // read nRegions. readRegions(meta.nRegions); // N-regions readRegions(meta.mRegions); // mask regions // check. this number should be zero as per the spec. if (0 != nextInt()) { throw Exception(__PRETTY_FUNCTION__, "Unexpected data. Bad 2-bit file."); } // store start of packed data meta.packedPos_ = file_.tellg(); }
/* * The only special thing being done in this function is that we're skipping * to generate the sequence ${ because this could result in a property * being generated that DTF would later try to resolve. */ void nextBytes(char* bytes, int length) { int i,rnd,len,n,prev; for (i = 0, prev = 0, len = length; i < len; ) { for (rnd = nextInt(), n = min(len - i, INTEGER_SIZE/BYTE_SIZE); n-- > 0; rnd >>= BYTE_SIZE) { char b = (char)rnd; if ( b == '{' && prev == '$' ) continue; bytes[i++] = b; } } }
void FlyTerrain :: setPoint( int point ) { static int fly_difficulty_levels[] = { 5, 10, 15 }; if ( nextInt(100) >= 75 ) dir *= -1; int prevPoint = mapBottom[point-1]; int nextPoint = prevPoint + (dir * nextInt( fly_difficulty_levels[0] ) ); if ( nextPoint > sHeight ) { nextPoint = sHeight; dir *= -1; } else if ( nextPoint < maxHeight ) { nextPoint = maxHeight; dir *= 1; } mapBottom[point] = nextPoint; }
/*C-style Comment*/ void Random::Function() { char C = '"'; std::string Demo = "Project 1"; std::cout << Demo; Demo += "Lexical Scanner"; // It is a CPP comment for (int i = 0; i < 5; ++i) int num = nextInt(20); return rand() % range; for (int i = 0; i < N; ++i) { std::string DoNothing; } }
/** * Returns a random ministep from the given interval. */ MiniStep * Chain::randomMiniStep(MiniStep * pFirstMiniStep, MiniStep * pLastMiniStep) const { int length = this->intervalLength(pFirstMiniStep, pLastMiniStep); int index = nextInt(length); MiniStep * pMiniStep = pFirstMiniStep; while (index > 0) { pMiniStep = pMiniStep->pNext(); index--; } return pMiniStep; }
std::string TrampolineMgr::ArgumentWalker::next(char type) { std::stringstream ss; void* ptr; if (type == 'u') ss << unsigned(nextInt()); else if (type == 'i') ss << nextInt(); else if (type == 'q') ss << nextLL(); else if (type == 'f') ss << nextFloat(); else if (type == 'd') ss << nextDouble(); else if (type == 'p' || isupper(type)) ss << nextPointer(); else if (type == 'c') ss << char(nextInt()); else if (type == 's') { const char* s = (const char*) nextPointer(); ss << (void*)s; if (s) ss << " \"" << safeString(s) << '"'; } else if (type == 'v') ss << "(void)"; else ss << '?'; if (isupper(type)) m_pointers.push_back(std::make_pair(tolower(type), ptr)); return ss.str(); }
void SFCaveGame :: addBlock() { for ( int i = 0 ; i < BLOCKSIZE ; ++i ) { if ( blocks[i].y() == -1 ) { int x = sWidth; int y = terrain->getMapTop( MAPSIZE-1 ) + (int)(nextInt(terrain->getMapBottom( MAPSIZE-1 ) - terrain->getMapTop( MAPSIZE-1 ) - blockHeight)); blocks[i].setRect( x, y, blockWidth, blockHeight ); break; } } }
void Random::Function() { for (int i = 0; i < 5; ++i) int num = nextInt(20); return rand() % range; for (;;); for (;;) std::string TestPassed; for (int i = 0; i < N; ++i) { std::string DoNothing; } for ( ; ; ); for (; ; ) std::string KeepLooping; }
void TwoBitFile::createSequenceMeta() { // create SequenceMeta objects from name and offset uint32_t seqNameLen, offset; char seqName[SEQNAME_MAX_LEN]; std::string seqNameStr; // name as std::string for (uint32_t i = 0; i < sequenceCount_; ++i) { seqNameLen = nextChar(); // length file_.read(seqName, seqNameLen); // sequence name seqNameStr = std::string(seqName, seqNameLen); offset = nextInt(); // offset // add meta data. sequences_.emplace(seqNameStr, TwoBitSequenceMeta(seqNameStr, offset, filename_, swapped_)); sequenceNames_.push_back(seqNameStr); } }
void scalefree(edge *g, agent *a) { edge ne = 1; agent deg[N] = {0}; for (agent i = 1; i <= M; i++) { for (agent j = 0; j < i; j++) { createedge(g, a, i, j, ne); deg[i]++; deg[j]++; ne++; } } chunk t[C] = { 0 }, t1[C] = { 0 }; for (agent i = M + 1; i < N; i++) { ONES(t1, i, C); MASKANDNOT(t, t1, t, C); for (agent j = 0; j < M; j++) { agent d = 0; for (agent h = 0; h < i; h++) if (!GET(t, h)) d += deg[h]; if (d > 0) { int p = nextInt(d); agent q = 0; while (p >= 0) { if (!GET(t, q)) p = p - deg[q]; q++; } q--; SET(t, q); createedge(g, a, i, q, ne); deg[i]++; deg[q]++; ne++; } } } }
int main() { //scanf("%d%d%d%d", &W, &H, &n, &m); W = nextInt(); H = nextInt(); n = nextInt(); m = nextInt(); W++; H++; for(int i = 1; i <= n; i++) { int x1, x2, y1, y2; //scanf("%d%d%d%d", &x1, &y1, &x2, &y2); x1 = nextInt(); y1 = nextInt(); x2 = nextInt(); y2 = nextInt(); x2++; y2++; edge1[++num1] = (Edge){std::max(1, x1-m+1), x2, y1, 1}; edge1[++num1] = (Edge){std::max(1, x1-m+1), x2, y2, -1}; edge2[++num2] = (Edge){std::max(1, y1-m+1), y2, x1, 1}; edge2[++num2] = (Edge){std::max(1, y1-m+1), y2, x2, -1}; } long long res = 0; res += solve(edge1, num1, W, H); if(m > 1) res += solve(edge2, num2, H, W); printf("%lld\n", res); return 0; }
/** * Creates a matrix by reading values from the given socket. * \return NULL if bad input was received and the matrix could not be created. */ struct Matrix *readMatrix(int sd) { int width, height, err; int i, j; struct Matrix *mat = NULL; int tmp; mat = (struct Matrix *)calloc(1, sizeof(struct Matrix)); if (!mat) { perror("calloc"); goto error_exit; } if (nextInt(sd, &height) != 0) { fprintf(stderr, "Couldn't read matrix height\n"); goto error_exit; } if (nextInt(sd, &width) != 0) { fprintf(stderr ,"Couldn't read matrix width\n"); goto error_exit; } if (width <= 0) { fprintf(stderr, "Illegal nonpositive width (%d)\n", width); goto error_exit; } if (height <= 0) { fprintf(stderr, "Illegal nonpositive height (%d)\n", height); goto error_exit; } mat->width = width; mat->height = height; mat->rows = (int **)calloc(mat->height, sizeof(int *)); if (!mat->rows) { perror("calloc"); goto error_exit; } /* read the matrix values, allocating rows as we go */ i = j = err = 0; while (i < mat->height) { err = nextInt(sd, &tmp); if (err != 0) break; if (j == 0) { /* starting a new row; allocate memory for it */ mat->rows[i] = (int *)calloc(mat->width, sizeof(int)); if (!mat->rows[i]) { perror("calloc"); goto error_exit; } } mat->rows[i][j] = tmp; ++j; if (j == mat->width) { ++i; j = 0; } } if (err > 0) { /* nextInt() will have already printed a more descriptive message */ fprintf(stderr, "Error reading matrix\n"); goto error_exit; } /* ZYM: patch here, err == EOF == -1 if ( i != mat->height ) { fprintf(stderr, "Error reading matrix\n"); goto error_exit; } */ return mat; /* // STONESOUP:CROSSOVER_POINT */ error_exit: freeMatrix(mat); return NULL; }
//varValues[0] - srand //varValues[1] - last buf __kernel void genetic_2d( __global char* inBuffer, __global char* outBuffer, __global const uint* constSizes, __global uint* varValues, __global int* mapBuffer, __local char* tempBuffer, __constant int* maps, __global float* bestResult, __global float* sumResult, __global char* bestIndivid ) { uint N = get_global_size(0); uint M = get_global_size(1); uint x = get_global_id(0); uint y = get_global_id(1); uint statesCount = constSizes[0]; uint stateSize = constSizes[1]; uint mapSize = constSizes[2]; uint bufSize = 1 + 2 * statesCount * stateSize; uint myPos = x*M + y; uint myBuf = myPos * bufSize; uint srand = varValues[0]; uint random_value = nextInt( srand+(srand*x - srand*y)%(N*M) ); __local float cache[ max_size*max_size ]; __local uint bestResults[ max_size ]; __local float sumResults[ max_size ]; __global int* myMapsPtr = mapBuffer + myPos*mapSize; //todo: in/out due to the varValues[1] __global char* inputBuffer = inBuffer;// = (1-koeff)*inBuffer + koeff*outBuffer; __global char* outputBuffer = outBuffer;// = (1-koeff)*outBuffer + koeff*inBuffer; uint koeff = varValues[1]; if ( koeff%2 != 0 ) { inputBuffer = outBuffer; outputBuffer = inBuffer; } uint gensNum = constSizes[3]; //for ( uint i=0; i<bufSize; ++i ) // tempBuffer[myBuf + i] = inputBuffer[myBuf + i]; for ( uint counter = 0; counter < gensNum; ++counter ) { float result = -1.0f; //try me uint hisPos = x*M + y; uint hisBuf = hisPos * bufSize; //random_value = mutateHim( statesCount, stateSize, tempBuffer + myBuf, random_value ); //bestResult = tryHim( bufSize, myBuf, statesCount, stateSize, tempBuffer, bestResult, myMapsPtr, outputBuffer, ptr+myPos*200 ); // with left of him // myMapsPtr += mapSize; hisPos = x*M + (y + M - 1)%M; hisBuf = hisPos * bufSize; random_value = crossThem( bufSize, myBuf, tempBuffer, hisBuf, inputBuffer, random_value ); //random_value = mutateHim( statesCount, stateSize, tempBuffer + myBuf, random_value ); result = tryHim( bufSize, myBuf, statesCount, stateSize, tempBuffer, result, myMapsPtr, outputBuffer, maps ); // with up of him hisPos = ((x + N - 1)%N)*M + y; hisBuf = hisPos * bufSize; random_value = crossThem( bufSize, myBuf, tempBuffer, hisBuf, inputBuffer, random_value ); //random_value = mutateHim( statesCount, stateSize, tempBuffer + myBuf, random_value ); result = tryHim( bufSize, myBuf, statesCount, stateSize, tempBuffer, result, myMapsPtr, outputBuffer, maps ); //with right of him hisPos = x*M + (y + 1)%M; hisBuf = hisPos * bufSize; random_value = crossThem( bufSize, myBuf, tempBuffer, hisBuf, inputBuffer, random_value ); //random_value = mutateHim( statesCount, stateSize, tempBuffer + myBuf, random_value ); result = tryHim( bufSize, myBuf, statesCount, stateSize, tempBuffer, result, myMapsPtr, outputBuffer, maps ); //with down of him hisPos = ((x + 1)%N)*M + y; hisBuf = hisPos * bufSize; random_value = crossThem( bufSize, myBuf, tempBuffer, hisBuf, inputBuffer, random_value ); //random_value = mutateHim( statesCount, stateSize, tempBuffer + myBuf, random_value ); result = tryHim( bufSize, myBuf, statesCount, stateSize, tempBuffer, result, myMapsPtr, outputBuffer, maps ); cache[myPos] = result; barrier( CLK_GLOBAL_MEM_FENCE ); if ( y == M - 1 ) { uint max = 0; float sum = 0; for ( uint i=0; i<M; ++i ) { sum += cache[ x*M + i ]; if ( cache[ x*M + i ] > cache[ x*M + max ] ) max = i; } bestResults[x] = max; sumResults[x] = sum; } barrier( CLK_LOCAL_MEM_FENCE ); //change to local if (( y == M - 1 ) && (x == N - 1) ) { uint max = 0; float sum = 0; for ( uint i=0; i<N; ++i ) { sum += sumResults[i]; if ( cache[ i*M + bestResults[i] ] > cache[ max*M + bestResults[max] ] ) max = i; } bestResult[counter] = cache[ max*M + bestResults[max] ]; sumResult[counter] = sum / (N*M); hisPos = max*M + bestResults[max]; hisBuf = hisPos * bufSize; for ( uint i=0; i < bufSize; ++i ) bestIndivid[ counter*bufSize + i ] = outputBuffer[ hisBuf + i ]; //set new values for next turn //srand: varValues[0] = nextInt( random_value ); varValues[1] = ( varValues[1] + 1 )%2; } //swap buffers: __global char* tmp = inputBuffer; inputBuffer = outputBuffer; outputBuffer = tmp; barrier( CLK_GLOBAL_MEM_FENCE ); } }
/** * Generates a random chain connecting the start and end observations of the * given data object for the given period. The chain is simple in the sense * that no two ministeps cancel each other out. */ void Chain::connect(int period, MLSimulation * pMLSimulation) { this->clear(); this->lperiod = period; vector<MiniStep *> miniSteps; // Create the required ministeps for (unsigned variableIndex = 0; variableIndex < this->lpData->rDependentVariableData().size(); variableIndex++) { LongitudinalData * pVariableData = this->lpData->rDependentVariableData()[variableIndex]; NetworkLongitudinalData * pNetworkData = dynamic_cast<NetworkLongitudinalData *>(pVariableData); BehaviorLongitudinalData * pBehaviorData = dynamic_cast<BehaviorLongitudinalData *>(pVariableData); if (pNetworkData) { const Network * pNetwork1 = pNetworkData->pNetwork(period); const Network * pNetwork2 = pNetworkData->pNetwork(period + 1); for (int i = 0; i < pNetwork1->n(); i++) { IncidentTieIterator iter1 = pNetwork1->outTies(i); IncidentTieIterator iter2 = pNetwork2->outTies(i); while (iter1.valid() || iter2.valid()) { if (iter1.valid() && (!iter2.valid() || iter1.actor() < iter2.actor())) { if (!pNetworkData->structural(i, iter1.actor(), period) // || !pNetworkData->structural(i, iter1.actor(), // period + 1) ) { miniSteps.push_back( new NetworkChange(pNetworkData, i, iter1.actor(), false)); iter1.next(); } else { // create step in structural subchain? } } else if (iter2.valid() && (!iter1.valid() || iter2.actor() < iter1.actor())) { if (!pNetworkData->structural(i, iter2.actor(), period) // || !pNetworkData->structural(i, iter2.actor(), // period + 1) ) { miniSteps.push_back( new NetworkChange(pNetworkData, i, iter2.actor(), false)); iter2.next(); } else { // create step in structural subchain? } } else { iter1.next(); iter2.next(); } } } } else if (pBehaviorData) { for (int i = 0; i < pBehaviorData->n(); i++) { int delta = pBehaviorData->value(period + 1, i) - pBehaviorData->value(period, i); int singleChange = 1; if (delta < 0) { delta = -delta; singleChange = -1; } for (int j = 0; j < delta; j++) { if (!pBehaviorData->structural(period, j) //|| !pBehaviorData->structural(period, j + 1) ) { miniSteps.push_back( new BehaviorChange(pBehaviorData, i, singleChange)); } else { // create step in structural subchain? } } } } } // If we have no constraints we can go ahead and add to the chain in a // random order. If we do have contraints we need to make sure our chain // is valid. For now we have two distinct loops: if (this->lpData->rNetworkConstraints().size() == 0) { // Randomize the ministeps for (unsigned i = 1; i < miniSteps.size(); i++) { int j = nextInt(i + 1); MiniStep * pTempMiniStep = miniSteps[i]; miniSteps[i] = miniSteps[j]; miniSteps[j] = pTempMiniStep; } // And finally add the ministeps to this chain for (unsigned i = 0; i < miniSteps.size(); i++) { this->insertBefore(miniSteps[i], this->lpLast); } } else { unsigned count = 0; vector<MiniStep *> remainingMiniSteps; while(miniSteps.size() > 0 && count < this->lpData->rDependentVariableData().size()) { count++; remainingMiniSteps.clear(); for (unsigned i = 0; i < miniSteps.size(); i++) { // first try random insert //const NetworkChange * pNetworkChange = // dynamic_cast<const NetworkChange *>(miniSteps[i]); MiniStep * pMiniStep = this->randomMiniStep(this->lpFirst->pNext(), this->lpLast); bool valid = false; if (miniSteps[i]->behaviorMiniStep()) { valid = true; } else { // get current state at this place pMLSimulation->initialize(this->lperiod); pMLSimulation->executeMiniSteps(this->lpFirst->pNext(), pMiniStep); // see if valid here DependentVariable * pVariable = pMLSimulation->rVariables()[miniSteps[i]->variableId()]; // PrintValue(getMiniStepDF(*miniSteps[i])); if (!pVariable->validMiniStep(miniSteps[i])) { // Rprintf("first inval\n"); // no go, so try to find somewhere else to put it MiniStep * pLastMiniStep = this->pLastMiniStepForLink(miniSteps[i]); if (pLastMiniStep != this->lpFirst) { // Rprintf("lastl\n"); // PrintValue(getMiniStepDF(*pLastMiniStep)); pMiniStep = this->randomMiniStep(pLastMiniStep->pNext(), this->lpLast); // PrintValue(getMiniStepDF(*pMiniStep)); pMLSimulation->initialize(this->lperiod); pMLSimulation->executeMiniSteps(this->lpFirst-> pNext(), pMiniStep); // see if valid here if (!pVariable->validMiniStep(miniSteps[i])) { // Rprintf("second inval\n"); // no go, so try to find somewhere else to put // it MiniStep * pFirstMiniStep = this->pFirstMiniStepForLink(miniSteps[i]); // if (pFirstMiniStep != this->lpFirst) //{ // PrintValue(getMiniStepDF(*pFirstMiniStep)); pMiniStep = this->randomMiniStep(this-> lpFirst->pNext(), pFirstMiniStep); // PrintValue(getMiniStepDF(*pMiniStep)); pMLSimulation->initialize(this->lperiod); pMLSimulation-> executeMiniSteps(pFirstMiniStep, pMiniStep); // see if valid here if (pVariable->validMiniStep(miniSteps[i])) { Rprintf("thirsd true val\n"); valid = true; } // } } else { valid = true; } } } else { valid = true; } } if (valid) { this->insertBefore(miniSteps[i], pMiniStep); } else { remainingMiniSteps.push_back(miniSteps[i]); } } miniSteps = remainingMiniSteps; } // PrintValue(getChainDF(*this, false)); // Rprintf("****** count %d\n", count); if (miniSteps.size() > 0) { for (unsigned i = 0; i < miniSteps.size(); i++) { PrintValue(getMiniStepDF(*miniSteps[i])); } error("Cannot create minimal chain due to constraints"); } } }
/** * Returns a random behavior change with missing observed data. */ MiniStep * Chain::randomMissingBehaviorMiniStep() const { return this->lmissingBehaviorMiniSteps[ nextInt(this->lmissingBehaviorMiniSteps.size())]; }
/** * Returns a random network change with missing observed data. */ MiniStep * Chain::randomMissingNetworkMiniStep() const { return this->lmissingNetworkMiniSteps[ nextInt(this->lmissingNetworkMiniSteps.size())]; }
/** * Returns the first mini step of a random consecutive canceling pair. */ MiniStep * Chain::randomConsecutiveCancelingPair() const { return this->lccpMiniSteps[nextInt(this->lccpMiniSteps.size())]; }
/** * Returns a random diagonal ministep. */ MiniStep * Chain::randomDiagonalMiniStep() const { return this->ldiagonalMiniSteps[nextInt(this->ldiagonalMiniSteps.size())]; }
/** Entry point of the program * @param argc count of arguments, will always be at least 1 * @param argv array of parameters to program argv[0] is the name of * the program, so additional parameters will begin at index 1. * @return 0 the Linux convention for success. */ int main (int argc, char* argv[]) { char line[MAX_LINE_LENGTH]; int count, addr; char *cmd, *name; sym_table_t* symTab; if (argc != 2) usage(); symTab = symbol_init(atoi(argv[1])); while (fgets(line, sizeof(line), stdin) != NULL) { char *cr = strchr(line ,'\n'); /* get rid of trailing \n, if any */ if (cr) *cr = '\0'; cmd = strtok(line, delim); if (! cmd) continue; if (strcmp(cmd, "add") == 0) { name = nextToken(); addr = nextInt(); printf("%s\n", (symbol_add(symTab, name, addr) ? "OK" : "Duplicate")); } else if (strcmp(cmd, "count") == 0) { count = 0; symbol_iterate(symTab, countSymbols, &count); printf("symbol count: %d\n", count); } else if ((strcmp(cmd, "exit") == 0) || (strcmp(cmd, "quit") == 0)) { break; } else if (strcmp(cmd, "get") == 0) { name = nextToken(); printResult(symbol_find_by_name(symTab, name), stdout); } else if (strcmp(cmd, "help") == 0) { help(); } else if (strcmp(cmd, "label") == 0) { addr = nextInt(); printf("label at addr %d '%s'\n", addr, symbol_find_by_addr(symTab, addr)); } else if (strcmp(cmd, "list") == 0) { symbol_iterate(symTab, printResult, stdout); } else if (strcmp(cmd, "reset") == 0) { symbol_reset(symTab); } else if (strcmp(cmd, "search") == 0) { int hash, index; name = nextToken(); struct node* node = symbol_search(symTab, name, &hash, &index); printf("symbol '%s' hash: %d index: %d is %s in symbol table\n", name, hash, index, (node ? "" : "NOT")); } else { help(); } } symbol_term(symTab); /* can check for memory leaks now */ return 0; }