mcb LEDA Extension Package  0.8
determinant.h
Go to the documentation of this file.
1 //
2 // This program can be freely used in an academic environment
3 // ONLY for research purposes, subject to the following restrictions:
4 //
5 // 1. The origin of this software must not be misrepresented; you must not
6 // claim that you wrote the original software. If you use this software
7 // an acknowledgment in the product documentation is required.
8 // 2. Altered source versions must be plainly marked as such, and must not be
9 // misrepresented as being the original software.
10 // 3. This notice may not be removed or altered from any source distribution.
11 //
12 // Any other use is strictly prohibited by the author, without an explicit
13 // permission.
14 //
15 // Note that this program uses the LEDA library, which is NOT free. For more
16 // details visit Algorithmic Solutions at http://www.algorithmic-solutions.com/
17 // There is also a free version of LEDA 6.0 or newer.
18 //
19 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
20 // ! Any commercial use of this software is strictly !
21 // ! prohibited without explicit permission by the !
22 // ! author. !
23 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
24 //
25 // This software is distributed in the hope that it will be useful,
26 // but WITHOUT ANY WARRANTY; without even the implied warranty of
27 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
28 //
29 // Copyright (C) 2004-2008 - Dimitrios Michail <dimitrios.michail@gmail.com>
30 //
31 
36 #ifndef DETERMINANT_H
37 #define DETERMINANT_H
38 
39 #include <LEP/mcb/spvecfp.h>
40 #include <LEP/mcb/edge_num.h>
41 #include <LEP/mcb/util.h>
42 
43 #ifdef LEDA_GE_V5
44 #include <LEDA/graph/graph.h>
45 #include <LEDA/numbers/integer.h>
46 #include <LEDA/numbers/integer_matrix.h>
47 #else
48 #include <LEDA/graph.h>
49 #include <LEDA/integer.h>
50 #include <LEDA/integer_matrix.h>
51 #endif
52 
53 // start our namespace
54 namespace mcb
55 {
56 
57 #if defined(LEDA_NAMESPACE)
58  using leda::graph;
59  using leda::array;
60  using leda::edge;
61  using leda::node;
62  using leda::integer_matrix;
63 #endif
64 
66 
91  template<class Container>
92  void cycle_matrix ( const graph& g,
93  const array<Container>& cb,
94  const mcb::edge_num& enumb,
95  integer_matrix& B )
96  {
97  int N = enumb.dim_cycle_space();
98  if ( N == 0 )
99  leda::error_handler(999,"determinant: cycle space dimension is zero!");
100 
101  if ( B.dim1() != N || B.dim2() != N )
102  leda::error_handler(999,"determinant: matrix has wrong dimensions!");
103 
104  array< mcb::spvecfp > oriented_cb ( N );
105  CycleOrienter<Container> orienter( g, enumb );
106  for( int i = 0; i < N; ++i )
107  oriented_cb[i] = orienter( cb[i] );
108 
109  cycle_matrix<mcb::spvecfp>( g, oriented_cb, enumb, B );
110  }
111 
112  template<>
113  void cycle_matrix<mcb::spvecfp> ( const graph& g,
114  const array<mcb::spvecfp>& cb,
115  const mcb::edge_num& enumb,
116  integer_matrix& B )
117  {
118  int N = enumb.dim_cycle_space();
119  if ( N == 0 )
120  leda::error_handler(999,"cycle_matrix: cycle space dimension is zero!");
121 
122  if ( B.dim1() != N || B.dim2() != N )
123  leda::error_handler(999,"cycle_matrix: matrix must have dimension NxN!");
124 
125  for( int i = 0; i < N; ++i ) {
126  leda::list_item it = cb[i].first();
127  while(it!=nil)
128  {
129  int index = cb[i].index(it);
130  if( ! enumb.tree( enumb( index ) ) )
131  {
132  B[i][index] = cb[i].inf(it);
133  }
134  it = cb[i].succ(it);
135  }
136  }
137  }
138 
139 
140 
147  std::ostream& output_maple_format( std::ostream& out, const integer_matrix& B );
148 
149 
161  template<class Container>
162  leda::integer determinant ( const graph& g,
163  const array< Container >& cb,
164  const mcb::edge_num& enumb
165  )
166  {
167  int N = enumb.dim_cycle_space();
168  if ( N == 0 )
169  leda::error_handler(999,"determinant: cycle space dimension is zero!");
170 
171  integer_matrix B( N, N );
172  cycle_matrix<Container>( g, cb, enumb, B );
173 
174  leda::integer d = abs( determinant(B) );
175  if ( d == 0 )
176  leda::error_handler(999,"determinant: not a directed cycle basis!");
177  return d;
178  }
179 
180 
182 
183 } // namespace mcb end
184 
185 #endif // DETERMINANT_H
186 
187 /* ex: set ts=4 sw=4 sts=4 et: */
188 
189 
Sparse vector in .
Definition of edge numbering.
An edge numbering class.
Definition: edge_num.h:75
The main package namespace.
std::ostream & output_maple_format(std::ostream &out, const integer_matrix &B)
Output a LEDA integer_matrix in a format compatible with maple.
leda::integer determinant(const graph &g, const array< Container > &cb, const mcb::edge_num &enumb)
Compute the determinant of a cycle basis.
Definition: determinant.h:162
void cycle_matrix(const graph &g, const array< Container > &cb, const mcb::edge_num &enumb, integer_matrix &B)
Compute the cycle matrix of a cycle basis.
Definition: determinant.h:92
int dim_cycle_space() const
Definition: edge_num.h:140