Merge branch 'TeamCGPU_TestWithBaseLayer' into Team_CMU_MergeBase

This commit is contained in:
Raphael Maenle 2017-12-18 21:24:21 +01:00
parent 0048f5b42d
commit 90e31ddba6
6 changed files with 247 additions and 16 deletions

View File

@ -0,0 +1,71 @@
#ifndef SOURCE_ABSTRAKTIONLAYER_BASE_H
#define SOURCE_ABSTRAKTIONLAYER_BASE_H
#include <map>
#include <vector>
#include "../../header/solve.h"
#include "../../header/input.h"
using namespace std;
typedef map<Part*, float> qualityVector;
/*
* Die Logik mit der Template-Basisklasse und den abgeleiteten Layern kam mit der Idee, dass die Layer
* nicht auf die Layer-Eigenschaften der anderen Layer zugreifen können, da die mit friend geschützt sind.
* Ansonsten könnte man auch verschiedene Objekte der Template Basisklasse erstellen
*/
/**
* @brief template base class for all different layers
* @tparam T template parameter which should be the property class of the layer
*/
template<typename T>
class AbstraktionLayer_Base
{
public:
/**
* @brief pure virtual method for the pre processing of the layer
* @param [in] partArray - References of all Parts, in which the properties of the Layer will be written
*/
virtual void PreProcessing(const vector<Part*>* partArray) = 0;
/**
* @brief pure virtual method for the quality evaluation of the layer
* @param [in] constraintCoordinate - Coordinate where the quality should evaluate for each given part
* @param [in/out] qualityVector - References of all parts with the quality of their quality to fit in the given coordinate
* @return Boolean if the quality was calculated right or not
*/
virtual bool EvalueteQuality (const coor constraintCoordinate, qualityVector& qVector) = 0;
/**
* @brief pure virtual method which sets the constraint on the given Coordinate in the m_constraintMatrix
* This function will be called from main for all layers
* @param [in] constraintCoordinate - Coordinate where the constraint should be placed
* @param [in] constraint - constraint which should be placed
* @return Boolean if the constraint was set or a failure happened
*/
virtual bool SetConstraintOnPosition(const coor constraintCoordinate, const T constraint) = 0;
/**
* @brief pure virtual method which remove the constraint on the given Coordinate of the m_constraintMatrix
* This function will be called from main for all layers
* @param [in] constraintCoordinate - Coordinate where the constraint should be removed
* @return Boolean if the remove was successfull or failed
*/
virtual bool RemoveConstraintOnPosition(const coor constraintCoordinate) = 0;
/**
* @brief virtual method to initialise the m_constraintMatrix to a given size
* @param [in] collumns - Wished collumns of the m_constraintMatrix
* @param [in] rows - Wished rows of the m_constraintMatrix
*/
virtual void InitialiseConstraintMatrixSize(const int32_t collumns, const int32_t rows)
{
m_constraintMatrix = vector<vector<T>>(collumns, vector<T>(rows));
}
vector<vector<T>> m_constraintMatrix; //!<-- Matrix where the constraints of the layer will be saved
};
#endif //SOURCE_ABSTRAKTIONLAYER_BASE_H

View File

@ -0,0 +1,91 @@
//
// Created by mpapa on 05.12.2017.
//
#include "AbstractionLayer_1.h"
#include <iostream>
void AbstractionLayer_1::PreProcessing(const vector<Part*>* partArray)
{
InitialiseConstraintMatrixSize(32+2, 28+2);
setEdgeZero();
}
bool AbstractionLayer_1::EvalueteQuality (const coor constraintCoordinate, qualityVector& qVector)
{
}
bool AbstractionLayer_1::SetConstraintOnPosition(const coor constraintCoordinate, const AbstractionLayer_1_Properties constraint)
{
}
bool AbstractionLayer_1::RemoveConstraintOnPosition(const coor constraintCoordinate)
{
}
bool AbstractionLayer_1::CreateRandomPuzzle()
{
for(int col=1;col<m_constraintMatrix.size()-1;col++){
for(int row=1;row<m_constraintMatrix[col].size()-1;row++)
{
uint8_t tempPiece = 0b00000000;
if(rand()%2)
tempPiece|=0b01000000;
else
tempPiece|=0b10000000;
if(rand()%2)
tempPiece|=0b00000100;
else
tempPiece|=0b00001000;
if(m_constraintMatrix[col-1][row].m_connections != 0b00000000 || m_constraintMatrix[col-1][row].m_connections != 0b11111111)
{
tempPiece|=(0b00110000 xor (0b00110000 & m_constraintMatrix[col-1][row].m_connections));
//tempPiece.shift();
}
}
//add shift function
else
{
if(rand()%2)
tempPiece|=0b00000001;
else
tempPiece|=0b00000010;
}
if(m_constraintMatrix[col-1][row].m_connections != 0b00000000 || m_constraintMatrix[col-1][row].m_connections != 0b11111111)
tempPiece |= (0b00110000 xor (0b00110000 & m_constraintMatrix[col-1][row].m_connections));
else
{
if(rand()%2)
tempPiece |= 0b00010000;
else
tempPiece |= 0b00100000;
}
}
//insert temppuzzlepiece into matrix
}
}
void AbstractionLayer_1::setEdgeZero()
{
for(int col=0;col<m_constraintMatrix.size();col++)
for(int row=0;row<m_constraintMatrix[col].size();row++)
if(col ==0 || col == m_constraintMatrix.size() || row == 0 || row == m_constraintMatrix[col].size())
m_constraintMatrix[col][row].m_connections=0b00000000;
}

