Main Page
Related Pages
Data Structures
Files
File List
Globals
src
libgfsm
gfsmPaths.h
Go to the documentation of this file.
1
/*=============================================================================*\
2
* File: gfsmPaths.h
3
* Author: Bryan Jurish <moocow.bovine@gmail.com>
4
* Description: finite state machine library
5
*
6
* Copyright (c) 2005-2011 Bryan Jurish.
7
*
8
* This library is free software; you can redistribute it and/or
9
* modify it under the terms of the GNU Lesser General Public
10
* License as published by the Free Software Foundation; either
11
* version 3 of the License, or (at your option) any later version.
12
*
13
* This library is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
* Lesser General Public License for more details.
17
*
18
* You should have received a copy of the GNU Lesser General Public
19
* License along with this library; if not, write to the Free Software
20
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
*=============================================================================*/
22
27
#ifndef _GFSM_PATHS_H
28
#define _GFSM_PATHS_H
29
30
#include <
gfsmAutomaton.h
>
31
32
/*======================================================================
33
* Types: paths
34
*/
35
37
typedef
struct
{
38
gfsmLabelVector
*
lo
;
39
gfsmLabelVector
*
hi
;
40
gfsmWeight
w
;
41
}
gfsmPath
;
42
44
/* The pointer data in the \a data field are (gfsmArc*)s
45
* (usually pointing into an existing gfsmAutomaton) for all but the final
46
* pointer element of the gfsmArcPath, and the
47
* final element is a gpointer-encoded gfsmWeight representing
48
* the final weight associated with the arc path; extract it
49
* e.g. with gfsm_ptr2weight(arcpath->data[arcpath->len-1]).
50
*/
51
typedef
GPtrArray
gfsmArcPath
;
52
53
54
/*======================================================================
55
* Methods: Path Utilities
56
*/
57
58
//------------------------------
60
61
62
gfsmLabelVector
*
gfsm_label_vector_copy
(
gfsmLabelVector
*dst,
gfsmLabelVector
*src);
63
65
#define gfsm_label_vector_dup(src) \
66
gfsm_label_vector_copy(g_ptr_array_sized_new(src->len), src)
67
69
gfsmLabelVector
*
gfsm_label_vector_reverse
(
gfsmLabelVector
*v);
71
72
//------------------------------
74
75
78
GFSM_INLINE
79
gfsmPath
*
gfsm_path_new_full
(
gfsmLabelVector
*lo,
gfsmLabelVector
*hi,
gfsmWeight
w);
80
82
#define gfsm_path_new(sr) \
83
gfsm_path_new_full(NULL,NULL,gfsm_sr_one(sr))
84
86
gfsmPath
*
gfsm_path_new_copy
(
gfsmPath
*p1);
87
89
gfsmPath
*
gfsm_path_new_append
(
gfsmPath
*p1,
gfsmLabelVal
lo,
gfsmLabelVal
hi,
gfsmWeight
w,
gfsmSemiring
*sr);
90
92
gfsmPath
*
gfsm_path_new_times_w
(
gfsmPath
*p1,
gfsmWeight
w,
gfsmSemiring
*sr);
93
95
GFSM_INLINE
96
void
gfsm_path_push
(
gfsmPath
*p,
gfsmLabelVal
lo,
gfsmLabelVal
hi,
gfsmWeight
w,
gfsmSemiring
*sr);
97
99
GFSM_INLINE
100
void
gfsm_path_pop
(
gfsmPath
*p,
gfsmLabelVal
lo,
gfsmLabelVal
hi);
101
103
gint
gfsm_path_compare_data
(
const
gfsmPath
*p1,
const
gfsmPath
*p2,
gfsmSemiring
*sr);
104
106
GFSM_INLINE
107
gfsmPath
*
gfsm_path_reverse
(
gfsmPath
*p);
108
110
GFSM_INLINE
111
void
gfsm_path_free
(
gfsmPath
*p);
113
114
//======================================================================
116
117
126
gfsmSet
*
gfsm_automaton_paths
(
gfsmAutomaton
*fsm,
gfsmSet
*paths);
127
141
gfsmSet
*
gfsm_automaton_paths_full
(
gfsmAutomaton
*fsm,
gfsmSet
*paths,
gfsmLabelSide
which);
142
143
145
gfsmSet
*
_gfsm_automaton_paths_r
(
gfsmAutomaton
*fsm,
146
gfsmSet
*paths,
147
gfsmLabelSide
which,
148
gfsmStateId
q,
149
gfsmPath
*path);
150
151
152
//------------------------------
156
GSList *
gfsm_paths_to_strings
(
gfsmSet
*paths,
157
gfsmAlphabet
*abet_lo,
158
gfsmAlphabet
*abet_hi,
159
gfsmSemiring
*sr,
160
gboolean warn_on_undefined,
161
gboolean att_style,
162
GSList *strings);
163
165
typedef
struct
gfsmPathsToStringsOptions_
{
166
gfsmAlphabet
*
abet_lo
;
167
gfsmAlphabet
*
abet_hi
;
168
gfsmSemiring
*
sr
;
169
gboolean
warn_on_undefined
;
170
gboolean
att_style
;
171
GSList *
strings
;
172
}
gfsmPathsToStringsOptions
;
173
175
#define _gfsm_paths_to_strings_options gfsmPathsToStringsOptions_
176
178
gboolean
_gfsm_paths_to_strings_foreach_func
(
gfsmPath
*path,
179
gpointer value_dummy,
180
gfsmPathsToStringsOptions
*opts);
181
187
GString *
gfsm_path_to_gstring
(
gfsmPath
*path,
188
GString *gs,
189
gfsmAlphabet
*abet_lo,
190
gfsmAlphabet
*abet_hi,
191
gfsmSemiring
*sr,
192
gboolean warn_on_undefined,
193
gboolean att_style);
194
199
char
*
gfsm_path_to_string
(
gfsmPath
*path,
200
gfsmAlphabet
*abet_lo,
201
gfsmAlphabet
*abet_hi,
202
gfsmSemiring
*sr,
203
gboolean warn_on_undefined,
204
gboolean att_style);
206
207
//------------------------------
208
// \name gfsmArcPath Utilities
210
211
GFSM_INLINE
212
gfsmArcPath
*
gfsm_arcpath_new
(
void
);
213
215
GFSM_INLINE
216
gfsmArcPath
*
gfsm_arcpath_new_append
(
gfsmArcPath
*p1,
gfsmArc
*a);
217
219
gfsmArcPath
*
gfsm_arcpath_copy
(
gfsmArcPath
*dst,
gfsmArcPath
*src);
220
222
GFSM_INLINE
223
gfsmArcPath
*
gfsm_arcpath_dup
(
gfsmArcPath
*p1);
224
226
GFSM_INLINE
227
void
gfsm_arcpath_free
(
gfsmArcPath
*p);
228
230
void
gfsm_arcpath_list_free
(GSList *arcpaths);
232
233
//======================================================================
235
236
252
GSList *
gfsm_automaton_arcpaths
(
gfsmAutomaton
*fsm);
253
254
263
void
_gfsm_automaton_arcpaths_r
(
gfsmAutomaton
*fsm,
264
gfsmStateId
qid,
265
GSList *path,
266
guint path_len,
267
GSList **paths,
268
GSList **nodes
269
);
270
272
typedef
struct
gfsmArcPathToStringOptions_
{
273
gfsmStateId
q0
;
274
gfsmAlphabet
*
abet_q
;
275
gfsmAlphabet
*
abet_lo
;
276
gfsmAlphabet
*
abet_hi
;
277
gfsmSemiring
*
sr
;
278
gboolean
warn_on_undefined
;
279
gboolean
att_style
;
280
gboolean
compress_id
;
281
gboolean
show_states
;
282
}
gfsmArcPathToStringOptions
;
283
284
290
GString *
gfsm_arcpath_to_gstring
(
gfsmArcPath
*path, GString *gs,
gfsmArcPathToStringOptions
*opts);
291
296
char
*
gfsm_arcpath_to_string
(
gfsmArcPath
*path,
gfsmArcPathToStringOptions
*opts);
297
299
GSList *
gfsm_arcpaths_to_strings
(GSList *paths,
gfsmArcPathToStringOptions
*opts);
300
302
303
//======================================================================
305
306
315
#define gfsm_viterbi_trellis_paths(trellis,paths) \
316
gfsm_viterbi_trellis_paths_full((trellis),(paths),gfsmLSUpper)
317
318
327
gfsmSet
*
gfsm_viterbi_trellis_paths_full
(
gfsmAutomaton
*trellis,
gfsmSet
*paths,
gfsmLabelSide
which);
328
329
333
#define gfsm_viterbi_trellis_bestpath(trellis,path) \
334
gfsm_viterbi_trellis_bestpath_full((trellis),(path),gfsmLSUpper)
335
339
gfsmPath
*
gfsm_viterbi_trellis_bestpath_full
(
gfsmAutomaton
*trellis,
gfsmPath
*path,
gfsmLabelSide
which);
340
342
void
_gfsm_viterbi_trellis_bestpath_r
(
gfsmAutomaton
*trellis,
343
gfsmPath
*path,
344
gfsmLabelSide
which,
345
gfsmStateId
qid);
346
348
349
//-- inline definitions
350
#ifdef GFSM_INLINE_ENABLED
351
# include <gfsmPaths.hi>
352
#endif
353
354
#endif
/* _GFSM_PATHS_H */
Generated on Tue Oct 21 2014 09:44:47 for libgfsm by
1.8.1.2