@@ -37,6 +37,13 @@ bool BFSMatching::ExitCondition::full_match() { return full_match_; }
3737
3838bool BFSMatching::ExitCondition::found_paths () { return found_paths_; }
3939
40+ bool BFSMatching::ExitCondition::isSatisfied ()
41+ {
42+ return full_match_ || !found_paths_;
43+ }
44+
45+ // Algorithm -------------------------------------------------------------------
46+
4047BFSMatching::BFSMatching () : M_(SET_FACT.createSet()), dsbg_()
4148 , direction_(Direction::kForward ) {}
4249
@@ -157,31 +164,37 @@ BFSMatching::ExitCondition BFSMatching::step(const Set& right_vertices)
157164 // Calculate exit conditions
158165 Set matchedU = dsbg_.mapD ().image (M_);
159166 bool full_match = right_vertices.difference (matchedU).isEmpty ();
160- bool found_paths = !M_ .isEmpty ();
167+ bool found_paths = !augmenting_edges .isEmpty ();
161168
162169 return ExitCondition (full_match, found_paths);
163170}
164171
165- bool BFSMatching::ExitCondition::isSatisfied ( )
172+ void BFSMatching::init ( const BipartiteSBG& bsbg )
166173{
167- return full_match_ || !found_paths_ ;
168- }
174+ PWMap map1 = bsbg. map1 (). compact () ;
175+ PWMap map2 = bsbg. map2 (). compact ();
169176
170- void BFSMatching::init ( const SBG& sbg)
171- {
172- dsbg_ = DSBG (sbg. V (). compact (), sbg. Vmap (). compact (), sbg. map2 ()
173- , sbg. map1 (). compact (), sbg. Emap (). compact (), sbg. subEmap (). compact () );
177+ Set Y = bsbg. Y ();
178+ PWMap map1_toY = map1. restrict (map1. preImage (Y));
179+ PWMap map2_toY = map2. restrict (map2. preImage (Y));
180+ PWMap mapB = map1_toY. concatenation (map2_toY );
174181
175- return ;
182+ Set X = bsbg.X ();
183+ PWMap map1_toX = map1.restrict (map1.preImage (X));
184+ PWMap map2_toX = map2.restrict (map2.preImage (X));
185+ PWMap mapD = map1_toX.concatenation (map2_toX);
186+
187+ dsbg_ = DSBG (bsbg.V ().compact (), bsbg.Vmap ().compact (), mapB, mapD
188+ , bsbg.Emap ().compact (), bsbg.subEmap ().compact ());
176189}
177190
178- MatchData BFSMatching::calculate (const SBG& sbg )
191+ MatchData BFSMatching::calculate (const BipartiteSBG& bsbg )
179192{
180- Util::DEBUG_LOG << " Matching sbg : \n " << sbg << " \n\n " ;
193+ Util::DEBUG_LOG << " Matching bsbg : \n " << bsbg << " \n\n " ;
181194
182195 auto begin = std::chrono::high_resolution_clock::now ();
183- init (sbg );
184- Set right_vertices = dsbg_. mapB (). image ();
196+ init (bsbg );
197+ Set right_vertices = bsbg. Y ();
185198
186199 ExitCondition exit_cond (false , false );
187200 do {
@@ -192,7 +205,7 @@ MatchData BFSMatching::calculate(const SBG& sbg)
192205 end - begin);
193206 Util::SBG_LOG << " Total matching exec time: " << total.count () << " [μs]\n " ;
194207
195- MatchData result (sbg , M_.compact (), exit_cond.full_match ());
208+ MatchData result (bsbg , M_.compact (), exit_cond.full_match ());
196209 Util::SBG_LOG << result << " \n\n " ;
197210
198211 return result;
0 commit comments