TimQu
7 years ago
6 changed files with 221 additions and 33 deletions
-
11src/storm/modelchecker/multiobjective/pcaa/SparseMdpRewardBoundedPcaaWeightVectorChecker.cpp
-
7src/storm/modelchecker/prctl/helper/SparseMdpPrctlHelper.cpp
-
32src/storm/solver/AbstractEquationSolver.cpp
-
13src/storm/solver/AbstractEquationSolver.h
-
84src/storm/utility/ProgressMeasurement.cpp
-
107src/storm/utility/ProgressMeasurement.h
@ -0,0 +1,84 @@ |
|||
#include "storm/utility/ProgressMeasurement.h"
|
|||
|
|||
#include <sstream>
|
|||
|
|||
#include "storm/settings/SettingsManager.h"
|
|||
#include "storm/settings/modules/GeneralSettings.h"
|
|||
#include "storm/utility/macros.h"
|
|||
|
|||
namespace storm { |
|||
namespace utility { |
|||
|
|||
ProgressMeasurement::ProgressMeasurement(std::string const& itemName) : itemName(itemName) { |
|||
delay = storm::settings::getModule<storm::settings::modules::GeneralSettings>().getShowProgressDelay(); |
|||
} |
|||
|
|||
void ProgressMeasurement::startNewMeasurement(uint64_t startCount) { |
|||
lastDisplayedCount = startCount; |
|||
timeOfStart = std::chrono::high_resolution_clock::now(); |
|||
timeOfLastMessage = timeOfStart; |
|||
} |
|||
|
|||
bool ProgressMeasurement::updateProgress(uint64_t count) { |
|||
std::stringstream stream; |
|||
if (updateProgress(count, stream)) { |
|||
std::string message = stream.str(); |
|||
// Remove the line break at the end of the message.
|
|||
message.pop_back(); |
|||
STORM_LOG_INFO(message); |
|||
return true; |
|||
} |
|||
return false; |
|||
} |
|||
|
|||
bool ProgressMeasurement::updateProgress(uint64_t count, std::ostream& outstream) { |
|||
auto now = std::chrono::high_resolution_clock::now(); |
|||
// Get the duration since the last message in milliseconds.
|
|||
auto durationSinceLastMessage = static_cast<uint64_t>(std::chrono::duration_cast<std::chrono::milliseconds>(now - this->timeOfLastMessage).count()); |
|||
if (durationSinceLastMessage >= this->delay * 1000) { |
|||
double itemsPerSecond = (static_cast<double>(count - this->lastDisplayedCount) * 1000.0 / static_cast<double>(durationSinceLastMessage)); |
|||
outstream << "Completed " << count << " " << itemName << " " |
|||
<< (this->isMaxCountSet() ? "(out of " + std::to_string(this->getMaxCount()) + ") " : "") |
|||
<< "in " << std::chrono::duration_cast<std::chrono::seconds>(now - timeOfStart).count() << "s (currently " << itemsPerSecond << " " << itemName << " per second)." << std::endl; |
|||
timeOfLastMessage = std::chrono::high_resolution_clock::now(); |
|||
lastDisplayedCount = count; |
|||
return true; |
|||
} |
|||
return false; |
|||
} |
|||
|
|||
bool ProgressMeasurement::isMaxCountSet() const { |
|||
return this->maxCount > 0; |
|||
} |
|||
|
|||
uint64_t ProgressMeasurement::getMaxCount() const { |
|||
STORM_LOG_ASSERT(this->isMaxCountSet(), "Tried to get the maximal count but it was not set before."); |
|||
return this->maxCount; |
|||
} |
|||
|
|||
void ProgressMeasurement::setMaxCount(uint64_t maxCount) { |
|||
this->maxCount = maxCount; |
|||
} |
|||
|
|||
void ProgressMeasurement::unsetMaxCount() { |
|||
this->maxCount = 0; |
|||
} |
|||
|
|||
uint64_t ProgressMeasurement::getShowProgressDelay() const { |
|||
return this->delay; |
|||
} |
|||
|
|||
void ProgressMeasurement::setShowProgressDelay(uint64_t delay) { |
|||
this->delay = delay; |
|||
} |
|||
|
|||
std::string const& ProgressMeasurement::getItemName() const { |
|||
return this->itemName; |
|||
} |
|||
|
|||
void ProgressMeasurement::setItemName(std::string const& name) { |
|||
this->itemName = name; |
|||
} |
|||
|
|||
} |
|||
} |
@ -0,0 +1,107 @@ |
|||
#pragma once |
|||
|
|||
#include <chrono> |
|||
#include <ostream> |
|||
#include <boost/optional.hpp> |
|||
|
|||
namespace storm { |
|||
namespace utility { |
|||
|
|||
/*! |
|||
* A class that provides convenience operations to display run times. |
|||
*/ |
|||
class ProgressMeasurement { |
|||
public: |
|||
typedef decltype(std::chrono::duration_cast<std::chrono::seconds>(std::chrono::seconds::zero()).count()) SecondType; |
|||
typedef decltype(std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::milliseconds::zero()).count()) MilisecondType; |
|||
typedef decltype(std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::nanoseconds::zero()).count()) NanosecondType; |
|||
|
|||
/*! |
|||
* Initializes progress measurement. |
|||
* @param itemName the name of what we are counting (iterations, states, ...). |
|||
*/ |
|||
ProgressMeasurement(std::string const& itemName = "items"); |
|||
|
|||
/*! |
|||
* Starts a new measurement, dropping all progress information collected so far. |
|||
* @param startCount the initial count. |
|||
*/ |
|||
void startNewMeasurement(uint64_t startCount); |
|||
|
|||
/*! |
|||
* Updates the progress to the current count. |
|||
* @param count The currently achieved count. |
|||
* @return true iff the progress was printed (i.e., the delay passed). |
|||
*/ |
|||
bool updateProgress(uint64_t count); |
|||
|
|||
/*! |
|||
* Updates the progress to the current count. |
|||
* @param count The currently achieved count. |
|||
* @param outstream The stream to which the progress is printed (if the delay passed) |
|||
* @return true iff the progress was printed (i.e., the delay passed) |
|||
*/ |
|||
bool updateProgress(uint64_t value, std::ostream& outstream); |
|||
|
|||
/*! |
|||
* Returns whether a maximal count (which is required to achieve 100% progress) has been specified |
|||
*/ |
|||
bool isMaxCountSet() const; |
|||
|
|||
/*! |
|||
* Returns the maximal possible count (if specified). |
|||
*/ |
|||
uint64_t getMaxCount() const; |
|||
|
|||
/*! |
|||
* Sets the maximal possible count. |
|||
*/ |
|||
void setMaxCount(uint64_t maxCount); |
|||
|
|||
/*! |
|||
* Erases a previously specified maximal count. |
|||
*/ |
|||
void unsetMaxCount(); |
|||
|
|||
/*! |
|||
* Returns the currently specified minimal delay (in seconds) between two progress messages. |
|||
*/ |
|||
uint64_t getShowProgressDelay() const; |
|||
|
|||
/*! |
|||
* Customizes the minimal delay between two progress messages. |
|||
* @param delay the delay (in seconds). |
|||
*/ |
|||
void setShowProgressDelay(uint64_t delay); |
|||
|
|||
/*! |
|||
* Returns the current name of what we are counting (e.g. iterations, states, ...) |
|||
*/ |
|||
std::string const& getItemName() const; |
|||
|
|||
/*! |
|||
* Customizes the name of what we are counting (e.g. iterations, states, ...) |
|||
* @param name the name of what we are counting. |
|||
*/ |
|||
void setItemName(std::string const& name); |
|||
|
|||
private: |
|||
|
|||
// The delay (in seconds) between progress emission. |
|||
uint64_t delay; |
|||
// A name for what this is measuring (iterations, states, ...) |
|||
std::string itemName; |
|||
|
|||
// The maximal count that can be achieved. Zero means unspecified. |
|||
uint64_t maxCount; |
|||
|
|||
// The last displayed count |
|||
uint64_t lastDisplayedCount; |
|||
|
|||
std::chrono::high_resolution_clock::time_point timeOfStart; |
|||
std::chrono::high_resolution_clock::time_point timeOfLastMessage; |
|||
|
|||
}; |
|||
|
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue