search_statistics.cpp
Go to the documentation of this file.
00001 #include "search_statistics.h"
00002 #include "globals.h"
00003 #include <stdio.h>
00004 
00005 SearchStatistics::SearchStatistics()
00006 {
00007     generated_states = 0;
00008 
00009     lastDumpClosedListSize = 0;
00010     lastDumpGeneratedStates = 0;
00011     lastDumpTime = time(NULL);
00012     startTime = lastDumpTime;
00013 }
00014 
00015 SearchStatistics::~SearchStatistics()
00016 {
00017 }
00018 
00019 void SearchStatistics::countChild(int openListIndex)
00020 {
00021     generated_states++;
00022     childrenPerOpenList[openListIndex]++;
00023 }
00024 
00025 void SearchStatistics::finishExpansion()
00026 {
00027     int numChildren = 0;
00028     for(std::map<int, int>::iterator it = childrenPerOpenList.begin(); it != childrenPerOpenList.end(); it++) {
00029         std::map<int, Statistics<double> >::iterator statIt = branchingFactors.find(it->first);
00030         if(statIt == branchingFactors.end()) {
00031             char* buf = new char[1024];
00032             sprintf(buf, "Open List %d", it->first);
00033             branchingFactors[it->first] = Statistics<double>(buf);
00034         }
00035         branchingFactors[it->first].addMeasurement(it->second); // count
00036         numChildren += it->second;
00037         it->second = 0; // reset for next expansion
00038     }
00039     overallBranchingFactor.addMeasurement(numChildren);
00040 }
00041 
00042 void SearchStatistics::dump(unsigned int closedListSize, time_t & current_time)
00043 {
00044     double dt = current_time - lastDumpTime;
00045     double dTotal = current_time - startTime;
00046 
00047     cout << "Expanded Nodes: " << closedListSize << " state(s)." << endl;
00048     double dClosedList = closedListSize - lastDumpClosedListSize;
00049     printf("Rate: %.1f Nodes/s (over %.1fs) %.1f Nodes/s (total average)\n", dClosedList/dt, dt,
00050             double(closedListSize)/dTotal);
00051 
00052     cout << "Generated Nodes: " << generated_states << " state(s)." << endl;
00053     double dGeneratedNodes = generated_states - lastDumpGeneratedStates;
00054     printf("Rate: %.1f Nodes/s (over %.1fs) %.1f Nodes/s (total average)\n", dGeneratedNodes/dt, dt,
00055             double(generated_states)/dTotal);
00056 
00057     cout << "Overall branching factor by list sizes: " << (generated_states / (double) closedListSize) << endl;
00058     printf("Averaged overall branching factor: ");
00059     overallBranchingFactor.print();
00060     printf("Branching factors by open list:\n");
00061     for(std::map<int, Statistics<double> >::iterator it = branchingFactors.begin();
00062             it != branchingFactors.end(); it++) {
00063         it->second.print();
00064     }
00065 
00066     lastDumpGeneratedStates = generated_states;
00067     lastDumpClosedListSize = closedListSize;
00068     lastDumpTime = current_time;
00069 }
00070 


tfd_modules
Author(s): Maintained by Christian Dornhege (see AUTHORS file).
autogenerated on Mon Oct 6 2014 07:52:06