23 #include "../combinatorial_optimization/HillClimbingAlogrithm.hpp" 25 #include "../combinatorial_optimization/ExponentialCoolingSchedule.hpp" 26 #include "../combinatorial_optimization/SimulatedAnnealingAlgorithm.hpp" 28 #include "../combinatorial_optimization/RecordHuntAlgorithm.hpp" 29 #include "../combinatorial_optimization/CostDeltaAcceptanceFunction.hpp" 36 mStartTime = ptime(boost::posix_time::microsec_clock::local_time());
41 std::vector<TopologyPtr> startTopologies;
44 startTopologies.push_back(startTopology);
51 if (!selectedStartTopology)
54 return std::make_pair(-1,
TreePtr());
69 startTopologies.clear();
70 startTopologies.push_back(randomStartTopology);
73 if (optimizationResult->cost < bestTopology->cost)
75 bestTopology = optimizationResult;
86 tree->getISM()->voteSpecifiersPerObject);
88 return std::make_pair(
mCostFunction->calculateCost(bestTopology), tree);
99 if (startTopologies.empty())
107 if (
mCostFunction->calculateCost(randomTopology) != std::numeric_limits<double>::infinity())
113 startTopologies.push_back(randomTopology);
124 for (
unsigned int i = 0; i < startTopologies.size(); ++i)
126 mTopologyManager->evaluateTopology(startTopologies[i],
"start_topology_" + std::to_string(i));
183 +
" is not a valid costFunctionId!";
185 throw std::runtime_error(errorMessage);
233 +
" is not a valid optimizationAlgorithmId!";
235 throw std::runtime_error(errorMessage);
243 double bestCost = std::numeric_limits<unsigned int>::max();
252 bestStartTopology = startTopology;
256 if (!bestStartTopology)
258 return bestStartTopology;
271 tree->getISM()->voteSpecifiersPerObject);
275 return bestStartTopology;
280 ptime endTime(boost::posix_time::microsec_clock::local_time());
283 std::vector<std::vector<std::pair<TopologyPtr, unsigned int>>> history =
mTopologyManager->getHistory();
286 const std::string bestTopologyIdentifier = bestTopology->identifier;
287 bool markedBest =
false;
288 for (
unsigned int i = 0; !markedBest && i < history.size(); i++)
290 for (
unsigned int j = 0; !markedBest && j < history[i].size(); j++)
292 if (history[i][j].first->identifier == bestTopologyIdentifier)
294 history[i][j].second = 4;
306 LogHelper::logMessage(
"Started combinatorial optimization to find the best the ism for the pattern " +
313 std::ostringstream oss;
314 oss <<
"Training for pattern " +
mCurrentPatternName +
" is done!" << std::endl << std::endl
315 <<
"The overall best topology was: " << bestTopology->objectRelations << std::endl
316 <<
" with the evaluation result of its ISM beeing: " << std::endl
317 << bestTopology->evaluationResult.getDescription() << std::endl << std::endl
318 <<
"The cost of this topology was: " << std::endl
326 std::ostringstream oss;
327 oss <<
"Selected the following topology as the best start Topology." 328 << std::endl << std::endl << bestStartTopology->objectRelations
329 <<
"with the evaluation result of its ISM beeing: " << std::endl
330 << bestStartTopology->evaluationResult.getDescription() << std::endl << std::endl
331 <<
"The cost of this topology is: " << std::endl
332 <<
mCostFunction->calculateCost(bestStartTopology) << std::endl << std::endl
333 <<
"Generating its tree again: " << std::endl;
339 std::ostringstream oss;
340 oss <<
"Evaluating all star topologies and the fully meshed topology " 341 <<
"to find the lowest and highest false positives and the slowest and fastest average recogniton runtime. " 342 <<
"Those values will be used to normalise the false positives and the recognition runtime of other topologies." 343 << std::endl << std::endl;
349 std::ostringstream oss;
350 oss <<
"Evaluated all star topologies and the fully meshed topology. The results are:" << std::endl << std::endl
361 std::ostringstream oss;
362 oss <<
"The start topology was invalid. Optimzation Failed!";
370 std::ostringstream oss;
371 oss <<
"Performing random restart!" << std::endl;
377 std::ostringstream oss;
378 oss <<
"Possible start topologies are: " << std::endl << std::endl;
379 for (
unsigned int i = 0; i < startTopologies.size(); ++i)
381 oss <<
"\t- Topology " << startTopologies[i]->identifier << std::endl;
void logSelectedStartTopology(TopologyPtr bestStartTopology)
unsigned int optimizationAlgorithmId
boost::shared_ptr< RecordHuntAlgorithm< InstanceType >> RecordHuntAlgorithmPtr
double averageRecognitionRuntime
bool mStoreStartTopologyISM
OptimizationAlgorithmPtr< TopologyPtr > mOptimizationAlgorithm
void logStartTopologies(const std::vector< TopologyPtr > &startTopologies)
boost::shared_ptr< CostFunction< InstanceType >> CostFunctionPtr
unsigned int mMaxFalsePositives
std::pair< double, TreePtr > runOptimization(const std::string &pattern, TopologyPtr startTopology=NULL)
unsigned int repetitionsBeforeUpdated
void analyzeStarAndFullyMeshedTopologies()
CostFunctionParameters mCostFunctionParameters
double mMinAverageRecognitionRuntime
static void logLine(LogLevel logLevel=LOG_INFO)
unsigned int falsePositives
TopologyPtr mFullyMeshedTopology
boost::shared_ptr< AcceptanceFunction > AcceptanceFunctionPtr
void logOptimizationFinish(TopologyPtr bestTopology)
void logStarsAndFullyMeshedResult()
double mMaxAverageRecognitionRuntime
boost::shared_ptr< CostDeltaAcceptanceFunction > CostDeltaAcceptanceFunctionPtr
void logInvalidStartTopology()
void prepareOptimizationRun(std::vector< TopologyPtr > &startTopologies)
boost::shared_ptr< Topology > TopologyPtr
double initialAcceptableCostDelta
boost::shared_ptr< SimulatedAnnealingAlgorithm< InstanceType >> SimulatedAnnealingAlgorithmPtr
double randomRestartProbability
TopologyPtr selectStartTopology(std::vector< TopologyPtr > &startTopologies)
static void logMessage(const std::string &message, LogLevel logLevel=LOG_INFO, const char *logColor=LOG_COLOR_DEFAULT)
double randomWalkProbability
TopologyManagerPtr mTopologyManager
boost::shared_ptr< CoolingSchedule > CoolingSchedulePtr
unsigned int mMinFalsePositives
bool mStoreFullyMeshedISM
double costDeltaDecreaseFactor
boost::shared_ptr< ExponentialCoolingSchedule > ExponentialCoolingSchedulePtr
CostFunctionPtr< TopologyPtr > mCostFunction
bool startFromRandomTopology
boost::shared_ptr< Tree > TreePtr
void initOptimizationAlgorithm()
DocumentationHelperPtr mDocumentationHelper
void logOptimizationStart(const std::string &patternName)
OptimizationAlgorithmParameters mOptimizationAlgorithmParameters
std::vector< TopologyPtr > mStarTopologies
std::uniform_real_distribution< double > mDistribution
void logAnalysingStarAndFullyMeshedTopologies()
this namespace contains all generally usable classes.
void documentOptimzationRun(TopologyPtr bestTopology)
std::string mCurrentPatternName
std::default_random_engine mGenerator
boost::shared_ptr< HillClimbingAlogrithm< InstanceType >> HillClimbingAlogrithmPtr
const char * LOG_COLOR_OPTIMIZATION_STRATEGY
unsigned int costFunctionId