Class HostEnvironmentDirectedGraph

Nested Relationships

Nested Types

Class Documentation

class HostEnvironmentDirectedGraph

HostAPI handle to a specific directed graph stored within the environment.

Allows a specific directed graph to be updated by creating new vertices/edges, or updating properties assigned to them

Public Functions

HostEnvironmentDirectedGraph(std::shared_ptr<detail::CUDAEnvironmentDirectedGraphBuffers> &_directed_graph, cudaStream_t _stream, detail::CUDAScatter &_scatter, unsigned int _streamID)
void importGraph(const std::string &in_file)

Attempts to import edge and vertex data from the specified file

This file must be in the appropriate format as documented in the FLAMEGPU documentation

See also

exportGraph()

Parameters:

in_file – Path to the file on disk containing the graph

Throws:
  • exception::InvalidFilePath – If the file does not exist, or cannot be opened

  • exception::UnsupportedFileType – If the specified file type does not correspond to a known format

  • exception::InvalidInputFile – If the loaded file cannot be parsed as a valid graph

void exportGraph(const std::string &out_file)

Attempts to export the edge and vertex data to the specified file

See also

importGraph()

Parameters:

out_file – Path to the file on disk containing to store the graph

Throws:
  • exception::InvalidFilePath – If the file cannot be opened for writing

  • exception::UnsupportedFileType – If the specified file type does not correspond to a known format

  • exception::RapidJSONError – If conversion to JSON fails for any reason

void setVertexCount(flamegpu::size_type count)

Set the number of vertices present in the graph This causes the internal data structure to be (re)allocated, and existing vertex data is not retained. Calling this regularly may harm performance

Note

Calling this will also invalidate any existing edges (as the vertices will nolonger exist)

Parameters:

count – The number of vertices

size_type getVertexCount()

Returns the current number of vertices present in the graph

void setEdgeCount(flamegpu::size_type count)

Set the number of edges present in the graph This causes the internal data structure to be (re)allocated, and existing edge data is not retained. Calling this regularly may harm performance

Parameters:

count – The number of edges

size_type getEdgeCount()

Returns the current number of edges present in the graph

VertexMap vertices()

Returns a map for accessing vertices The vertices are accessed via their ID, and will be created if they don’t already exist It is necessary to first call setVertexCount() to initialise the storage for vertices

EdgeMap edges()

Returns a map for accessing edges The edges are accessed via their source-destination pair, and will be created if they don’t already exist It is necessary to first call setEdgeCount() to initialise the storage for edges

class EdgeMap

A map for accessing edge storage via vertex ID

Public Functions

size_type size() const
Returns:

The number of edges with a valid source/destination vertex pair

size_type allocated_size() const

Returns:

The number of edges that memory has been allocated for

Edge operator[](SrcDestPair source_dest_vertex_ids)

Return a view into the edge map of the specified edge If the edge has not already been created, it will be created

Parameters:

source_dest_vertex_ids – Identifier of the source vertex of the edge

Throws:
Edge atIndex(unsigned int index)

Return a view into the allocated edge buffer at the specified index

Throws:

exception::OutOfBoundsException – If index exceeds the number of vertices allocated via HostEnvironmentDirectedGraph::setEdgeCount()

inline Iterator begin()

Returns an iterator to the first edge in the buffer that backs the edge map

Unlike a traditional C++ map iterator, this does not dereference to a key-value pair, as it returns all allocated edges including those which have not had their key (source/destination vertex) set, such IDs evaluate as ID_NOT_SET

Note

The order of edges is not stable and is likely to change when the graph is rebuilt

inline Iterator end()

Returns an iterator to one beyond the last edge in the buffer that backs the edge map

Unlike a traditional C++ map iterator, this does not dereference to a key-value pair, as it returns all allocated edges including those which have not had their key (source/destination vertex) set, such IDs evaluate as ID_NOT_SET

Note

The order of edges is not stable and is likely to change when the graph is rebuilt

class Edge

Public Functions

Edge(std::shared_ptr<detail::CUDAEnvironmentDirectedGraphBuffers> _directed_graph, cudaStream_t _stream, id_t _source_vertex_id, id_t _dest_vertex_id)
Edge(std::shared_ptr<detail::CUDAEnvironmentDirectedGraphBuffers> _directed_graph, cudaStream_t _stream, unsigned int edge_index)
void setSourceVertexID(id_t source_vertex_id)

Set the source vertex’s id for the current edge

Parameters:

source_vertex_id – The value to set the current edge’s source vertex id

void setDestinationVertexID(id_t dest_vertex_id)

Set the destination vertex’s id for the current edge

Parameters:

dest_vertex_id – The value to set the current edge’s destination vertex id

void setSourceDestinationVertexID(id_t source_vertex_id, id_t dest_vertex_id)

Set the source and destination vertices’ ids for the current edge

Parameters:
  • source_vertex_id – The value to set the current edge’s source vertex id

  • dest_vertex_id – The value to set the current edge’s destination vertex id

template<typename T>
void setProperty(const std::string &property_name, T property_value)

Set the value of the specified property of the current edge

Parameters:
  • property_name – The name of the property to set

  • property_value – The value to set the current edge’s property

Template Parameters:

T – The type of the property

Throws:

exception::InvalidArgument – If property_name does not refer to a valid edge property

