Construct version 5.4.3
An agent based modeling framework
graph_utils::graph_iterator< link_type > Struct Template Referenceabstract

Finds the next index that aligns iterators. More...

Inheritance diagram for graph_utils::graph_iterator< link_type >:
Collaboration diagram for graph_utils::graph_iterator< link_type >:

Public Member Functions

 graph_iterator (unsigned int row, unsigned int col, const Graph< link_type > *parent, void *ptr)
 
virtual const link_type & examine (void) const =0
 Returns the value of the link the iterator is pointing to. More...
 
- Public Member Functions inherited from typeless_graph_iterator
 typeless_graph_iterator (unsigned int row=0, unsigned int col=0, void *ptr=NULL)
 
unsigned int row (void) const noexcept
 The row index this iterator is pointing to.
 
unsigned int col (void) const noexcept
 The column index this iterator is pointing to.
 
virtual unsigned int index () const noexcept
 Depending on implementation, returns either row or col. More...
 
virtual unsigned int max () const noexcept
 Returns the maximum value that Construct can return. More...
 
virtual const typeless_graph_iteratoroperator++ (void) const
 Depending on implementation, increments the iterator to point to the next relevant element. More...
 

Public Attributes

Graph< link_type > * _parent = NULL
 
- Public Attributes inherited from typeless_graph_iterator
void * _ptr
 
unsigned int _row
 
unsigned int _col
 

Detailed Description

template<typename link_type>
struct graph_utils::graph_iterator< link_type >

Finds the next index that aligns iterators.

Each iterator is advanced until each typeless_graph_iterator::index are all equal. If an iterator's index ever equals typeless_graph_iterator::max, all other iterators are advanced until they are set to their maximum index.

Parameters
it_listA vector of iterator pointers this function will align.

Example

//int main()
//{
// Graph<int>* mygraph;
//
// // Graph<int>* mygraph has been initialized with the following data
// // 0 1 4 2
// // 1 0 0 0
// // 0 0 2 3
// // 4 5 3 6
// // the default value for mygraph being zero.
// // each element with a zero does not have a data entry
//
// auto iit = mygraph->full_row_begin(3);
// auto jit = mygraph->sparse_row_begin(2, 0);
// std::vector<typeless_graph_iterator*> it_list = { &iit, &jit };
//
// for(graph_utils::init_align(it_list); iit != mygraph->row_end(3); graph_utils::it_align(it_list)) {
// std::cout << "Agent 3 has a value of " << *iit << " and agent 2 has a value of " << *jit << std::endl;
// }
//}
//

Output:

//Agent 3 has a value of 2 and agent 2 has a value of 3
//Agent 3 has a value of 3 and agent 2 has a value of 6
//

Complexity

Dependent on the number of elements in the iterator vector and the number of increment operator calls on the iterators.

Exception Safety

An assertion is raised if it_list has size 0 or 1. ‍/ void it_align(std::vector<typeless_graph_iterator*>& it_list);

