Skip to content

Commit 294d963

Browse files
committed
[iss-45]
1 parent 3da928d commit 294d963

4 files changed

Lines changed: 799 additions & 397 deletions

File tree

sbg/map.cpp

Lines changed: 34 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -76,57 +76,27 @@ SetPiece image(SetPiece mdi, Exp mdle)
7676
}
7777

7878

79-
std::pair<MD_NAT, MD_NAT> calcularMinMaxPer(const Set dom) {
80-
MD_NAT maximo(dom.arity(), 0);
81-
MD_NAT minimo(dom.arity(), Inf);
82-
83-
for (const SetPiece &mdi : dom) {
84-
MD_NAT candidatoMax = mdi.maxElem();
85-
MD_NAT candidatoMin = mdi.minElem();
86-
87-
for (std::size_t i = 0; i < maximo.arity(); ++i) {
88-
maximo[i] = std::max(maximo[i], candidatoMax[i]);
89-
minimo[i] = std::min(minimo[i], candidatoMin[i]);
90-
}
91-
}
92-
93-
return { minimo, maximo };
94-
}
95-
9679

9780
////////////////////////////////////////////////////////////////////////////////
9881
// Map Implementation ----------------------------------------------------------
9982
////////////////////////////////////////////////////////////////////////////////
10083

10184
member_move_imp(Map, Set, dom);
10285
member_move_imp(Map, Exp, exp);
103-
member_move_imp(Map, MD_NAT, minPer);
104-
member_move_imp(Map, MD_NAT, maxPer);
86+
10587

10688

10789

10890
Map::~Map() {}
109-
Map::Map(const SetAF &fact) : fact_(fact), dom_(fact.createSet()) {}
91+
Map::Map(const SetAF &fact) : fact_(fact), dom_(fact.createSet()){}
11092
Map::Map(const SetAF &fact, MD_NAT x, Exp exp)
111-
: fact_(fact), dom_(fact.createSet(x)), exp_(exp), minPer_(), maxPer_()
112-
{
113-
std::tie(minPer_, maxPer_) = calcularMinMaxPer(dom_);
114-
}
93+
: fact_(fact), dom_(fact.createSet(x)), exp_(exp){}
11594
Map::Map(const SetAF &fact, Interval i, LExp le)
116-
: fact_(fact), dom_(fact.createSet(i)), exp_(Exp(le)), minPer_(), maxPer_()
117-
{
118-
std::tie(minPer_, maxPer_) = calcularMinMaxPer(dom_);
119-
}
95+
: fact_(fact), dom_(fact.createSet(i)), exp_(Exp(le)){}
12096
Map::Map(const SetAF &fact, SetPiece mdi, Exp exp)
121-
: fact_(fact), dom_(fact.createSet(mdi)), exp_(exp), minPer_(), maxPer_()
122-
{
123-
std::tie(minPer_, maxPer_) = calcularMinMaxPer(dom_);
124-
}
97+
: fact_(fact), dom_(fact.createSet(mdi)), exp_(exp){}
12598
Map::Map(const SetAF &fact, Set s, Exp exp)
126-
: fact_(fact), dom_(std::move(s)), exp_(exp), minPer_(), maxPer_()
127-
{
128-
std::tie(minPer_, maxPer_) = calcularMinMaxPer(dom_);
129-
}
99+
: fact_(fact), dom_(std::move(s)), exp_(exp){}
130100

131101
bool Map::operator==(const Map &other) const
132102
{
@@ -150,28 +120,24 @@ Map &Map::operator=(const Map &other)
150120
{
151121
dom_ = other.dom_;
152122
exp_ = other.exp_;
153-
minPer_ = other.minPer_;
154-
maxPer_ = other.maxPer_;
155123

156124
return *this;
157125
}
158126

159127
bool Map::operator<(const Map &other) const
160128
{
161129

162-
return minPer_ < other.minPer_;
130+
return minPer() < other.minPer();
163131
}
164132

165-
/*
166-
MD_NAT Map::minPerimeter() const
133+
134+
135+
MD_NAT Map::minPer() const
167136
{
168137
MD_NAT minimo(dom_.arity(), Inf);
169-
170138

171-
172139
if (dom_.isEmpty())
173140
return minimo;
174-
175141

176142
for (const SetPiece &mdi : dom_) {
177143
MD_NAT candidato = mdi.minElem();
@@ -180,16 +146,17 @@ MD_NAT Map::minPerimeter() const
180146
minimo[i] = std::min(minimo[i], candidato[i]);
181147
}
182148
}
183-
149+
184150
return minimo;
185151
}
186152

187-
MD_NAT Map::maxPerimeter() const
153+
MD_NAT Map::maxPer() const
188154
{
189155
MD_NAT maximo(dom_.arity(), 0);
190156

191157
if (dom_.isEmpty())
192158
return maximo;
159+
193160

194161
for (const SetPiece &mdi : dom_) {
195162
MD_NAT candidato = mdi.maxElem();
@@ -198,10 +165,10 @@ MD_NAT Map::maxPerimeter() const
198165
maximo[i] = std::max(maximo[i], candidato[i]);
199166
}
200167
}
201-
168+
202169
return maximo;
203170
}
204-
*/
171+
205172

206173
Map Map::operator+(const Map &other) const
207174
{
@@ -333,6 +300,25 @@ MaybeMap Map::compact(const Map &other) const
333300
return {};
334301
}
335302

303+
/*
304+
void Map::calcularMinMaxPer() {
305+
MD_NAT maximo(dom_.arity(), 0);
306+
MD_NAT minimo(dom_.arity(), Inf);
307+
308+
for (const SetPiece &mdi : dom_) {
309+
MD_NAT candidatoMax = mdi.maxElem();
310+
MD_NAT candidatoMin = mdi.minElem();
311+
312+
for (std::size_t i = 0; i < maximo.arity(); ++i) {
313+
maximo[i] = std::max(maximo[i], candidatoMax[i]);
314+
minimo[i] = std::min(minimo[i], candidatoMin[i]);
315+
}
316+
}
317+
318+
minPer_ = minimo;
319+
maxPer_ = maximo;
320+
}*/
321+
336322
} // namespace LIB
337323

