diff --git a/sbg/pw_map.cpp b/sbg/pw_map.cpp index 96a8b25..9d73d9f 100755 --- a/sbg/pw_map.cpp +++ b/sbg/pw_map.cpp @@ -667,14 +667,13 @@ PWMap PWMap::minMap(const PWMap &other) const } template -PWMap PWMap::minAdjMap(const PWMap &other2, const PWMap &other3) const +PWMap PWMap::minAdjMap( + const PWMap &other2, const PWMap &other3, const PWMap &other4 +) const { PWMap res; - Set partitioned_dom3 = other3.preImage(other3.image()); - Set partitioned_dom = other2.preImage(partitioned_dom3); - partitioned_dom = dom().intersection(partitioned_dom); - partitioned_dom = other2.dom().intersection(partitioned_dom); + Set partitioned_dom = dom().intersection(other2.dom()); Set visited; for (const SetPiece &mdi : partitioned_dom) { @@ -699,18 +698,11 @@ PWMap PWMap::minAdjMap(const PWMap &other2, const PWMap &other3) const e_res = map2.exp().composition(e1.inverse()); else { - for (const Map &map3 : other3) { - Set dom3 = map3.dom(), s3 = dom3.intersection(im2); - if (!s3.isEmpty()) { - if (!map3.exp().isConstant()) { - Set min3(map3.image(s3).minElem()); - MD_NAT min2 = map3.preImage(min3).minElem(); - e_res = MDLExp(min2); - } - - else e_res = MDLExp(im2.minElem()); - } - } + Set min3(other3.image(im2).minElem()); + Set mins2 = other3.preImage(min3); + MD_NAT min4 = other4.image(mins2).minElem(); + MD_NAT min2 = other4.preImage(min4).minElem(); + e_res = MDLExp(min2); } } } @@ -734,6 +726,20 @@ PWMap PWMap::minAdjMap(const PWMap &other2, const PWMap &other3) const return res; } +template +PWMap PWMap::minAdjMap(const PWMap &other2, const PWMap &other3) const +{ + if (!other2.isEmpty()) { + Exp id(other2.nmbrDims(), LExp()); + Map aux4(other2.image(), id); + PWMap id_map4(aux4); + + return minAdjMap(other2, other3, id_map4); + } + + return PWMap(); +} + template PWMap PWMap::minAdjMap(const PWMap &other) const { diff --git a/sbg/pw_map.hpp b/sbg/pw_map.hpp index 593c858..891a218 100755 --- a/sbg/pw_map.hpp +++ b/sbg/pw_map.hpp @@ -142,7 +142,8 @@ struct PWMap { ) const; PWMap minMap(const PWMap &other) const; - PWMap minAdjMap(const PWMap &other1, const PWMap &other2) const; + PWMap minAdjMap(const PWMap &other2, const PWMap &other3, const PWMap &other4) const; + PWMap minAdjMap(const PWMap &other2, const PWMap &other3) const; PWMap minAdjMap(const PWMap &other) const; /** @function firstInv diff --git a/sbg/sbg_algorithms.cpp b/sbg/sbg_algorithms.cpp index 9803a86..9a748b8 100755 --- a/sbg/sbg_algorithms.cpp +++ b/sbg/sbg_algorithms.cpp @@ -113,90 +113,6 @@ MinReach::MinReach(DSBGraph sbg, bool debug) member_imp_temp(template, MinReach, DSBGraph, dsbg); member_imp_temp(template, MinReach, bool, debug); -template -PWMap MinReach::minReach1( - const Set &reach, const PW &smap, const PW &rmap -) const -{ - DSBGraph dg = dsbg_; - Set V = dg.V(); - PW mapB = dg.mapB(), mapD = dg.mapD(); - - PW auto_succs = smap.filterMap([](const SBGMap &sbgmap) { - return eqId(sbgmap); - }); - Set auto_reps = auto_succs.equalImage(rmap); - Set not_auto_succs = smap.filterMap([](const SBGMap &sbgmap) { - return notEqId(sbgmap); - }).dom(); - Set usable_verts = auto_reps.cup(not_auto_succs); - - PWMap auxB = mapB.restrict(reach), auxD = mapD.restrict(reach); - // Get minimum adjacent vertex with minimum representative - PWMap adj_smap = auxB.minAdjMap(auxD, rmap); - // Get minimum between current rep and adjacent reps - PWMap new_smap = rmap.minMap(adj_smap, smap.restrict(usable_verts), rmap); - // Update rep iff new is less than current - new_smap = updateMap(V, smap, new_smap, rmap); - new_smap = new_smap.combine(adj_smap); - new_smap = new_smap.combine(smap); - - return new_smap; -} - -// Handle recursion -template -PathInfo MinReach::recursion( - unsigned int n, const Set &ER, const Set &rv - , const PW &smap, const PW &rmap -) const -{ - PW mapB = dsbg().mapB(), mapD = dsbg().mapD() - , Vmap = dsbg().Vmap(), Emap = dsbg().Emap(), subE_map = dsbg().subE_map(); - PW ERB = mapB.restrict(ER), ERD = mapD.restrict(ER); - - Set start = ERB.image(); - start = start.difference(ERD.image()); - Set first = Vmap.image(start); - - Set ER_plus = Emap.preImage(Emap.image(ER)); - Set VR_plus = mapB.image(ER_plus).cup(mapD.image(ER_plus)); - - PW new_smap, Dmap; - Set repeated = start.intersection(first); - for (unsigned int j = 0; j < n+1; ++j) { - // Vertices in the same set vertex as start - Set side = VR_plus.intersection(Vmap.preImage(Vmap.image(start))); - // Get edges orientated in the correct direction that are part of the - // recursion - Set ER_start = mapB.preImage(start).intersection(ER); - // Get edges in the same sub-set edge - Set ER_plus_start = subE_map.preImage(subE_map.image(ER_start)); - ER_plus_start = ER_plus_start.intersection(mapB.preImage(side)); - - PW sideB = mapB.restrict(ER_plus_start) - , sideD = mapD.restrict(ER_plus_start); - // Get successor in recursion - PW ith = sideD.composition(sideB.inverse()); - new_smap = ith.combine(new_smap); - - start = smap.image(start); - // Check if an already visited set-vertex is visited again - repeated = Vmap.image(start).intersection(first); - } - - // Solve recursion - Set endings = mapD.image(ER_plus).difference(mapB.image(ER_plus)); - PW smap_endings(endings); - new_smap = smap_endings.combine(new_smap); - new_smap = new_smap.restrict(VR_plus); - PW rmap_plus = rmap.composition(new_smap.mapInf(n-1)); - PW new_rmap = rmap.minMap(rmap_plus); - new_rmap = new_rmap.combine(rmap); - - return PathInfo(new_smap, new_rmap); -} - template PathInfo MinReach::calculate( const Set &starts, const Set &endings diff --git a/sbg/sbg_algorithms.hpp b/sbg/sbg_algorithms.hpp index 0f9d3d1..01ab149 100755 --- a/sbg/sbg_algorithms.hpp +++ b/sbg/sbg_algorithms.hpp @@ -69,11 +69,6 @@ struct MinReach { MinReach(DSBGraph dsbg, bool debug); PI calculate(const Set &starts, const Set &endings) const; - - private: - PW minReach1(const Set &reach, const PW &smap, const PW &rmap) const; - PI recursion(unsigned int n, const Set &ER, const Set ¬_rv - , const PW &smap, const PW &rmap) const; }; typedef MinReach BaseMR;