View File

@ -0,0 +1,30 @@
//
// Created by mpapa on 05.12.2017.
//
#ifndef SOURCE_ABSTRACTIONLAYER_1_H
#define SOURCE_ABSTRACTIONLAYER_1_H
#include "../AbstraktionLayer_Base.h"
#include "AbstractionLayer_1_Properties.h"
#include <vector>
#include <iostream>
#include <bitset>
class AbstractionLayer_1 : public AbstraktionLayer_Base<AbstractionLayer_1_Properties>
{
public:
void PreProcessing(const vector<Part*>* partArray);
bool EvalueteQuality (const coor constraintCoordinate, qualityVector& qVector);
bool SetConstraintOnPosition(const coor constraintCoordinate, const AbstractionLayer_1_Properties constraint);
bool RemoveConstraintOnPosition(const coor constraintCoordinate);
void setEdgeZero();
bool CreateRandomPuzzle();
private:
};
#endif //SOURCE_ABSTRACTIONLAYER_1_H

View File

@ -0,0 +1,21 @@
//
// Created by mpapa on 05.12.2017.
//
#ifndef SOURCE_ABSTRACTIONLAYER_1_PROPERTIES_H
#define SOURCE_ABSTRACTIONLAYER_1_PROPERTIES_H
#include <stdint.h>
#include "AbstractionLayer_1.h"
class AbstractionLayer_1_Properties
{
public:
AbstractionLayer_1_Properties() : m_connections(0b11111111) {}
private:
uint8_t m_connections;
friend class AbstractionLayer_1;
};
#endif //SOURCE_ABSTRACTIONLAYER_1_PROPERTIES_H

View File

@ -83,10 +83,10 @@ void solve(vector<LogEntry>& log, vector<PuzzlePiece*>& p_Box, Puzzle& puzzleMat
break; break;
} }
capLogElements(log); //capLogElements(log);
calculateWorth(log); //calculateWorth(log);
calculateTrueDestructionPower(log,puzzleMat); //calculateTrueDestructionPower(log,puzzleMat);
calculateNewCombinedProbablility(log); //calculateNewCombinedProbablility(log);
} }

View File

@ -1,22 +1,40 @@
#ifndef SOURCE_PART_H
#define SOURCE_PART_H
#include <stdint.h> #include <stdint.h>
#include "../functions/AbstractionLayers/Layer1/AbstractionLayer_1_Properties.h"
class Part class Part
{ {
public: public:
double r; Part() : m_partID(0) {}
double g;
double b;
Part(): connections(0){}
~Part() {} ~Part() {}
uint8_t getConnections() const
{return connections;}
void setConnections(uint8_t newconnections) int32_t GetPartID () const
{connections = newconnections;} {
return m_partID;
}
void SetPartID(const int32_t partID)
{
m_partID = partID;
}
uint8_t GetNumOfRotations () const
{
return m_numOfRotations;
}
void SetNumOfRotations(const uint8_t numOfRotations)
{
m_numOfRotations = numOfRotations;
}
AbstractionLayer_1_Properties m_test1;
private: private:
uint8_t connections; int32_t m_partID;
uint8_t m_numOfRotations;
}; };
#endif //SOURCE_PART_H