diff --git a/Simulator/Utils/Global.cpp b/Simulator/Utils/Global.cpp index 8b6b0db96..396d7273d 100644 --- a/Simulator/Utils/Global.cpp +++ b/Simulator/Utils/Global.cpp @@ -6,7 +6,6 @@ * @brief Globally available functions/variables and default parameter values. */ #include "Global.h" -#include "MTRand.h" #include "Norm.h" // Debugging log data and routines @@ -23,9 +22,9 @@ int g_debug_mask /// @param width width of the two-dimensional array /// @param height height of the two-dimensional array /// @return string with the converted indexes and square brackets surrounding them. -string index2dToString(int i, int width, int height) +std::string index2dToString(int i, int width, int height) { - stringstream ss; + std::stringstream ss; ss << "[" << i % width << "][" << i / height << "]"; return ss.str(); } @@ -34,9 +33,9 @@ string index2dToString(int i, int width, int height) /// @param x x coordinate. /// @param y y coordinate. /// @return returns the given coordinates surrounded by square brackets. -string coordToString(int x, int y) +std::string coordToString(int x, int y) { - stringstream ss; + std::stringstream ss; ss << "[" << x << "][" << y << "]"; return ss.str(); } @@ -46,9 +45,9 @@ string coordToString(int x, int y) /// @param y y coordinate. /// @param z z coordinate. /// @return returns the given coordinates surrounded by square brackets. -string coordToString(int x, int y, int z) +std::string coordToString(int x, int y, int z) { - stringstream ss; + std::stringstream ss; ss << "[" << x << "][" << y << "][" << z << "]"; return ss.str(); } @@ -62,10 +61,10 @@ int g_deviceId = 0; MTRand initRNG; // A normalized random number generator. -unique_ptr noiseRNG; +std::unique_ptr noiseRNG; // simulation vars -uint64_t g_simulationStep = 0; +std::uint64_t g_simulationStep = 0; //const BGFLOAT g_synapseStrengthAdjustmentConstant = 1.0e-8; @@ -115,8 +114,3 @@ void printPerformanceMetrics(const float total_time, int steps) cout << "t_gpu_calcSummation: " << t_gpu_calcSummation / steps << " ms/epoch" << endl; } #endif // PERFORMANCE_METRICS - -// TODO comment -const string MATRIX_TYPE = "complete"; -// TODO comment -const string MATRIX_INIT = "const"; diff --git a/Simulator/Utils/Global.h b/Simulator/Utils/Global.h index c4d48d800..aea869965 100644 --- a/Simulator/Utils/Global.h +++ b/Simulator/Utils/Global.h @@ -52,23 +52,21 @@ extern int g_debug_mask; +#include "BGTypes.h" +#include "GraphProperties.h" +#include "Matrix/MatrixDefaults.h" #include +#include #include +#include #include -#ifdef _WIN32 //needs to be before #include "bgtypes.h" or the #define BGFLOAT will cause problems - #include //warning! windows.h also defines BGFLOAT -using uint64_t = unsigned long long int; //included in inttypes.h, which is not available in WIN32 -#else - #include //used for uint64_t, unavailable in WIN32 -#endif -#include "BGTypes.h" - //#include "Norm.h" +#include +#include +//#include "Norm.h" #include "Coordinate.h" #include "VectorMatrix.h" #include "VertexType.h" -using namespace std; - // If defined, a table with time and each neuron voltage will output to stdout. //#define DUMP_VOLTAGES @@ -84,12 +82,12 @@ extern const BGFLOAT pi; extern MTRand initRNG; // A normalized random number generator. -extern unique_ptr noiseRNG; +extern std::unique_ptr noiseRNG; // The current simulation step. -extern uint64_t g_simulationStep; +extern std::uint64_t g_simulationStep; -const int g_nMaxChunkSize = 100; +constexpr int g_nMaxChunkSize = 100; // Edge types. // NEURO: @@ -127,27 +125,27 @@ inline std::ostream &operator<<(std::ostream &os, edgeType eT) } // The default time step size. -#define DEFAULT_dt (1e-4) // MODEL INDEPENDENT +constexpr double DEFAULT_dt = 1e-4; // MODEL INDEPENDENT // } NMV-END // Converts a 1-d index into a coordinate string. -string index2dToString(int i, int width, int height); +std::string index2dToString(int i, int width, int height); // Converts a 2-d coordinate into a string. -string coordToString(int x, int y); +std::string coordToString(int x, int y); // Converts a 3-d coordinate into a string. -string coordToString(int x, int y, int z); +std::string coordToString(int x, int y, int z); -template ostream &operator<<(ostream &os, const vector &v) +template std::ostream &operator<<(std::ostream &os, const std::vector &v) { - for (T element : v) { + for (const auto &element : v) { os << element << " "; } return os; } -template string vectorToXML(const vector &v, const string &name) +template std::string vectorToXML(const std::vector &v, const std::string &name) { - stringstream ss; + std::stringstream ss; ss << " \n"; ss << " " << v << "\n"; ss << " "; @@ -155,11 +153,12 @@ template string vectorToXML(const vector &v, const string &name) } template -string vector2dToXML(const vector &v, const string &name, const string &rowName) +std::string vector2dToXML(const std::vector &v, const std::string &name, + const std::string &rowName) { - stringstream ss; + std::stringstream ss; ss << " \n"; - for (int i = 0; i < v.size(); ++i) { + for (size_t i = 0; i < v.size(); ++i) { if (v[i].empty()) { continue; } // No log to print @@ -186,54 +185,3 @@ extern double t_gpu_calcSummation; void printPerformanceMetrics(const float total_time, int steps); #endif // PERFORMANCE_METRICS - -// TODO comment -extern const string MATRIX_TYPE; -// TODO comment -extern const string MATRIX_INIT; - -/*****************************************************************************/ -/* Structures to hold the GraphML properties */ -/*****************************************************************************/ -// We are using the Boost Graph Library (BGL) to load the simulator's initial -// graph. BGL needs to associate the GraphML properties, we do that by -// registering them before loading the graph. -// The following structures are used to register those properties with the -// GraphManager class, which is just a wrapper around BGL. The corresponding -// classes (Layout, Connections, etc) need to do this before we can load the -// graph. - -/// @brief Parent structure to store common properties for all graph vertices -struct VertexProperties { - string type; - double x; - double y; -}; - -/// @brief Derived structure for NG911-specific properties -/// Inherits from VertexProperty and includes attributes specific to 911 networks -struct NG911VertexProperties : public VertexProperties { - string objectID; - string name; - int servers = 0; - int trunks = 0; - string segments; -}; - -/// @brief Derived structure for Neural Network-specific properties -struct NeuralVertexProperties : public VertexProperties { - bool active; -}; - -/// @brief The structure to hold the edge properties -struct NeuralEdgeProperties { - int source; - int target; - double weight; -}; - - -/// @brief The structure to hold the Graph properties -struct GraphProperties { - // TODO: Graph Properties -}; diff --git a/Simulator/Utils/GraphManager.h b/Simulator/Utils/GraphManager.h index 6430d87ef..09e6f1399 100644 --- a/Simulator/Utils/GraphManager.h +++ b/Simulator/Utils/GraphManager.h @@ -30,8 +30,8 @@ * - The entire GraphManager class is included in the header file to ensure that * the templated class can be compiled without requiring separate declarations. * - * The structures for `VertexProperties`, `EdgeProperties`, and `GraphProperties` - * are declared in `Global.h`. + * The structures for `VertexProperties`, `NeuralEdgeProperties`, and + * `GraphProperties` are declared in `GraphProperties.h`. * * This class follows the Singleton design pattern, ensuring a single instance * is used throughout the simulation for consistent graph management. @@ -39,10 +39,13 @@ #pragma once -#include "Global.h" +#include "GraphProperties.h" #include "ParameterManager.h" #include #include +#include +#include +#include #include #include diff --git a/Simulator/Utils/GraphProperties.h b/Simulator/Utils/GraphProperties.h new file mode 100644 index 000000000..861f245b9 --- /dev/null +++ b/Simulator/Utils/GraphProperties.h @@ -0,0 +1,37 @@ +#pragma once + +#include + +/// @brief Parent structure to store common properties for all graph vertices +struct VertexProperties { + std::string type; + double x = 0.0; + double y = 0.0; +}; + +/// @brief Derived structure for NG911-specific properties +/// Inherits from VertexProperty and includes attributes specific to 911 networks +struct NG911VertexProperties : public VertexProperties { + std::string objectID; + std::string name; + int servers = 0; + int trunks = 0; + std::string segments; +}; + +/// @brief Derived structure for Neural Network-specific properties +struct NeuralVertexProperties : public VertexProperties { + bool active = false; +}; + +/// @brief The structure to hold the edge properties +struct NeuralEdgeProperties { + int source = 0; + int target = 0; + double weight = 0.0; +}; + +/// @brief The structure to hold the Graph properties +struct GraphProperties { + // TODO: Graph Properties +}; diff --git a/Simulator/Utils/Matrix/MatrixDefaults.h b/Simulator/Utils/Matrix/MatrixDefaults.h new file mode 100644 index 000000000..488ddb995 --- /dev/null +++ b/Simulator/Utils/Matrix/MatrixDefaults.h @@ -0,0 +1,5 @@ +#pragma once + +// Default matrix implementation and initialization mode used across simulator modules. +const char MATRIX_TYPE[] = "complete"; +const char MATRIX_INIT[] = "const";