Bridges-C++  3.2.0
Bridges(C++API)
GraphAdjList.h
Go to the documentation of this file.
1 #ifndef GRAPH_ADJ_LIST
2 #define GRAPH_ADJ_LIST
3 
4 #include <stdexcept>
5 #include <sstream>
6 #include <unordered_map>
7 #include <JSONutil.h>
8 
9 using namespace std;
10 
11 #include "SLelement.h"
12 #include "Edge.h"
13 
14 namespace bridges {
15  namespace datastructure {
107  template<typename K, typename E1 = K, typename E2 = E1>
108  class GraphAdjList : public DataStructure {
109  private:
110  // list of graph vertices
111  // maintained as a map to accommodate strings
112  unordered_map<K, Element<E1>* > vertices;
113  // adjacency lists
114  unordered_map<K, SLelement<Edge<K, E2> >*> adj_list;
115 
116  // large graph related
117  static const int LargeGraphVertSize = 2000;
118 
119  bool forceLargeViz = false;
120  bool forceSmallViz = false;
121 
122 
123  GraphAdjList(const GraphAdjList& gr) = delete; //would not be correct
124  const GraphAdjList& operator= (const GraphAdjList& gr) = delete; //would not be correct
125  public:
126 
127  GraphAdjList() = default;
128  GraphAdjList(GraphAdjList&& gr) = default;
129 
130  virtual ~GraphAdjList() override {
131  for (auto& v : vertices) {
132  if (adj_list[v.first]) {
133  // discard the edges in the adj. list
134  SLelement<Edge<K, E2>> *tmp;
135  for (SLelement<Edge<K, E2>> *sle =
136  adj_list[v.first]; sle != nullptr; ) {
137  tmp = sle;
138  sle = sle->getNext();
139  delete tmp;
140  }
141  adj_list[v.first] = nullptr;
142  }
143  delete vertices[v.first]; // free the element at v
144  vertices[v.first] = nullptr;
145 
146  }
147  }
153  virtual const string getDStype() const override {
154  if (forceLargeViz || (!forceSmallViz &&
155  vertices.size() > LargeGraphVertSize &&
156  areAllVerticesLocated())) {
157  return "largegraph";
158  }
159  return "GraphAdjacencyList";
160  }
161 
174  void addVertex(const K& k, const E1& e = E1()) {
175  stringstream conv;
176  conv << k;
177  if (vertices.find(k) == vertices.end()) {
178  // vertex does not exist, create one
179  vertices[k] = new Element<E1>(e, conv.str());
180  adj_list[k] = nullptr;
181  }
182  }
197  void addEdge(const K& src, const K& dest, const E2& data = E2()) {
198  try {
199  vertices.at(src);
200  vertices.at(dest);
201  // links structure is redundant and needs
202  // to be removed in future implementations!
203  vertices[src]->links[vertices.at(dest)]; //In C++ this creates the linkvisualizer
204 
205  stringstream conv;
206  conv << dest;
207  // add the edge
208  adj_list.at(src) =
209  new SLelement<Edge<K, E2> > (adj_list.at(src),
210  Edge<K, E2> (src, dest, &(vertices[src]->links[vertices.at(dest)]), data), conv.str());
211 
212  }
213  catch ( const out_of_range& ) {
214  cerr << "addEdge(): Nonexistent vertex?" << endl <<
215  "Create vertices first prior to adding edges that use that vertex" << endl
216  << "Cannot add edge between non-existent verticies"
217  << endl;
218  throw;
219  }
220  }
228  const E1& getVertexData (const K& src)& {
229  try {
230  Element<E1> *el = vertices.at(src);
231  return (vertices.at(src))->getValue();
232  }
233  catch ( const out_of_range& ) {
234  cerr << "getVertexData(): vertex not found" << endl;
235  throw;
236  }
237  // should never reach here
238  throw "getVertexData(): vertex not found";
239  }
247  void setVertexData (const K& vertID, E1 const & data) {
248  try {
249  Element<E1> *el = vertices.at(vertID);
250  el->setValue (data);
251  }
252  catch ( const out_of_range& ) {
253  cerr << "setVertexData(): Nonexistent vertex" << endl;
254  throw;
255  }
256  catch (const char* msg) {
257  cerr << msg << endl;
258  }
259  }
268  E2& getEdgeData (const K& src, const K& dest) {
269  try {
270  vertices.at(src);
271  vertices.at(dest);
272  SLelement<Edge<K, E2> > *sle = adj_list.at(src);
273  while (sle) {
274  Edge<K, E2> ed = sle->getValue();
275  if (ed.getVertex() == dest) { //edge exists
276  return ed.getEdgeData();
277  }
278  sle = sle->getNext();
279  }
280  throw "Edge not found!";
281  }
282  catch ( const out_of_range& ) {
283  cerr << "getEdgeData(): Edge not found" << endl;
284  throw;
285  }
286  catch (const char* msg) {
287  cerr << msg << endl;
288  }
289  // should never reach here
290  throw "getEdgeData(): Edge not found";
291  }
300  E2 const& getEdgeData (const K& src, const K& dest) const {
301  try {
302  vertices.at(src);
303  vertices.at(dest);
304  SLelement<Edge<K, E2> > *sle = adj_list.at(src);
305  while (sle) {
306  Edge<K, E2> ed = sle->getValue();
307  if (ed.getVertex() == dest) { //edge exists
308  return ed.getEdgeData();
309  }
310  sle = sle->getNext();
311  }
312  throw "Edge not found!";
313  }
314  catch ( const out_of_range& ) {
315  cerr << "getEdgeData(): Edge not found" << endl;
316  throw;
317  }
318  catch (const char* msg) {
319  cerr << msg << endl;
320  }
321  // should never reach here
322  throw "getEdgeData(): Edge not found";
323  }
324 
325 
334  void setEdgeData (const K& src, const K& dest, E2& data) {
335  try {
336  vertices.at(src);
337  vertices.at(dest);
338  SLelement<Edge<K, E2> > *sle = adj_list.at(src);
339  while (sle) {
340  Edge<K, E2> ed = sle->getValue();
341  if (ed.getVertex() == dest) { //edge exists
342  ed.setEdgeData(data); //change edge data
343  sle->setValue(ed); //change slelement data
344  return;
345  }
346  sle = sle->getNext();
347  }
348  throw "getEdgeData(): Edge not found!";
349  }
350  catch ( const out_of_range& ) {
351  cerr << "setEdgeData(): Nonexistent vertices or " <<
352  " edge not found" << endl;
353  throw;
354  }
355  catch (const char* msg) {
356  cerr << msg << endl;
357  }
358  // will never reach here, but avoids compiler warnings
359  throw "getEdgeData(): Edge not found";
360  }
366  unordered_map<K, Element<E1>*>* getVertices() {
367  return &vertices;
368  }
369 
375  const unordered_map<K, Element<E1>*>* getVertices() const {
376  return &vertices;
377  }
383  const Element<E1>* getVertex(const K& key) const {
384  try {
385  return vertices.at(key);
386  }
387  catch (const std::out_of_range& oor) {
388  /* std::cerr << "Out of Range error: " << oor.what() */
389  /* << "returning null pointer\n"; */
390  return nullptr;
391  }
392  }
393 
394 
400  Element<E1>* getVertex(const K& key) {
401  try {
402  return vertices.at(key);
403  }
404  catch (const std::out_of_range& oor) {
405  /* std::cerr << "Out of Range error: " << oor.what() */
406  /* << "returning null pointer\n"; */
407  return nullptr;
408  }
409  }
410 
418  Edge<K, E2> getEdge(const K& src, const K& dest) {
419  // check to see if the two vertices exist, else
420  // return null
421  try {
422  // look for the edge
423  SLelement<Edge<K, E2>> *sle = adj_list[src];
424  while (sle != nullptr) {
425  K edge_dest = ((Edge<K, E2>) sle->getValue()).to();
426  if (edge_dest == dest) // found
427  return sle->getValue();
428  sle = sle->getNext();
429  }
430  }
431  catch (const std::out_of_range& oor) {
432  // one or both vertices doesnt exist
433  std::cout << "one or both vertices are likely missing from graph\n";
434  throw;
435  }
436  }
437 
442  const unordered_map<K, SLelement<Edge<K, E2> >*>&
444  return adj_list;
445  }
446 
456  try {
457  return adj_list.at(k);
458  }
459  catch (const out_of_range& ) {
460  cerr << "Cannot getAdjacencyList() of a non-existent vertex!"
461  << endl;
462  throw;
463  }
464  }
465 
474  const SLelement<Edge<K, E2> >* getAdjacencyList(const K& k) const {
475  try {
476  return adj_list.at(k);
477  }
478  catch (const out_of_range& ) {
479  cerr << "Cannot getAdjacencyList() of a non-existent vertex!"
480  << endl;
481  throw;
482  }
483  }
484 
485 
495  try {
496  Element<E1> *el = vertices.at(k);
497 
498  return el->getVisualizer();
499  }
500  catch (const out_of_range& ) {
501  cerr << "Graph vertex " << k << " not found in graph!" << endl;
502  throw;
503  }
504  }
515  LinkVisualizer *getLinkVisualizer (const K& k1, const K& k2) {
516  try {
517  return getEdge(k1, k2).getLinkVisualizer();
518  }
519  catch (const out_of_range& ) {
520  cerr << "Either source or destination node not found in graph!\n";
521  throw;
522  }
523  }
524  private:
530  virtual const string getDataStructureRepresentation() const override {
532 
533  // map the nodes to a sequence of ids, 0...N-1
534  // then get the JSON string for nodes placeholder
535  // nullptr prevents insertion of other nullptrs
536 
537  // check for large graph
538  if (forceLargeViz ||
539  (!forceSmallViz &&
540  vertices.size() > LargeGraphVertSize &&
541  areAllVerticesLocated())) {
542  return getDataStructureRepresentationLargeGraph();
543  }
544 
545  unordered_map<K, int> node_map;
546  int i = 0;
547  string nodes_JSON = "", links_JSON = "";
548 
549  for (const auto& v : vertices) {
550  if (node_map.emplace(v.first, i).second) {
551  i++;
552  nodes_JSON += v.second->getElementRepresentation() + COMMA;
553  }
554  }
555 
556  //Remove trailing comma and nullptr entry
557 
558  if (nodes_JSON.size()) {
559  nodes_JSON = nodes_JSON.erase(nodes_JSON.size() - 1);
560  }
561 
562  // iterate through the vertices and form the links JSON
563 
564  for (const auto& v : vertices) {
565  // get adj. list
566  Element<E1>* src_vert = vertices.at(v.first);
567  // iterate through list and form links
568  for (SLelement<Edge<K, E2>>* it = adj_list.at(v.first); it != nullptr;
569  it = it->getNext()) {
570  Element<E1>* dest_vert = vertices.at(it->getValue().to() );
571  links_JSON += src_vert->getLinkRepresentation(
572  *(src_vert->getLinkVisualizer(dest_vert)),
573  JSONencode(node_map.at(v.first)),
574  JSONencode(node_map.at(it->getValue().to())) ) + COMMA;
575  }
576  }
577 
578  //Remove trailing comma
579  if (links_JSON.size()) {
580  links_JSON = links_JSON.erase(links_JSON.size() - 1);
581  }
582 
583  string graph_alist_json =
584  QUOTE + "nodes" + QUOTE + COLON +
585  OPEN_BOX + nodes_JSON + CLOSE_BOX + COMMA +
586  QUOTE + "links" + QUOTE + COLON + OPEN_BOX +
587  links_JSON + CLOSE_BOX +
588  CLOSE_CURLY;
589 
590 
591  return graph_alist_json;
592  }
603  string getDataStructureRepresentationLargeGraph () const {
604 
606  // map the nodes to a sequence of ids, 0...N-1
607  // then get the JSON string for nodes placeholder
608  // nullptr prevents insertion of other nullptrs
609 
610  unordered_map<K, int> node_map;
611  int i = 0;
612  string nodes_JSON = "";
613 
614  for (const auto& v : vertices) {
615  if (node_map.emplace(v.first, i).second) {
616  i++;
617  const ElementVisualizer *elvis =
618  vertices.at(v.first)->getVisualizer();
619  string loc_str = "";
620  if ( (elvis->getLocationX() != INFINITY) &&
621  (elvis->getLocationY() != INFINITY) ) {
622  loc_str =
623  OPEN_BOX +
624  JSONencode(elvis->getLocationX()) + COMMA +
625  JSONencode(elvis->getLocationY()) +
626  CLOSE_BOX + COMMA;
627  }
628  nodes_JSON += OPEN_BOX + loc_str +
629  elvis->getColor().getCSSRepresentation() +
630  CLOSE_BOX + COMMA;
631  }
632  }
633 
634  //Remove trailing comma and nullptr entry
635 
636  if (nodes_JSON.size()) {
637  nodes_JSON = nodes_JSON.erase(nodes_JSON.size() - 1);
638  }
639 
640  // next link information
641  string links_JSON = "";
642  for (const auto& v : vertices) {
643  // get adj. list
644  Element<E1>* src_vert = vertices.at(v.first);
645  // iterate through list and form links
646  for (SLelement<Edge<K, E2>>* it = adj_list.at(v.first); it != nullptr;
647  it = it->getNext()) {
648  Element<E1>* dest_vert = vertices.at(it->getValue().to() );
649  LinkVisualizer *lv = src_vert->getLinkVisualizer(dest_vert);
650  string src = JSONencode(node_map.at(v.first));
651  string dest = JSONencode(node_map.at(it->getValue().to()));
652  links_JSON += OPEN_BOX +
653  src + COMMA +
654  dest + COMMA +
656  CLOSE_BOX + COMMA;
657 
658  }
659  }
660  //Remove trailing comma
661  if (links_JSON.size())
662  links_JSON = links_JSON.erase(links_JSON.size() - 1);
663 
664  string graph_alist_json =
665  QUOTE + "nodes" + QUOTE + COLON +
666  OPEN_BOX + nodes_JSON + CLOSE_BOX + COMMA +
667  QUOTE + "links" + QUOTE + COLON +
668  OPEN_BOX + links_JSON + CLOSE_BOX +
669  CLOSE_CURLY;
670 
671  return graph_alist_json;
672 
673  }
677  bool areAllVerticesLocated() const {
678  for (const auto& v : vertices) {
679  ElementVisualizer *elvis = v.second->getVisualizer();
680  if (elvis->getLocationX() == INFINITY
681  || elvis->getLocationY() == INFINITY)
682  return false;
683  }
684  return true;
685  }
686 
687 
688  public:
689 
706  void forceLargeVisualization(bool f) {
707  if (f) {
708  forceLargeViz = true;
709  forceSmallViz = false;
710  }
711  else {
712  forceLargeViz = false;
713  }
714  }
715 
732  void forceSmallVisualization(bool f) {
733  if (f) {
734  forceSmallViz = true;
735  forceLargeViz = false;
736  }
737  else {
738  forceSmallViz = false;
739  }
740  }
741 
742  // @brief This is a helper class to return sets of vertices
743  // in a way that are iterable with range for loops.
744  // Students should not have to use this directly.
746  std::unordered_map<K, Element<E1>* > const & underlying_map;
747 
748  public:
749  KeySet_helper (std::unordered_map<K, Element<E1>* > const & um)
750  : underlying_map(um)
751  {}
752 
754  typename std::unordered_map<K, Element<E1>* >::const_iterator it;
755  public:
756  const_iterator(typename std::unordered_map<K, Element<E1>* >::const_iterator i )
757  : it(i)
758  {}
759 
760  bool operator!=(const const_iterator& it) const {
761  return this->it != it.it;
762  }
763 
764  const K& operator*() const {
765  return it->first;
766  }
767 
769  it ++;
770  return *this;
771  }
772  };
773 
775  return const_iterator(underlying_map.begin());
776  }
777 
778  const_iterator end() const {
779  return const_iterator(underlying_map.end());
780  }
781  };
782 
793  return KeySet_helper(this->vertices);
794  }
795 
800  typename SLelement<Edge<K, E2>>::SLelement_listhelper
801  outgoingEdgeSetOf(K const & k) {
802  return typename SLelement<Edge<K, E2>>::SLelement_listhelper(getAdjacencyList(k));
803  }
804 
809  typename SLelement<Edge<K, E2>>::SLelement_constlisthelper
810  outgoingEdgeSetOf(K const & k) const {
811  return typename SLelement<Edge<K, E2>>::SLelement_constlisthelper(getAdjacencyList(k));
812  }
813 
814 
821  typename std::unordered_map<K, Element<E1>* > & underlying_map;
822 
823  public:
824  VertexElementSet_listhelper (std::unordered_map<K, Element<E1>* > & um)
825  : underlying_map(um)
826  {}
827 
833  class iterator {
834  typename std::unordered_map<K, Element<E1>* >::iterator it;
835  public:
836  iterator(typename std::unordered_map<K, Element<E1>* >::iterator i )
837  : it(i)
838  {}
839 
840  bool operator!=(const iterator& it) const {
841  return this->it != it.it;
842  }
843 
845  return it->second;
846  }
847 
849  it ++;
850  return *this;
851  }
852  };
853 
860  typename std::unordered_map<K, Element<E1>* >::const_iterator it;
861  public:
862  const_iterator(typename std::unordered_map<K, Element<E1>* >::const_iterator i )
863  : it(i)
864  {}
865 
866  bool operator!=(const const_iterator& it) const {
867  return this->it != it.it;
868  }
869 
870  Element<E1> const* operator*() const {
871  return it->second;
872  }
873 
875  it ++;
876  return *this;
877  }
878  };
879 
880 
882  return iterator(underlying_map.begin());
883  }
884 
886  return iterator(underlying_map.end());
887  }
888 
890  return const_iterator(underlying_map.begin());
891  }
892 
893  const_iterator end() const {
894  return const_iterator(underlying_map.end());
895  }
896 
897  };
898 
904  return VertexElementSet_listhelper(vertices);
905  }
906 
907 
914  typename std::unordered_map<K, Element<E1>* > const & underlying_map;
915 
916  public:
917  constVertexElementSet_listhelper (std::unordered_map<K, Element<E1>* > const& um)
918  : underlying_map(um)
919  {}
920 
923  typename std::unordered_map<K, Element<E1>* >::const_iterator it;
924  public:
925  const_iterator(typename std::unordered_map<K, Element<E1>* >::const_iterator i )
926  : it(i)
927  {}
928 
929  bool operator!=(const const_iterator& it) const {
930  return this->it != it.it;
931  }
932 
933  Element<E1> const* operator*() const {
934  return it->second;
935  }
936 
938  it ++;
939  return *this;
940  }
941  };
942 
944  return const_iterator(underlying_map.begin());
945  }
946 
947  const_iterator end() const {
948  return const_iterator(underlying_map.begin());
949  }
950  };
956  return constVertexElementSet_listhelper(vertices);
957  }
958  };
959 
960  //end of GraphAdjList class
961  }
962 }//end of bridges namespace
963 #endif
VertexElementSet_listhelper vertexSet()
Definition: GraphAdjList.h:903
void forceSmallVisualization(bool f)
Force the rendering engine to use small graph visualization.
Definition: GraphAdjList.h:732
This is a helper class to return sets of vertices in a way that are iterable with range for loops...
Definition: GraphAdjList.h:833
double getLocationY() const
get Y coordinate of element location
Definition: ElementVisualizer.h:173
double getLocationX() const
get X coordinate of element location
Definition: ElementVisualizer.h:166
void setValue(const E &val)
Sets generic object to "val".
Definition: Element.h:229
static const string getLinkRepresentation(const LinkVisualizer &lv, const string &src, const string &dest)
Definition: Element.h:273
This is a helper class to return sets of vertices ina way that are iterable with range for loops...
Definition: GraphAdjList.h:922
void setEdgeData(const E2 &data)
Sets edge data to "data".
Definition: Edge.h:94
ElementVisualizer * getVisualizer(const K &k)
Returns the visualizer corresponding to a graph vertex. convenient method to set attributes of the gr...
Definition: GraphAdjList.h:494
bool operator!=(const const_iterator &it) const
Definition: GraphAdjList.h:866
E2 & getEdgeData(const K &src, const K &dest)
Gets edge data for the edge from "src" to "dest".
Definition: GraphAdjList.h:268
SLelement< Edge< K, E2 > > * getAdjacencyList(const K &k)
Returns adjacency list of a vertex with name k.
Definition: GraphAdjList.h:455
const string COLON
Definition: DataStructure.h:51
STL namespace.
E const & getValue() const
Gets the object held in the generic object E.
Definition: Element.h:210
iterator(typename std::unordered_map< K, Element< E1 > * >::iterator i)
Definition: GraphAdjList.h:836
constVertexElementSet_listhelper(std::unordered_map< K, Element< E1 > * > const &um)
Definition: GraphAdjList.h:917
SLelement< Edge< K, E2 > >::SLelement_listhelper outgoingEdgeSetOf(K const &k)
This method is useful for iterating through a set of outgoing edges from a vertex.
Definition: GraphAdjList.h:801
This class maintains the visual properties of the a Bridges element.
Definition: ElementVisualizer.h:31
const string OPEN_BOX
Definition: DataStructure.h:54
const_iterator end() const
Definition: GraphAdjList.h:947
Element< E1 > const * operator*() const
Definition: GraphAdjList.h:870
const_iterator(typename std::unordered_map< K, Element< E1 > * >::const_iterator i)
Definition: GraphAdjList.h:925
const_iterator begin() const
Definition: GraphAdjList.h:774
const_iterator(typename std::unordered_map< K, Element< E1 > * >::const_iterator i)
Definition: GraphAdjList.h:862
const string CLOSE_CURLY
Definition: DataStructure.h:53
const Element< E1 > * getVertex(const K &key) const
Return the vertex corresponding to a key.
Definition: GraphAdjList.h:383
const E1 & getVertexData(const K &src) &
Gets vertex data for a graph vertex.
Definition: GraphAdjList.h:228
const_iterator end() const
Definition: GraphAdjList.h:778
Element< E1 > * getVertex(const K &key)
Definition: GraphAdjList.h:400
The singly linked list element, derived from Element.
Definition: SLelement.h:27
This is a helper class to return sets of vertices in a way that are iterable with range for loops...
Definition: GraphAdjList.h:859
const_iterator end() const
Definition: GraphAdjList.h:893
void forceLargeVisualization(bool f)
Force the rendering engine to use large graph visualization.
Definition: GraphAdjList.h:706
void addVertex(const K &k, const E1 &e=E1())
Adds a vertex to the graph.
Definition: GraphAdjList.h:174
const_iterator(typename std::unordered_map< K, Element< E1 > * >::const_iterator i)
Definition: GraphAdjList.h:756
bool operator!=(const iterator &it) const
Definition: GraphAdjList.h:840
these methods convert byte arrays in to base64 codes and are used in BRIDGES to represent the color a...
Definition: alltypes.h:4
const_iterator begin() const
Definition: GraphAdjList.h:943
virtual const string getDStype() const override
Get the string representation of this data structure type.
Definition: GraphAdjList.h:153
const string CLOSE_BOX
Definition: DataStructure.h:55
bool operator!=(const const_iterator &it) const
Definition: GraphAdjList.h:929
const E2 & getEdgeData() const
Return the edge data.
Definition: Edge.h:102
const string getCSSRepresentation() const
Definition: Color.h:404
bool operator!=(const const_iterator &it) const
Definition: GraphAdjList.h:760
This is a helper class to return sets of vertices in a way that are iterable with range for loops...
Definition: GraphAdjList.h:913
const_iterator begin() const
Definition: GraphAdjList.h:889
KeySet_helper(std::unordered_map< K, Element< E1 > * > const &um)
Definition: GraphAdjList.h:749
unordered_map< K, Element< E1 > * > * getVertices()
Return the graph nodes.
Definition: GraphAdjList.h:366
constVertexElementSet_listhelper vertexSet() const
Definition: GraphAdjList.h:955
Edge< K, E2 > getEdge(const K &src, const K &dest)
Get the edge between src and dest vertices.
Definition: GraphAdjList.h:418
const_iterator & operator++()
Definition: GraphAdjList.h:768
void setVertexData(const K &vertID, E1 const &data)
Loads vertex specific information for a graph vertex.
Definition: GraphAdjList.h:247
virtual SLelement * getNext()
Returns the next element in the list.
Definition: SLelement.h:75
const unordered_map< K, Element< E1 > * > * getVertices() const
Return the graph nodes - const version.
Definition: GraphAdjList.h:375
const K & operator*() const
Definition: GraphAdjList.h:764
This is a helper class to return sets of vertices in a way that are iterable with range for loops...
Definition: GraphAdjList.h:820
Element< E1 > const * operator*() const
Definition: GraphAdjList.h:933
const SLelement< Edge< K, E2 > > * getAdjacencyList(const K &k) const
Definition: GraphAdjList.h:474
VertexElementSet_listhelper(std::unordered_map< K, Element< E1 > * > &um)
Definition: GraphAdjList.h:824
KeySet_helper keySet() const
Definition: GraphAdjList.h:792
Color getColor() const
Return the element color.
Definition: ElementVisualizer.h:110
virtual ~GraphAdjList() override
Definition: GraphAdjList.h:130
ElementVisualizer * getVisualizer()
Get the element visualizer object.
Definition: Element.h:144
const string COMMA
Definition: DataStructure.h:50
const string QUOTE
Definition: DataStructure.h:49
const unordered_map< K, SLelement< Edge< K, E2 > > * > & getAdjacencyList() const
Return the adjacency list.
Definition: GraphAdjList.h:443
LinkVisualizer * getLinkVisualizer(const K &k1, const K &k2)
Returns the link visualizer corresponding to an edge. Returns the link visualizer corresponding to tw...
Definition: GraphAdjList.h:515
SLelement< Edge< K, E2 > >::SLelement_constlisthelper outgoingEdgeSetOf(K const &k) const
This method is useful for iterating through a set of outgoing edges from a vertex - const version...
Definition: GraphAdjList.h:810
E2 const & getEdgeData(const K &src, const K &dest) const
Gets edge data for the edge from "src" to "dest" - const version.
Definition: GraphAdjList.h:300
void addEdge(const K &src, const K &dest, const E2 &data=E2())
Add an edge with data.
Definition: GraphAdjList.h:197
This helper class is used by the graph classes - GraphAdjList , GraphAdjMatrix - to keep track of edg...
Definition: Edge.h:36
void setEdgeData(const K &src, const K &dest, E2 &data)
Loads edge specific information for the edge from "src" to "dest".
Definition: GraphAdjList.h:334
std::string JSONencode(const T &d)
Definition: JSONutil.h:37
LinkVisualizer * getLinkVisualizer(const Element *el)
Returns the LinkVisualizer of element.
Definition: Element.h:165