Skip to content

Commit 8543bc0

Browse files
committed
Small changes
1 parent ff95518 commit 8543bc0

7 files changed

Lines changed: 80 additions & 63 deletions

File tree

algorithms/scc/minreach_scc.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,12 @@ SCCData MinReachSCC::calculate(const DSBG& dsbg)
7070
PWMap rmap = PW_FACT.createPWMap();
7171
Set Ediff = SET_FACT.createSet();
7272
Set oldE = dsbg.E();
73+
Set deleted_edges = SET_FACT.createSet();
7374
do {
7475
oldE = dsbg_.E();
7576
rmap = sccStep();
7677
Ediff = oldE.difference(dsbg_.E());
78+
deleted_edges = deleted_edges.disjointCup(Ediff);
7779
} while (Ediff != SET_FACT.createSet());
7880
rmap = rmap.compact();
7981
auto end = std::chrono::high_resolution_clock::now();
@@ -85,7 +87,7 @@ SCCData MinReachSCC::calculate(const DSBG& dsbg)
8587

8688
Util::DEBUG_LOG << "MinReachSCC result: " << rmap << "\n\n";
8789

88-
return SCCData(dsbg, rmap, Ediff);
90+
return SCCData(dsbg, rmap, deleted_edges);
8991
}
9092

9193
////////////////////////////////////////////////////////////////////////////////

sbg/dom_ord_pwmap.cpp

Lines changed: 36 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,6 @@ PWMapStratPtr DomOrdPWMap::inverse() const
341341
Internal::emplaceBack(res, inv);
342342
}
343343
}
344-
345344
std::sort(res.begin(),res.end(), operator<);
346345

347346
return std::make_unique<DomOrdPWMap>(res);
@@ -353,29 +352,28 @@ PWMapStratPtr DomOrdPWMap::composition(const PWMapStrategy& other) const
353352
DomOrdPWMapCRef othr = static_cast<DomOrdPWMapCRef>(other);
354353

