beforemerge

This commit is contained in:
Raphael Maenle
2017-12-22 22:55:55 +01:00
parent bfed4aba05
commit edd3c8620b
7 changed files with 195 additions and 22 deletions

View File

@ -1,6 +1,8 @@
#include "../../header.h"
void status(vector<LogEntry>& log, vector<Part*>& p_Box);
bool setBestOrMoreLayers(vector<LogEntry>& log);
void calculateTrueDestructionPower(vector<LogEntry>& log, Puzzle& puzzleMat, float Layerworth);
void capLogElements(vector<LogEntry>& log);
bool next(vector<LogEntry>& log, vector<Part*>& p_Box,Puzzle& puzzleMat)
{
@ -15,9 +17,9 @@ bool next(vector<LogEntry>& log, vector<Part*>& p_Box,Puzzle& puzzleMat)
//case last log element has multiple entries
else if(log.back().PieceCollector.size() > 1)
{
//moreLayers is 0, setbest is 1
//if(SetBestorMoreLayers()) setsolution(log,p_Box,puzzleMat);
//else solve(log,p_Box,puzzleMat);
//moreLayers is 0, setbest is 1
if(setBestOrMoreLayers(log)) setsolution(log,p_Box,puzzleMat);
else solve(log,p_Box,puzzleMat);
}
//case last log exactly one solution
else if(log.back().PieceCollector.size() == 1)
@ -42,8 +44,8 @@ void createNextLogElement(vector<LogEntry>& log, vector<Part*>& p_Box, Puzzle& p
{
log.emplace_back(LogEntry(coor(0, 0)));
log.back().myCoor = calculateNextCoor(log, p_Box,puzzleMat);
//getLayerDestructionPowerfromSurrounding();
solve(log, p_Box,puzzleMat);
puzzleMat.dp->DestructionOfSurrounding(log.back().myCoor);//calculate dp from surrounding
solve(log, p_Box,puzzleMat);
}
@ -63,12 +65,11 @@ coor calculateNextCoor(vector<LogEntry>& log, vector<Part*>& p_Box, Puzzle& puzz
if(m<puzzleMat.getSizeAsCoor().col-1) m++;
else if(n<puzzleMat.getSizeAsCoor().row-1){ m=0; n++;}
return {m,n};
//return nextCoor;
}
void solve(vector<LogEntry>& log, vector<Part*>& p_Box, Puzzle& puzzleMat)
{
//getNextHighestLayerworth(puzzleMat); //sets in abstractionLevel
puzzleMat.dp->getNextAbstractionLayer(log.back().myCoor,log.back().abstractionLevel); //sets in abstractionLevel
//status(log,p_Box,puzzleMat);
switch(log.back().abstractionLevel)
{
@ -160,4 +161,140 @@ void calculateTrueDestructionPower(vector<LogEntry>& log, Puzzle& puzzleMat, flo
//hier muss noch rein, wo die zeit der Abstractionlevels gespeichter wird
float destructionPower=sqrt(Layerworth * log.back().abstractionLevel);
//puzzleMat.setdestructionPower(log.back().myCoor,log.back().abstractionLevel,destructionPower);
}
}
// PART RAUER_WEIDINGER
/*
void sort()
{
}
void cut()
{
}
void capLogElements(vector<LogEntry>& log)
{
// Till Now only ground structure -> incorrect variable ans vector names
double limit = 0.6;
double diff = 0;
double maxdiff = 0;
int vectorsizeBefore = 0;
int vectorsizeAfter = 0;
double destroyed = 0; // destroyed parts in %
double worth = 0;
vectorsizeBefore = log.back().PieceCollector.size();
sort(); // Sort the vector after probabilities
auto idxcut;
for(idxcut:log.back().PieceCollector)
if(idxcut.second < limit)
break;
while(idxcut != log.back().PieceCollector.end())
{
diff = part[i] - part[i+1];
if(diff > maxdiff)
{
maxdiff = diff;
idxcut = i;
}
i++;
}
cut();
vectorsizeAfter = vector.size();
destroyed = (vectorsizeBefore - vectorsizeAfter) / vectorsizeBefore;
worth = sqrt(destroyed*maxdiff);
//return worth;
} */
//partdavid
bool setBestOrMoreLayers(vector<LogEntry>& log)
{
int countBest = 0;
float tempBest = 0.0;
// count how many Pieces are greater than the threshold value
for(auto it:log.back().PieceCollector)
{
// check Probability of current Puzzle Piece in this vector
if (it.second >= 0.90) // 0.90 as threshold
countBest++;
else
if (it.second > tempBest)
tempBest = it.second;
}
// return true if only one piece is left
if (1 == countBest)
{
return true;
}
//else if (countBest > 1 && countBest < 10) // TODO: add possible constraints
else
{
return false;
}
}
void calculateNewCombinedProbabilityForPuzzlePiecesArithmetic(vector<LogEntry>& log)
{
float totalValue = 0.0;
int i;
for(int i; i < log.back().PieceCollector.size(); i++)
{
// sum Probability of current Puzzle Piece in PieceCollector vector
//totalValue += *(log.back().PieceCollector.);
}
//return totalValue / i;
}
/*
//PartDavid
void calculateNewCombinedProbabilityForPuzzlePiecesTopK(vector<LogEntry>& log, int executedLayers)
{
float TopK[executedLayers][2] = {0.0}; // in Log speichern?
float sumTopK[executedLayers] = {0.0};
float HighestProbability = 0.0;
// searching for Top2 probability values in PieceCollector for each layer
for (int currentLayer = 0; currentLayer < executedLayers; currentLayer++)
{
// searching for Top2 probabilities in currentLayer
for(int i = 0; i < log.back().PieceCollector.size() && log.back().abstractionLevel == currentLayer; i++)
{
if (*(log.back().PieceCollector[i]) > TopK[currentLayer][0])
{
TopK[currentLayer][0] = *log.back().PieceCollector[i];
}
else if (*(log.back().PieceCollector[i]) > TopK[currentLayer][1])
{
TopK[currentLayer][1] = *log.back().PieceCollector[i];
}
else
{
// Spezialfall fuer 0 Ueberlegen
}
}
sumTopK[currentLayer] = TopK[currentLayer][0] + TopK[currentLayer][1];
}
// searching for highest probability for designated Position
for (int currentLayer = 0; currentLayer < executedLayers; currentLayer++)
{
if (sumTopK[currentLayer+1] > sumTopK[currentLayer])
{
HighestProbability = sumTopK[currentLayer+1];
}
}
}
*/