1 /* Erin Parker (parker@cs.unc.edu), March 2004 */
7 double count_accepting_paths(DFA
*dfa
, int num_states
, int num_freevars
)
9 int dead_state
[num_states
]; /* list of dead states */
10 int num_edges_from
[num_states
]; /* number of (live) edges from state i */
11 int edge_from
[num_states
][num_states
];/* state on edge from state i */
12 double weight
[num_states
][num_states
];/* weight on edge from state i */
13 double N1
[num_states
]; /* number of paths to state i */
14 double N2
[num_states
];
17 int L
= 0; /* length of longest path considered */
25 for (i
= 0; i
< num_states
; i
++) {
26 pp
[i
] = make_paths(dfa
->bddm
, dfa
->q
[i
]);
28 num_edges_from
[i
] = 0;
31 if (dfa
->f
[i
]==-1 && pp
[i
]->next
==NULL
&& pp
[i
]->to
==i
)
37 for (i
= 0; i
< num_states
; i
++) {
42 /* Do while there are remaining edges from state i . . . */
46 for (j
= 0; j
< num_edges_from
[i
]; j
++)
47 if (edge_from
[i
][j
] == pp
[i
]->to
) {
54 edge_from
[i
][j
] = pp
[i
]->to
;
57 /* Check if edge (i,pp[i]->to) leads to a dead state, continue if not */
58 if (!dead_state
[pp
[i
]->to
]) {
62 /* First, go through each track whose label is '0' or '1' */
63 for (tp
= pp
[i
]->trace
, k
=0; tp
; tp
= tp
->next
, k
++) {;}
65 /* Then, the label for each remaining track must be 'X',
66 update count appropriately */
67 for (; k
< num_freevars
; k
++)
70 /* Update weight on edge (i,pp[i]->to) */
71 weight
[i
][j
] += count
;
74 /* Get next edge from state i and repeat */
79 for (i
= 0; i
< num_states
; i
++)
83 /* Recurrence operation on array N */
84 N1
[0] = N2
[0] = 1; /* base case: N = {1 0 0 0 0 ... 0 0 } */
87 double temp
[num_states
];
90 /* N_i = N_{i-1} * W */
91 for (j
= 0; j
< num_states
; j
++)
95 for (k
= 0; k
< num_states
; k
++)
96 for (j
= 0; j
< num_edges_from
[k
]; j
++)
97 temp
[edge_from
[k
][j
]] += N1
[k
] * weight
[k
][j
];
99 for (k
= 0; k
< num_states
; k
++)
100 for (j
= 0; j
< num_edges_from
[k
]; j
++)
101 temp
[edge_from
[k
][j
]] += N2
[k
] * weight
[k
][j
];
104 for (j
= 0; j
< num_states
; j
++)
109 for (j
= 0; j
< num_states
; j
++)
114 for (j
= 0; j
< num_states
&& same
==1; j
++)
115 if((N1
[j
]==0 && N2
[j
]>0) || (N1
[j
]>0 && N2
[j
]==0))
124 for(j
= 0; j
< num_states
; j
++)