From 882737bd30411478f93a52c12c628c0ee8511705 Mon Sep 17 00:00:00 2001 From: Raphael Maenle <17550607+g-spacewhale@users.noreply.github.com> Date: Sat, 6 Jan 2018 23:23:42 +0100 Subject: [PATCH] Abstraction1 Komplett eingebunden - Probleme nun auf Dispatcherseite MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Die Bilder sind in einem Ordner über dem Github abgespeichert, sieht man eh wohin die PATH zeigt. Bilder werden die "WORKING PIECES" verwendet. --- .../DestructionPower/DestructionPower.cpp | 30 +++++++++++----- .../DestructionPower/DestructionPower.h | 1 + .../Layer1/AbstractionLayer_1.cpp | 36 ++++++++++++------- .../Layer1/AbstractionLayer_1.h | 2 +- Source/functions/solve/puzzleExtension.cpp | 18 ++++++++++ Source/functions/solve/structure.cpp | 8 +++-- Source/header/solve.h | 9 +++-- Source/main.cpp | 8 ++--- 8 files changed, 79 insertions(+), 33 deletions(-) diff --git a/Source/functions/AbstractionLayers/DestructionPower/DestructionPower.cpp b/Source/functions/AbstractionLayers/DestructionPower/DestructionPower.cpp index 17d8e42..0b8dc84 100644 --- a/Source/functions/AbstractionLayers/DestructionPower/DestructionPower.cpp +++ b/Source/functions/AbstractionLayers/DestructionPower/DestructionPower.cpp @@ -31,40 +31,52 @@ bool DestructionPower::RemoveConstraintOnPosition(const coor constraintCoordinat { } -//gets destruction power from left and from top if possibe and normalizes +//gets destruction power from left and from top if possible and normalizes void DestructionPower::DestructionOfSurrounding(const coor constraintCoordinate) { float newDestructionArray[DESTRUCTION_COUNT]; + for (int i = 0; i < DESTRUCTION_COUNT; ++i) { + m_constraintMatrix[constraintCoordinate.col][constraintCoordinate.row].DestructionArray.push_back(0); int divisor=0; if(constraintCoordinate.row > 0) { divisor++; - newDestructionArray[i] += m_constraintMatrix[constraintCoordinate.col][constraintCoordinate.row-1].DestructionArray[i]; + m_constraintMatrix[constraintCoordinate.col][constraintCoordinate.row].DestructionArray[i] += m_constraintMatrix[constraintCoordinate.col][constraintCoordinate.row-1].DestructionArray[i]; } if(constraintCoordinate.col > 0) { divisor++; - newDestructionArray[i] += m_constraintMatrix[constraintCoordinate.col-1][constraintCoordinate.row].DestructionArray[i]; + m_constraintMatrix[constraintCoordinate.col][constraintCoordinate.row].DestructionArray[i] += m_constraintMatrix[constraintCoordinate.col-1][constraintCoordinate.row].DestructionArray[i]; } if(divisor) - newDestructionArray[i] /=divisor; + m_constraintMatrix[constraintCoordinate.col][constraintCoordinate.row].DestructionArray[i] /=divisor; + else + //create default destructionPower //TODO find some better solution for default + m_constraintMatrix[constraintCoordinate.col][constraintCoordinate.row].DestructionArray[i] =1-m_constraintMatrix[constraintCoordinate.col][constraintCoordinate.row].SpeedTable[i+1]; } } + +float DestructionPower::defaultDestructionPower(int i) +{ + +} + //gets next highest valued abstraction layer down from current one (if first, get highest) int DestructionPower::getNextAbstractionLayer(coor newCoordinate, int currentAbstractionLayer) { - float currentPower=-1; + float currentPower = 1; int nextLayer=-1; float nextLayerPower=0; if (currentAbstractionLayer>=0) currentPower = m_constraintMatrix[newCoordinate.row][newCoordinate.col].DestructionArray[currentAbstractionLayer]; int i=0; - for(float it:m_constraintMatrix[newCoordinate.row][newCoordinate.col].DestructionArray) + + //giff next most valuable layer + for(auto it:m_constraintMatrix[newCoordinate.row][newCoordinate.col].DestructionArray) { if(it <= currentPower) - { - //if equal, then has to be the next one (activated from left to right) + {//if equal, then has to be the next one (activated from left to right) if(it == currentPower) if(i>currentAbstractionLayer) return i; @@ -74,8 +86,8 @@ int DestructionPower::getNextAbstractionLayer(coor newCoordinate, int currentAbs nextLayerPower=it; nextLayer=i; } - i++; } + i++; } return nextLayer; } diff --git a/Source/functions/AbstractionLayers/DestructionPower/DestructionPower.h b/Source/functions/AbstractionLayers/DestructionPower/DestructionPower.h index 53c9431..56d3ecf 100644 --- a/Source/functions/AbstractionLayers/DestructionPower/DestructionPower.h +++ b/Source/functions/AbstractionLayers/DestructionPower/DestructionPower.h @@ -29,4 +29,5 @@ public: { m_constraintMatrix[myCoor.col][myCoor.row].DestructionArray[AbstractionLevel] = destructionPower;} private: + float defaultDestructionPower(int i); }; diff --git a/Source/functions/AbstractionLayers/Layer1/AbstractionLayer_1.cpp b/Source/functions/AbstractionLayers/Layer1/AbstractionLayer_1.cpp index e44d2cd..a57cbe5 100644 --- a/Source/functions/AbstractionLayers/Layer1/AbstractionLayer_1.cpp +++ b/Source/functions/AbstractionLayers/Layer1/AbstractionLayer_1.cpp @@ -10,26 +10,26 @@ bool AbstractionLayer_1::PreProcessing(coor mySize, const vector* partArray) { - + const vector& ref_partArray = *partArray; analyseParts analyse(1008); - vector parts; Part buf; - + int iterator=0; if(!analyse.getImages()) { cerr << "Error occured in getImages!" << endl; return false; } - else - { - unsigned char tabs = 0; + else // hier werden alle vier verschiedenen Rotationsarten 'gleichzeitig' abgespeichert for(int i = 0; i < 1008; i++) { - tabs = analyse.getTabs(i); - buf.m_a1.m_connections=tabs; - parts.push_back(buf); + unsigned char poempel = analyse.getTabs(i);; + for (int j=0;j<4;j++) + { + ref_partArray[iterator]->m_a1.m_connections=poempel; + shift(poempel,1); + iterator++; + } } - } //Zugriff auf den vector mit den einzelnen teilen: part[0].getConnenctions() entspricht pömpel von bild 0.jpg und liefert ein unsigned char, poempl Belegung wie ausgemacht @@ -44,11 +44,16 @@ bool AbstractionLayer_1::PreProcessing(coor mySize, const vector* partAr //it through qualityVector and removes all that do not trigger PlaceOfPartGood bool AbstractionLayer_1::EvaluateQuality (const coor constraintCoordinate, qualityVector& qVector) { - for(auto it = qVector.begin(); it != qVector.end(); it++) + int j=0; + for(int i = 0;isecond->m_a1.m_connections)) + j++; + cout <<"qVector size: " << qVector.size() << endl; + cout << "ID: " << qVector[i].second->GetPartID() << ", rotations: " << (int)qVector[i].second->GetNumOfRotations() << endl; + qVector[i].second->print(); + if(PlaceOfPartGood(constraintCoordinate, qVector[i].second->m_a1.m_connections)) continue; - qVector.erase(it++); + qVector.erase(qVector.begin()+(i--)); cout << endl << endl; } } @@ -148,6 +153,9 @@ void AbstractionLayer_1::setEdgeZero() //checks if the myPart in its current orientation is legal in position m, n bool AbstractionLayer_1::PlaceOfPartGood(coor myCoor, uint8_t& myPart) { + //sets coordinates to correct position for layer + myCoor.row++; + myCoor.col++; uint8_t negativePart=0b00000000; @@ -156,6 +164,8 @@ bool AbstractionLayer_1::PlaceOfPartGood(coor myCoor, uint8_t& myPart) negativePart or_eq (m_constraintMatrix[myCoor.row-1][myCoor.col].m_connections & 0b00001100); negativePart or_eq (m_constraintMatrix[myCoor.row][myCoor.col+1].m_connections & 0b00000011); shift(negativePart,2); + if(negativePart & 0b11000000) + return 1; if ( ( ((((negativePart & 0b11000000) ^ (myPart & 0b11000000)) != 0b00000000) && (((myPart & 0b11000000) != 0b00000000) && (negativePart & 0b11000000) != 0b00000000)) || ((((negativePart & 0b11000000) == 0b11000000) || ((myPart & 0b11000000) == 0b11000000)) && (((myPart & 0b11000000) != 0b00000000) && (negativePart & 0b11000000) != 0b00000000)) diff --git a/Source/functions/AbstractionLayers/Layer1/AbstractionLayer_1.h b/Source/functions/AbstractionLayers/Layer1/AbstractionLayer_1.h index f424c31..d079332 100644 --- a/Source/functions/AbstractionLayers/Layer1/AbstractionLayer_1.h +++ b/Source/functions/AbstractionLayers/Layer1/AbstractionLayer_1.h @@ -24,7 +24,7 @@ #include #define DISPLAY false -#define PATH "..\\pieces\\%d.png" +#define PATH "..\\..\\..\\pieces\\%04d.jpg" #define IMG_SIZE 400 #define TOP 6 #define RIGHT 4 diff --git a/Source/functions/solve/puzzleExtension.cpp b/Source/functions/solve/puzzleExtension.cpp index 5e5fea9..177b1c2 100644 --- a/Source/functions/solve/puzzleExtension.cpp +++ b/Source/functions/solve/puzzleExtension.cpp @@ -67,5 +67,23 @@ void Puzzle::createRandomPuzzle() void Puzzle::createp_box() { + for(int i=0;i& log, vector& p_Box, Puzzle& p log.emplace_back(LogEntry(coor(0, 0))); log.back().myCoor = calculateNextCoor(log, p_Box,puzzleMat); puzzleMat.dp.DestructionOfSurrounding(log.back().myCoor);//calculate dp from surrounding + for(auto it:p_Box) + log.back().PieceCollector.emplace_back(pair(0,it)); + cout << p_Box.size() << endl; + cout << log.back().PieceCollector.size() << endl; solve(log, p_Box,puzzleMat); } @@ -72,11 +76,11 @@ coor calculateNextCoor(vector& log, vector& p_Box, Puzzle& puzz void solve(vector& log, vector& p_Box, Puzzle& puzzleMat) { - puzzleMat.dp.getNextAbstractionLayer(log.back().myCoor,log.back().abstractionLevel); //sets in abstractionLevel + log.back().abstractionLevel = puzzleMat.dp.getNextAbstractionLayer(log.back().myCoor,log.back().abstractionLevel); //sets in abstractionLevel //status(log,p_Box,puzzleMat); switch(log.back().abstractionLevel) { - case 1: + case 0: puzzleMat.a1.EvaluateQuality(log.back().myCoor, log.back().PieceCollector); break; diff --git a/Source/header/solve.h b/Source/header/solve.h index 5105cc8..a93c896 100755 --- a/Source/header/solve.h +++ b/Source/header/solve.h @@ -43,11 +43,13 @@ public: bool PreProcessing() { - return a1.PreProcessing({rows,cols}, nullptr); + createBox(); createp_box(); + dp.PreProcessing({rows,cols}, nullptr); + a1.PreProcessing({rows,cols}, &p_myBox); + return true; } - coor getSizeAsCoor() - {return {cols,rows};} + coor getSizeAsCoor() {return {cols,rows};} DestructionPower dp; AbstractionLayer_1 a1; @@ -60,6 +62,7 @@ public: void createRandomPuzzle(); void putIntoBox(); void shuffle(); + void createBox(); void createp_box(); vector myBox; diff --git a/Source/main.cpp b/Source/main.cpp index fe8d765..16cf718 100644 --- a/Source/main.cpp +++ b/Source/main.cpp @@ -5,21 +5,19 @@ int LogEntry::randomed(0); int main() { - unsigned int cols=5, rows=6; + unsigned int cols=36, rows=28; vector log; Puzzle puzzleMat(cols, rows); if(!puzzleMat.PreProcessing()) { - cerr << "Error occured at PreProcessing!"; + cerr << "Error occurred at PreProcessing!"; return 0; } - puzzleMat.createRandomBox(); - cout << "here" << endl; + //puzzleMat.createRandomBox(); puzzleMat.a1.printConstraintMatrix(); - //vector> ab1class = abstractionLayer1classify(log, p_myFirstBox,puzzleMat); while(next(log, puzzleMat.p_myBox,puzzleMat)); puzzleMat.printPuzzle();