Changed qualityVector from map to vector of pairs
This change is better for the dispatcher, as he can sort the qualityvector now easily by the quality of each part
This commit is contained in:
parent
ce6fc0db72
commit
4f9f43991c
@ -1,13 +1,12 @@
|
|||||||
#ifndef SOURCE_ABSTRAKTIONLAYER_BASE_H
|
#ifndef SOURCE_ABSTRAKTIONLAYER_BASE_H
|
||||||
#define SOURCE_ABSTRAKTIONLAYER_BASE_H
|
#define SOURCE_ABSTRAKTIONLAYER_BASE_H
|
||||||
|
|
||||||
#include <map>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "../../header/input.h"
|
#include "../../header/input.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
typedef map<Part*, float> qualityVector;
|
typedef vector<pair<float, Part*>> qualityVector;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Die Logik mit der Template-Basisklasse und den abgeleiteten Layern kam mit der Idee, dass die Layer
|
* Die Logik mit der Template-Basisklasse und den abgeleiteten Layern kam mit der Idee, dass die Layer
|
||||||
|
@ -46,7 +46,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_a1.m_connections))
|
if(PlaceOfPartGood(constraintCoordinate, it->second->m_a1.m_connections))
|
||||||
continue;
|
continue;
|
||||||
qVector.erase(it++);
|
qVector.erase(it++);
|
||||||
}
|
}
|
||||||
|
@ -99,7 +99,7 @@ void setsolution(vector<LogEntry>& log, vector<Part*>& p_Box, Puzzle& puzzleMat)
|
|||||||
|
|
||||||
//remove first element in last logelement from box
|
//remove first element in last logelement from box
|
||||||
for(int i=0;i<p_Box.size();)
|
for(int i=0;i<p_Box.size();)
|
||||||
if(p_Box[i]==log.back().PieceCollector.begin()->first)//mach ich das richtig so?!
|
if(p_Box[i]==log.back().PieceCollector.begin()->second)//mach ich das richtig so?!
|
||||||
p_Box.erase(p_Box.begin()+i);
|
p_Box.erase(p_Box.begin()+i);
|
||||||
else
|
else
|
||||||
i++;
|
i++;
|
||||||
@ -113,7 +113,7 @@ 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)
|
||||||
{
|
{
|
||||||
p_Box.push_back(log.back().PieceCollector.begin()->first);
|
p_Box.push_back(log.back().PieceCollector.begin()->second);
|
||||||
log.back().PieceCollector.erase(log.back().PieceCollector.begin());
|
log.back().PieceCollector.erase(log.back().PieceCollector.begin());
|
||||||
|
|
||||||
if(log.back().PieceCollector.size()==1)
|
if(log.back().PieceCollector.size()==1)
|
||||||
@ -128,7 +128,7 @@ bool backtrack(vector<LogEntry>& log, vector<Part*>& p_Box, Puzzle& puzzleMat)
|
|||||||
{
|
{
|
||||||
puzzleMat.removeConstrains(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.begin()->first);
|
p_Box.emplace_back(log.back().PieceCollector.begin()->second);
|
||||||
log.pop_back();
|
log.pop_back();
|
||||||
backtrack(log,p_Box,puzzleMat);
|
backtrack(log,p_Box,puzzleMat);
|
||||||
}
|
}
|
||||||
@ -182,9 +182,9 @@ float capLogElements(vector<LogEntry>& log)
|
|||||||
vectorsizeBefore = log.back().PieceCollector.size();
|
vectorsizeBefore = log.back().PieceCollector.size();
|
||||||
|
|
||||||
sort(log); // Sort the vector after probabilities
|
sort(log); // Sort the vector after probabilities
|
||||||
std::map<Part*,float>::const_iterator idxcut =log.back().PieceCollector.begin();
|
qualityVector::const_iterator idxcut =log.back().PieceCollector.begin();
|
||||||
for(;idxcut !=log.back().PieceCollector.end();idxcut++)
|
for(;idxcut !=log.back().PieceCollector.end();idxcut++)
|
||||||
if(idxcut->second < limit)
|
if(idxcut->first < limit)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
||||||
@ -200,7 +200,7 @@ float capLogElements(vector<LogEntry>& log)
|
|||||||
newidxcut = idxcut;
|
newidxcut = idxcut;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cut(log,newidxcut->first);
|
cut(log,newidxcut->second);
|
||||||
|
|
||||||
vectorsizeAfter = log.back().PieceCollector.size();
|
vectorsizeAfter = log.back().PieceCollector.size();
|
||||||
|
|
||||||
@ -218,14 +218,32 @@ void sort(vector<LogEntry>& log)
|
|||||||
//the monkey desperately tried to hold on to the flying dorm room.
|
//the monkey desperately tried to hold on to the flying dorm room.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qualityVector::iterator FindPartInLog(vector<LogEntry>& log, Part* wishedPartPointer)
|
||||||
|
{
|
||||||
|
qualityVector::iterator partOnPositionIterator = log.back().PieceCollector.begin();
|
||||||
|
|
||||||
|
while (partOnPositionIterator != log.back().PieceCollector.end())
|
||||||
|
{
|
||||||
|
if(partOnPositionIterator.base()->second == wishedPartPointer)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
partOnPositionIterator++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return partOnPositionIterator;
|
||||||
|
}
|
||||||
|
|
||||||
void cut(vector<LogEntry>& log, Part* cutID)
|
void cut(vector<LogEntry>& log, Part* cutID)
|
||||||
{
|
{
|
||||||
auto it = log.back().PieceCollector.find(cutID)++;
|
auto it = FindPartInLog(log, cutID);
|
||||||
while(it != log.back().PieceCollector.end())
|
while(it != log.back().PieceCollector.end())
|
||||||
log.back().PieceCollector.erase(it++);
|
log.back().PieceCollector.erase(it++);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//partdavid
|
//partdavid
|
||||||
bool setBestOrMoreLayers(vector<LogEntry>& log)
|
bool setBestOrMoreLayers(vector<LogEntry>& log)
|
||||||
{
|
{
|
||||||
@ -236,11 +254,11 @@ bool setBestOrMoreLayers(vector<LogEntry>& log)
|
|||||||
for(auto it:log.back().PieceCollector)
|
for(auto it:log.back().PieceCollector)
|
||||||
{
|
{
|
||||||
// check Probability of current Puzzle Piece in this vector
|
// check Probability of current Puzzle Piece in this vector
|
||||||
if (it.second >= 0.90) // 0.90 as threshold
|
if (it.first >= 0.90) // 0.90 as threshold
|
||||||
countBest++;
|
countBest++;
|
||||||
else
|
else
|
||||||
if (it.second > tempBest)
|
if (it.first > tempBest)
|
||||||
tempBest = it.second;
|
tempBest = it.first;
|
||||||
}
|
}
|
||||||
|
|
||||||
// return true if only one piece is left
|
// return true if only one piece is left
|
||||||
|
@ -10,13 +10,12 @@
|
|||||||
#include "../functions/AbstractionLayers/Layer1/AbstractionLayer_1.h"
|
#include "../functions/AbstractionLayers/Layer1/AbstractionLayer_1.h"
|
||||||
#include "../functions/AbstractionLayers/DestructionPower/DestructionPower.h"
|
#include "../functions/AbstractionLayers/DestructionPower/DestructionPower.h"
|
||||||
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
class LogEntry
|
class LogEntry
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
map<Part*, float> PieceCollector;
|
qualityVector PieceCollector;
|
||||||
int abstractionLevel;
|
int abstractionLevel;
|
||||||
coor myCoor;
|
coor myCoor;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user