-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implementation of probabilities computation
- Loading branch information
Showing
6 changed files
with
189 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#pragma once | ||
|
||
#include <filestorm/data_sizes.h> | ||
|
||
#include <filesystem> | ||
|
||
namespace fs_utils { | ||
std::filesystem::space_info get_fs_status(const std::filesystem::path& path) { return std::filesystem::space(path); } | ||
} // namespace fs_utils |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#pragma once | ||
|
||
#include <cstdlib> | ||
#include <iostream> | ||
#include <vector> | ||
|
||
class State { | ||
public: | ||
State(std::string name) : name(name) {} | ||
State(const char* name) : name(name) {} | ||
const std::string& getName() const { return name; } | ||
|
||
private: | ||
std::string name; | ||
}; | ||
|
||
class Transition { | ||
private: | ||
State& _from; | ||
State& _to; | ||
|
||
std::function<double()> _probability_function; | ||
|
||
public: | ||
Transition(State& from, State& to, std::function<double()> probability_callback) : _from(from), _to(to), _probability_function(probability_callback) {} | ||
|
||
const State& from() const { return _from; } | ||
const State& to() const { return _to; } | ||
double probability() const { return _probability_function(); } | ||
}; | ||
|
||
class ProbabilisticStateMachine { | ||
public: | ||
ProbabilisticStateMachine(std::map<std::string, State>& states, std::map<std::string, Transition>& transitions, State& init) : _states(states), _transitions(transitions), _currentState(init) {} | ||
|
||
void performTransition() { | ||
// Choose a transition based on probabilities | ||
double randomValue = static_cast<double>(rand()) / RAND_MAX; | ||
double cumulativeProbability = 0.0; | ||
|
||
for (const auto& transition : _transitions) { | ||
if (transition.second.from().getName() != _currentState.getName()) { | ||
continue; | ||
} | ||
|
||
cumulativeProbability += transition.second.probability(); | ||
if (randomValue <= cumulativeProbability) { | ||
// Transition to the next state | ||
_currentState = transition.second.to(); | ||
std::cout << "Performed transition from " << transition.second.from().getName() << " to " << transition.second.to().getName() << std::endl; | ||
break; | ||
} | ||
} | ||
throw std::runtime_error("No transitions from current state"); | ||
} | ||
|
||
const State& getCurrentState() const { return _currentState; } | ||
|
||
private: | ||
State& _currentState; | ||
std::map<std::string, State>& _states; | ||
std::map<std::string, Transition>& _transitions; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include <chrono> | ||
#include <filesystem> | ||
#include <iostream> | ||
|
||
namespace fs = std::filesystem; | ||
using namespace std::chrono; | ||
|
||
int main() { | ||
try { | ||
auto start = high_resolution_clock::now(); | ||
|
||
// Replace "C:" with the drive or path you want to check | ||
fs::space_info spaceInfo = fs::space("/Users/jjurca/Nextcloud"); | ||
|
||
auto stop = high_resolution_clock::now(); | ||
auto duration = duration_cast<microseconds>(stop - start); | ||
|
||
std::cout << "Available space: " << spaceInfo.available << " bytes\n"; | ||
|
||
// Convert capacity to gigabytes | ||
double capacityGB = static_cast<double>(spaceInfo.capacity) / (1 << 30); | ||
std::cout << "Total space: " << capacityGB << " GB\n"; | ||
|
||
// Convert free space to gigabytes | ||
double freeGB = static_cast<double>(spaceInfo.free) / (1 << 30); | ||
std::cout << "Free space: " << freeGB << " GB\n"; | ||
|
||
std::cout << "Time taken by function: " << duration.count() << " microseconds\n"; | ||
} catch (const std::exception& ex) { | ||
std::cerr << "Error: " << ex.what() << std::endl; | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters