# Heuristics for Deriving Adaptive Homing and Distinguishing Sequences for Nondeterministic Finite State Machines

## Abstract

Distinguishing Sequences (DS) and Homing Sequences (HS) are used for state identification purposes in Finite State Machine (FSM) based testing. For deterministic FSMs, DS and HS related problems are well studied, for both preset and adaptive cases. There are also recent algorithms for checking the existence and constructing Adaptive DS and Adaptive HS for nondeterministic FSMs. However, most of the related problems are proven to be PSPACE-complete, while the worst case height of Adaptive DS and HS is known to be exponential. Therefore, novel heuristics and FSM classes where they can be applied need to be provided for effective derivation of such sequences. In this paper, we present a work in progress on the minimization of Adaptive DS and Adaptive HS for nondeterministic FSMs.

## Keywords

Nondeterministic finite state machines Adaptive homing sequence Adaptive distinguishing sequence Novel heuristics## 1 Introduction

Distinguishing Sequences (DS) and Homing Sequences (HS) are used for state identification purposes in Finite State Machine (FSM) based testing [1, 2, 3]. A DS identifies the initial state of the FSM under investigation, while an HS is used to identify the final state after the sequence has been applied. A sequence is *adaptive* if the next input to be applied to an FSM under investigation is chosen based on the previously observed outputs, and the sequence is *preset* if the outputs need to be observed only after the entire sequence applied. The methods to derive preset/adaptive HS/DS are well elaborated for complete and deterministic FSMs [3, 4, 5]. Even though the length of most of these sequences is polynomial w.r.t. the number of FSM states, the current complexity of digital systems and software makes it almost impossible to derive a complete deterministic behavior of the system integrated into the overall software and/or hardware environment. Moreover, current specifications of telecommunication protocols and other digital systems include an optionality of output responses under the same queries. That is the reason why researchers turn their attention towards special FSM types, and in particular, nondeterministic FSMs.

A method for deriving a DS for two states of an observable nondeterministic FSM has been proposed in [6], where the length of this sequence is shown to be exponential for nondeterministic FSMs. The upper bound on the length of an HS for an observable nondeterministic FSM is shown to be exponential as well, and this upper bound is reachable [7]. As for adaptive experiments for nondeterministic FSMs, it has been shown that the length of a shortest adaptive DS for two states of an observable nondeterministic FSM with *n* states is at most *n*(*n –* 1)/2 [8]. Whenever such an adaptive sequence is derived to distinguish *m* > 2 states of an observable nondeterministic FSM, the length of this sequence grows exponentially [9]. The problem of checking the existence of a preset DS is known to be PSPACE-complete even for complete *deterministic* FSMs [3]. The latter means one cannot directly apply these techniques to effectively derive test sequences against FSM specifications. That is the reason why a number of heuristics to decrease such complexity have been proposed. In particular, various heuristic methods to construct reduced adaptive DS for complete deterministic FSMs have been proposed in [10]. However, it has been also proven that constructing a minimal adaptive DS for complete deterministic FSMs is an NP-hard problem [11]. Therefore, novel heuristics need to be provided for effective derivation of adaptive HS and adaptive DS for nondeterministic FSMs.

In this paper, we focus on two techniques for deriving adaptive DS and adaptive HS for nondeterministic FSMs. In particular, we present a class of nondeterministic FSMs for which it is possible to construct an adaptive DS without using any nondeterministic transitions. We also argue how existing adaptive DS minimization approaches can be used for such nondeterministic FSMs. As for adaptive HS, we address a method proposed in [9] that constructs an adaptive HS for an observable nondeterministic FSM when each state pair is adaptively homing. We discuss how this method can be improved so that the resulting adaptive HS can be shorter. Therefore, the main contributions of this work in progress are two novel heuristics for effective derivation of adaptive DSs for nondeterministic FSMs and adaptive HSs for observable nondeterministic FSMs.

The paper is organized as follows. Section 2 contains preliminaries. A heuristic method for effective adaptive DS derivation for nondeterministic FSMs is given in Sect. 3 while Sect. 4 presents an approach for minimizing adaptive HS for observable nondeterministic FSMs. Section 5 concludes the paper.

## 2 Preliminaries