/*!

Aligns the iterators if they are not already.

Does nothing if all typeless_graph_iterator::index are equal. Otherwise it_align is used to align the iterators.

Parameters
it_listA vector of iterator pointers this function will align.

Example

// int main()
// {
// Graph<int>* mygraph;
//
// // Graph<int>* mygraph has been initialized with the following data
// // 0 1 4 2
// // 1 0 0 0
// // 0 0 2 3
// // 4 5 3 6
// // the default value for mygraph being zero.
// // each element with a zero does not have a data entry
//
// auto iit = mygraph->full_row_begin(3);
// auto jit = mygraph->sparse_row_begin(2, 0);
// std::vector<typeless_graph_iterator*> it_list = { &iit, &jit };
//
// for(graph_utils::init_align(it_list); iit != mygraph->row_end(3); graph_utils::it_align(it_list)) {
// std::cout << "Agent 3 has a value of " << *iit << " and agent 2 has a value of " << *jit << std::endl;
// }
// }
//

Output:

//  Agent 3 has a value of 2 and agent 2 has a value of 3
//  Agent 3 has a value of 3 and agent 2 has a value of 6
//  

Complexity

If the iterators are aligned, linear in number of iterators. Otherwise, Dependent on the number of elements in the iterator vector and the number of increment operator calls on the iterators.

Exception Safety

An assertion is raised if it_list has size 0 or 1. ‍/ void init_align(std::vector<typeless_graph_iterator*>& it_list);

/*!

Finds the next index that aligns iterators except the first iterator.

The first iterator is incremented if its typeless_graph_iterator::index is less than any of the other iterators in the vector. If the first iterator index is ever equal to any other iterator, both iterators are incremented.

Parameters
it_listA vector of iterator pointers this function will align.

Example

// int main()
// {
// Graph<int>* mygraph;
//
// // Graph<int>* mygraph has been initialized with the following data
// // 0 1 4 2
// // 1 0 0 0
// // 0 0 2 3
// // 4 5 3 6
// // the default value for mygraph being zero.
// // each element with a zero does not have a data entry
//
// auto iit = mygraph->full_row_begin(3);
// auto jit = mygraph->sparse_row_begin(2, 0);
// std::vector<typeless_graph_iterator*> it_list = { &iit, &jit };
//
// for(graph_utils::init_align(it_list); iit != mygraph->row_end(3); graph_utils::it_align(it_list)) {
// std::cout << "Agent 3 has a value of " << *iit << " and agent 2 has a value of " << *jit << std::endl;
// }
// }
//

Output:

//  Agent 3 has a value of 2 and agent 2 has a value of 3
//  Agent 3 has a value of 3 and agent 2 has a value of 6
//  

Complexity

Dependent on the number of elements in the iterator vector and the number of increment operator calls on the iterators.

Exception Safety

An assertion is raised if it_list has size 0 or 1. ‍/ void it_align_before_first(std::vector<typeless_graph_iterator*>& it_list);

/*!

Aligns the iterators if they are not already.

Does nothing if all typeless_graph_iterator::index are equal. Otherwise it_align is used to align the iterators.

Parameters
it_listA vector of iterator pointers this function will align.

Example

// int main()
// {
// Graph<int>* mygraph;
//
// // Graph<int>* mygraph has been initialized with the following data
// // 0 1 4 2
// // 1 0 0 0
// // 0 0 2 3
// // 4 5 3 6
// // the default value for mygraph being zero.
// // each element with a zero does not have a data entry
//
// auto iit = mygraph->full_row_begin(3);
// auto jit = mygraph->sparse_row_begin(2, 0);
// std::vector<typeless_graph_iterator*> it_list = { &iit, &jit };
//
// for(graph_utils::init_align(it_list); iit != mygraph->row_end(3); graph_utils::it_align(it_list)) {
// std::cout << "Agent 3 has a value of " << *iit << " and agent 2 has a value of " << *jit << std::endl;
// }
// }
//

Output:

//  Agent 3 has a value of 2 and agent 2 has a value of 3
//  Agent 3 has a value of 3 and agent 2 has a value of 6
//  

Complexity

If the iterators are aligned, linear in number of iterators. Otherwise, Dependent on the number of elements in the iterator vector and the number of increment operator calls on the iterators.

Exception Safety

An assertion is raised if it_list has size 0 or 1. ‍/ void init_align_before_first(std::vector<typeless_graph_iterator*>& it_list);

/*! <summary>
An iterator parent with a template type that stores the parent graph pointer.
<para>
All graph_iterator pointers rely on the parent graph to tell it how to interpret the data it stores.
</para>
</summary>

Member Function Documentation

◆ examine()

template<typename link_type >
virtual const link_type & graph_utils::graph_iterator< link_type >::examine ( void  ) const
pure virtual

Returns the value of the link the iterator is pointing to.

Implemented in graph_utils::row_graph_iterator< link_type >, and graph_utils::col_graph_iterator< link_type >.

Member Data Documentation

◆ _parent

template<typename link_type >
Graph<link_type>* graph_utils::graph_iterator< link_type >::_parent = NULL

summary>