338324
} // namespace SBG

sbg/map.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ struct Map {
5151
public:
5252
member_class(Set, dom);
5353
member_class(Exp, exp);
54-
member_class(MD_NAT, minPer);
55-
member_class(MD_NAT, maxPer);
5654

5755
~Map();
5856

@@ -88,10 +86,10 @@ struct Map {
8886
bool operator!=(const Map &other) const;
8987
Map &operator=(const Map &other);
9088
bool operator<(const Map &other) const;
91-
/*
92-
MD_NAT minPerimeter() const;
93-
MD_NAT maxPerimeter() const;
94-
*/
89+
90+
MD_NAT minPer() const;
91+
MD_NAT maxPer() const;
92+
9593
/**
9694
* @brief Calculates the sum of both maps for elements that belong to both
9795
* domains.
@@ -154,6 +152,8 @@ struct Map {
154152
* not, the result isn't a map, so no value is returned.
155153
*/
156154
MaybeMap compact(const Map &other) const;
155+
156+
//void calcularMinMaxPer();
157157
};
158158
std::ostream &operator<<(std::ostream &out, const Map &s);
159159

sbg/pw_map.cpp

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1391,24 +1391,42 @@ PWMapDelegPtr OrdPWMap::composition(const PWMapDelegate &other) const {
13911391
for (const Map &mO : othr.pieces_) {
13921392
const auto &img = mO.image();
13931393

1394+
//std::cout << "perimetro\n";
13941395
OrdAF fact;
13951396
Map imgMap(fact,img,Exp(img.arity(),LExp(0,0)));
13961397
const auto mOMin = imgMap.minPer();
13971398
const auto mOMax = imgMap.maxPer();
1399+
//std::cout << "perimetro fin\n";
13981400

1401+
//std::cout << "advance\n";
13991402
posGlobal = res.advanceHint(mO.minPer(), posGlobal);
1400-
1403+
//std::cout << "advance fin\n";
14011404
for (const Map &mT : pieces_) {
1405+
//std::cout << "perimetro 2 \n";
14021406
const auto mTMin = mT.minPer();
14031407
const auto mTMax = mT.maxPer();
1404-
1405-
if (mTMax[0] < mOMin[0]) continue;
1406-
if (mOMax[0] < mTMin[0]) break;
1407-
1408+
//std::cout << "perimetro 2 fin\n";
1409+
1410+
//std::cout << "comparizon \n";
1411+
//std::cout << mT <<"mapathis\n";
1412+
//std::cout << mTMin <<"minpthis\n";
1413+
//std::cout << mTMax <<"maxpthis\n";
1414+
//std::cout << mO <<"mapao\n";
1415+
//std::cout << mOMin <<"minpo\n";
1416+
//std::cout << mOMax <<"maxpo\n";
1417+
if (mTMax[0] < mOMin[0]){
1418+
//std::cout << "comparizon in 1 \n";
1419+
continue;}
1420+
if (mOMax[0] < mTMin[0]){
1421+
//std::cout << "comparizon in 2 \n";
1422+
break;}
1423+
//std::cout << "comparizon fin \n";
14081424
if (!(mTMax.menorThan(mOMin)) && !(mOMax.menorThan(mTMin))) {
14091425
auto resCom = mT.composition(mO);
14101426
if (!resCom.dom().isEmpty()) {
1427+
//std::cout << "empleace \n";
14111428
res.emplaceHint(resCom, posGlobal);
1429+
//std::cout << "empleace fin \n";
14121430
}
14131431
}
14141432
}
@@ -1423,7 +1441,7 @@ PWMapDelegPtr OrdPWMap::mapInf(unsigned int n) const
14231441

14241442
PWMapDelegPtr res = std::make_unique<OrdPWMap>(*this);
14251443
PWMapDelegPtr old_res = std::make_unique<OrdPWMap>(fact_);
1426-
std::cout << "valor de n\n" << n;
1444+
//std::cout << "valor de n\n" << n;
14271445
if (!dom().isEmpty()) {
14281446
for (unsigned int j = 0; old_res != res && j < n; ++j) {
14291447
OrdPWMap *rs = static_cast<OrdPWMap *>(res.get());
@@ -1444,9 +1462,12 @@ PWMapDelegPtr OrdPWMap::mapInf(unsigned int n) const
14441462
do {
14451463
OrdPWMap *rs = static_cast<OrdPWMap *>(res.get());
14461464
old_res = std::make_unique<OrdPWMap>(*rs);
1447-
1465+
1466+
14481467
PWMapDelegPtr new_res = res->composition(*res);
1468+
14491469
new_res = new_res->reduce();
1470+
14501471
res = std::move(new_res);
14511472
} while (*old_res != *res);
14521473
}

0 commit comments

Comments
 (0)