355354
NAT global_pos = 0;
356-
for (const MapEntry& o_mpe : othr.pieces_) {
357-
const auto& o_m = o_mpe.first;
358-
auto img = o_m.image();
355+
for (const MapEntry& other_mpe : othr.pieces_) {
356+
const Map& other_map = other_mpe.first;
357+
Set img = other_map.image();
359358

360-
SetPerimeter i_sp = calculatePerimeter(img);
361-
auto i_max_per = i_sp.second;
362-
363-
advanceHint(res, o_mpe.second.first, global_pos);
364-
365-
for (const MapEntry& t_mpe : pieces_) {
366-
const auto& t_m = t_mpe.first;
367-
const SetPerimeter& t_sp = t_mpe.second;
368-
auto t_min_per = t_sp.first;
359+
SetPerimeter image_sp = calculatePerimeter(img);
360+
MD_NAT image_max = image_sp.second;
361+
advanceHint(res, other_mpe.second.first, global_pos);
362+
363+
for (const MapEntry& this_mpe : pieces_) {
364+
const Map& this_map = this_mpe.first;
365+
const SetPerimeter& this_sp = this_mpe.second;
366+
MD_NAT this_min = this_sp.first;
369367

370-
if (doInt(t_sp, i_sp)) {
371-
auto res_com = t_m.composition(o_m);
372-
if (!res_com.isEmpty()) {
373-
emplaceHint(res, res_com, global_pos);
368+
if (doInt(this_sp, image_sp)) {
369+
Map composition = this_map.composition(other_map);
370+
if (!composition.isEmpty()) {
371+
emplaceHint(res, composition, global_pos);
374372
}
375373
continue;
376374
}
377375

378-
if (i_max_per < t_min_per) {
376+
if (image_max < this_min) {
379377
break;
380378
}
381379
}
@@ -455,7 +453,6 @@ PWMapStratPtr DomOrdPWMap::concatenation(const PWMapStrategy& other) const
455453

456454
auto it1 = pieces_.begin(), it2 = othr.pieces_.begin();
457455
auto end1 = pieces_.end(), end2 = othr.pieces_.end();
458-
459456

460457
for (; it1 != end1 && it2 != end2;) {
461458
auto min_per_m1 = it1->second.first;
@@ -490,26 +487,25 @@ PWMapStratPtr DomOrdPWMap::combine(const PWMapStrategy& other) const
490487
OrdMapCollection res = pieces_;
491488

492489
NAT global_pos = 0;
493-
494-
SetPerimeter t_sp = calculatePerimeter(dom());
495-
496-
for (const MapEntry& o_mpe : othr.pieces_) {
497-
const Map& o_m = o_mpe.first;
498-
const SetPerimeter& o_sp = o_mpe.second;
499-
Map res_comb(o_m.dom(), o_m.exp());
500-
501-
if (doInt(o_sp, t_sp)){
502-
Set dom_o_m = o_m.dom(), new_dom = dom_o_m.difference(dom());
503-
if (new_dom.isEmpty())
490+
SetPerimeter this_sp = calculatePerimeter(dom());
491+
for (const MapEntry& other_mpe : othr.pieces_) {
492+
const Map& other_map = other_mpe.first;
493+
const SetPerimeter& other_sp = other_mpe.second;
494+
495+
// There is intersection of domains
496+
Map exclusive_other(other_map.dom(), other_map.exp());
497+
if (doInt(other_sp, this_sp)) {
498+
Set new_dom = other_map.dom().difference(dom());
499+
if (new_dom.isEmpty()) {
504500
continue;
505-
res_comb = Map(new_dom, o_m.exp());
501+
}
502+
exclusive_other = Map(new_dom, other_map.exp());
506503
}
507-
508-
advanceHint(res, o_sp.first, global_pos);
509-
emplaceHint(res, res_comb, global_pos);
504+
advanceHint(res, other_sp.first, global_pos);
505+
emplaceHint(res, exclusive_other, global_pos);
510506
}
511507

512-
return std::make_unique<DomOrdPWMap>(res);
508+
return std::make_unique<DomOrdPWMap>(res);
513509
}
514510

515511
PWMapStratPtr DomOrdPWMap::reduce(const Interval& i, const LExp& le) const
@@ -596,23 +592,24 @@ PWMapStratPtr DomOrdPWMap::reduce(const Map& map) const
596592
if (!was_reduced)
597593
not_reduced.emplaceBack(dom_piece);
598594
}
599-
600-
if(!not_reduced.isEmpty())
601-
Internal::emplaceBack(res, Map(not_reduced, e)); // Add unreduced subpieces
595+
596+
// Add not reduced subpieces
597+
if (!not_reduced.isEmpty())
598+
Internal::emplaceBack(res, Map(not_reduced, e));
602599

603600
return std::make_unique<DomOrdPWMap>(res);
604601
}
605602

606603
PWMapStratPtr DomOrdPWMap::reduce() const
607604
{
608605
OrdMapCollection res;
606+
609607
for (const MapEntry& mpe : pieces_) {
610608
PWMapStratPtr ith = reduce(mpe.first);
611609
DomOrdPWMap *ith_c = static_cast<DomOrdPWMap *>(ith.get());
612610
for (const MapEntry& mpe_ith_elem : ith_c->pieces_)
613611
Internal::emplaceBack(res, mpe_ith_elem);
614612
}
615-
616613
std::sort(res.begin(), res.end(), operator<);
617614

618615
return std::make_unique<DomOrdPWMap>(res);
@@ -693,12 +690,10 @@ PWMapStratPtr DomOrdPWMap::firstInv(const Set& subdom) const
693690
const SetPerimeter& t_sp = t_mpe.second;
694691
auto t_min_per = t_sp.first;
695692

696-
697693
if (doInt(t_sp, short_sp)) {
698694
Set img = t_m.image(subdom);
699695

700696
if (!img.isEmpty()) {
701-
702697
if (!visited.isEmpty()) {
703698
SetPerimeter i_sp = calculatePerimeter(img);
704699
SetPerimeter v_sp = calculatePerimeter(visited);

sbg/multidim_lexp.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,13 @@ std::ostream &operator<<(std::ostream &out, const MDLExp &mdle)
8181
{
8282
unsigned int sz = mdle.arity();
8383

84+
out << "|";
8485
if (sz > 0) {
8586
for (unsigned int j = 0; j < sz-1; ++j)
8687
out << mdle[j] << "|";
8788
out << mdle[sz-1];
8889
}
90+
out << "|";
8991

9092
return out;
9193
}

sbg/ord_pwmap.cpp

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -714,28 +714,12 @@ Set OrdPWMap::equalImage(const PWMapStrategy& other) const
714714
{
715715
Set set_in = SET_FACT.createSet();
716716
Set set_out = SET_FACT.createSet();
717-
OrdMapCollection no_used;
718-
processMapsOrd(other, set_in, set_out, no_used, &OrdPWMap::processEqualImage
717+
OrdMapCollection unused;
718+
processMapsOrd(other, set_in, set_out, unused, &OrdPWMap::processEqualImage
719719
, false);
720720
return set_out;
721721
}
722722

723-
Set OrdPWMap::lessImage(const PWMapStrategy& other) const
724-
{
725-
if (isEmpty() || other.isEmpty())
726-
return SET_FACT.createSet();
727-
728-
OrdPWMapCRef othr = static_cast<OrdPWMapCRef>(other);
729-
Set min_in_pw1 = SET_FACT.createSet();
730-
for (const MapEntry& me1 : pieces_) {
731-
for (const MapEntry& me2 : othr.pieces_) {
732-
min_in_pw1 = min_in_pw1.disjointCup(me1.first.lessImage(me2.first));
733-
}
734-
}
735-
736-
return min_in_pw1;
737-
}
738-
739723
void OrdPWMap::processEqualImage(const Map& m1, const Map& m2,
740724
Set& set_in, Set& set_out,
741725
OrdMapCollection& ord_pwmap,
@@ -750,6 +734,24 @@ void OrdPWMap::processEqualImage(const Map& m1, const Map& m2,
750734
}
751735
}
752736

737+
Set OrdPWMap::lessImage(const PWMapStrategy& other) const
738+
{
739+
Set set_in = SET_FACT.createSet();
740+
Set set_out = SET_FACT.createSet();
741+
OrdMapCollection unused;
742+
processMapsOrd(other, set_in, set_out, unused, &OrdPWMap::processLessImage
743+
, true);
744+
return set_out;
745+
}
746+
747+
void OrdPWMap::processLessImage(const Map& m1, const Map& m2,
748+
Set& set_in, Set& set_out,
749+
OrdMapCollection& ord_pwmap,
750+
NAT global_pos) const
751+
{
752+
set_out = set_out.disjointCup(m1.lessImage(m2));
753+
}
754+
753755
void OrdPWMap::processMapsOrd(
754756
const PWMapStrategy& other,
755757
Set& set_in,

sbg/ord_pwmap.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,17 @@ struct OrdPWMap : public PWMapStrategy {
159159
Set& set_out,
160160
OrdMapCollection& ord_pwmap,
161161
NAT global_pos) const;
162+
163+
/**
164+
* @brief Calculates the lessImage core, which contains the entire main process of the function.
165+
*/
166+
void processLessImage(
167+
const Map& m1,
168+
const Map& m2,
169+
Set& set_in,
170+
Set& set_out,
171+
OrdMapCollection& ord_pwmap,
172+
NAT global_pos) const;
162173

163174
/**
164175
* @brief Type used in the 'processMapsOrd' declaration to reduce its size.

test/err.test

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
//dims = 2;
1+
dims = 2;
2+
3+
pw1 = <<{[1:100]x[1:100], [101:200]x[101:200], [201:300]x[201:300]} -> |x|x|, {[301:400]x[301:400], [401:500]x[401:500], [501:600]x[501:600]} -> |x+1|x+1|, {[601:700]x[601:700], [701:800]x[701:800], [801:900]x[801:900]} -> |x+2|x+2|>>;
24

35
//{[1:10]x[1:10], [11:20]x[1:5], [11:20]x[6:10], [30:34]x[20:30], [35:40]x[20:30], [30:40]x[21:29]};
46
//{[1:1:5]x[1:1:5], [6:1:10]x[1:1:5], [1:1:5]x[6:1:10], [6:1:10]x[6:1:10]};
@@ -9,3 +11,6 @@
911
//restrict(<<>>, {[10001:10001]});
1012
//<<{[800000:18446744073709551615]} -> |0|, {[0:799999]} -> |(-1)*x+799999|>>;
1113
//restrict(<<{[800000:18446744073709551615]} -> |0|, {[0:799999]} -> |N*x+799999|>>, {[100001:100001]});
14+
15+
// Examples for issue 111
16+
reduce(pw1);

test/performance/pw_map_perf.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,7 @@ TEST(PWMapPerf, UnordCompact)
729729
pw.compact();
730730
auto end = std::chrono::high_resolution_clock::now();
731731
auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
732-
std::cout << "PWL MAP ORDERED COMPACT TEST elapsed time: " << elapsed.count() << "ms\n";
732+
std::cout << "PWL MAP UNORDERED COMPACT TEST elapsed time: " << elapsed.count() << "ms\n";
733733

734734
SUCCEED();
735735
}
@@ -1040,7 +1040,7 @@ TEST(PWMapPerf, OrdEqualImage)
10401040
pw.equalImage(pw2);
10411041
auto end = std::chrono::high_resolution_clock::now();
10421042
auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
1043-
std::cout << "PWL MAP UNORDERED EQUALIMAGE TEST elapsed time: " << elapsed.count() << "ms\n";
1043+
std::cout << "PWL MAP ORDERED EQUALIMAGE TEST elapsed time: " << elapsed.count() << "ms\n";
10441044

10451045
SUCCEED();
10461046
}

0 commit comments

Comments
 (0)