Skip to content

Commit

Permalink
New minAdj version [to be tested]
Browse files Browse the repository at this point in the history
  • Loading branch information
Kalashnikovni committed May 7, 2024
1 parent 202cefd commit be4beec
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 107 deletions.
40 changes: 23 additions & 17 deletions sbg/pw_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -667,14 +667,13 @@ PWMap<Set> PWMap<Set>::minMap(const PWMap &other) const
}

template<typename Set>
PWMap<Set> PWMap<Set>::minAdjMap(const PWMap &other2, const PWMap &other3) const
PWMap<Set> PWMap<Set>::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) {
Expand All @@ -699,18 +698,11 @@ PWMap<Set> PWMap<Set>::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);
}
}
}
Expand All @@ -734,6 +726,20 @@ PWMap<Set> PWMap<Set>::minAdjMap(const PWMap &other2, const PWMap &other3) const
return res;
}

template<typename Set>
PWMap<Set> PWMap<Set>::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<typename Set>
PWMap<Set> PWMap<Set>::minAdjMap(const PWMap &other) const
{
Expand Down
3 changes: 2 additions & 1 deletion sbg/pw_map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
84 changes: 0 additions & 84 deletions sbg/sbg_algorithms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,90 +113,6 @@ MinReach<Set>::MinReach(DSBGraph<Set> sbg, bool debug)
member_imp_temp(template<typename Set>, MinReach<Set>, DSBGraph<Set>, dsbg);
member_imp_temp(template<typename Set>, MinReach<Set>, bool, debug);

template<typename Set>
PWMap<Set> MinReach<Set>::minReach1(
const Set &reach, const PW &smap, const PW &rmap
) const
{
DSBGraph<Set> dg = dsbg_;
Set V = dg.V();
PW mapB = dg.mapB(), mapD = dg.mapD();

PW auto_succs = smap.filterMap([](const SBGMap<Set> &sbgmap) {
return eqId(sbgmap);
});
Set auto_reps = auto_succs.equalImage(rmap);
Set not_auto_succs = smap.filterMap([](const SBGMap<Set> &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<typename Set>
PathInfo<Set> MinReach<Set>::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<Set>(new_smap, new_rmap);
}

template<typename Set>
PathInfo<Set> MinReach<Set>::calculate(
const Set &starts, const Set &endings
Expand Down
5 changes: 0 additions & 5 deletions sbg/sbg_algorithms.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,6 @@ struct MinReach {
MinReach(DSBGraph<Set> 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 &not_rv
, const PW &smap, const PW &rmap) const;
};

typedef MinReach<UnordSet> BaseMR;
Expand Down

0 comments on commit be4beec

Please sign in to comment.