Ticket #682: vf2Fix.patch
File vf2Fix.patch, 7.5 KB (added by , 6 months ago) |
---|
-
lemon/vf2.h
# HG changeset patch # User Peter Madarasi <madarasi@cs.elte.hu> # Date 1715881419 -7200 # Thu May 16 19:43:39 2024 +0200 # Node ID 7929660eaed36cd926a6b0a43266d2f375250569 # Parent a278d16bd2d082aa3c52ff4a9b0e2224ddc0549a Bugfix in Vf2 and Vf2++; extend tests diff -r a278d16bd2d0 -r 7929660eaed3 lemon/vf2.h
a b 98 98 class NEQ = bits::vf2::AlwaysEq > 99 99 #endif 100 100 class Vf2 { 101 template<class T> 102 friend class Vf2Wizard; 103 101 104 //The graph to be embedded 102 105 const G1 &_g1; 103 106 -
lemon/vf2pp.h
diff -r a278d16bd2d0 -r 7929660eaed3 lemon/vf2pp.h
a b 66 66 class M2 = typename G2::template NodeMap<int> > 67 67 #endif 68 68 class Vf2pp { 69 template<class T> 70 friend class Vf2ppWizard; 71 69 72 //The graph to be embedded 70 73 const G1 &_g1; 71 74 … … 119 122 //indicates whether the mapping or the labels must be deleted in the destructor 120 123 bool _deallocMappingAfterUse,_deallocLabelsAfterUse; 121 124 122 123 125 //improved cutting function 124 126 template<MappingType MT> 125 127 bool cutByLabels(const typename G1::Node n1,const typename G2::Node n2) { … … 776 778 if(Base::_local_mapping) 777 779 ptr->_deallocMappingAfterUse=true; 778 780 if(Base::_local_nodeLabels) 779 ptr->_deallocLabel MapsAfterUse=true;781 ptr->_deallocLabelsAfterUse=true; 780 782 781 783 return ptr; 782 784 } -
test/vf2_test.cc
diff -r a278d16bd2d0 -r 7929660eaed3 test/vf2_test.cc
a b 292 292 293 293 succ = vf2pp(g,h).nodeLabels(c1_IntConv,c2_IntConv).mapping(r).run(); 294 294 succ = vf2pp(g,h).nodeLabels(c1_IntConv,c2_IntConv).mapping(r).run(); 295 296 auto* vf2ppPtr = vf2pp(g, h).mapping(r).nodeLabels(c1, c2).induced() 297 .getPtrToVf2ppObject(); 295 298 } 296 299 297 300 void vf2ppCompile() { … … 373 376 } 374 377 375 378 template<class G1,class G2,class L1,class L2,class T> 376 bool checkSub(const G1 &g1, const G2 &g2, const L1 &l1, const L2 &l2, const T &vf2) { 379 bool checkSub(const G1 &g1, const G2 &g2, const L1 &l1, const L2 &l2, 380 const T &vf2) { 377 381 typename G1:: template NodeMap<typename G2::Node> iso(g1,INVALID); 378 382 if (const_cast<T&>(vf2).nodeLabels(l1,l2).mapping(iso).run()){ 379 383 checkSubIso(g1,g2,iso); … … 402 406 } 403 407 404 408 template<class G1,class G2,class L1,class L2> 405 void checkSub(const G1 &g1, const G2 &g2, const L1 &l1, const L2 &l2, bool expected, const char* msg) { 409 void checkSub(const G1 &g1, const G2 &g2, const L1 &l1, const L2 &l2, 410 bool expected, const char* msg) { 406 411 check(checkSub(g1,g2,l1,l2,vf2(g1,g2)) == expected, msg); 407 412 check(checkSub(g1,g2,l1,l2,vf2pp(g1,g2)) == expected, msg); 408 413 } 409 414 415 416 template<class G1,class G2> 417 void checkSubCount(const G1 &g1, const G2 &g2, int expected, const char* msg) { 418 check(vf2(g1,g2).count() == expected, msg); 419 check(vf2pp(g1,g2).count() == expected, msg); 420 { 421 auto* vf2ppPtr = vf2pp(g1, g2).getPtrToVf2ppObject(); 422 int cnt = 0; 423 while(vf2ppPtr->find()) 424 ++cnt; 425 check(cnt == expected, msg); 426 } 427 { 428 auto* vf2Ptr = vf2(g1, g2).getPtrToVf2Object(); 429 int cnt = 0; 430 while(vf2Ptr->find()) 431 ++cnt; 432 check(cnt == expected, msg); 433 } 434 } 435 436 template<class G1,class G2> 437 void checkIndCount(const G1 &g1, const G2 &g2, int expected, const char* msg) { 438 check(vf2(g1,g2).induced().count() == expected, msg); 439 check(vf2pp(g1,g2).induced().count() == expected, msg); 440 { 441 typename G1::NodeMap<char> l1(g1,0); 442 typename G2::NodeMap<char> l2(g2,0); 443 typename G1::NodeMap<typename G1::Node> m(g1); 444 auto* vf2ppPtr = vf2pp(g1, g2).induced().mapping(m).nodeLabels(l1,l2) 445 .getPtrToVf2ppObject(); 446 int cnt = 0; 447 while(vf2ppPtr->find()) 448 ++cnt; 449 check(cnt == expected, msg); 450 } 451 { 452 typename G1::NodeMap<char> l1(g1,0); 453 typename G2::NodeMap<char> l2(g2,0); 454 typename G1::NodeMap<typename G1::Node> m(g1); 455 auto* vf2Ptr = vf2(g1, g2).induced().mapping(m).nodeLabels(l1,l2) 456 .getPtrToVf2Object(); 457 int cnt = 0; 458 while(vf2Ptr->find()) 459 ++cnt; 460 check(cnt == expected, msg); 461 } 462 } 463 464 template<class G1,class G2> 465 void checkIsoCount(const G1 &g1, const G2 &g2, int expected, const char* msg) { 466 check(vf2(g1,g2).iso().count() == expected, msg); 467 check(vf2pp(g1,g2).iso().count() == expected, msg); 468 { 469 auto* vf2ppPtr = vf2pp(g1, g2).iso().getPtrToVf2ppObject(); 470 int cnt = 0; 471 while(vf2ppPtr->find()) 472 ++cnt; 473 check(cnt == expected, msg); 474 } 475 { 476 auto* vf2Ptr = vf2(g1, g2).iso().getPtrToVf2Object(); 477 int cnt = 0; 478 while(vf2Ptr->find()) 479 ++cnt; 480 check(cnt == expected, msg); 481 } 482 } 483 410 484 int main() { 411 485 make_graphs(); 412 486 413 487 checkSub(c5,petersen,true, 414 488 "There should exist a C5->Petersen mapping."); 489 checkSubCount(c5,petersen,120, 490 "There should exist 120 Petersen->Petersen mappings."); 415 491 checkSub(c7,petersen,false, 416 492 "There should not exist a C7->Petersen mapping."); 417 493 checkSub(p10,petersen,true, 418 494 "There should exist a P10->Petersen mapping."); 495 checkSubCount(p10,petersen,240, 496 "There should exist 240 Petersen->Petersen mappings."); 419 497 checkSub(c10,petersen,false, 420 498 "There should not exist a C10->Petersen mapping."); 421 499 checkSub(petersen,petersen,true, 422 500 "There should exist a Petersen->Petersen mapping."); 501 checkSubCount(petersen,petersen,120, 502 "There should exist 120 Petersen->Petersen mappings."); 423 503 424 504 checkInd(c5,petersen,true, 425 "There should exist a C5->Petersen spanned mapping."); 505 "There should exist a C5->Petersen induced mapping."); 506 checkIndCount(c5,petersen,120, 507 "There should exist 120 C5->Petersen induced mappings."); 426 508 checkInd(c7,petersen,false, 427 "There should exist a C7->Petersen spanned mapping.");509 "There should exist a C7->Petersen induced mapping."); 428 510 checkInd(p10,petersen,false, 429 "There should not exist a P10->Petersen spanned mapping.");511 "There should not exist a P10->Petersen induced mapping."); 430 512 checkInd(c10,petersen,false, 431 "There should not exist a C10->Petersen spanned mapping.");513 "There should not exist a C10->Petersen induced mapping."); 432 514 checkInd(petersen,petersen,true, 433 "There should exist a Petersen->Petersen spanned mapping."); 515 "There should exist a Petersen->Petersen induced mapping."); 516 checkIndCount(petersen,petersen,120, 517 "There should exist 120 Petersen->Petersen induced mappings."); 434 518 435 519 checkSub(petersen,c10,false, 436 520 "There should not exist a Petersen->C10 mapping."); 437 521 checkSub(p10,c10,true, 438 522 "There should exist a P10->C10 mapping."); 523 checkSubCount(p10,c10,20, 524 "There should exist 20 P10->C10 mappings."); 439 525 checkInd(p10,c10,false, 440 "There should not exist a P10->C10 spanned mapping.");526 "There should not exist a P10->C10 induced mapping."); 441 527 checkSub(c10,p10,false, 442 528 "There should not exist a C10->P10 mapping."); 443 529 … … 446 532 checkIso(c10,c10,true, 447 533 "C10 and C10 are isomorphic."); 448 534 535 checkSubCount(c10,c10,20, 536 "There should exists 20 C10 -> C10 mappings."); 537 checkIndCount(c10,c10,20, 538 "There should exists 20 C10 -> C10 induced mappings."); 539 checkIsoCount(c10,c10,20, 540 "There should exists 20 C10 -> C10 iso mappings."); 541 449 542 checkSub(c5,petersen,c5_col,petersen_col1,false, 450 543 "There should exist a C5->Petersen mapping."); 451 544 checkSub(c5,petersen,c5_col,petersen_col2,true,