@@ -28,124 +28,20 @@ namespace SBG {
2828namespace LIB {
2929
3030// //////////////////////////////////////////////////////////////////////////////
31- // Cut-set algorithm -------------------------------------- ---------------------
31+ // Vertex Cut Set Algorithm Abstract Strategy Constructors ---------------------
3232// //////////////////////////////////////////////////////////////////////////////
3333
34- CutVertex::CutVertex (const DSBG &dsbg, bool debug)
35- : fact_(dsbg.fact()), dsbg_(dsbg), debug_(debug) {}
34+ CVStrategy::CVStrategy () {}
3635
37- member_imp (CutVertex, DSBG, dsbg);
38- member_imp (CutVertex, bool , debug);
36+ // //////////////////////////////////////////////////////////////////////////////
37+ // Vertex Cut Set Algorithm Interface ------------------------------------------
38+ // //////////////////////////////////////////////////////////////////////////////
3939
40- PWMap CutVertex::getDegMap (const DSBG &dsbg)
41- {
42- Set V = dsbg.V ();
43- PWMap mapB = dsbg.mapB (), mapD = dsbg.mapD ();
44-
45- auto dims = V.arity ();
46- MD_NAT zero (dims, 0 ), one (dims, 1 );
47- PWMap dmap = fact_.createPWMap (fact_.createMap (V, Exp (zero)));
48-
49- for (const Map &SE : dsbg.subEmap ()) {
50- Set dom = SE.dom ();
51- MD_NAT n (dims, dom.cardinal ());
52- Set vsB = mapB.image (dom), vsD = mapD.image (dom);
53- if (vsB.cardinal () == 1 ) {
54- PWMap ith = dmap.restrict (vsD).offsetImage (n);
55- dmap = ith.combine (dmap);
56- ith = dmap.restrict (vsB).offsetImage (one);
57- dmap = ith.combine (dmap);
58- }
59- else if (vsD.cardinal () == 1 ) {
60- PWMap ith = dmap.restrict (vsB).offsetImage (n);
61- dmap = ith.combine (dmap);
62- ith = dmap.restrict (vsD).offsetImage (one);
63- dmap = ith.combine (dmap);
64- }
65- else {
66- PWMap ith = dmap.restrict (vsB.cup (vsD)).offsetImage (one);
67- dmap = ith.combine (dmap);
68- }
69- }
70-
71- return dmap;
72- }
40+ CutVertex::CutVertex (CVStratPtr strat) : strategy_(std::move(strat)) {}
7341
74- Set CutVertex::calculate ()
42+ Set CutVertex::calculate (const DSBG& dsbg) const
7543{
76- auto begin = std::chrono::high_resolution_clock::now ();
77- DSBG dg = dsbg ();
78- PWMap Vmap = dg.Vmap (), mapB = dg.mapB (), mapD = dg.mapD ();
79- PWMap rmap = SCC (dg, debug ()).calculate ();
80- Set newD = fact_.createSet (), oldD = newD, visitedV = newD, V = dg.V ();
81- if (debug ())
82- Util::SBG_LOG << " initial dg vertex cut set:\n " << dg << " \n " ;
83-
84- PWMap dmap = getDegMap (dg);
85- // Degree map
86- if (debug ())
87- Util::SBG_LOG << " initial dmap: " << dmap << " \n\n " ;
88-
89- while (rmap.dom () != rmap.image ()) {
90- oldD = newD;
91-
92- MD_NAT aux = dmap.image ().maxElem ();
93- MD_NAT vmax = dmap.preImage (fact_.createSet (aux)).minElem ();
94- Set vmaxSV = Vmap.image (fact_.createSet (vmax));
95- newD = newD.cup (fact_.createSet (vmax));
96-
97- if (!visitedV.intersection (vmaxSV).isEmpty ()) {
98- MD_NAT vmaxD = newD.intersection (Vmap.preImage (vmaxSV)).minElem ();
99-
100- SetPiece mdi;
101- for (unsigned int j = 0 ; j < vmax.arity (); ++j) {
102- if (vmax[j] < vmaxD[j]) {
103- NAT st = vmaxD[j] - vmax[j];
104- NAT beg = vmax[j] % st;
105- mdi.emplaceBack (Interval (beg, st, vmax[j]));
106- }
107-
108- else
109- mdi.emplaceBack (Interval (vmaxD[j], vmax[j] - vmaxD[j], Inf));
110- }
111- if (debug ()) {
112- Util::SBG_LOG << " vmax: " << vmax << " \n " ;
113- Util::SBG_LOG << " vmaxD: " << vmaxD << " \n " ;
114- Util::SBG_LOG << " mdi: " << mdi << " \n\n " ;
115- }
116- Set mdi_set = fact_.createSet (mdi);
117- newD = newD.cup (mdi_set.intersection (Vmap.preImage (vmaxSV)));
118- }
119-
120- // Update graph info erasing newD vertices
121- visitedV = visitedV.cup (vmaxSV);
122- dg = dg.eraseVertices (newD);
123- Vmap = dg.Vmap ();
124- mapB = dg.mapB ();
125- mapD = dg.mapD ();
126-
127- // Update degree map
128- dmap = getDegMap (dg);
129-
130- // Resulting SCC from induced graph
131- rmap = SCC (dg, debug ()).calculate ();
132-
133- if (debug ()) {
134- Util::SBG_LOG << " oldD: " << oldD << " \n " ;
135- Util::SBG_LOG << " newD: " << newD << " \n " ;
136- Util::SBG_LOG << " resulting graph:\n " << dg << " \n " ;
137- Util::SBG_LOG << " new degree map: " << dmap << " \n " ;
138- Util::SBG_LOG << " new rmap: " << rmap << " \n\n " ;
139- }
140- }
141- auto end = std::chrono::high_resolution_clock::now ();
142-
143- auto total = std::chrono::duration_cast<std::chrono::microseconds>(
144- end - begin
145- );
146- Util::SBG_LOG << " Total vertex cut set exec time: " << total.count () << " [μs]\n\n " ;
147-
148- return newD.compact ();
44+ return strategy_->calculate (dsbg);
14945}
15046
15147} // namespace LIB
0 commit comments