BoiseState-AdaptLab / IEGenLib

Inspector/Executor Generation Library for manipulating sets and relations with uninterpreted function symbols.
BSD 2-Clause "Simplified" License
2 stars 4 forks source link

add getSymbolIterator() to Relation #158

Closed cathieO closed 2 years ago

cathieO commented 2 years ago

Conjunction already has a function getSymbolIterator(), but I'd like one at the Relation level as well. This one will need to iterate over mConjuntions and make the corresponding call.

This function belongs in the Relation class. Unit tests must be added before the function is added.

cathieO commented 2 years ago

Here is some code that I want to work (below) I want to call a function getSymbolIterator() on a Relation. As of now, that function exists for a Conjunction, but not for a Relation. I need a function to be added to Relation that calls the function for each Conjunction of the Relation and combines the results.

 24    // COO to Dense
 25     Relation * coo2dns = new Relation(
 26      "{[n] ->[i,j]:row1(n)=i and col1(n) =j }");
 27 
 28     Relation * dns2csr = new Relation(
 29      "{[i,j] ->[k]:rowptr(i)<=k<rowptr(i+ 1) and col2(k)=j and P2(i,j)=k}");
 30 
 31     Relation * coo2csr = dns2csr->Compose(coo2dns);
 32     Relation * closure = coo2csr->TransitiveClosure() ;
 33 
 34     std::cout<< closure->prettyPrintString() << "\n";
 35 
 36
 37     // extract all known UFs
 38     StringIterator* knownUFsIter = coo2dns->getSymbolIterator();
 39     std::vector<string> knownUFs;
 40     std::cout << "Known UFS\n";
 41     while (knownUFsIter->hasNext()) {
 42        knownUFs.push_back( knownUFsIter->next() );
 43        std::cout << knownUFs.back() << std::endl;
 44     }
 45     // extract all unknown UFs
 46     StringIterator* unknownUFsIter = dns2csr->getSymbolIterator();
 47     std::vector<string> knownUFs;
 48     std::cout << "unknown UFS\n";
 49     while (knownUFsIter->hasNext()) {
 50        knownUFs.push_back( knownUFsIter->next() );
 51        std::cout << unknownUFs.back() << std::endl;
 52     }
 53 
kalyanbhetwal commented 2 years ago

I have implemented a method in the Relation class to do so. Below is the section of the code. Could you please check if this is the correct implementation?


StringIterator* Relation::getSymbolIterator() const {
    std::set<std::string> finalSymbolSet;
        for (std::list<Conjunction*>::const_iterator it=mConjunctions.begin();
            it != mConjunctions.end(); it++) {
                StringIterator* subSymIter = (*it)->getSymbolIterator();
                while (subSymIter->hasNext()) {
                    finalSymbolSet.insert( subSymIter->next() );
                }
        delete subSymIter;
        }
    return new StringIterator(finalSymbolSet);
}