redid some of the includes and changed way statics are saved

This commit is contained in:
Raphael Maenle
2017-12-21 12:20:57 +01:00
parent 0faadc8c25
commit dd9f8f3250
14 changed files with 159 additions and 110 deletions

View File

@ -3,7 +3,7 @@
#include <map>
#include <vector>
#include "../../header/solve.h"
#include "../../header/input.h"
using namespace std;
@ -19,7 +19,7 @@ typedef map<Part*, float> qualityVector;
* @tparam T template parameter which should be the property class of the layer
*/
template<typename T>
class AbstraktionLayer_Base
class AbstractionLayer_Base
{
public:
/**
@ -63,7 +63,7 @@ public:
m_constraintMatrix = vector<vector<T>>(collumns, vector<T>(rows));
}
vector<vector<T>> m_constraintMatrix; //!<-- Matrix where the constraints of the layer will be saved
vector<vector<T>> m_constraintMatrix{}; //!<-- Matrix where the constraints of the layer will be saved
};

View File

@ -3,7 +3,13 @@
//
#include "DestructionPower.h"
#include <iostream>
map<int,float> DestructionPower_Properties::SpeedTable =
{
{1,0.001}
};
void DestructionPower::PreProcessing(const vector<Part*>* partArray)
{
@ -31,14 +37,18 @@ void DestructionPower::DestructionOfSurrounding(const coor constraintCoordinate)
if(constraintCoordinate.row > 0)
{
divisor++;
newDestructionArray[i] += m_constraintMatrix[constraintCoordinate.col][constraintCoordinate.row-1].m_destruction.DestructionArray[i];
newDestructionArray[i] += m_constraintMatrix[constraintCoordinate.col][constraintCoordinate.row-1].DestructionArray[i];
}
if(constraintCoordinate.col > 0)
{
divisor++;
newDestructionArray[i] += m_constraintMatrix[constraintCoordinate.col-1][constraintCoordinate.row].m_destruction.DestructionArray[i];
newDestructionArray[i] += m_constraintMatrix[constraintCoordinate.col-1][constraintCoordinate.row].DestructionArray[i];
}
if(divisor)
newDestructionArray[i] /=divisor;
}
}
DestructionPower_Properties::DestructionPower_Properties() {
for(int i=0;i<sizeof(DestructionArray);i++)
DestructionArray.emplace_back(DestructionPower_Properties::SpeedTable[i]*DESTRUCTION_INIT);
}

View File

@ -5,25 +5,25 @@
#ifndef SOURCE_DESTRUCTIONPOWER_H
#define SOURCE_DESTRUCTIONPOWER_H
#define DESTRUCTION_INIT 0.5
#define DESTRUCTION_COUNT 1
#include "../AbstraktionLayer_Base.h"
#include "DestructionPower_Properties.h"
#include "../AbstraktionLayer_Base.h"
#include <vector>
#include <iostream>
#include <bitset>
#include <random>
class DestructionPower : public AbstraktionLayer_Base<DestructionPower_Properties>
class DestructionPower : public AbstractionLayer_Base<DestructionPower_Properties>
{
public:
void PreProcessing(const vector<Part*>* partArray);//override
bool EvaluateQuality (const coor constraintCoordinate, qualityVector& qVector);
bool SetConstraintOnPosition(const coor constraintCoordinate, const AbstractionLayer_1_Properties constraint);
bool RemoveConstraintOnPosition(const coor constraintCoordinate);
void PreProcessing(const vector<Part*>* partArray) override;
bool EvaluateQuality (coor constraintCoordinate, qualityVector& qVector) override;
bool SetConstraintOnPosition(coor constraintCoordinate, AbstractionLayer_1_Properties constraint);
bool RemoveConstraintOnPosition(coor constraintCoordinate)override;
void DestructionOfSurrounding(const coor constraintCoordinate);
void DestructionOfSurrounding(coor constraintCoordinate);
private:
};

View File

@ -1,47 +1,29 @@
//
// Created by mpapa on 05.12.2017.
//
#pragma once
#ifndef SOURCE_DESTRUCTIONPOWER_PROPERTIES_H
#define SOURCE_DESTRUCTIONPOWER_PROPERTIES_H
#define DESTRUCTION_INIT 0.5
#include <stdint.h>
#include "DestructionPower.h"
#include <map>
#include <vector>
using namespace std;
class DestructionPower_Properties
{
public:
DestructionPower_Properties()
{
for(int i=0;i<sizeof(DestructionArray);i++)
DestructionArray[i]=(SpeedTable[i]*DESTRUCTION_INIT);
setSpeedTable();
}
explicit DestructionPower_Properties();
map<int,float> getSpeedTable()
{
return SpeedTable;
}
void setSpeedTable()
{ SpeedTable=create_SpeedTable();}
void setSpeedTable();
private:
static map<int,float> create_SpeedTable();
static map<int,float> SpeedTable;
float DestructionArray[DESTRUCTION_COUNT];
vector<float> DestructionArray;
friend class DestructionPower;
};
map<int,float> DestructionPower_Properties::create_SpeedTable()
{
map<int, float> m;
m[1] = 0.001;
return m;
}
#endif //SOURCE_DESTRUCTIONPOWER_PROPERTIES_H
};

View File

@ -3,6 +3,8 @@
//
#include "AbstractionLayer_1.h"
#include "../../../header.h"
#include <iostream>
void AbstractionLayer_1::PreProcessing(const vector<Part*>* partArray)
@ -16,7 +18,7 @@ bool AbstractionLayer_1::EvaluateQuality (const coor constraintCoordinate, quali
{
for(auto it = qVector.begin(); it != qVector.end(); it++)
{
if(PlaceOfPartGood(constraintCoordinate, it->first->m_test1.m_connections))
if(PlaceOfPartGood(constraintCoordinate, it->first->myLayers->m_test1.m_connections))
continue;
qVector.erase(it++);
}
@ -90,7 +92,7 @@ qualityVector AbstractionLayer_1::returnInBox(vector<Part>& PuzzleBox)
int i=0;
for(int col=1;col<m_constraintMatrix.size()-1;col++)
for(int row=1;row<m_constraintMatrix[col].size()-1;row++)
PuzzleBox[i++].m_test1.m_connections=m_constraintMatrix[col][row].m_connections;
PuzzleBox[i++].myLayers->m_test1.m_connections=m_constraintMatrix[col][row].m_connections;
}
@ -106,7 +108,7 @@ void AbstractionLayer_1::setEdgeZero()
bool AbstractionLayer_1::PlaceOfPartGood(coor myCoor, uint8_t& myPart)
{
uint8_t negativePart(0)=0b00000000;
uint8_t negativePart=0b00000000;
negativePart or_eq (m_constraintMatrix[myCoor.col][myCoor.row+1].m_connections & 0b11000000);
negativePart or_eq (m_constraintMatrix[myCoor.col-1][myCoor.row].m_connections & 0b00110000);

View File

@ -5,14 +5,15 @@
#ifndef SOURCE_ABSTRACTIONLAYER_1_H
#define SOURCE_ABSTRACTIONLAYER_1_H
#include "../AbstraktionLayer_Base.h"
#include "AbstractionLayer_1_Properties.h"
#include "../AbstraktionLayer_Base.h"
#include <vector>
#include <iostream>
#include <bitset>
#include <random>
class AbstractionLayer_1 : public AbstraktionLayer_Base<AbstractionLayer_1_Properties>
class AbstractionLayer_1 : public AbstractionLayer_Base<AbstractionLayer_1_Properties>
{
public:
void PreProcessing(const vector<Part*>* partArray);//override

View File

@ -6,7 +6,6 @@
#define SOURCE_ABSTRACTIONLAYER_1_PROPERTIES_H
#include <stdint.h>
#include "AbstractionLayer_1.h"
class AbstractionLayer_1_Properties
{

View File

@ -0,0 +1,11 @@
//
// Created by Raphael Maenle on 21/12/2017.
//
#include "../../header/solve.h"
void Puzzle::printPuzzle() {}
void Puzzle::putIntoBox() {}//puts a puzzlepiece back into its box
void Puzzle::shuffle() {}//shuffles the existing box in Puzzle
void Puzzle::removeConstrains(coor removeCoordinates) {}//deletes all constraints from all abstractionlayers

View File

@ -1,15 +1,14 @@
#include "../../header.h"
void status(vector<LogEntry>& log, vector<Part*>& p_Box);
bool next(vector<LogEntry>& log, vector<Part*>& p_Box)
bool next(vector<LogEntry>& log, vector<Part*>& p_Box,Puzzle& puzzleMat)
{
//last log element is set, create new log element or log not yet started
if(!(log.size()) || log.back().isSet())
{
if(!(p_Box.size())) return false; //puzzle solved
else createNextLogElement(log,p_Box);
else createNextLogElement(log,p_Box,puzzleMat);
}
//last log element is empty, backtrack
else if(!(log.back().PieceCollector.size())) backtrack(log,p_Box,puzzleMat);
@ -25,30 +24,30 @@ bool next(vector<LogEntry>& log, vector<Part*>& p_Box)
{
if(log.back().hasRandomed())
{
if(log.back().abstractionLevel < MAX_ABSTRAX)
if(log.back().abstractionLevel < 2)//do 2 at least two best abstractions to check if part is okay
{
log.back().advance();
solve(log,p_Box);
solve(log,p_Box,puzzleMat);
}
else
setsolution(log,p_Box);
setsolution(log,p_Box,puzzleMat);
}
else
setsolution(log,p_Box);
setsolution(log,p_Box,puzzleMat);
}
return true;
}
void createNextLogElement(vector<LogEntry>& log, vector<Part*>& p_Box)
void createNextLogElement(vector<LogEntry>& log, vector<Part*>& p_Box, Puzzle& puzzleMat)
{
log.emplace_back(LogEntry());
log.back().myCoor = calculateNextCoor(log, p_Box);
log.back().myCoor = calculateNextCoor(log, p_Box,puzzleMat);
//getLayerDestructionPowerfromSurrounding();
solve(log, p_Box);
solve(log, p_Box,puzzleMat);
}
coor calculateNextCoor(vector<LogEntry>& log, vector<Part*>& p_Box)
coor calculateNextCoor(vector<LogEntry>& log, vector<Part*>& p_Box, Puzzle& puzzleMat)
{
//level 1:
//go left to right, then increase current row
@ -57,25 +56,25 @@ coor calculateNextCoor(vector<LogEntry>& log, vector<Part*>& p_Box)
return {0,0};
int m= log.rbegin()[1].myCoor.col;
int n= log.rbegin()[1].myCoor.row;
unsigned int m= log.rbegin()[1].myCoor.col;
unsigned int n= log.rbegin()[1].myCoor.row;
if(m<puzzleMat.getCols()-1) m++;
else if(n<puzzleMat.getRows()-1){ m=0; n++;}
if(m<puzzleMat.getSizeAsCoor().col-1) m++;
else if(n<puzzleMat.getSizeAsCoor().row-1){ m=0; n++;}
else return {};
return {m,n};
//return nextCoor;
}
void solve(vector<LogEntry>& log, vector<Part*>& p_Box)
void solve(vector<LogEntry>& log, vector<Part*>& p_Box, Puzzle& puzzleMat)
{
//getNextHighestLayerworth(puzzleMat); //sets in abstractionLevel
//status(log,p_Box,puzzleMat);
switch(log.back().abstractionLevel)
{
case 1:
puzzleMat.AbstractionLayer_1solver.EvalueteQuality(log.back().PieceCollector);
puzzleMat.a1->EvaluateQuality(log.back().myCoor, log.back().PieceCollector);
break;
default:
@ -90,7 +89,7 @@ void solve(vector<LogEntry>& log, vector<Part*>& p_Box)
}
//removes from box and makes log "set"
void setsolution(vector<LogEntry>& log, vector<Part*>& p_Box)
void setsolution(vector<LogEntry>& log, vector<Part*>& p_Box, Puzzle& puzzleMat)
{
//advance number of randomed part count
if(log.back().PieceCollector.size()>1) log.back().advanceRandomed();
@ -106,7 +105,7 @@ void setsolution(vector<LogEntry>& log, vector<Part*>& p_Box)
log.back().Set();
}
bool backtrack(vector<LogEntry>& log, vector<Part*>& p_Box, puzzleMat)
bool backtrack(vector<LogEntry>& log, vector<Part*>& p_Box, Puzzle& puzzleMat)
{
//if more pieces possible, take next piece
if((log.back().PieceCollector.size())>1)
@ -124,15 +123,15 @@ bool backtrack(vector<LogEntry>& log, vector<Part*>& p_Box, puzzleMat)
//else remove log element and backtrack once more
else
{
puzzleMat.removePiece(log.back().myCoor); //this should remove constraints from all layers
if(!(log.back().PieceCollector.size()))
p_Box.emplace_back(log.back().PieceCollector[0]);
puzzleMat.removeConstrains(log.back().myCoor); //this should remove constraints from all layers
if((log.back().PieceCollector.size()))
p_Box.emplace_back(log.back().PieceCollector.begin()->first);
log.pop_back();
backtrack(log,p_Box,puzzleMat);
}
}
void status(vector<LogEntry>& log, vector<Part*>& p_Box, puzzleMat)
void status(vector<LogEntry>& log, vector<Part*>& p_Box, Puzzle& puzzleMat)
{
cout << "----------------------------" << endl;
cout << "status:" << endl;
@ -151,18 +150,13 @@ void status(vector<LogEntry>& log, vector<Part*>& p_Box, puzzleMat)
cout << endl;
cout << "Box:" << endl;
cout << "size: " << p_Box.size() << endl;
for(auto i:p_Box)
{
i->printPiece();
cout << endl;
}
cout << "Puzzle:" << endl;
puzzleMat.printPuzzle();
cout << "----------------------------" << endl;
}
void calculateTrueDestructionPower(vector<LogEntry>& log, puzzleMat, float Layerworth)
void calculateTrueDestructionPower(vector<LogEntry>& log, Puzzle& puzzleMat, float Layerworth)
{
//hier muss noch rein, wo die zeit der Abstractionlevels gespeichter wird
float destructionPower=sqrt(Layerworth * log.back().abstractionLevel);