00001 /* 00002 * Copyright 2007 Martin von Gagern 00003 * 00004 * 00005 * This file is part of bande. 00006 * 00007 * bande is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; either version 3 of the License, or 00010 * (at your option) any later version. 00011 * 00012 * bande is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00019 */ 00020 00021 00022 /** 00023 * @file 00024 * Implementation of class bande::Statistics. 00025 */ 00026 00027 #include "bande.hh" 00028 00029 namespace bande { 00030 00031 /** 00032 * Get current user time in seconds. 00033 * 00034 * The time will be reported as a floating point number, allowing 00035 * for fractions of a second. Only the CPU time dedicated to this 00036 * process will count, so that the time as returned by this function 00037 * will pass slower the more other processes occupy the CPU. As the 00038 * returned value is intended for difference calculation, the 00039 * initial offset is irrelevant. 00040 * 00041 * @return the current user time as a floating point number. 00042 */ 00043 double Statistics::getTime() { 00044 struct rusage usage; 00045 getrusage(RUSAGE_SELF, &usage); 00046 return usage.ru_utime.tv_sec + usage.ru_utime.tv_usec*1e-6; 00047 } 00048 00049 /** 00050 * A solution has been found. 00051 * 00052 * @param depth the depth in the search tree at which the solution 00053 * has been found. 00054 */ 00055 void Statistics::solution(int depth) { 00056 double now = getTime(); 00057 ++numSolutions; 00058 std::cout << "Solution " << numSolutions << ", "; 00059 if (now == startTime) { 00060 std::cout << "just started"; 00061 } 00062 else { 00063 double clk = now - startTime; 00064 if (numSolutions > clk) 00065 std::cout << numSolutions/clk << " solutions per second"; 00066 else 00067 std::cout << "new solution every " << clk/numSolutions << " seconds"; 00068 } 00069 std::cout << std::endl; 00070 } 00071 00072 }
1.6.0