redid some of the includes and changed way statics are saved
This commit is contained in:
parent
0faadc8c25
commit
dd9f8f3250
@ -7,10 +7,14 @@ set(CMAKE_CXX_STANDARD 11)
|
|||||||
set(SOURCE_FILES
|
set(SOURCE_FILES
|
||||||
main.cpp
|
main.cpp
|
||||||
header.h
|
header.h
|
||||||
functions/solve/classExtension.cpp
|
|
||||||
functions/solve/structure.cpp
|
functions/solve/structure.cpp
|
||||||
|
|
||||||
functions/AbstractionLayers/AbstraktionLayer_Base.h
|
functions/AbstractionLayers/AbstraktionLayer_Base.h
|
||||||
)
|
functions/AbstractionLayers/Layer1/AbstractionLayer_1.cpp
|
||||||
|
functions/AbstractionLayers/DestructionPower/DestructionPower.cpp
|
||||||
|
header/solve.h
|
||||||
|
header/input.h
|
||||||
|
functions/solve/puzzleExtension.cpp)
|
||||||
add_executable(PuzzleSolver ${SOURCE_FILES})
|
add_executable(PuzzleSolver ${SOURCE_FILES})
|
||||||
include_directories(${OpenCV_INCLUDE_DIRS})
|
include_directories(${OpenCV_INCLUDE_DIRS})
|
||||||
target_link_libraries(PuzzleSolver ${OpenCV_LIBS})
|
target_link_libraries(PuzzleSolver ${OpenCV_LIBS})
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "../../header/solve.h"
|
#include "../../header/input.h"
|
||||||
|
|
||||||
using namespace std;
|
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
|
* @tparam T template parameter which should be the property class of the layer
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
class AbstraktionLayer_Base
|
class AbstractionLayer_Base
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
@ -63,7 +63,7 @@ public:
|
|||||||
m_constraintMatrix = vector<vector<T>>(collumns, vector<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
|
vector<vector<T>> m_constraintMatrix{}; //!<-- Matrix where the constraints of the layer will be saved
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -3,7 +3,13 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#include "DestructionPower.h"
|
#include "DestructionPower.h"
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
|
map<int,float> DestructionPower_Properties::SpeedTable =
|
||||||
|
{
|
||||||
|
{1,0.001}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
void DestructionPower::PreProcessing(const vector<Part*>* partArray)
|
void DestructionPower::PreProcessing(const vector<Part*>* partArray)
|
||||||
{
|
{
|
||||||
@ -31,14 +37,18 @@ void DestructionPower::DestructionOfSurrounding(const coor constraintCoordinate)
|
|||||||
if(constraintCoordinate.row > 0)
|
if(constraintCoordinate.row > 0)
|
||||||
{
|
{
|
||||||
divisor++;
|
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)
|
if(constraintCoordinate.col > 0)
|
||||||
{
|
{
|
||||||
divisor++;
|
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)
|
if(divisor)
|
||||||
newDestructionArray[i] /=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);
|
||||||
|
}
|
@ -5,25 +5,25 @@
|
|||||||
#ifndef SOURCE_DESTRUCTIONPOWER_H
|
#ifndef SOURCE_DESTRUCTIONPOWER_H
|
||||||
#define SOURCE_DESTRUCTIONPOWER_H
|
#define SOURCE_DESTRUCTIONPOWER_H
|
||||||
|
|
||||||
#define DESTRUCTION_INIT 0.5
|
|
||||||
#define DESTRUCTION_COUNT 1
|
#define DESTRUCTION_COUNT 1
|
||||||
|
|
||||||
#include "../AbstraktionLayer_Base.h"
|
|
||||||
#include "DestructionPower_Properties.h"
|
#include "DestructionPower_Properties.h"
|
||||||
|
#include "../AbstraktionLayer_Base.h"
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <bitset>
|
#include <bitset>
|
||||||
#include <random>
|
#include <random>
|
||||||
|
|
||||||
class DestructionPower : public AbstraktionLayer_Base<DestructionPower_Properties>
|
class DestructionPower : public AbstractionLayer_Base<DestructionPower_Properties>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void PreProcessing(const vector<Part*>* partArray);//override
|
void PreProcessing(const vector<Part*>* partArray) override;
|
||||||
bool EvaluateQuality (const coor constraintCoordinate, qualityVector& qVector);
|
bool EvaluateQuality (coor constraintCoordinate, qualityVector& qVector) override;
|
||||||
bool SetConstraintOnPosition(const coor constraintCoordinate, const AbstractionLayer_1_Properties constraint);
|
bool SetConstraintOnPosition(coor constraintCoordinate, AbstractionLayer_1_Properties constraint);
|
||||||
bool RemoveConstraintOnPosition(const coor constraintCoordinate);
|
bool RemoveConstraintOnPosition(coor constraintCoordinate)override;
|
||||||
|
|
||||||
void DestructionOfSurrounding(const coor constraintCoordinate);
|
void DestructionOfSurrounding(coor constraintCoordinate);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
|
@ -1,47 +1,29 @@
|
|||||||
//
|
//
|
||||||
// Created by mpapa on 05.12.2017.
|
// Created by mpapa on 05.12.2017.
|
||||||
//
|
//
|
||||||
|
#pragma once
|
||||||
|
|
||||||
#ifndef SOURCE_DESTRUCTIONPOWER_PROPERTIES_H
|
#define DESTRUCTION_INIT 0.5
|
||||||
#define SOURCE_DESTRUCTIONPOWER_PROPERTIES_H
|
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "DestructionPower.h"
|
#include <map>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
class DestructionPower_Properties
|
class DestructionPower_Properties
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DestructionPower_Properties()
|
explicit DestructionPower_Properties();
|
||||||
{
|
|
||||||
for(int i=0;i<sizeof(DestructionArray);i++)
|
|
||||||
DestructionArray[i]=(SpeedTable[i]*DESTRUCTION_INIT);
|
|
||||||
|
|
||||||
setSpeedTable();
|
|
||||||
|
|
||||||
}
|
|
||||||
map<int,float> getSpeedTable()
|
map<int,float> getSpeedTable()
|
||||||
{
|
{
|
||||||
return SpeedTable;
|
return SpeedTable;
|
||||||
}
|
}
|
||||||
void setSpeedTable()
|
void setSpeedTable();
|
||||||
{ SpeedTable=create_SpeedTable();}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
static map<int,float> create_SpeedTable();
|
|
||||||
static map<int,float> SpeedTable;
|
static map<int,float> SpeedTable;
|
||||||
|
vector<float> DestructionArray;
|
||||||
float DestructionArray[DESTRUCTION_COUNT];
|
|
||||||
|
|
||||||
friend class DestructionPower;
|
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
|
|
@ -3,6 +3,8 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#include "AbstractionLayer_1.h"
|
#include "AbstractionLayer_1.h"
|
||||||
|
#include "../../../header.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
void AbstractionLayer_1::PreProcessing(const vector<Part*>* partArray)
|
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++)
|
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;
|
continue;
|
||||||
qVector.erase(it++);
|
qVector.erase(it++);
|
||||||
}
|
}
|
||||||
@ -90,7 +92,7 @@ qualityVector AbstractionLayer_1::returnInBox(vector<Part>& PuzzleBox)
|
|||||||
int i=0;
|
int i=0;
|
||||||
for(int col=1;col<m_constraintMatrix.size()-1;col++)
|
for(int col=1;col<m_constraintMatrix.size()-1;col++)
|
||||||
for(int row=1;row<m_constraintMatrix[col].size()-1;row++)
|
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)
|
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][myCoor.row+1].m_connections & 0b11000000);
|
||||||
negativePart or_eq (m_constraintMatrix[myCoor.col-1][myCoor.row].m_connections & 0b00110000);
|
negativePart or_eq (m_constraintMatrix[myCoor.col-1][myCoor.row].m_connections & 0b00110000);
|
||||||
|
@ -5,14 +5,15 @@
|
|||||||
#ifndef SOURCE_ABSTRACTIONLAYER_1_H
|
#ifndef SOURCE_ABSTRACTIONLAYER_1_H
|
||||||
#define SOURCE_ABSTRACTIONLAYER_1_H
|
#define SOURCE_ABSTRACTIONLAYER_1_H
|
||||||
|
|
||||||
#include "../AbstraktionLayer_Base.h"
|
|
||||||
#include "AbstractionLayer_1_Properties.h"
|
#include "AbstractionLayer_1_Properties.h"
|
||||||
|
#include "../AbstraktionLayer_Base.h"
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <bitset>
|
#include <bitset>
|
||||||
#include <random>
|
#include <random>
|
||||||
|
|
||||||
class AbstractionLayer_1 : public AbstraktionLayer_Base<AbstractionLayer_1_Properties>
|
class AbstractionLayer_1 : public AbstractionLayer_Base<AbstractionLayer_1_Properties>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void PreProcessing(const vector<Part*>* partArray);//override
|
void PreProcessing(const vector<Part*>* partArray);//override
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
#define SOURCE_ABSTRACTIONLAYER_1_PROPERTIES_H
|
#define SOURCE_ABSTRACTIONLAYER_1_PROPERTIES_H
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "AbstractionLayer_1.h"
|
|
||||||
|
|
||||||
class AbstractionLayer_1_Properties
|
class AbstractionLayer_1_Properties
|
||||||
{
|
{
|
||||||
|
11
Source/functions/solve/puzzleExtension.cpp
Normal file
11
Source/functions/solve/puzzleExtension.cpp
Normal 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
|
@ -1,15 +1,14 @@
|
|||||||
#include "../../header.h"
|
#include "../../header.h"
|
||||||
|
|
||||||
void status(vector<LogEntry>& log, vector<Part*>& p_Box);
|
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
|
//last log element is set, create new log element or log not yet started
|
||||||
if(!(log.size()) || log.back().isSet())
|
if(!(log.size()) || log.back().isSet())
|
||||||
{
|
{
|
||||||
if(!(p_Box.size())) return false; //puzzle solved
|
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
|
//last log element is empty, backtrack
|
||||||
else if(!(log.back().PieceCollector.size())) backtrack(log,p_Box,puzzleMat);
|
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().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();
|
log.back().advance();
|
||||||
solve(log,p_Box);
|
solve(log,p_Box,puzzleMat);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
setsolution(log,p_Box);
|
setsolution(log,p_Box,puzzleMat);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
setsolution(log,p_Box);
|
setsolution(log,p_Box,puzzleMat);
|
||||||
}
|
}
|
||||||
return true;
|
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.emplace_back(LogEntry());
|
||||||
log.back().myCoor = calculateNextCoor(log, p_Box);
|
log.back().myCoor = calculateNextCoor(log, p_Box,puzzleMat);
|
||||||
//getLayerDestructionPowerfromSurrounding();
|
//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:
|
//level 1:
|
||||||
//go left to right, then increase current row
|
//go left to right, then increase current row
|
||||||
@ -57,25 +56,25 @@ coor calculateNextCoor(vector<LogEntry>& log, vector<Part*>& p_Box)
|
|||||||
return {0,0};
|
return {0,0};
|
||||||
|
|
||||||
|
|
||||||
int m= log.rbegin()[1].myCoor.col;
|
unsigned int m= log.rbegin()[1].myCoor.col;
|
||||||
int n= log.rbegin()[1].myCoor.row;
|
unsigned int n= log.rbegin()[1].myCoor.row;
|
||||||
|
|
||||||
|
|
||||||
if(m<puzzleMat.getCols()-1) m++;
|
if(m<puzzleMat.getSizeAsCoor().col-1) m++;
|
||||||
else if(n<puzzleMat.getRows()-1){ m=0; n++;}
|
else if(n<puzzleMat.getSizeAsCoor().row-1){ m=0; n++;}
|
||||||
else return {};
|
else return {};
|
||||||
return {m,n};
|
return {m,n};
|
||||||
//return nextCoor;
|
//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
|
//getNextHighestLayerworth(puzzleMat); //sets in abstractionLevel
|
||||||
//status(log,p_Box,puzzleMat);
|
//status(log,p_Box,puzzleMat);
|
||||||
switch(log.back().abstractionLevel)
|
switch(log.back().abstractionLevel)
|
||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
puzzleMat.AbstractionLayer_1solver.EvalueteQuality(log.back().PieceCollector);
|
puzzleMat.a1->EvaluateQuality(log.back().myCoor, log.back().PieceCollector);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -90,7 +89,7 @@ void solve(vector<LogEntry>& log, vector<Part*>& p_Box)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//removes from box and makes log "set"
|
//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
|
//advance number of randomed part count
|
||||||
if(log.back().PieceCollector.size()>1) log.back().advanceRandomed();
|
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();
|
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 more pieces possible, take next piece
|
||||||
if((log.back().PieceCollector.size())>1)
|
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 remove log element and backtrack once more
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
puzzleMat.removePiece(log.back().myCoor); //this should remove constraints from all layers
|
puzzleMat.removeConstrains(log.back().myCoor); //this should remove constraints from all layers
|
||||||
if(!(log.back().PieceCollector.size()))
|
if((log.back().PieceCollector.size()))
|
||||||
p_Box.emplace_back(log.back().PieceCollector[0]);
|
p_Box.emplace_back(log.back().PieceCollector.begin()->first);
|
||||||
log.pop_back();
|
log.pop_back();
|
||||||
backtrack(log,p_Box,puzzleMat);
|
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 << "----------------------------" << endl;
|
||||||
cout << "status:" << endl;
|
cout << "status:" << endl;
|
||||||
@ -151,18 +150,13 @@ void status(vector<LogEntry>& log, vector<Part*>& p_Box, puzzleMat)
|
|||||||
cout << endl;
|
cout << endl;
|
||||||
cout << "Box:" << endl;
|
cout << "Box:" << endl;
|
||||||
cout << "size: " << p_Box.size() << endl;
|
cout << "size: " << p_Box.size() << endl;
|
||||||
for(auto i:p_Box)
|
|
||||||
{
|
|
||||||
i->printPiece();
|
|
||||||
cout << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
cout << "Puzzle:" << endl;
|
cout << "Puzzle:" << endl;
|
||||||
puzzleMat.printPuzzle();
|
puzzleMat.printPuzzle();
|
||||||
cout << "----------------------------" << endl;
|
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
|
//hier muss noch rein, wo die zeit der Abstractionlevels gespeichter wird
|
||||||
float destructionPower=sqrt(Layerworth * log.back().abstractionLevel);
|
float destructionPower=sqrt(Layerworth * log.back().abstractionLevel);
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
#ifndef HEADER_H
|
||||||
|
#define HEADER_H
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <bitset>
|
#include <bitset>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
@ -6,14 +9,9 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <random>
|
#include <random>
|
||||||
|
|
||||||
#define MAX_ABSTRAX 1
|
|
||||||
#define structdebug
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
/**
|
#include "header/input.h"
|
||||||
* IMPORTANT: Each new layer must be included there, to avoid compile errors
|
|
||||||
*/
|
|
||||||
#include "functions/AbstractionLayers/Layer1/AbstractionLayer_1.h"
|
|
||||||
#include "functions/AbstractionLayers/DestructionPower/DestructionPower.h"
|
|
||||||
#include "header/solve.h"
|
#include "header/solve.h"
|
||||||
|
|
||||||
|
#endif //HEADER_H
|
@ -1,7 +1,18 @@
|
|||||||
|
//
|
||||||
|
// Created by mpapa on 05.12.2017.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef SOURCE_INPUT_H
|
||||||
|
#define SOURCE_INPUT_H
|
||||||
|
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "../functions/AbstractionLayers/Layer1/AbstractionLayer_1_Properties.h"
|
#include "../functions/AbstractionLayers/Layer1/AbstractionLayer_1_Properties.h"
|
||||||
#include "../functions/AbstractionLayers/DestructionPower/DestructionPower_Properties.h"
|
#include "../functions/AbstractionLayers/DestructionPower/DestructionPower_Properties.h"
|
||||||
|
|
||||||
|
class LayerContainer;
|
||||||
|
|
||||||
class Part
|
class Part
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -28,10 +39,19 @@ public:
|
|||||||
m_numOfRotations = numOfRotations;
|
m_numOfRotations = numOfRotations;
|
||||||
}
|
}
|
||||||
|
|
||||||
AbstractionLayer_1_Properties m_test1;
|
LayerContainer* myLayers;
|
||||||
DestructionPower_Properties m_destruction;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int32_t m_partID;
|
int32_t m_partID;
|
||||||
uint8_t m_numOfRotations;
|
uint8_t m_numOfRotations;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class coor
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
unsigned int col, row;
|
||||||
|
coor(unsigned int newcol=-1,unsigned int newrow=-1): col(newcol), row(newrow)
|
||||||
|
{}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif //SOURCE_INPUT_H
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
//
|
||||||
|
// Created by mpapa on 05.12.2017.
|
||||||
|
//
|
||||||
|
|
||||||
#ifndef SOURCE_SOLVE_H
|
#ifndef SOURCE_SOLVE_H
|
||||||
#define SOURCE_SOLVE_H
|
#define SOURCE_SOLVE_H
|
||||||
|
|
||||||
@ -6,18 +10,12 @@
|
|||||||
#include <opencv2/highgui/highgui.hpp>
|
#include <opencv2/highgui/highgui.hpp>
|
||||||
#include <opencv2/imgproc/imgproc.hpp>
|
#include <opencv2/imgproc/imgproc.hpp>
|
||||||
|
|
||||||
class Part;
|
#include "../functions/AbstractionLayers/Layer1/AbstractionLayer_1.h"
|
||||||
|
#include "../functions/AbstractionLayers/DestructionPower/DestructionPower.h"
|
||||||
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
class coor
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
unsigned int col, row;
|
|
||||||
coor(int newcol=-1,int newrow=-1): col(newcol), row(newrow)
|
|
||||||
{}
|
|
||||||
};
|
|
||||||
|
|
||||||
class LogEntry
|
class LogEntry
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -34,7 +32,7 @@ public:
|
|||||||
|
|
||||||
LogEntry()
|
LogEntry()
|
||||||
{
|
{
|
||||||
myCoor = coor();
|
myCoor = coor(0,0);
|
||||||
abstractionLevel=0;
|
abstractionLevel=0;
|
||||||
set=0;
|
set=0;
|
||||||
}
|
}
|
||||||
@ -43,11 +41,47 @@ private:
|
|||||||
static int randomed;
|
static int randomed;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class Puzzle
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Puzzle(unsigned int newcols,unsigned int newrows):rows(newrows),cols(newcols){}
|
||||||
|
|
||||||
|
coor getSizeAsCoor()
|
||||||
|
{return {cols,rows};}
|
||||||
|
|
||||||
|
DestructionPower* dp;
|
||||||
|
AbstractionLayer_1* a1;
|
||||||
|
|
||||||
|
void removeConstrains(coor removeCoordinates);
|
||||||
|
void printPuzzle();
|
||||||
|
|
||||||
|
void createRandomBox(){createRandomPuzzle();putIntoBox();shuffle();}
|
||||||
|
void createRandomPuzzle(){a1->CreateRandomPuzzle();}
|
||||||
|
void putIntoBox();
|
||||||
|
void shuffle();
|
||||||
|
|
||||||
|
vector<Part> myBox;
|
||||||
|
vector<Part*> p_myBox;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
unsigned int rows;
|
||||||
|
unsigned int cols;
|
||||||
|
};
|
||||||
|
|
||||||
|
class LayerContainer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
AbstractionLayer_1_Properties m_test1;
|
||||||
|
DestructionPower_Properties m_destruction;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
bool next(vector<LogEntry>& log, vector<Part*>& p_Box, Puzzle& puzzleMat);
|
bool next(vector<LogEntry>& log, vector<Part*>& p_Box, Puzzle& puzzleMat);
|
||||||
coor calculateNextCoor(vector<LogEntry>& log, vector<Part*>& p_Box, Puzzle& puzzleMat);
|
coor calculateNextCoor(vector<LogEntry>& log, vector<Part*>& p_Box, Puzzle& puzzleMat);
|
||||||
void solve(vector<LogEntry>& log, vector<Part*>& p_Box, Puzzle& puzzleMat);
|
void solve(vector<LogEntry>& log, vector<Part*>& p_Box, Puzzle& puzzleMat);
|
||||||
void setsolution(vector<LogEntry>& log, vector<Part*>& p_Box, Puzzle& puzzleMat);
|
void setsolution(vector<LogEntry>& log, vector<Part*>& p_Box, Puzzle& puzzleMat);
|
||||||
bool backtrack(vector<LogEntry>& log, vector<Part*>& p_Box, puzzleMat);
|
bool backtrack(vector<LogEntry>& log, vector<Part*>& p_Box, Puzzle& puzzleMat);
|
||||||
|
|
||||||
void createNextLogElement(vector<LogEntry>& log, vector<Part*>& p_Box, Puzzle& puzzleMat);
|
void createNextLogElement(vector<LogEntry>& log, vector<Part*>& p_Box, Puzzle& puzzleMat);
|
||||||
|
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
#include "header.h"
|
#include "header.h"
|
||||||
#include "header/input.h"
|
|
||||||
|
|
||||||
int LogEntry::randomed(0);
|
int LogEntry::randomed(0);
|
||||||
unsigned int PuzzlePiece::idcount(0);
|
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
@ -10,21 +8,17 @@ int main()
|
|||||||
unsigned int cols=5, rows=6;
|
unsigned int cols=5, rows=6;
|
||||||
|
|
||||||
//some basic random puzzle stuff
|
//some basic random puzzle stuff
|
||||||
vector<Part> myFirstBox = createBox(coor(cols,rows));
|
Puzzle myFirstPuzzle(cols,rows);
|
||||||
|
myFirstPuzzle.createRandomBox();
|
||||||
|
|
||||||
//some advanced solver stuff
|
//some advanced solver stuff
|
||||||
vector<LogEntry> log;
|
vector<LogEntry> log;
|
||||||
vector<Part*> p_myFirstBox;
|
vector<Part*> p_myFirstBox;
|
||||||
|
|
||||||
//BoxClassify myFirstBox();
|
|
||||||
cout << endl;
|
|
||||||
for(auto &i:myFirstBox)
|
|
||||||
p_myFirstBox.push_back(&i);
|
|
||||||
|
|
||||||
Puzzle puzzleMat(cols, rows);
|
Puzzle puzzleMat(cols, rows);
|
||||||
|
|
||||||
//vector<vector<PuzzlePiece*>> ab1class = abstractionLayer1classify(log, p_myFirstBox,puzzleMat);
|
//vector<vector<PuzzlePiece*>> ab1class = abstractionLayer1classify(log, p_myFirstBox,puzzleMat);
|
||||||
while(next(log, p_myFirstBox,puzzleMat));
|
while(next(log, puzzleMat.p_myBox,puzzleMat));
|
||||||
|
|
||||||
puzzleMat.printPuzzle();
|
puzzleMat.printPuzzle();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user