From cf576db19def26437adb1e925ed607d70ed8d0ce Mon Sep 17 00:00:00 2001 From: Raphael Maenle <17550607+g-spacewhale@users.noreply.github.com> Date: Mon, 29 Jan 2018 20:05:37 +0100 Subject: [PATCH] added dp calcualtion --- .../DestructionPower/DestructionPower.cpp | 41 ++++++++++------ .../DestructionPower/DestructionPower.h | 2 +- .../AbstractionLayer_ColorMatching.cpp | 12 +++-- Source/functions/solve/puzzleExtension.cpp | 7 +-- Source/functions/solve/structure.cpp | 49 +++++++++++++------ 5 files changed, 73 insertions(+), 38 deletions(-) diff --git a/Source/functions/AbstractionLayers/DestructionPower/DestructionPower.cpp b/Source/functions/AbstractionLayers/DestructionPower/DestructionPower.cpp index a9756aa..50b0ec4 100644 --- a/Source/functions/AbstractionLayers/DestructionPower/DestructionPower.cpp +++ b/Source/functions/AbstractionLayers/DestructionPower/DestructionPower.cpp @@ -16,6 +16,11 @@ bool DestructionPower::PreProcessing(coor mySize,const vector* partArray) cout << "DestructionPower Preprocessing... "; InitialiseConstraintMatrixSize(mySize.col,mySize.row); + + for(auto& it:m_constraintMatrix) + for(auto& ti:it) + for(int i=0;i 0) + //check if not at edge and if information is valid + if(constraintCoordinate.row > 0 && m_constraintMatrix[constraintCoordinate.col][constraintCoordinate.row-1].DestructionArray[i] > 0) { divisor++; m_constraintMatrix[constraintCoordinate.col][constraintCoordinate.row].DestructionArray[i] += m_constraintMatrix[constraintCoordinate.col][constraintCoordinate.row-1].DestructionArray[i]; } - if(constraintCoordinate.col > 0) + if(constraintCoordinate.col > 0 && m_constraintMatrix[constraintCoordinate.col-1][constraintCoordinate.row].DestructionArray[i] > 0) { divisor++; m_constraintMatrix[constraintCoordinate.col][constraintCoordinate.row].DestructionArray[i] += m_constraintMatrix[constraintCoordinate.col-1][constraintCoordinate.row].DestructionArray[i]; } + if(constraintCoordinate.col < m_constraintMatrix.size()-1 && m_constraintMatrix[constraintCoordinate.col+1][constraintCoordinate.row].DestructionArray[i] > 0) + { + divisor++; + m_constraintMatrix[constraintCoordinate.col][constraintCoordinate.row].DestructionArray[i] += m_constraintMatrix[constraintCoordinate.col+1][constraintCoordinate.row].DestructionArray[i]; + } + if(constraintCoordinate.row < m_constraintMatrix[i].size()-1 && m_constraintMatrix[constraintCoordinate.col][constraintCoordinate.row+1].DestructionArray[i] > 0) + { + divisor++; + m_constraintMatrix[constraintCoordinate.col][constraintCoordinate.row].DestructionArray[i] += m_constraintMatrix[constraintCoordinate.col-1][constraintCoordinate.row].DestructionArray[i]; + } if(divisor) m_constraintMatrix[constraintCoordinate.col][constraintCoordinate.row].DestructionArray[i] /=divisor; else @@ -63,19 +77,16 @@ void DestructionPower::DestructionOfSurrounding(const coor constraintCoordinate) } } -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) { //hardcode advance - if(currentAbstractionLayerm_acm.m_centerColor); + //float value1 = PlaceOfPartGood(constraintCoordinate, qVector[i].second->m_acm.m_centerColor); + if(constraintCoordinate.col==5 && constraintCoordinate.row ==27) + { + ; + } + float value1 = (float)(1-(abs(m_constraintMatrix[constraintCoordinate.col][constraintCoordinate.row].m_centerColor.h-qVector[i].second->m_acm.m_centerColor.h))/180); float value2 = (float)(1-(abs(m_constraintMatrix[constraintCoordinate.col][constraintCoordinate.row].m_centerColor.s-qVector[i].second->m_acm.m_centerColor.s))/255); float value3 = (float)(1-(abs(m_constraintMatrix[constraintCoordinate.col][constraintCoordinate.row].m_centerColor.v-qVector[i].second->m_acm.m_centerColor.v))/255); - qVector[i].first = (value1+value2+value3)/3; + qVector[i].first = (value1*4+value2*2+value3*1)/6; } } diff --git a/Source/functions/solve/puzzleExtension.cpp b/Source/functions/solve/puzzleExtension.cpp index 5859c14..60fabd2 100644 --- a/Source/functions/solve/puzzleExtension.cpp +++ b/Source/functions/solve/puzzleExtension.cpp @@ -65,6 +65,7 @@ void Puzzle::shuffle() //deletes all constraints from all abstractionlayers void Puzzle::removeConstrains(coor removeCoordinates) { + this->dp.RemoveConstraintOnPosition(removeCoordinates); this->a1.RemoveConstraintOnPosition(removeCoordinates); this->a3.RemoveConstraintOnPosition(removeCoordinates); this->a4.RemoveConstraintOnPosition(removeCoordinates); @@ -74,9 +75,9 @@ void Puzzle::removeConstrains(coor removeCoordinates) void Puzzle::setConstraints(coor setConstraints, Part* constraintPiece) { //dp -// this->dp.m_constraintMatrix[setConstraints.col][setConstraints.row].DestructionArray.clear(); -// for(auto it:this->tmp_destructionArray) -// this->dp.m_constraintMatrix[setConstraints.col][setConstraints.row].DestructionArray.emplace_back(it); + this->dp.m_constraintMatrix[setConstraints.col][setConstraints.row].DestructionArray.clear(); + for(auto it:this->tmp_destructionArray) + this->dp.m_constraintMatrix[setConstraints.col][setConstraints.row].DestructionArray.emplace_back(it); //a1 this->a1.SetConstraintOnPosition(setConstraints,constraintPiece->m_a1); diff --git a/Source/functions/solve/structure.cpp b/Source/functions/solve/structure.cpp index 7653fd3..7a3005f 100755 --- a/Source/functions/solve/structure.cpp +++ b/Source/functions/solve/structure.cpp @@ -54,14 +54,38 @@ void createNextLogElement(vector& log, Puzzle& puzzleMat) coor calculateNextCoor(vector& log, Puzzle& puzzleMat) { - //level 1: - //go left to right, then increase current row + if (log.size() == 1) return {0,0}; - unsigned int col= log.rbegin()[1].myCoor.col; - unsigned int row= log.rbegin()[1].myCoor.row; + unsigned int col= log.rbegin()[1].myCoor.col; + unsigned int row= log.rbegin()[1].myCoor.row; + //level 2 edges first + + if(col == 0 && row < 27) + return {col,++row}; + if(row== 27 && col < 35) + return {++col,row}; + if(col == 35 && row >0) + return {col, --row}; + if(col >1&& row ==0) + return{--col,row}; + if(col==1 && row==0) + return {1,1}; + + + log.pop_back();//vis only!!! + puzzleMat.resultImage(log);//vis only!!! + + + if(row& log,Puzzle& puzzleMat) case 0://pömpel puzzleMat.a1.EvaluateQuality(log.back().myCoor,log.back().PieceCollector); break; - case 3://SURFFeature + case 2://SURFFeature // return; puzzleMat.a4.EvaluateQuality(log.back().myCoor,log.back().PieceCollector); break; - case 2://poempelposition + case 3://poempelposition puzzleMat.a3.EvaluateQuality(log.back().myCoor,log.back().PieceCollector); break; case 1://color @@ -121,8 +145,7 @@ void setsolution(vector& log, Puzzle& puzzleMat) puzzleMat.setConstraints(log.back().myCoor,log.back().PieceCollector.begin()->second); cout << "set:" << log.back().myCoor.col << "," << log.back().myCoor.row << endl; //cout << "ID: " << log.back().PieceCollector[0].second->GetPartID() << endl; - if(log.back().myCoor.col>=3 && log.back().myCoor.row==2) - puzzleMat.resultImage(log); + puzzleMat.resultImage(log); } @@ -144,9 +167,9 @@ bool backtrack(vector& log, Puzzle& puzzleMat) //remove similar in log - Part myPart = *log.back().PieceCollector[0].second;//tmpsaves bad part - log.back().PieceCollector.erase(log.back().PieceCollector.begin());//removes bad part from log - puzzleMat.removeSimilar(log.back().PieceCollector,myPart); //removes all pieces from log that are similar to bad part + Part myPart = *log.back().PieceCollector[0].second;//tmpsaves bad part + log.back().PieceCollector.erase(log.back().PieceCollector.begin());//removes bad part from log + puzzleMat.removeSimilar(log.back().PieceCollector,myPart); //removes all pieces from log that are similar to bad part //TODO reprogram similar removal to allow multilayer tracking if(log.back().PieceCollector.size()) // this checks if 'removeSimilar' has cleared entire LogElement { @@ -173,7 +196,6 @@ bool backtrack(vector& log, Puzzle& puzzleMat) } -//this is addon stuff that should later all be extracted into a sererate cpp as it is not core dispatcher functionality void calculateTrueDestructionPower(vector& log, Puzzle& puzzleMat, float Layerworth) { float destructionPower = sqrt( Layerworth * puzzleMat.dp.m_constraintMatrix[0][0].SpeedTable[log.back().abstractionLevel]); @@ -211,8 +233,6 @@ float capLogElements(vector& log) if(log.back().PieceCollector[id].first < limit) break; } - cut(log,id);//for debugging - return 0;//for debugging int newid=0; //check if all over @@ -253,7 +273,6 @@ void cut(vector& log, int& cutID) // geeignete Threshold values muessen noch getestet werden bool SetBestOrMoreLayersArithmetical(vector& log, qualityVector& cqVector) { - return false; float threshold, tempBest = 0.0; unsigned int countHigherThreshold = 0;