template<typename T, flamegpu::size_type N = 0>
void setProperty(const std::string &property_name, flamegpu::size_type element_index, T property_value)
template<typename T, flamegpu::size_type N>
void setProperty(const std::string &property_name, const std::array<T, N> &property_value)
id_t getSourceVertexID() const

Returns the source vertex’s id for the current edge

id_t getDestinationVertexID() const

Returns the destination vertex’s id for the current edge

template<typename T>
T getProperty(const std::string &property_name) const

Returns the value of the specified property of the current edge

Parameters:

property_name – The name of the property to set

Template Parameters:

T – The type of the property

Throws:
  • exception::InvalidArgument – If property_name does not refer to a valid edge property

  • exception::InvalidGraphProperty – If a edge property with the matching name and type does not exist

template<typename T, flamegpu::size_type N = 0>
T getProperty(const std::string &property_name, unsigned int element_index) const
template<typename T, flamegpu::size_type N>
std::array<T, N> getProperty(const std::string &property_name) const
struct Iterator

Iterator for EdgeMap

Unlike a traditional C++ map iterator, this does not dereference to a key-value pair, as it returns all allocated edges including those which have not had their key (source/destination vertex) set, such IDs evaluate as ID_NOT_SET

Public Types

using iterator_category = std::forward_iterator_tag
using difference_type = unsigned int
using value_type = Edge
using pointer = Edge*
using reference = Edge&

Public Functions

inline Iterator(std::shared_ptr<detail::CUDAEnvironmentDirectedGraphBuffers> _directed_graph, const cudaStream_t _stream, difference_type _index)
inline reference operator*() const
inline pointer operator->() const
inline Iterator &operator++()
inline Iterator operator++(int)
inline bool operator==(const Iterator &other) const
inline bool operator!=(const Iterator &other) const
inline Iterator begin()
inline Iterator end()
class VertexMap

A map for accessing vertex storage via vertex ID

Public Functions

size_type size() const
Returns:

The number of vertices with a valid ID

size_type allocated_size() const

Returns:

The number of vertices that memory has been allocated for

Vertex operator[](id_t vertex_id)

Return a view into the vertex map of the specified vertex If the vertex has not already been created, it will be created

Parameters:

vertex_id – Identifier of the vertex to access

Throws:
Vertex atIndex(unsigned int index)

Return a view into the allocated vertex buffer at the specified index

Throws:

exception::OutOfBoundsException – If index exceeds the number of vertices allocated via HostEnvironmentDirectedGraph::setVertexCount()

inline Iterator begin()

Returns an iterator to the first vertex in the buffer that backs the vertex map

Unlike a traditional C++ map iterator, this does not dereference to a key-value pair, as it returns all allocated vertices including those which have not had their key (ID) set, such IDs evaluate as ID_NOT_SET

inline Iterator end()

Returns an iterator to one beyond the last vertex in the buffer that backs the vertex map

Unlike a traditional C++ map iterator, this does not dereference to a key-value pair, as it returns all allocated vertices including those which have not had their key (ID) set, such IDs evaluate as ID_NOT_SET

struct Iterator

Iterator for VertexMap

Unlike a traditional C++ map iterator, this does not dereference to a key-value pair, as it returns all allocated vertices including those which have not had their key (ID) set, such IDs evaluate as ID_NOT_SET

Public Types

using iterator_category = std::forward_iterator_tag
using difference_type = unsigned int
using value_type = Vertex
using pointer = Vertex*
using reference = Vertex&

Public Functions

inline Iterator(std::shared_ptr<detail::CUDAEnvironmentDirectedGraphBuffers> _directed_graph, const cudaStream_t _stream, difference_type _index)
inline reference operator*() const
inline pointer operator->() const
inline Iterator &operator++()
inline Iterator operator++(int)
inline bool operator==(const Iterator &other) const
inline bool operator!=(const Iterator &other) const
inline Iterator begin()
inline Iterator end()
class Vertex

Public Functions

Vertex(std::shared_ptr<detail::CUDAEnvironmentDirectedGraphBuffers> _directed_graph, cudaStream_t _stream, id_t _vertex_id, bool is_index = false)
void setID(id_t vertex_id)

Set the id for the current vertex

Parameters:

vertex_id – The value to set the current vertex’s id

template<typename T>
void setProperty(const std::string &property_name, T property_value)

Set the value of the specified property of the current vertex

Parameters:
  • property_name – The name of the property to set

  • property_value – The value to set the current vertex’s property

Template Parameters:

T – The type of the property

Throws:

exception::InvalidArgument – If property_name does not refer to a valid vertex property

template<typename T, flamegpu::size_type N = 0>
void setProperty(const std::string &property_name, flamegpu::size_type element_index, T property_value)
template<typename T, flamegpu::size_type N>
void setProperty(const std::string &property_name, const std::array<T, N> &property_value)
id_t getID() const

Returns the id for the current vertex

template<typename T>
T getProperty(const std::string &property_name) const

Returns the value of the specified property of the current vertex

Parameters:

property_name – The name of the property to set

Template Parameters:

T – The type of the property

Throws:
  • exception::InvalidArgument – If property_name does not refer to a valid vertex property

  • exception::InvalidGraphProperty – If a vertex property with the matching name and type does not exist

template<typename T, flamegpu::size_type N = 0>
T getProperty(const std::string &property_name, unsigned int element_index) const
template<typename T, flamegpu::size_type N>
std::array<T, N> getProperty(const std::string &property_name) const