1)Making naiveencoder and encoding graph use tuner 2)Adding timeout to the sat solver...
[satune.git] / src / ASTAnalyses / Encoding / subgraph.cc
index f99783e42410e63fda746d12cfb3e74dc4694c2a..de76e4d0e6890d149fd703795f3713dc455ad3be 100644 (file)
@@ -121,6 +121,58 @@ uint EncodingSubGraph::estimateNewSize(EncodingSubGraph *sg) {
        return newSize;
 }
 
+double EncodingSubGraph::measureSimilarity(EncodingNode *node) {
+       uint common = 0;
+       Hashset64Int intSet;
+       SetIteratorEncodingNode *nit = nodes.iterator();
+       while (nit->hasNext()) {
+               EncodingNode *en = nit->next();
+               for(uint i=0; i < en->getSize(); i++){
+                       intSet.add(en->getIndex(i));
+               }
+       }
+       for(uint i=0; i < node->getSize(); i++){
+               if(intSet.contains( node->getIndex(i) )){
+                       common++;
+               }
+       }
+//     model_print("measureSimilarity:139: common=%u\t GraphSize=%u\tnodeSize=%u\tGraphSim=%f\tnodeSim=%f\n", common, intSet.getSize(), node->getSize(), 1.0*common/intSet.getSize(), 1.0*common/node->getSize());
+       delete nit;
+       return common*1.0/intSet.getSize() + common*1.0/node->getSize();
+}
+
+double EncodingSubGraph::measureSimilarity(EncodingSubGraph *sg) {
+       uint common = 0;
+       Hashset64Int set1;
+       Hashset64Int set2;
+       SetIteratorEncodingNode *nit = nodes.iterator();
+       while (nit->hasNext()) {
+               EncodingNode *en = nit->next();
+               for(uint i=0; i < en->getSize(); i++){
+                       set1.add(en->getIndex(i));
+               }
+       }
+       delete nit;
+       nit = sg->nodes.iterator();
+       while (nit->hasNext()) {
+               EncodingNode *en = nit->next();
+               for(uint i=0; i < en->getSize(); i++){
+                       set2.add(en->getIndex(i));
+               }
+       }
+       delete nit;
+       SetIterator64Int *setIter1 = set1.iterator();
+       while(setIter1->hasNext()){
+               uint64_t item1 = setIter1->next();
+               if( set2.contains(item1)){
+                       common++;
+               }
+       }
+       delete setIter1;
+//     model_print("measureSimilarity:139: common=%u\tGraphSize1=%u\tGraphSize2=%u\tGraphSize1=%f\tGraphSize2=%f\n", common, set1.getSize(), set2.getSize(), 1.0*common/set1.getSize(), 1.0*common/set2.getSize());
+       return common*1.0/set1.getSize() + common*1.0/set2.getSize();
+}
+
 uint EncodingSubGraph::estimateNewSize(EncodingNode *n) {
        SetIteratorEncodingEdge *eeit = n->edges.iterator();
        uint newsize = n->getSize();