added dp calcualtion

This commit is contained in:
Raphael Maenle 2018-01-29 20:05:37 +01:00
parent a6da2298c8
commit cf576db19d
5 changed files with 73 additions and 38 deletions

View File

@ -16,6 +16,11 @@ bool DestructionPower::PreProcessing(coor mySize,const vector<Part*>* partArray)
cout << "DestructionPower Preprocessing... "; cout << "DestructionPower Preprocessing... ";
InitialiseConstraintMatrixSize(mySize.col,mySize.row); InitialiseConstraintMatrixSize(mySize.col,mySize.row);
for(auto& it:m_constraintMatrix)
for(auto& ti:it)
for(int i=0;i<DESTRUCTION_COUNT;i++)
ti.DestructionArray.push_back(0);
cout << "Done!" << endl; cout << "Done!" << endl;
return true; return true;
} }
@ -31,23 +36,32 @@ bool DestructionPower::SetConstraintOnPosition(const coor constraintCoordinate,
bool DestructionPower::RemoveConstraintOnPosition(const coor constraintCoordinate) bool DestructionPower::RemoveConstraintOnPosition(const coor constraintCoordinate)
{ {
for(int i=0;i<m_constraintMatrix[constraintCoordinate.col][constraintCoordinate.row].DestructionArray.size();i++)
m_constraintMatrix[constraintCoordinate.col][constraintCoordinate.row].DestructionArray[i]=0;
} }
//gets destruction power from left and from top if possible and normalizes //gets destruction power from left and from top if possible and normalizes
void DestructionPower::DestructionOfSurrounding(const coor constraintCoordinate) { void DestructionPower::DestructionOfSurrounding(const coor constraintCoordinate) {
for(int i = 0; i < m_constraintMatrix[constraintCoordinate.col][constraintCoordinate.row].DestructionArray.size(); ++i)
m_constraintMatrix[constraintCoordinate.col][constraintCoordinate.row].DestructionArray.pop_back();
for (int i = 0; i < DESTRUCTION_COUNT; ++i) { for (int i = 0; i < DESTRUCTION_COUNT; ++i) {
m_constraintMatrix[constraintCoordinate.col][constraintCoordinate.row].DestructionArray.push_back(0);
int divisor=0; int divisor=0;
if(constraintCoordinate.row > 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++; divisor++;
m_constraintMatrix[constraintCoordinate.col][constraintCoordinate.row].DestructionArray[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) 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++; divisor++;
m_constraintMatrix[constraintCoordinate.col][constraintCoordinate.row].DestructionArray[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];
@ -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) //gets next highest valued abstraction layer down from current one (if first, get highest)
int DestructionPower::getNextAbstractionLayer(coor newCoordinate, int currentAbstractionLayer) int DestructionPower::getNextAbstractionLayer(coor newCoordinate, int currentAbstractionLayer)
{ {
//hardcode advance //hardcode advance
if(currentAbstractionLayer<DESTRUCTION_COUNT) // if(currentAbstractionLayer<DESTRUCTION_COUNT-1)
return ++currentAbstractionLayer; // return ++currentAbstractionLayer;
return -1; // return -1;
if(currentAbstractionLayer==-1)
return 0;//poempel in out
float currentPower = 1; float currentPower = 1;
int nextLayer=-1; int nextLayer=-1;
float nextLayerPower=0; float nextLayerPower=0;

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
//TODO!! increase Destructioncount //TODO!! increase Destructioncount
#define DESTRUCTION_COUNT 2 #define DESTRUCTION_COUNT 3
#include "DestructionPower_Properties.h" #include "DestructionPower_Properties.h"
#include "../AbstraktionLayer_Base.h" #include "../AbstraktionLayer_Base.h"

View File

@ -21,13 +21,12 @@ bool AbstractionLayer_ColorMatching::PreProcessing(coor mySize, const vector<Par
for (int r = 0; r < mySize.row; r++) { for (int r = 0; r < mySize.row; r++) {
for (int c = 0; c < mySize.col; c++) { for (int c = 0; c < mySize.col; c++) {
Mat ExtPart = puzzle(CvRect(c*X, r*Y, X, Y)); Mat ExtPart = puzzle(CvRect(c * X, r * Y, X, Y));
// crop image to ROI // crop image to ROI
Mat ExtPartCropped = ExtPart( Mat ExtPartCropped = ExtPart(
Rect(ExtPart.size().width / 3, ExtPart.size().height / 3, ExtPart.size().width / 3, Rect(ExtPart.size().width / 3, ExtPart.size().height / 3, ExtPart.size().width / 3,
ExtPart.size().height / 3)); ExtPart.size().height / 3));
// Create a new matrix to hold the HSV image // Create a new matrix to hold the HSV image
Mat HSVExtPart; Mat HSVExtPart;
// convert RGB image to HSV // convert RGB image to HSV
@ -166,14 +165,19 @@ bool AbstractionLayer_ColorMatching::EvaluateQuality (const coor constraintCoord
{ {
for(int i = 0;i<qVector.size();i++) for(int i = 0;i<qVector.size();i++)
{ {
float value1 = PlaceOfPartGood(constraintCoordinate, qVector[i].second->m_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 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); 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;
} }
} }

View File

@ -65,6 +65,7 @@ void Puzzle::shuffle()
//deletes all constraints from all abstractionlayers //deletes all constraints from all abstractionlayers
void Puzzle::removeConstrains(coor removeCoordinates) void Puzzle::removeConstrains(coor removeCoordinates)
{ {
this->dp.RemoveConstraintOnPosition(removeCoordinates);
this->a1.RemoveConstraintOnPosition(removeCoordinates); this->a1.RemoveConstraintOnPosition(removeCoordinates);
this->a3.RemoveConstraintOnPosition(removeCoordinates); this->a3.RemoveConstraintOnPosition(removeCoordinates);
this->a4.RemoveConstraintOnPosition(removeCoordinates); this->a4.RemoveConstraintOnPosition(removeCoordinates);
@ -74,9 +75,9 @@ void Puzzle::removeConstrains(coor removeCoordinates)
void Puzzle::setConstraints(coor setConstraints, Part* constraintPiece) void Puzzle::setConstraints(coor setConstraints, Part* constraintPiece)
{ {
//dp //dp
// this->dp.m_constraintMatrix[setConstraints.col][setConstraints.row].DestructionArray.clear(); this->dp.m_constraintMatrix[setConstraints.col][setConstraints.row].DestructionArray.clear();
// for(auto it:this->tmp_destructionArray) 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.emplace_back(it);
//a1 //a1
this->a1.SetConstraintOnPosition(setConstraints,constraintPiece->m_a1); this->a1.SetConstraintOnPosition(setConstraints,constraintPiece->m_a1);

View File

@ -54,14 +54,38 @@ void createNextLogElement(vector<LogEntry>& log, Puzzle& puzzleMat)
coor calculateNextCoor(vector<LogEntry>& log, Puzzle& puzzleMat) coor calculateNextCoor(vector<LogEntry>& log, Puzzle& puzzleMat)
{ {
//level 1:
//go left to right, then increase current row
if (log.size() == 1) if (log.size() == 1)
return {0,0}; return {0,0};
unsigned int col= log.rbegin()[1].myCoor.col; unsigned int col= log.rbegin()[1].myCoor.col;
unsigned int row= log.rbegin()[1].myCoor.row; 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<puzzleMat.getSizeAsCoor().row-2) row++;
else if(col<puzzleMat.getSizeAsCoor().col-2){ row=1; col++;}
return {col,row};
//level 1:
//go left to right, then increase current row
if(row<puzzleMat.getSizeAsCoor().row-1) row++; if(row<puzzleMat.getSizeAsCoor().row-1) row++;
@ -81,11 +105,11 @@ void solve(vector<LogEntry>& log,Puzzle& puzzleMat)
case 0://pömpel case 0://pömpel
puzzleMat.a1.EvaluateQuality(log.back().myCoor,log.back().PieceCollector); puzzleMat.a1.EvaluateQuality(log.back().myCoor,log.back().PieceCollector);
break; break;
case 3://SURFFeature case 2://SURFFeature
// return; // return;
puzzleMat.a4.EvaluateQuality(log.back().myCoor,log.back().PieceCollector); puzzleMat.a4.EvaluateQuality(log.back().myCoor,log.back().PieceCollector);
break; break;
case 2://poempelposition case 3://poempelposition
puzzleMat.a3.EvaluateQuality(log.back().myCoor,log.back().PieceCollector); puzzleMat.a3.EvaluateQuality(log.back().myCoor,log.back().PieceCollector);
break; break;
case 1://color case 1://color
@ -121,7 +145,6 @@ void setsolution(vector<LogEntry>& log, Puzzle& puzzleMat)
puzzleMat.setConstraints(log.back().myCoor,log.back().PieceCollector.begin()->second); puzzleMat.setConstraints(log.back().myCoor,log.back().PieceCollector.begin()->second);
cout << "set:" << log.back().myCoor.col << "," << log.back().myCoor.row << endl; cout << "set:" << log.back().myCoor.col << "," << log.back().myCoor.row << endl;
//cout << "ID: " << log.back().PieceCollector[0].second->GetPartID() << 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);
} }
@ -173,7 +196,6 @@ bool backtrack(vector<LogEntry>& 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<LogEntry>& log, Puzzle& puzzleMat, float Layerworth) { void calculateTrueDestructionPower(vector<LogEntry>& log, Puzzle& puzzleMat, float Layerworth) {
float destructionPower = sqrt( float destructionPower = sqrt(
Layerworth * puzzleMat.dp.m_constraintMatrix[0][0].SpeedTable[log.back().abstractionLevel]); Layerworth * puzzleMat.dp.m_constraintMatrix[0][0].SpeedTable[log.back().abstractionLevel]);
@ -211,8 +233,6 @@ float capLogElements(vector<LogEntry>& log)
if(log.back().PieceCollector[id].first < limit) if(log.back().PieceCollector[id].first < limit)
break; break;
} }
cut(log,id);//for debugging
return 0;//for debugging
int newid=0; int newid=0;
//check if all over //check if all over
@ -253,7 +273,6 @@ void cut(vector<LogEntry>& log, int& cutID)
// geeignete Threshold values muessen noch getestet werden // geeignete Threshold values muessen noch getestet werden
bool SetBestOrMoreLayersArithmetical(vector<LogEntry>& log, qualityVector& cqVector) bool SetBestOrMoreLayersArithmetical(vector<LogEntry>& log, qualityVector& cqVector)
{ {
return false;
float threshold, tempBest = 0.0; float threshold, tempBest = 0.0;
unsigned int countHigherThreshold = 0; unsigned int countHigherThreshold = 0;