/** * Deallocates this chain. */ Chain::~Chain() { this->clear(); delete this->lpFirst; delete this->lpLast; this->lpFirst = 0; this->lpLast = 0; this->lpData = 0; this->lminiSteps.clear(); delete this->lpInitialState; this->lpInitialState = 0; deallocateVector(this->linitialStateDifferences); deallocateVector(this->lendStateDifferences); }
/** * Deallocates the data. */ Data::~Data() { // Activity indicators for (unsigned i = 0; i < this->lactorSets.size(); i++) { const ActorSet * pActorSet = this->lactorSets[i]; bool ** active = this->lactive[pActorSet]; for (int i = 0; i < pActorSet->n(); i++) { delete[] active[i]; } delete[] active; } this->lactive.clear(); // Various vectors deallocateVector(this->ldependentVariableData); deallocateVector(this->lconstantCovariates); deallocateVector(this->lchangingCovariates); deallocateVector(this->lconstantDyadicCovariates); deallocateVector(this->lchangingDyadicCovariates); deallocateVector(this->lactorSets); deallocateVector(this->lnetworkConstraints); // Delete the exogenous events. // for (int i = 0; i < this->lobservationCount - 1; i++) for (int i = 0; i < this->lobservationCount; i++) { while (!this->lexogenousEvents[i]->empty()) { ExogenousEvent * pEvent = *this->lexogenousEvents[i]->begin(); this->lexogenousEvents[i]->erase( this->lexogenousEvents[i]->begin()); delete pEvent; } delete this->lexogenousEvents[i]; } this->lexogenousEvents.clear(); }
/** * Clears the vector of endStateDifferences */ void Chain::clearEndStateDifferences() { deallocateVector(this->lendStateDifferences); }
/** * Generates a chain connecting the original and simulated initial * 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::createInitialStateDifferences() { deallocateVector(this->linitialStateDifferences); //Rprintf("******** %d create initial\n",this->linitialStateDifferences.size() ); Data * pData = this->lpData; State * initialState = this->lpInitialState; int period = this->lperiod; // Create the required ministeps for (unsigned variableIndex = 0; variableIndex < pData->rDependentVariableData().size(); variableIndex++) { LongitudinalData * pVariableData = pData->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 = initialState->pNetwork(pNetworkData->name()); 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) ) { NetworkChange * pMiniStep = new NetworkChange(pNetworkData, i, iter1.actor(), false); // PrintValue(getMiniStepDF(*pMiniStep)); this->linitialStateDifferences. push_back(pMiniStep); iter1.next(); // PrintValue(getMiniStepDF( // *this->linitialStateDifferences.back())); } 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) ) { this->linitialStateDifferences.push_back( new NetworkChange(pNetworkData, i, iter2.actor(), false)); iter2.next(); //PrintValue(getMiniStepDF( // *this->linitialStateDifferences.back())); } else { // create step in structural subchain? } } else { iter1.next(); iter2.next(); } } } } else if (pBehaviorData) { for (int i = 0; i < pBehaviorData->n(); i++) { int delta = initialState-> behaviorValues(pBehaviorData->name())[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) ) { this->linitialStateDifferences.push_back( new BehaviorChange(pBehaviorData, i, singleChange)); // Rprintf(" %d %d in beh\n", i, singleChange); } else { // create step in structural subchain? } } } } } // Rprintf("xx ********%d %d end create initial diff\n", this->linitialStateDifferences.size(), period); }
//function only called when run button pressed int scannar::splitStr() { deallocateVector(); //need to add this otherwise the last value will be cut of. //Space used because space will be ignored srcCode+=" \n"; //position size_t pos=0; size_t range=1; bool push=false; //numerals,alphabets and _ string regex="abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ_."; //filtering all the non aplhabetical and numerical symbols size_t delimiter = srcCode.find_first_not_of(regex); size_t oldPos=0; while (delimiter!=std::string::npos) { size_t length=delimiter-pos; //if not string,char or comment if(srcCode.substr(delimiter,1).compare("\"")!=0 &&srcCode.substr(delimiter,1).compare("'")!=0 &&srcCode.substr(delimiter,2).compare("//")!=0) { //length>0 because when then :: problems get eliminated ie //problems related to continues delimiters. if(length>0) { codeFragments.push_back(srcCode.substr(pos,length)); } //gets rid of space if(srcCode.substr(delimiter,1).compare(" ")!=0) { codeFragments.push_back(srcCode.substr(delimiter,1)); } range=1; } else{ bool comment=false; found=false; size_t findQuotes=0; //if it is a string type if(srcCode.substr(delimiter,1).compare("\"")==0) { findQuotes= srcCode.find_first_of("\"",delimiter+1); } //if it is a comment else if(srcCode.substr(delimiter,1).compare("/")==0){ if(srcCode.substr(delimiter+1,1).compare("/")==0) { if(length>0) { codeFragments.push_back(srcCode.substr(pos,length)); } findQuotes= srcCode.find_first_of("\n",delimiter+2); comment=true; } } else { findQuotes= srcCode.find_first_of("'",delimiter+1); } if(findQuotes==string::npos&&comment==false) { range=delimiter; return 6; } else { length=findQuotes-delimiter; range=length+1; if(!comment) { codeFragments.push_back(srcCode.substr(delimiter,length+1)); } else { ++lineNumber; codeFragments.push_back("\n"); } } push=true; } pos=delimiter+range; //used only for comments oldPos=delimiter; delimiter=srcCode.find_first_not_of(regex,delimiter+range); } int msg= appendToken(); return msg; }