In this paper, we focus on minimizing adaptive HS and DS for nondeterministic FSMs. As usual, an *FSM* \( {\sf{S}} \) is a 4-tuple \( (S, I, O, h_{\textsf{S}}) \), where **S** is a finite set of states; *I* and *O* are finite non-empty disjoint sets of inputs and outputs, respectively; *h* _{S} ⊆ *S* × *I* × *O* × *S* is a *transition relation*, where a 4-tuple (*s*, *i*, *o*, *s*′) ∈ \( h_{\textsf{S}} \) is a *transition*. An FSM is *complete* if for each pair (*s*, *i*) ∈ *S* × *I* there exists (*o*, *s*′) ∈ *O* × *S* such that (*s*, *i*, *o*, *s*′) ∈ \( h_{\textsf{S}} \). Otherwise it is called *partially specified*. If for some pair (*s*, *i*) ∈ *S* × *I*, there exist two transitions (*s*, *i*, *o* _{1}, *s* _{1}), (*s*, *i*, *o* _{2}, *s* _{2}) ∈ *h* _{S}, such that *o* _{1} ≠ *o* _{2} or *s* _{1} ≠ *s* _{2} then **s** is called *nondeterministic*. For a nondeterministic FSM the nondeterminism is *observable* if each input/output pair *i*/*o* uniquely identifies the successor of each FSM state (if it exists). Given a state *s* of **s** and an input/output sequence α/β, the α/β-*successor* of state *s* is the set of all states that are reached from *s* via an application of α when an output reaction β is produced. Note that for an observable FSM **s**, the cardinality of the α/β-*successor* of state *s* is at most one for any input/output sequence α/β.

A sequence α is a *distinguishing* (*homing*) sequence (DS/HS) for the FSM **S** if after applying α and observing output reaction β one can uniquely conclude about the initial (final/current) state of **S**. The length of preset DS and HS is exponential for nondeterministic FSMs, however sometimes this length can be shorter when adaptivity is used. An adaptive DS/HS can be represented as a tree or as a specific acyclic single-input output-complete FSM that are called test cases [3, 12].

A number of methods for deriving adaptive DS and HS for nondeterministic FSMs have been proposed (see, for example [9]). However, the length of the corresponding sequence in general case remains exponential and thus, novel heuristics need to be provided for minimizing the length of such sequences.

## 3 Nondeterministic FSMs with a Deterministic Adaptive DS

For a complete deterministic FSM with *n* states, it is known that *n*(*n* – 1)/2 is the tight upper bound for the height of an adaptive DS [3]. However, for nondeterministic FSMs, the height of an adaptive DS is exponential in general. In this section, we present a class of nondeterministic FSMs for which the height of an adaptive DS is at most 2*n* ^{2} – *n* – 1 and existing algorithms of adaptive DS minimization can be readily applied.

A transition (*s*, *i*, *o*′, *s*′) ∈ *h* _{S} is a *deterministic transition* if for any transition (*s*, *i*, *o*′′, *s*′′) ∈ \( h_{\textsf{S}} \) we have *o*′′= *o*′ and *s*′′= *s*′. For a given FSM **S**, we define *the deterministic projection* **S** ^{d} of **S** as follows. **S** ^{d} and **S** have the same set **S** of states. For a transition (*s*, *i*, *o*′, *s*′) \( \in h_{{\textsf{S}}} \), (*s*, *i*, *o*′, *s*′) \( \in {h^{\text{d}}}_{\textsf{S}} \), if and only if (*s*, *i*, *o*′, *s*′) is a deterministic transition in **S**. *I* ^{d} and *O* ^{d} consist of the inputs and outputs used in the transitions in \( {h^{\text{d}}}_{{\textsf{S}}} \). Intuitively, **S** ^{d} is the same FSM as **S** where the deterministic transitions are preserved but all other transitions are removed. Hence, **S** ^{d} is a deterministic FSM by definition. It is easy to see that an adaptive DS for **S** ^{d} can be directly used as an adaptive DS for **S** as well, and it will be a *deterministic adaptive DS* in the sense that only the deterministic transitions are used throughout the application of the adaptive DS in **S**. In the lucky case that **S** ^{ d } is a complete deterministic FSM, the existence check and the adaptive DS construction algorithms given in [3] can be directly applied. However, in general, **S** ^{d} is a partially specified deterministic FSM. Moreover, in the worst case the transition relation of **S** ^{d} can be empty, and in this case, the question of existence of an ADS for **S** remains open.

Although there usually is a complexity jump for the algorithms when one considers partially specified FSMs, this is not the case for the problems related to adaptive DS. In [13] a polynomial time algorithm is provided to check if a partially specified FSM has an adaptive DS or not. In this paper, we adapt this algorithm for efficient derivation of an ADS for a nondeterministic FSM that requires a partial deterministic projection. We also improve the upper bound on the length of such ADS compared to the one given in [13]. In fact, the approach given in [13] is based on constructing a complete deterministic FSM *C*(**S** ^{ d }) from a given partially specified deterministic FSM **S** ^{d} such that there exists an adaptive DS with the height *H* for *C*(**S** ^{ d }) iff there exists an adaptive DS with height *H* – 1 for *C*(**S** ^{ d }). The number of states in *C*(**S** ^{d}) is 2*n*, where *n* is the number of states in **S** ^{ d }. Therefore, it is possible to check if there exists an adaptive DS for **S** ^{ d } (and hence a deterministic ADS for **S**) in *O*(*pn*lg*n*) time [3], where *p* is the cardinality of *I* ^{d}.

If there exists an adaptive DS for *C*(**S** ^{ d }), one can then use the LY algorithm (the adaptive DS construction algorithm given in [3]) to construct an adaptive DS. Although [13] provides an upper bound of π^{2} *n* ^{2}/3 for the height *H* of the adaptive DS constructed for *C*(**S** ^{ d }), using the result in [14], the LY algorithm actually constructs an adaptive DS with the height at most *H* = 2*n* ^{2} – *n* for *C*(**S** ^{ d }). Therefore, the height of the adaptive DS for **S** ^{ d } is at most *H* – 1 = 2*n* ^{2} – *n* – 1.

Note that the LY algorithm does not aim for the minimization of the adaptive DS it constructs. However, there exist heuristics for the minimization of adaptive DSs with respect to different metrics (e.g. height, total external path length, etc.) for complete deterministic FSMs [10]. Since *C*(**S** ^{d}) is a complete deterministic FSM, one can directly use these heuristics in order to construct minimized adaptive DSs for *C*(**S** ^{ d }), and hence for the nondeterministic FSM **S**. Note that **S** can be nonobservable as well.

## 4 Minimizing Adaptive HS for Nondeterministic FSMs

In this section, we discuss how to optimize the procedure for deriving an adaptive HS for an observable FSM **S**. The procedure is taken from [9] while the complexity of the related problem is given in [15]. The homing test case derivation strategy is based on the condition that each state pair of **S** is adaptively homing. In other words, there exists a homing test case for **S** if there exists an adaptive homing sequence for each subset {*s* _{ i }, *s* _{ j }} ⊆ *S* of states of the observable nondeterministic FSM **S**. A test case **P** _{ i,j } is a *homing* *test case* for the subset {*s* _{ i }, *s* _{ j }} ⊆ *S* of states if for every input/output sequence α/β defined in **P** _{ i,j }, the α/β-successor of the subset {*s* _{ i }, *s* _{ j }} ⊆ *S* has at most one state.

If there exists a homing test case for the FSM **S** then the set *S* is a *homing* *set* and the test case **P** is a *homing test case* *for the set* *S* or the test case **P** *homes* states of the set *S*. Otherwise, the set *S* is not homing. The homing test case for the set *S* = {*s* _{1},.., *s* _{ n }} is derived iteratively. As mentioned above, **P** _{ i,j } is a homing test case for the subset (pair) {*s* _{ i }, *s* _{ j }} ⊆ *S* of FSM states. The procedure starts with a homing test case **P** _{1,2} for the set {*s* _{1}, *s* _{2}}, then state *s* _{3} is added to the subset {*s* _{1}, *s* _{2}} ⊆ *S*. Each input/output sequence α/β that is defined in the test case **P** _{1,2} is applied at state *s* _{3}. If the sequence α/β is defined at state *s* _{3}, then the deadlock state *q* in the test case **P** _{1,2} is replaced with a test case **P** _{ q,z }, where *q* is the α/β-successor of state pair {*s* _{1}, *s* _{2}}, while *z* is the α/β-successor of state *s* _{3}. All the input/output sequences α/β′ that are defined at state *s* _{3} but not defined in the test case **P** _{1,2} are also included into the test case **P** _{1,2,3}. Proceeding in this way by iteratively adding the remaining states *s* _{4}, *s* _{5}, …, *s* _{ n }, the test case **P** _{1,2,...,n } is derived.

We note that there exist various homing test cases **P** _{ i,j } for the same state pair {*s* _{ i }, *s* _{ j }} ⊆ *S*. Therefore, the first optimization step can be to consider a somehow optimal test case **P** _{ i,j } that is chosen for the first state pair and for those test cases **P** _{ q,z } that are appended iteratively, when **P** _{1,2,...,n } is being derived. On the other hand, the length of the resulting test case can significantly depend on the choice of state *s* _{ j } that is added to the test case **P** _{1,2,...,j–1} . Thus, the second optimization criterion can be on an optimal choice of the next state *s* _{ j } when the test case **P** _{1,2,...,j–1} is already constructed. We further discuss how these two ideas can be taken into account to effectively derive a test case **P** _{1,2,...,n }. We mention that when optimizing the length of the corresponding adaptive HS, represented as a test case, we focus on optimizing not only the height of the corresponding tree but also the number of transitions in the acyclic FSM.

The first type of heuristics is related to making an optimal choice between possible initial state pairs {*s* _{ i }, *s* _{ j }} ⊆ *S*, *i* < *j*, as well as defining the best homing test case **P** _{ i,j } for this pair. As it is shown in [9], the length of the overall homing test case **P** _{1,2,...,n }significantly depends even on the first input to be included into the test case P_{1,2}. As the test case **P** _{1,2,...,j } is defined based on the test case **P** _{1,2,...,j–1} , the height/the number of transitions of it significantly depends on the number of sequences that are defined in the test case **P** _{1,2,...,j–1} and in state *s* _{ j } that will be added to the root of the corresponding successor tree. That is the reason why we suggest to choose a pair {*s* _{ i }, *s* _{ j }} ⊆ *S* to start with in such a way that its homing test case **P** _{ i,j } is a homing test case for some other state pairs. It is naturally to assume that the more state pairs are ‘covered’ by a homing test case **P** _{ i,j } , the better is the resulting test case **P** _{1,2,...,n }. Therefore, we suggest to choose the first state pair {*s* _{ i }, *s* _{ j }} ⊆ *S*, *i* < *j*, such that there exists a homing test case**P**for this pair that homes as much state pairs in **S** as possible.

The idea behind the second optimization step is the same as in the previous case. In particular, we suggest choosing the next state *s* _{ j } to be added to a test case **P** _{1,2,...,j–1} in such a way that the number of input/output sequences that are defined in **P** _{1,2,...,j–1} and are not defined at state *s* _{ j } would be minimal. This fact can help to reduce the number of homing test cases **P** _{ q,z } that have to be appended at each state *z*, where *z* is the α/β-successor of state *s* _{ j }, and *q* is the α/β-successor of the set {*s* _{1}, …, *s* _{ j - 1}}. Moreover, as for each pair of states {*q*, *z*} there can exist various adaptive homing test cases, the best choice of the test case **P** _{ q,z } can affect the overall height / transition number of the test case **P** _{1,2,...,n }. Therefore, it is also necessary to consider which test case **P** _{ q,z } should be chosen for an intermediate state pair {*q*, *z*} ⊆ *S*.

We mention that both optimization steps for deriving an adaptive homing test case **P** _{1,2,...,n } need to be thoroughly estimated. On one hand, theoretical investigation on FSM classes that have shorter adaptive HS need to be elaborated, and on the other, experimental evaluation on the efficiency of proposed heuristics needs to be performed.

## 5 Conclusion

In this paper, we proposed two heuristic methods for optimizing the size of adaptive DS and adaptive HS for nondeterministic FSMs. The topic of such optimization is always motivated by the fact that the length of such sequences is exponential for nondeterministic FSMs. Moreover, related decision problems on the existence of such sequences even for the preset case are known to be PSPACE-complete. We note that this current work in progress only presents the ideas behind optimization criteria and optimization techniques to achieve shorter resulting trees for adaptive DS or HS. As a future work, we plan to perform experimental evaluation over machines of various types (random, protocol specifications, etc.) to estimate the efficiency of the proposed techniques.

## Notes

### Acknowledgments

The authors gratefully acknowledge Prof. N. Yevtushenko for interesting discussions.

This work is partially supported by RFBR Grant# 15-58-46013 CT_a and TÜBİTAK Grant# 114E921.

## References

- 1.Dorofeeva, R., El-Fakih, K., Maag, S., Cavalli, A.R., Yevtushenko, N.: FSM-based conformance testing methods: a survey annotated with experimental evaluation. Inf. Softw. Technol. 52, 1286–1297 (2010)Google Scholar
- 2.Gill, A.: State-identification experiments in finite automata. Inf. Control
**4**, 132–154 (1961)zbMATHCrossRefGoogle Scholar - 3.Lee, D., Yannakakis, M.: Testing finite-state machines: state identification and verification. IEEE Trans. Comput.
**43**(3), 306–320 (1994)MathSciNetCrossRefGoogle Scholar - 4.Kohavi, Z.: Switching and Finite Automata Theory. McGraw-Hill, New York (1978)zbMATHGoogle Scholar
- 5.Moore, E.F.: Gedanken-experiments on sequential machines. In: Automata Studies (Annals of Mathematical Studies no.1), pp. 129–153. Princeton University Press (1956)Google Scholar
- 6.Spitsyna, N., El-Fakih, K., Yevtushenko, N.: Studying the separability relation between finite state machines. Softw. Test. Verification Reliab.
**17**(4), 227–241 (2007)CrossRefGoogle Scholar - 7.Kushik, N., Yevtushenko, N.: On the length of homing sequences for nondeterministic finite state machines. In: Proceedings of CIAA 2013, pp. 220–231 (2013)Google Scholar
- 8.Alur, R. Courcoubetis, C., Yannakakis, M.: Distinguishing tests for nondeterministic and probabilistic machines. In: Proceedings of the 27th ACM Symposium on Theory of Computing, pp. 363-372 (1995)Google Scholar
- 9.Kushik, N., El-Fakih, K., Yevtushenko, N., Cavalli, A.R.: On adaptive experiments for nondeterministic finite state machines. Softw. Tools Technol. Transf. (2014). doi: 10.1007/s10009-014-0357-7 Google Scholar
- 10.Türker, U.C., Ünlüyurt, T., Yenigün, H.: Lookahead-based approaches for minimizing adaptive distinguishing sequences. In: Merayo, M.G., de Oca, E.M. (eds.) ICTSS 2014. LNCS, vol. 8763, pp. 32–47. Springer, Heidelberg (2014)Google Scholar
- 11.Türker, U.C., Yenigün, H.: Hardness and inapproximability of minimizing adaptive distinguishing sequences. Formal Meth. Syst. Des.
**44**(3), 264–294 (2014)zbMATHCrossRefGoogle Scholar - 12.Petrenko, A., Yevtushenko, N.: Conformance tests as checking experiments for partial nondeterministic FSM. In: Grieskamp, W., Weise, C. (eds.) FATES 2005. LNCS, vol. 3997, pp. 118–133. Springer, Heidelberg (2005)CrossRefGoogle Scholar
- 13.Hierons, R.M., Türker, U.C.: Distinguishing sequences for partially specified FSMs. In: Badger, J.M., Rozier, K.Y. (eds.) NFM 2014. LNCS, vol. 8430, pp. 62–76. Springer, Heidelberg (2014)CrossRefGoogle Scholar
- 14.Sokolovskii, M.N.: Diagnostic experiments with automata. Cybern. Syst. Anal.
**7**, 988–994 (1971)Google Scholar - 15.Kushik, N., Yevtushenko, N.: Adaptive Homing is in P. In: Proceedings of MBT 2015, pp. 73–78 (2015)Google Scholar