6 #ifndef FST_EXTENSIONS_COMPRESS_RANDMOD_H_ 7 #define FST_EXTENSIONS_COMPRESS_RANDMOD_H_ 16 template <
class Arc,
class G>
20 typedef typename Arc::Label
Label;
27 RandMod(StateId nstates, StateId nclasses, Label nlabels,
bool trans,
34 for (StateId s = 0; s < nstates; ++s) {
35 classes_.push_back(rand() % nclasses);
41 StateId start = rand() % nstates_;
43 for (StateId s = 0; s < nstates_; ++s) {
45 if (s == start) fst->
SetStart(start);
46 for (StateId n = 0; n <= nstates_; ++n) {
49 if (!RandArc(s, d, &arc))
continue;
62 bool RandArc(StateId s, StateId d, Arc *arc) {
63 StateId sclass = classes_[s];
64 StateId dclass = d !=
kNoStateId ? classes_[d] : 0;
66 int r = sclass + dclass + 2;
67 if ((rand() % r) != 0)
75 ilabel = (dclass % nlabels_) + 1;
77 olabel = (sclass % nlabels_) + 1;
82 Weight weight = Weight::One();
83 if (generate_) weight = (*generate_)();
96 std::vector<StateId> classes_;
101 #endif // FST_EXTENSIONS_COMPRESS_RANDMOD_H_
void Generate(StdMutableFst *fst)
virtual void AddArc(StateId, const Arc &arc)=0
virtual void SetStart(StateId)=0
virtual void SetFinal(StateId, Weight)=0
virtual StateId AddState()=0
virtual void DeleteStates(const std::vector< StateId > &)=0
RandMod(StateId nstates, StateId nclasses, Label nlabels, bool trans, const G *generate)