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) {
|
||||
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;
|
||||
}
|
||||
|
@ -29,4 +29,5 @@ public:
|
||||
{ m_constraintMatrix[myCoor.col][myCoor.row].DestructionArray[AbstractionLevel] = destructionPower;}
|
||||
|
||||
private:
|
||||
float defaultDestructionPower(int i);
|
||||
};
|
||||
|
@ -10,26 +10,26 @@
|
||||
|
||||
bool AbstractionLayer_1::PreProcessing(coor mySize, const vector<Part*>* partArray)
|
||||
{
|
||||
|
||||
const vector<Part*>& ref_partArray = *partArray;
|
||||
analyseParts analyse(1008);
|
||||
vector<Part> 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<Part*>* 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;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;
|
||||
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))
|
||||
|
@ -24,7 +24,7 @@
|
||||
#include <bitset>
|
||||
|
||||
#define DISPLAY false
|
||||
#define PATH "..\\pieces\\%d.png"
|
||||
#define PATH "..\\..\\..\\pieces\\%04d.jpg"
|
||||
#define IMG_SIZE 400
|
||||
#define TOP 6
|
||||
#define RIGHT 4
|
||||
|
@ -67,5 +67,23 @@ void Puzzle::createRandomPuzzle()
|
||||
|
||||
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.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<float,Part*>(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<LogEntry>& log, vector<Part*>& p_Box, Puzzle& puzz
|
||||
|
||||
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);
|
||||
switch(log.back().abstractionLevel)
|
||||
{
|
||||
case 1:
|
||||
case 0:
|
||||
puzzleMat.a1.EvaluateQuality(log.back().myCoor, log.back().PieceCollector);
|
||||
break;
|
||||
|
||||
|
@ -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<Part> myBox;
|
||||
|
@ -5,21 +5,19 @@ int LogEntry::randomed(0);
|
||||
int main()
|
||||
{
|
||||
|
||||
unsigned int cols=5, rows=6;
|
||||
unsigned int cols=36, rows=28;
|
||||
|
||||
vector<LogEntry> 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<vector<PuzzlePiece*>> ab1class = abstractionLayer1classify(log, p_myFirstBox,puzzleMat);
|
||||
while(next(log, puzzleMat.p_myBox,puzzleMat));
|
||||
|
||||
puzzleMat.printPuzzle();
|
||||
|
Loading…
Reference in New Issue
Block a user