The CyMeAlg Software (Release 0.01)
digraphtab.h
Go to the documentation of this file.
1 /// @addtogroup cymealg
2 /// @{
3 
4 /////////////////////////////////////////////////////////////////////////////
5 ///
6 /// @file
7 ///
8 /// This header file contains the definition of a few functions
9 /// for interfacing with directed graphs using tables.
10 ///
11 /// @author Pawel Pilarczyk
12 ///
13 /////////////////////////////////////////////////////////////////////////////
14 
15 // Copyright (C) 1997-2020 by Pawel Pilarczyk.
16 //
17 // This file is part of my research software. This is free software:
18 // you can redistribute it and/or modify it under the terms of the GNU
19 // General Public License as published by the Free Software Foundation,
20 // either version 3 of the License, or (at your option) any later version.
21 //
22 // This software is distributed in the hope that it will be useful,
23 // but WITHOUT ANY WARRANTY; without even the implied warranty of
24 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 // GNU General Public License for more details.
26 //
27 // You should have received a copy of the GNU General Public License
28 // along with this software; see the file "license.txt". If not,
29 // please, see <http://www.gnu.org/licenses/>.
30 
31 // Started in January 2006. Last revision: August 23, 2019.
32 
33 
34 #ifndef _CYMEALG_DIGRAPHTAB_H_
35 #define _CYMEALG_DIGRAPHTAB_H_
36 
37 // include selected CHomP header files
38 #include "chomp/system/config.h"
39 
40 namespace cymealg {
41 
42 /// Sets the weights of all the edges at a time.
43 /// The weights are pulled from the table with the [] operator.
44 template <class Graph, class Table>
45 inline void setWeights (Graph &g, const Table &tab)
46 {
47  int_t nEdges (g. countEdges ());
48  for (int_t i = 0; i < nEdges; ++ i)
49  g. setWeight (i, tab [i]);
50  return;
51 } /* setWeights */
52 
53 /// Gets the weights of all the edges at a time.
54 /// The weights are put into the table with the [] operator.
55 template <class Graph, class Table>
56 inline void getWeights (const Graph &g, Table &tab)
57 {
58  int_t nEdges (g. countEdges ());
59  for (int_t i = 0; i < nEdges; ++ i)
60  tab [i] = g. getWeight (i);
61  return;
62 } /* getWeights */
63 
64 /// Fills out a table that represents all the edges of the graph.
65 /// The indices of a starting and ending vertex of the n-th edge
66 /// are written to "tab [n] [0]" and "tab [n] [1]", respectively.
67 /// The weights are ignored; use "getWeights" to store them separately.
68 template <class Graph, class Table>
69 inline void writeEdges (const Graph &g, Table &tab)
70 {
71  int_t nVertices (g. countVertices ());
72  int_t curEdge (0);
73  for (int_t curVertex = 0; curVertex < nVertices; ++ curVertex)
74  {
75  int_t nEdges = g. countEdges (curVertex);
76  for (int_t i = 0; i < nEdges; ++ i)
77  {
78  tab [curEdge] [0] = curVertex;
79  tab [curEdge] [1] = g. getEdge (curVertex, i);
80  ++ curEdge;
81  }
82  }
83  return;
84 } /* diGraph::writeEdges */
85 
86 
87 } // namespace cymealg
88 
89 #endif // _CYMEALG_DIGRAPHTAB_H_
90 
91 /// @}
92 
void setWeights(Graph &g, const Table &tab)
Sets the weights of all the edges at a time.
Definition: digraphtab.h:45
void getWeights(const Graph &g, Table &tab)
Gets the weights of all the edges at a time.
Definition: digraphtab.h:56
void writeEdges(const Graph &g, Table &tab)
Fills out a table that represents all the edges of the graph.
Definition: digraphtab.h:69