From caa74198bd72b9040d780cea2d49fe662c80c6ab Mon Sep 17 00:00:00 2001 From: Raphael Maenle <17550607+g-spacewhale@users.noreply.github.com> Date: Sat, 23 Dec 2017 21:46:41 +0100 Subject: [PATCH] NON FINAL: added dp calculation and most of RW code, included david code still not runable code as dispatcher functions are only placeholders! --- .../DestructionPower/DestructionPower.h | 3 + .../DestructionPower_Properties.h | 8 +- Source/functions/solve/structure.cpp | 84 +++++++++++-------- 3 files changed, 54 insertions(+), 41 deletions(-) diff --git a/Source/functions/AbstractionLayers/DestructionPower/DestructionPower.h b/Source/functions/AbstractionLayers/DestructionPower/DestructionPower.h index 2319f9e..8790202 100644 --- a/Source/functions/AbstractionLayers/DestructionPower/DestructionPower.h +++ b/Source/functions/AbstractionLayers/DestructionPower/DestructionPower.h @@ -25,5 +25,8 @@ public: void DestructionOfSurrounding(coor constraintCoordinate); int getNextAbstractionLayer(coor newCoordinate, int currentAbstractionLayer); + void setDestructionPower(coor myCoor, int AbstractionLevel, float destructionPower) + { m_constraintMatrix[myCoor.col][myCoor.row].DestructionArray[AbstractionLevel] = destructionPower;} + private: }; diff --git a/Source/functions/AbstractionLayers/DestructionPower/DestructionPower_Properties.h b/Source/functions/AbstractionLayers/DestructionPower/DestructionPower_Properties.h index bbdedca..d2f294c 100644 --- a/Source/functions/AbstractionLayers/DestructionPower/DestructionPower_Properties.h +++ b/Source/functions/AbstractionLayers/DestructionPower/DestructionPower_Properties.h @@ -14,13 +14,13 @@ class DestructionPower_Properties { public: explicit DestructionPower_Properties(); - map getSpeedTable() {return SpeedTable;} void setSpeedTable(); + static map SpeedTable; + + + vector DestructionArray; private: - - static map SpeedTable; - vector DestructionArray; friend class DestructionPower; }; \ No newline at end of file diff --git a/Source/functions/solve/structure.cpp b/Source/functions/solve/structure.cpp index cfa5a78..8ea726f 100755 --- a/Source/functions/solve/structure.cpp +++ b/Source/functions/solve/structure.cpp @@ -2,7 +2,10 @@ void status(vector& log, vector& p_Box); bool setBestOrMoreLayers(vector& log); void calculateTrueDestructionPower(vector& log, Puzzle& puzzleMat, float Layerworth); -void capLogElements(vector& log); +void sort(vector& log); +void cut(vector& log, Part* cutID); +float capLogElements(vector& log); +void calculateNewCombinedProbabilityForPuzzlePiecesArithmetic(vector& log); bool next(vector& log, vector& p_Box,Puzzle& puzzleMat) { @@ -18,8 +21,8 @@ bool next(vector& log, vector& p_Box,Puzzle& puzzleMat) else if(log.back().PieceCollector.size() > 1) { //moreLayers is 0, setbest is 1 - if(setBestOrMoreLayers(log)) setsolution(log,p_Box,puzzleMat); - else solve(log,p_Box,puzzleMat); + 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) @@ -81,10 +84,10 @@ void solve(vector& log, vector& p_Box, Puzzle& puzzleMat) break; } - //capLogElements(log); - //calculateWorth(log); - //calculateTrueDestructionPower(log,puzzleMat); - //calculateNewCombinedProbablility(log); + capLogElements(log); + float worth = capLogElements(log); + calculateTrueDestructionPower(log,puzzleMat, worth); + calculateNewCombinedProbabilityForPuzzlePiecesArithmetic(log); } @@ -156,24 +159,16 @@ void status(vector& log, vector& p_Box, Puzzle& puzzleMat) cout << "----------------------------" << endl; } -void calculateTrueDestructionPower(vector& log, Puzzle& puzzleMat, float Layerworth) -{ - //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); +//this is addon stuff that should later all be extracted into a sererate cpp as it is not core dispatcher functionality + +void calculateTrueDestructionPower(vector& log, Puzzle& puzzleMat, float Layerworth) { + float destructionPower = sqrt( + Layerworth * puzzleMat.dp.m_constraintMatrix[0][0].SpeedTable[log.back().abstractionLevel]); + puzzleMat.dp.setDestructionPower(log.back().myCoor, log.back().abstractionLevel, destructionPower); } // PART RAUER_WEIDINGER -/* -void sort() -{ -} - -void cut() -{ -} - -void capLogElements(vector& log) +float capLogElements(vector& log) { // Till Now only ground structure -> incorrect variable ans vector names double limit = 0.6; @@ -186,34 +181,50 @@ void capLogElements(vector& log) vectorsizeBefore = log.back().PieceCollector.size(); - sort(); // Sort the vector after probabilities - auto idxcut; - for(idxcut:log.back().PieceCollector) - if(idxcut.second < limit) + sort(log); // Sort the vector after probabilities + std::map::const_iterator idxcut =log.back().PieceCollector.begin(); + for(;idxcut !=log.back().PieceCollector.end();idxcut++) + if(idxcut->second < limit) break; + + auto newidxcut = idxcut; + + while(idxcut != log.back().PieceCollector.end()) { - diff = part[i] - part[i+1]; + diff = idxcut->second - (++idxcut)->second; if(diff > maxdiff) { maxdiff = diff; - idxcut = i; + newidxcut = idxcut; } - i++; } - cut(); + cut(log,newidxcut->first); - vectorsizeAfter = vector.size(); + vectorsizeAfter = log.back().PieceCollector.size(); destroyed = (vectorsizeBefore - vectorsizeAfter) / vectorsizeBefore; - worth = sqrt(destroyed*maxdiff); + return (float)sqrt(destroyed*maxdiff); - //return worth; +} + +void sort(vector& log) +{ + //this does all the sorting that needs to happen + //saddly this is a false statement + //the monkey desperately tried to hold on to the flying dorm room. +} + +void cut(vector& log, Part* cutID) +{ + auto it = log.back().PieceCollector.find(cutID)++; + while(it != log.back().PieceCollector.end()) + log.back().PieceCollector.erase(it++); +} -} */ //partdavid bool setBestOrMoreLayers(vector& log) @@ -248,11 +259,10 @@ void calculateNewCombinedProbabilityForPuzzlePiecesArithmetic(vector& { float totalValue = 0.0; int i; - for(int i; i < log.back().PieceCollector.size(); 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; }