added dp calcualtion
This commit is contained in:
parent
a6da2298c8
commit
cf576db19d
@ -16,6 +16,11 @@ bool DestructionPower::PreProcessing(coor mySize,const vector<Part*>* partArray)
|
||||
cout << "DestructionPower Preprocessing... ";
|
||||
|
||||
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;
|
||||
return true;
|
||||
}
|
||||
@ -31,27 +36,36 @@ bool DestructionPower::SetConstraintOnPosition(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
|
||||
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) {
|
||||
|
||||
m_constraintMatrix[constraintCoordinate.col][constraintCoordinate.row].DestructionArray.push_back(0);
|
||||
for (int i = 0; i < DESTRUCTION_COUNT; ++i) {
|
||||
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++;
|
||||
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(currentAbstractionLayer<DESTRUCTION_COUNT)
|
||||
return ++currentAbstractionLayer;
|
||||
return -1;
|
||||
// if(currentAbstractionLayer<DESTRUCTION_COUNT-1)
|
||||
// return ++currentAbstractionLayer;
|
||||
// return -1;
|
||||
|
||||
if(currentAbstractionLayer==-1)
|
||||
return 0;//poempel in out
|
||||
float currentPower = 1;
|
||||
int nextLayer=-1;
|
||||
float nextLayerPower=0;
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
//TODO!! increase Destructioncount
|
||||
#define DESTRUCTION_COUNT 2
|
||||
#define DESTRUCTION_COUNT 3
|
||||
|
||||
#include "DestructionPower_Properties.h"
|
||||
#include "../AbstraktionLayer_Base.h"
|
||||
|
@ -21,13 +21,12 @@ bool AbstractionLayer_ColorMatching::PreProcessing(coor mySize, const vector<Par
|
||||
|
||||
for (int r = 0; r < mySize.row; r++) {
|
||||
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
|
||||
Mat ExtPartCropped = ExtPart(
|
||||
Rect(ExtPart.size().width / 3, ExtPart.size().height / 3, ExtPart.size().width / 3,
|
||||
ExtPart.size().height / 3));
|
||||
|
||||
// Create a new matrix to hold the HSV image
|
||||
Mat HSVExtPart;
|
||||
// convert RGB image to HSV
|
||||
@ -166,14 +165,19 @@ bool AbstractionLayer_ColorMatching::EvaluateQuality (const coor constraintCoord
|
||||
{
|
||||
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 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -54,14 +54,38 @@ void createNextLogElement(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)
|
||||
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<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++;
|
||||
@ -81,11 +105,11 @@ void solve(vector<LogEntry>& 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<LogEntry>& 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<LogEntry>& 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<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) {
|
||||
float destructionPower = sqrt(
|
||||
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)
|
||||
break;
|
||||
}
|
||||
cut(log,id);//for debugging
|
||||
return 0;//for debugging
|
||||
|
||||
int newid=0;
|
||||
//check if all over
|
||||
@ -253,7 +273,6 @@ void cut(vector<LogEntry>& log, int& cutID)
|
||||
// geeignete Threshold values muessen noch getestet werden
|
||||
bool SetBestOrMoreLayersArithmetical(vector<LogEntry>& log, qualityVector& cqVector)
|
||||
{
|
||||
return false;
|
||||
float threshold, tempBest = 0.0;
|
||||
unsigned int countHigherThreshold = 0;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user