Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 8 additions & 14 deletions Simulator/Utils/Global.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* @brief Globally available functions/variables and default parameter values.
*/
#include "Global.h"
#include "MTRand.h"
#include "Norm.h"
Comment thread
CodersRepo marked this conversation as resolved.

// Debugging log data and routines
Expand All @@ -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 << "]";
Comment thread
CodersRepo marked this conversation as resolved.
return ss.str();
}
Expand All @@ -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();
}
Expand All @@ -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();
}
Expand All @@ -62,10 +61,10 @@ int g_deviceId = 0;
MTRand initRNG;

// A normalized random number generator.
unique_ptr<MTRand> noiseRNG;
std::unique_ptr<MTRand> noiseRNG;

// simulation vars
uint64_t g_simulationStep = 0;
std::uint64_t g_simulationStep = 0;

//const BGFLOAT g_synapseStrengthAdjustmentConstant = 1.0e-8;

Expand Down Expand Up @@ -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";
98 changes: 23 additions & 75 deletions Simulator/Utils/Global.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,21 @@

extern int g_debug_mask;

#include "BGTypes.h"
#include "GraphProperties.h"
#include "Matrix/MatrixDefaults.h"
#include <cassert>
#include <cstdint>
#include <memory>
#include <ostream>
#include <sstream>
#ifdef _WIN32 //needs to be before #include "bgtypes.h" or the #define BGFLOAT will cause problems
#include <windows.h> //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 <inttypes.h> //used for uint64_t, unavailable in WIN32
#endif
#include "BGTypes.h"
//#include "Norm.h"
#include <string>
#include <vector>
//#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

Expand All @@ -84,12 +82,12 @@ extern const BGFLOAT pi;
extern MTRand initRNG;

// A normalized random number generator.
extern unique_ptr<MTRand> noiseRNG;
extern std::unique_ptr<MTRand> 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:
Expand Down Expand Up @@ -127,39 +125,40 @@ 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 <typename T> ostream &operator<<(ostream &os, const vector<T> &v)
template <typename T> std::ostream &operator<<(std::ostream &os, const std::vector<T> &v)
{
for (T element : v) {
for (const auto &element : v) {
os << element << " ";
}
return os;
}

template <typename T> string vectorToXML(const vector<T> &v, const string &name)
template <typename T> std::string vectorToXML(const std::vector<T> &v, const std::string &name)
{
stringstream ss;
std::stringstream ss;
ss << " <Matrix name=\"" << name << "\">\n";
ss << " " << v << "\n";
ss << " </Matrix>";
return ss.str();
}

template <typename T>
string vector2dToXML(const vector<T> &v, const string &name, const string &rowName)
std::string vector2dToXML(const std::vector<T> &v, const std::string &name,
const std::string &rowName)
{
stringstream ss;
std::stringstream ss;
ss << " <Matrix name=\"" << name << "\">\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
Expand All @@ -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
};
9 changes: 6 additions & 3 deletions Simulator/Utils/GraphManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,22 @@
* - 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.
*/

#pragma once

#include "Global.h"
#include "GraphProperties.h"
#include "ParameterManager.h"
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/graphml.hpp>
#include <fstream>
#include <iostream>
#include <list>
#include <string>
#include <utility>

Expand Down
37 changes: 37 additions & 0 deletions Simulator/Utils/GraphProperties.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#pragma once

#include <string>

/// @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
Comment thread
CodersRepo marked this conversation as resolved.
Comment thread
CodersRepo marked this conversation as resolved.
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
};
5 changes: 5 additions & 0 deletions Simulator/Utils/Matrix/MatrixDefaults.h
Original file line number Diff line number Diff line change
@@ -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";
Loading