Abstraction1 Komplett eingebunden - Probleme nun auf Dispatcherseite
Die Bilder sind in einem Ordner über dem Github abgespeichert, sieht man eh wohin die PATH zeigt. Bilder werden die "WORKING PIECES" verwendet.
This commit is contained in:
parent
9d98ed83fa
commit
882737bd30
@ -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) {
|
void DestructionPower::DestructionOfSurrounding(const coor constraintCoordinate) {
|
||||||
float newDestructionArray[DESTRUCTION_COUNT];
|
float newDestructionArray[DESTRUCTION_COUNT];
|
||||||
|
|
||||||
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)
|
if(constraintCoordinate.row > 0)
|
||||||
{
|
{
|
||||||
divisor++;
|
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)
|
if(constraintCoordinate.col > 0)
|
||||||
{
|
{
|
||||||
divisor++;
|
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)
|
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)
|
//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)
|
||||||
{
|
{
|
||||||
float currentPower=-1;
|
float currentPower = 1;
|
||||||
int nextLayer=-1;
|
int nextLayer=-1;
|
||||||
float nextLayerPower=0;
|
float nextLayerPower=0;
|
||||||
if (currentAbstractionLayer>=0)
|
if (currentAbstractionLayer>=0)
|
||||||
currentPower = m_constraintMatrix[newCoordinate.row][newCoordinate.col].DestructionArray[currentAbstractionLayer];
|
currentPower = m_constraintMatrix[newCoordinate.row][newCoordinate.col].DestructionArray[currentAbstractionLayer];
|
||||||
|
|
||||||
int i=0;
|
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(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(it == currentPower)
|
||||||
if(i>currentAbstractionLayer)
|
if(i>currentAbstractionLayer)
|
||||||
return i;
|
return i;
|
||||||
@ -74,8 +86,8 @@ int DestructionPower::getNextAbstractionLayer(coor newCoordinate, int currentAbs
|
|||||||
nextLayerPower=it;
|
nextLayerPower=it;
|
||||||
nextLayer=i;
|
nextLayer=i;
|
||||||
}
|
}
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
return nextLayer;
|
return nextLayer;
|
||||||
}
|
}
|
||||||
|
@ -29,4 +29,5 @@ public:
|
|||||||
{ m_constraintMatrix[myCoor.col][myCoor.row].DestructionArray[AbstractionLevel] = destructionPower;}
|
{ m_constraintMatrix[myCoor.col][myCoor.row].DestructionArray[AbstractionLevel] = destructionPower;}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
float defaultDestructionPower(int i);
|
||||||
};
|
};
|
||||||
|
@ -10,26 +10,26 @@
|
|||||||
|
|
||||||
bool AbstractionLayer_1::PreProcessing(coor mySize, const vector<Part*>* partArray)
|
bool AbstractionLayer_1::PreProcessing(coor mySize, const vector<Part*>* partArray)
|
||||||
{
|
{
|
||||||
|
const vector<Part*>& ref_partArray = *partArray;
|
||||||
analyseParts analyse(1008);
|
analyseParts analyse(1008);
|
||||||
vector<Part> parts;
|
|
||||||
Part buf;
|
Part buf;
|
||||||
|
int iterator=0;
|
||||||
if(!analyse.getImages())
|
if(!analyse.getImages())
|
||||||
{
|
{
|
||||||
cerr << "Error occured in getImages!" << endl;
|
cerr << "Error occured in getImages!" << endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else
|
else // hier werden alle vier verschiedenen Rotationsarten 'gleichzeitig' abgespeichert
|
||||||
{
|
|
||||||
unsigned char tabs = 0;
|
|
||||||
for(int i = 0; i < 1008; i++)
|
for(int i = 0; i < 1008; i++)
|
||||||
{
|
{
|
||||||
tabs = analyse.getTabs(i);
|
unsigned char poempel = analyse.getTabs(i);;
|
||||||
buf.m_a1.m_connections=tabs;
|
for (int j=0;j<4;j++)
|
||||||
parts.push_back(buf);
|
{
|
||||||
|
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
|
//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<Part*>* partAr
|
|||||||
//it through qualityVector and removes all that do not trigger PlaceOfPartGood
|
//it through qualityVector and removes all that do not trigger PlaceOfPartGood
|
||||||
bool AbstractionLayer_1::EvaluateQuality (const coor constraintCoordinate, qualityVector& qVector)
|
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;i<qVector.size();i++)
|
||||||
{
|
{
|
||||||
if(PlaceOfPartGood(constraintCoordinate, it->second->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;
|
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
|
//checks if the myPart in its current orientation is legal in position m, n
|
||||||
bool AbstractionLayer_1::PlaceOfPartGood(coor myCoor, uint8_t& myPart)
|
bool AbstractionLayer_1::PlaceOfPartGood(coor myCoor, uint8_t& myPart)
|
||||||
{
|
{
|
||||||
|
//sets coordinates to correct position for layer
|
||||||
|
myCoor.row++;
|
||||||
|
myCoor.col++;
|
||||||
|
|
||||||
uint8_t negativePart=0b00000000;
|
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-1][myCoor.col].m_connections & 0b00001100);
|
||||||
negativePart or_eq (m_constraintMatrix[myCoor.row][myCoor.col+1].m_connections & 0b00000011);
|
negativePart or_eq (m_constraintMatrix[myCoor.row][myCoor.col+1].m_connections & 0b00000011);
|
||||||
shift(negativePart,2);
|
shift(negativePart,2);
|
||||||
|
if(negativePart & 0b11000000)
|
||||||
|
return 1;
|
||||||
if (
|
if (
|
||||||
( ((((negativePart & 0b11000000) ^ (myPart & 0b11000000)) != 0b00000000) && (((myPart & 0b11000000) != 0b00000000) && (negativePart & 0b11000000) != 0b00000000))
|
( ((((negativePart & 0b11000000) ^ (myPart & 0b11000000)) != 0b00000000) && (((myPart & 0b11000000) != 0b00000000) && (negativePart & 0b11000000) != 0b00000000))
|
||||||
|| ((((negativePart & 0b11000000) == 0b11000000) || ((myPart & 0b11000000) == 0b11000000)) && (((myPart & 0b11000000) != 0b00000000) && (negativePart & 0b11000000) != 0b00000000))
|
|| ((((negativePart & 0b11000000) == 0b11000000) || ((myPart & 0b11000000) == 0b11000000)) && (((myPart & 0b11000000) != 0b00000000) && (negativePart & 0b11000000) != 0b00000000))
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
#include <bitset>
|
#include <bitset>
|
||||||
|
|
||||||
#define DISPLAY false
|
#define DISPLAY false
|
||||||
#define PATH "..\\pieces\\%d.png"
|
#define PATH "..\\..\\..\\pieces\\%04d.jpg"
|
||||||
#define IMG_SIZE 400
|
#define IMG_SIZE 400
|
||||||
#define TOP 6
|
#define TOP 6
|
||||||
#define RIGHT 4
|
#define RIGHT 4
|
||||||
|
@ -67,5 +67,23 @@ void Puzzle::createRandomPuzzle()
|
|||||||
|
|
||||||
void Puzzle::createp_box()
|
void Puzzle::createp_box()
|
||||||
{
|
{
|
||||||
|
for(int i=0;i<rows*cols*4;i++)
|
||||||
|
p_myBox.push_back(&myBox[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
//creates a box of puzzlepieces with nothing other than puzzle piece id and correct nr of pieces
|
||||||
|
void Puzzle::createBox(){
|
||||||
|
for(int i=0;i<rows*cols*4;i++)
|
||||||
|
{
|
||||||
|
Part temp;
|
||||||
|
temp.SetPartID(i);
|
||||||
|
for(uint8_t j=0;j<4;j++)
|
||||||
|
{
|
||||||
|
temp.SetNumOfRotations(j);
|
||||||
|
myBox.push_back(temp);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -48,6 +48,10 @@ void createNextLogElement(vector<LogEntry>& log, vector<Part*>& p_Box, Puzzle& p
|
|||||||
log.emplace_back(LogEntry(coor(0, 0)));
|
log.emplace_back(LogEntry(coor(0, 0)));
|
||||||
log.back().myCoor = calculateNextCoor(log, p_Box,puzzleMat);
|
log.back().myCoor = calculateNextCoor(log, p_Box,puzzleMat);
|
||||||
puzzleMat.dp.DestructionOfSurrounding(log.back().myCoor);//calculate dp from surrounding
|
puzzleMat.dp.DestructionOfSurrounding(log.back().myCoor);//calculate dp from surrounding
|
||||||
|
for(auto it:p_Box)
|
||||||
|
log.back().PieceCollector.emplace_back(pair<float,Part*>(0,it));
|
||||||
|
cout << p_Box.size() << endl;
|
||||||
|
cout << log.back().PieceCollector.size() << endl;
|
||||||
solve(log, p_Box,puzzleMat);
|
solve(log, p_Box,puzzleMat);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -72,11 +76,11 @@ coor calculateNextCoor(vector<LogEntry>& log, vector<Part*>& p_Box, Puzzle& puzz
|
|||||||
|
|
||||||
void solve(vector<LogEntry>& log, vector<Part*>& p_Box, Puzzle& puzzleMat)
|
void solve(vector<LogEntry>& log, vector<Part*>& 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);
|
//status(log,p_Box,puzzleMat);
|
||||||
switch(log.back().abstractionLevel)
|
switch(log.back().abstractionLevel)
|
||||||
{
|
{
|
||||||
case 1:
|
case 0:
|
||||||
puzzleMat.a1.EvaluateQuality(log.back().myCoor, log.back().PieceCollector);
|
puzzleMat.a1.EvaluateQuality(log.back().myCoor, log.back().PieceCollector);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -43,11 +43,13 @@ public:
|
|||||||
|
|
||||||
bool PreProcessing()
|
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()
|
coor getSizeAsCoor() {return {cols,rows};}
|
||||||
{return {cols,rows};}
|
|
||||||
|
|
||||||
DestructionPower dp;
|
DestructionPower dp;
|
||||||
AbstractionLayer_1 a1;
|
AbstractionLayer_1 a1;
|
||||||
@ -60,6 +62,7 @@ public:
|
|||||||
void createRandomPuzzle();
|
void createRandomPuzzle();
|
||||||
void putIntoBox();
|
void putIntoBox();
|
||||||
void shuffle();
|
void shuffle();
|
||||||
|
void createBox();
|
||||||
void createp_box();
|
void createp_box();
|
||||||
|
|
||||||
vector<Part> myBox;
|
vector<Part> myBox;
|
||||||
|
@ -5,21 +5,19 @@ int LogEntry::randomed(0);
|
|||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
|
||||||
unsigned int cols=5, rows=6;
|
unsigned int cols=36, rows=28;
|
||||||
|
|
||||||
vector<LogEntry> log;
|
vector<LogEntry> log;
|
||||||
Puzzle puzzleMat(cols, rows);
|
Puzzle puzzleMat(cols, rows);
|
||||||
if(!puzzleMat.PreProcessing())
|
if(!puzzleMat.PreProcessing())
|
||||||
{
|
{
|
||||||
cerr << "Error occured at PreProcessing!";
|
cerr << "Error occurred at PreProcessing!";
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
puzzleMat.createRandomBox();
|
//puzzleMat.createRandomBox();
|
||||||
cout << "here" << endl;
|
|
||||||
puzzleMat.a1.printConstraintMatrix();
|
puzzleMat.a1.printConstraintMatrix();
|
||||||
|
|
||||||
//vector<vector<PuzzlePiece*>> ab1class = abstractionLayer1classify(log, p_myFirstBox,puzzleMat);
|
|
||||||
while(next(log, puzzleMat.p_myBox,puzzleMat));
|
while(next(log, puzzleMat.p_myBox,puzzleMat));
|
||||||
|
|
||||||
puzzleMat.printPuzzle();
|
puzzleMat.printPuzzle();
|
||||||
|
Loading…
Reference in New Issue
Block a user