void String::display(ofstream &fp, StringSet &lits, LINT prob_comp) { LINT i, j; StringP lstr; int flag = 0; fp << setw(6) << prob_comp * prob << " " << setw(6) << conf << " "; for(i = 0; i < nitems; i++) { fp << "("; lstr = lits.get_pat(items[i]); for (j = 0; j < lstr->nitems; j++) { if ( flag == 0 ) { fp << lstr->items[j]; flag = 1; } else fp << "," << lstr->items[j]; } flag = 0; fp << ")"; } fp << endl; return; }
void String::display(ofstream &fp, StringSet &lits, LINT prob_comp) { LINT i, j; StringP lstr; fp << setw(6) << prob_comp * prob << " " << setw(6) << conf << " "; for (i = 0; i < nitems; i++) { fp << " << "; lstr = lits.get_pat(items[i]); for (j = 0; j < lstr->nitems; j++) fp << lstr->items[j] << " "; fp << ">>"; } fp << endl; return; }
// adds pattern to CustSeq // returns TRUE if pattern was added, FALSE else // REWORK!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! // BOOLEAN CustSeq::add(String &pat, StringSet &lits) { static UniformDist ud; LINT i, patlen; LINT pos; LINT newitems, olditems; BOOLEAN corrupt; // if TRUE, corrupt transactions too if ( ud() > pat.conf_lvl() ) corrupt = TRUE; // corrupt transactions else corrupt = FALSE; // don't corrupt transactions // corrupt the pattern by reducing its length; // conf_lvl for a pattern is decided at the time of pattern creation patlen = pat.size(); if ( corrupt ) while ( patlen > 0 && ud() > pat.conf_lvl() ) patlen--; if ( patlen == 0 ) // no trans. left in sequence return TRUE; // allows transactions to be dropped randomly from the sequence // if ( patlen < pat.size() ) Choose shuffle(pat.size(), patlen); // pat.shuffle(patlen); // calculate # of items in pattern for (newitems = 0, i = 0; i < patlen; i++) newitems += lits.get_pat( pat.item( shuffle.pos(i) ) )->size(); // newitems += lits.get_pat( pat.rand_item(i) )->size(); // in half of the cases, we drop the pattern that won't fit if ( (patlen > slen) || (newitems + nitems > slen * tlen) ) if ( ud() > 0.5 ) return FALSE; if ( patlen > maxsize ) { // need to allocate more memory TransactionP *old_trans = trans; LINT oldsize = maxsize; maxsize = patlen*2; trans = new TransactionP [maxsize]; for (i = 0; i < oldsize; i++) trans[i] = old_trans[i]; for (; i < maxsize; i++) trans[i] = NULL; delete [] old_trans; } // add new sequence Choose *shuffle1 = NULL; if (ntrans > patlen) shuffle1 = new Choose(ntrans, patlen); for (i = 0; i < patlen; i++) { if ( shuffle1 ) pos = shuffle1->pos(i); else pos = i; if ( trans[pos] == NULL ) trans[pos] = new Transaction(tlen); olditems = trans[pos]->size(); trans[pos]->add( *lits.get_pat(pat.item( shuffle.pos(i) )), corrupt ); // trans[pos]->add( *lits.get_pat(pat.rand_item(i)), corrupt ); nitems += trans[pos]->size() - olditems; // update count of #items } delete shuffle1; // pos = ud() * ntrans / patlen; // for (i = 0; i < patlen; i++) // { // if ( trans[pos] == NULL ) // trans[pos] = new Transaction(tlen); // olditems = trans[pos]->size(); // trans[pos]->add( *lits.get_pat(pat.item( shuffle.pos(i) )), corrupt ); // // trans[pos]->add( *lits.get_pat(pat.rand_item(i)), corrupt ); // nitems += trans[pos]->size() - olditems; // update count of #items // pos += 1 + ud() * ntrans / patlen; // } return TRUE; }