gravatar
alpar (Alpar Juttner)
alpar@cs.elte.hu
Get rid of exceptions in Preflow
0 1 0
default
1 file changed with 4 insertions and 14 deletions:
↑ Collapse diff ↑
Ignore white space 48 line context
1 1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 2
 *
3 3
 * This file is a part of LEMON, a generic C++ optimization library.
4 4
 *
5 5
 * Copyright (C) 2003-2008
6 6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 8
 *
9 9
 * Permission to use, modify and distribute this software is granted
10 10
 * provided that this copyright notice appears in all copies. For
11 11
 * precise terms see the accompanying LICENSE file.
12 12
 *
13 13
 * This software is provided "AS IS" with no warranty of any kind,
14 14
 * express or implied, and with no claim as to its suitability for any
15 15
 * purpose.
16 16
 *
17 17
 */
18 18

	
19 19
#ifndef LEMON_PREFLOW_H
20 20
#define LEMON_PREFLOW_H
21 21

	
22
#include <lemon/error.h>
23 22
#include <lemon/tolerance.h>
24 23
#include <lemon/elevator.h>
25 24

	
26 25
/// \file
27 26
/// \ingroup max_flow
28 27
/// \brief Implementation of the preflow algorithm.
29 28

	
30 29
namespace lemon {
31 30

	
32 31
  /// \brief Default traits class of Preflow class.
33 32
  ///
34 33
  /// Default traits class of Preflow class.
35 34
  /// \param _Graph Digraph type.
36 35
  /// \param _CapacityMap Type of capacity map.
37 36
  template <typename _Graph, typename _CapacityMap>
38 37
  struct PreflowDefaultTraits {
39 38

	
40 39
    /// \brief The digraph type the algorithm runs on.
41 40
    typedef _Graph Digraph;
42 41

	
43 42
    /// \brief The type of the map that stores the arc capacities.
44 43
    ///
45 44
    /// The type of the map that stores the arc capacities.
46 45
    /// It must meet the \ref concepts::ReadMap "ReadMap" concept.
... ...
@@ -111,59 +110,48 @@
111 110
  /// the algorithm.  The default traits class is \ref
112 111
  /// PreflowDefaultTraits.  See \ref PreflowDefaultTraits for the
113 112
  /// documentation of a %Preflow traits class.
114 113
  ///
115 114
  ///\author Jacint Szabo and Balazs Dezso
116 115
#ifdef DOXYGEN
117 116
  template <typename _Graph, typename _CapacityMap, typename _Traits>
118 117
#else
119 118
  template <typename _Graph,
120 119
            typename _CapacityMap = typename _Graph::template ArcMap<int>,
121 120
            typename _Traits = PreflowDefaultTraits<_Graph, _CapacityMap> >
122 121
#endif
123 122
  class Preflow {
124 123
  public:
125 124

	
126 125
    typedef _Traits Traits;
127 126
    typedef typename Traits::Digraph Digraph;
128 127
    typedef typename Traits::CapacityMap CapacityMap;
129 128
    typedef typename Traits::Value Value;
130 129

	
131 130
    typedef typename Traits::FlowMap FlowMap;
132 131
    typedef typename Traits::Elevator Elevator;
133 132
    typedef typename Traits::Tolerance Tolerance;
134 133

	
135
    /// \brief \ref Exception for uninitialized parameters.
136
    ///
137
    /// This error represents problems in the initialization
138
    /// of the parameters of the algorithms.
139
    class UninitializedParameter : public lemon::Exception {
140
    public:
141
      virtual const char* what() const throw() {
142
        return "lemon::Preflow::UninitializedParameter";
143
      }
144
    };
145

	
146 134
  private:
147 135

	
148 136
    TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
149 137

	
150 138
    const Digraph& _graph;
151 139
    const CapacityMap* _capacity;
152 140

	
153 141
    int _node_num;
154 142

	
155 143
    Node _source, _target;
156 144

	
157 145
    FlowMap* _flow;
158 146
    bool _local_flow;
159 147

	
160 148
    Elevator* _level;
161 149
    bool _local_level;
162 150

	
163 151
    typedef typename Digraph::template NodeMap<Value> ExcessMap;
164 152
    ExcessMap* _excess;
165 153

	
166 154
    Tolerance _tolerance;
167 155

	
168 156
    bool _phase;
169 157

	
... ...
@@ -187,69 +175,71 @@
187 175
    void destroyStructures() {
188 176
      if (_local_flow) {
189 177
        delete _flow;
190 178
      }
191 179
      if (_local_level) {
192 180
        delete _level;
193 181
      }
194 182
      if (_excess) {
195 183
        delete _excess;
196 184
      }
197 185
    }
198 186

	
199 187
  public:
200 188

	
201 189
    typedef Preflow Create;
202 190

	
203 191
    ///\name Named template parameters
204 192

	
205 193
    ///@{
206 194

	
207 195
    template <typename _FlowMap>
208 196
    struct DefFlowMapTraits : public Traits {
209 197
      typedef _FlowMap FlowMap;
210 198
      static FlowMap *createFlowMap(const Digraph&) {
211
        throw UninitializedParameter();
199
        LEMON_ASSERT(false, "FlowMap is not initialized");
200
        return 0; // ignore warnings
212 201
      }
213 202
    };
214 203

	
215 204
    /// \brief \ref named-templ-param "Named parameter" for setting
216 205
    /// FlowMap type
217 206
    ///
218 207
    /// \ref named-templ-param "Named parameter" for setting FlowMap
219 208
    /// type
220 209
    template <typename _FlowMap>
221 210
    struct DefFlowMap
222 211
      : public Preflow<Digraph, CapacityMap, DefFlowMapTraits<_FlowMap> > {
223 212
      typedef Preflow<Digraph, CapacityMap,
224 213
                      DefFlowMapTraits<_FlowMap> > Create;
225 214
    };
226 215

	
227 216
    template <typename _Elevator>
228 217
    struct DefElevatorTraits : public Traits {
229 218
      typedef _Elevator Elevator;
230 219
      static Elevator *createElevator(const Digraph&, int) {
231
        throw UninitializedParameter();
220
        LEMON_ASSERT(false, "Elevator is not initialized");
221
        return 0; // ignore warnings
232 222
      }
233 223
    };
234 224

	
235 225
    /// \brief \ref named-templ-param "Named parameter" for setting
236 226
    /// Elevator type
237 227
    ///
238 228
    /// \ref named-templ-param "Named parameter" for setting Elevator
239 229
    /// type
240 230
    template <typename _Elevator>
241 231
    struct DefElevator
242 232
      : public Preflow<Digraph, CapacityMap, DefElevatorTraits<_Elevator> > {
243 233
      typedef Preflow<Digraph, CapacityMap,
244 234
                      DefElevatorTraits<_Elevator> > Create;
245 235
    };
246 236

	
247 237
    template <typename _Elevator>
248 238
    struct DefStandardElevatorTraits : public Traits {
249 239
      typedef _Elevator Elevator;
250 240
      static Elevator *createElevator(const Digraph& digraph, int max_level) {
251 241
        return new Elevator(digraph, max_level);
252 242
      }
253 243
    };
254 244

	
255 245
    /// \brief \ref named-templ-param "Named parameter" for setting
0 comments (0 inline)