Merge branch 'master' into MergeBranch_resultImage

This commit is contained in:
Raphael Maenle
2018-01-20 22:01:53 +01:00
12 changed files with 160 additions and 50 deletions

View File

@ -1,7 +1,3 @@
//
// Created by mpapa on 05.12.2017.
//
#include "DestructionPower.h"
//TODO! Add more layers here!
@ -9,10 +5,11 @@
//sets relations of speed for the different layers
map<int,float> DestructionPower_Properties::SpeedTable =
{
{0,0.99}
{0,0.99},
{1,0.7},
{2,0.7}
};
bool DestructionPower::PreProcessing(coor mySize,const vector<Part*>* partArray)
{
cout << "DestructionPower Preprocessing... ";
@ -38,7 +35,10 @@ bool DestructionPower::RemoveConstraintOnPosition(const coor constraintCoordinat
//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);
int divisor=0;
if(constraintCoordinate.row > 0)
@ -55,7 +55,10 @@ void DestructionPower::DestructionOfSurrounding(const coor constraintCoordinate)
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];
m_constraintMatrix[constraintCoordinate.col][constraintCoordinate.row].DestructionArray[i] = m_constraintMatrix[constraintCoordinate.col][constraintCoordinate.row].SpeedTable[i];
//aging
if(m_constraintMatrix[constraintCoordinate.col][constraintCoordinate.row].DestructionArray[i]<0.9)
m_constraintMatrix[constraintCoordinate.col][constraintCoordinate.row].DestructionArray[i]=m_constraintMatrix[constraintCoordinate.col][constraintCoordinate.row].DestructionArray[i]*(float)1.001+(float)0.01;
}
}
@ -102,6 +105,6 @@ DestructionPower_Properties::DestructionPower_Properties() {
{
DestructionArray.emplace_back((DestructionPower_Properties::SpeedTable[i]*DESTRUCTION_INIT));
DestructionArray.back()<0.99 ? DestructionArray.back()*=aging:DestructionArray.back();
DestructionArray.back()<0.8 ? DestructionArray.back()=aging*DestructionArray.back()+(float)0.01:DestructionArray.back();
}
}

View File

@ -1,9 +1,5 @@
//
// Created by mpapa on 05.12.2017.
//
#pragma once
//TODO!! increase Destructioncount
#define DESTRUCTION_COUNT 1
#include "DestructionPower_Properties.h"

View File

@ -1,6 +1,3 @@
//
// Created by mpapa on 05.12.2017.
//
#pragma once
#define DESTRUCTION_INIT 0.5

View File

@ -1,10 +1,5 @@
//
// Created by mpapa on 05.12.2017.
//
#include "AbstractionLayer_1.h"
#include "../../../header.h"
#include <iostream>
#include <bitset>
@ -14,6 +9,7 @@ bool AbstractionLayer_1::PreProcessing(coor mySize, const vector<Part*>* partAr
const vector<Part*>& ref_partArray = *partArray;
analyseParts analyse(mySize.row*mySize.col);
Part buf;
int PSum=0;
int iterator=0;
if(!analyse.getImages())
{
@ -24,7 +20,8 @@ bool AbstractionLayer_1::PreProcessing(coor mySize, const vector<Part*>* partAr
//TODO rows and cols
for(int i = 0; i < mySize.row*mySize.col; i++)
{
unsigned char poempel = analyse.getTabs(i);;
unsigned char poempel = analyse.getTabs(i);
PSum+=PoempelSum(poempel); //preprocess correct check
for (int j=0;j<4;j++)
{
ref_partArray[iterator]->m_a1.m_connections=poempel;
@ -33,10 +30,12 @@ bool AbstractionLayer_1::PreProcessing(coor mySize, const vector<Part*>* partAr
}
}
if(PREPRO_CHECK && PSum)
return false;
//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
InitialiseConstraintMatrixSize(mySize.col+2, mySize.row+2); //col row switched in this function
setEdgeZero();
@ -44,9 +43,39 @@ bool AbstractionLayer_1::PreProcessing(coor mySize, const vector<Part*>* partAr
return true;
}
int AbstractionLayer_1::PoempelSum(uint8_t constraint)
{
int PoempelSum=0;
if((constraint & 0b11000000)==0b01000000)
PoempelSum--;
else if((constraint & 0b11000000)==0b10000000)
PoempelSum++;
if((constraint & 0b00110000)==0b00010000)
PoempelSum--;
else if((constraint & 0b00110000)==0b00100000)
PoempelSum++;
if((constraint & 0b00001100)==0b00000100)
PoempelSum--;
else if((constraint & 0b00001100)==0b00001000)
PoempelSum++;
if((constraint & 0b00000011)==0b00000001)
PoempelSum--;
else if((constraint & 0b00000011)==0b00000010)
PoempelSum++;
return PoempelSum;
}
//it through qualityVector and removes all that do not trigger PlaceOfPartGood
bool AbstractionLayer_1::EvaluateQuality (const coor constraintCoordinate, qualityVector& qVector)
{
if(constraintCoordinate.row==23 && constraintCoordinate.col==35)
cout << "in" << endl;
//evaluateQuality = evaluateProbabilaty
for(int i = 0;i<qVector.size();i++)
{
if(PlaceOfPartGood(constraintCoordinate, qVector[i].second->m_a1.m_connections))
@ -69,6 +98,20 @@ bool AbstractionLayer_1::RemoveConstraintOnPosition(const coor constraintCoordin
m_constraintMatrix[constraintCoordinate.col+1][constraintCoordinate.row+1].m_connections=0b11111111;
}
int AbstractionLayer_1::RemoveSimilar(qualityVector& qVector,uint8_t& constraints)
{
//
for(int i=0;i<qVector.size();)
{
if(qVector[i].second->m_a1.m_connections==constraints)
qVector.erase(qVector.begin()+i);
else
i++;
}
}
void AbstractionLayer_1::CreateRandomPuzzle()
{
std::minstd_rand simple_rand;
@ -120,8 +163,6 @@ void AbstractionLayer_1::CreateRandomPuzzle()
}
//puts all pieces of the current constraint matrix into a puzzlebox
qualityVector AbstractionLayer_1::returnInBox(vector<Part>& PuzzleBox)
{
@ -184,7 +225,11 @@ bool AbstractionLayer_1::PlaceOfPartGood(coor myCoor, uint8_t& myPart)
|| ((((negativePart & 0b00000011) == 0b00000011) || ((myPart & 0b00000011) == 0b00000011)) && (((myPart & 0b00000011) != 0b00000000) && (negativePart & 0b00000011) != 0b00000000))
|| (((negativePart & 0b00000011) == 0b00000000) && ((myPart & 0b00000011) == 0b00000000)) )
)
{
if(myCoor.row==18 && myCoor.col==35)
cout << "gud: " << std::bitset<8>(myPart) << endl;
return true;
}
return false;
}

View File

@ -49,10 +49,13 @@ public:
bool EvaluateQuality ( coor constraintCoordinate, qualityVector& qVector)override;
bool SetConstraintOnPosition( coor constraintCoordinate, AbstractionLayer_1_Properties constraint)override;
bool RemoveConstraintOnPosition( coor constraintCoordinate)override;
int RemoveSimilar(qualityVector&,uint8_t&);
bool PlaceOfPartGood(coor myCoor, uint8_t& myPart);
void shift(uint8_t& Part, int shifts);
void setEdgeZero();
int PoempelSum(uint8_t constraint);
void CreateRandomPuzzle();
qualityVector returnInBox(vector<Part>& PuzzleBox);