Dark Matter Caustics Caustics are a generic feature of the nonlinear growth of structure in the dark matter distribution. If the dark matter were absolutely cold, its mass density would diverge at caustics, and the integrated annihilation probability would also diverge for individual particles participating in them. For realistic dark matter candidates, this behaviour is regularised by small but non-zero initial thermal velocities. We present a mathematical treatment of evolution from Hot, Warm or Cold Dark Matter initial conditions which can be directly implemented in cosmological N-body codes. It allows the identification of caustics and the estimation of their annihilation radiation in fully general simulations of structure formation. The idea that the dark matter might consist of a collisionless "gas" of weakly interacting, neutral particles was first published by Cowsik & McClelland (1973) and Szalay & Marx (1976) , though earlier discussion can also be found in the textbook of Zel'dovich & Novikiv (1971) . These authors proposed neutrinos as a promising dark matter candidate, and a claimed measurement of the electron neutrino mass at very nearly the expected value (Lyubimov et al. 1981) led to a flurry of interest in neutrinodominated, so-called "Hot Dark Matter" universes. This continued until detailed numerical simulations showed the predictions for low-redshift structure to be quite inconsistent with observation (White et al. 1983) . Attention then shifted towards more exotic particle candidates for Warm or Cold Dark Matter (Pagels & Primack 1982; Peebles 1982) .. If a cold collisionless gas evolves from near-uniform initial conditions under the influence of gravity, the nonlinear phases of growth generically involve caustics analogous to those formed when light propagates through a non-uniform medium. This connection was explored in some depth by Russian cosmologists interested in neutrino-dominated universes (Arnold et al. 1982; Zeldovich et al. 1983) . Caustics are also a very evident feature of the similarity solutions for cold spherical infall published by Fillmore & Goldreich (1984) and Bertschinger (1985) . It was another 15 years, however, before Hogan (2001) realised that dark matter annihilation could be very substantially enhanced in such caustics. He showed that for absolutely cold dark matter the annihilation probability diverges logarithmically as a particle passes through a caustic, and that for realistic dark matter candidates this divergence is tamed by the small but finite initial thermal velocities ⋆ swhite@mpa-garching.mpg.de † vogelsma@mpa-garching.mpg.de of the particles. He argued that the annihilation radiation from dark halos might be dominated by emission from caustics.. Twenty years earlier Zeldovich & Shandarin (1982) had noted that thermal velocities limit the densities achievable in dark matter caustics, and the first rigorous calculation of annihilation rates in caustics was carried out by Mohayaee & Shandarin (2006) for Bertschinger's (1985) similarity solution. They found caustics to enhance the total annihilation flux substantially in the outer regions for plausible values of the initial dark matter velocity dispersion, but to be progressively less important at smaller radii. It is unclear whether either of these results will apply in general, since the behaviour of the similarity solution is strongly influenced by its spherical symmetry (which reduces its phase-space dimensionality from 6 to 2) and by its lack of small-scale structure.. In the present paper we present a theoretical treatment of the growth of structure which shows how the geodesic deviation equation can be used to follow local phase-space structure in a Lagrangian treatment of nonlinear evolution. This formalism is well suited for implementation in N-body simulation codes, allowing the annihilation signal from caustics to be treated in full generality provided numerical artifacts from discretisation and integration error can be kept under control. We have presented results from a first implementation of this scheme in Vogelsberger et al. (2008) . A closely related but somewhat more complex scheme is described by Alard & Colombi (2005) . Here we complement this work by giving a fuller description of the mathematics behind the approach, in particular of the regularisation of caustic densities by the finite velocity dispersion of the dark matter. In the next section we describe our idealisation of the initial conditions for structure formation in WIMP-dominated cosmologies. Section 3 then presents useful general results for nonlinear evolution from these initial conditions. These are used in section 4 to describe the evolution of the local phase-space structure, in particular of its projection onto configuration space, following individual particle trajectories. Caustic passages can be identified and the associated annihilation signal can be calculated explicitly. A final section discusses possible future uses of this approach. In this paper we have developed the mathematical background to enable a relatively precise evaluation of the annihilation radiation from dark matter caustics in fully general simulations of the nonlinear growth of structure. Our scheme allows the annihilation rate to be integrated along the trajectory of each simulation particle, including correctly the contributions from all the caustics in which it participates. Typically each particle experiences several such caustic passages in each orbit around the dark matter halo in which it resides (see Vogelsberger et al. 2008) . In order to include correctly the annihilation rate between particles which are members of different streams, it is necessary to estimate a local coarse-grained density at the position of each particle, and to add in the contribution due to streams other than its own. This can be done, for example, using the SPH technique, since the smoothing this introduces does not bias the luminosity predicted from inter-stream annihilations. When a particle passes through a caustic occurring in a stream other than its own, the time-integrated annihilation probability is still correctly reproduced in the smoothed system.. By implementing these methods in high-resolution simulations of galaxy formation it should be possible to achieve a complete numerical description of the expected annihilation radiation, limited only by the ability to resolve the smallest collapsed clumps of dark matter. This latter limitation can be severe when attempting to predict the total annihilation radiation from a representative cosmological volume. For a standard supersymmetric neutralino, for example, the emission should be dominated by the smallest collapsed objects, with masses well below that of the Sun (e.g. Taylor & Silk 2003) . Recent work has shown, however, that this problem is much less severe when predicting the observability of annihilation radiation from the Solar System, which lies just 8 kpc from the centre of the Milky Way ). According to these authors, less than 3 percent of the dark matter within 100 kpc of the Galactic Centre should be in small lumps; almost all the rest should be in extended streams of the kind discussed in this paper (see also Helmi & White 1999) . They argue that the highest signal-to-noise for detecting the annihilation signal will be that of the smooth dark matter distribution in the inner few kiloparsecs of the Galaxy; small subhalos will be significantly more difficult to detect. Application of the techniques we have presented here should allow a rigorous evaluation of an important and previously unresolved issue: whether the emission structure of this smooth component is significantly modified by caustic emission. In addition, they will allow an assessment of the expected morphology and observability of outer caustics around external galaxies, most notably the Andromeda nebula.

B I B B O O O O O O O O O O O O B I O O O B I O O O O O O O O O B O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O B O O O O O O B I O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O B I B O O O O O O O O O B O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O


Real-time view-based pose recognition and interpolation for tracking initialization Abstract In this paper we propose a new approach to real-time view-based pose recognition and interpolation. Pose recognition is particularly useful for identifying camera views in databases, video sequences, video streams, and live recordings. All of these applications require a fast pose recognition process, in many cases video real-time. It should further be possible to extend the database with new material, i.e., to update the recognition system online. The method that we propose is based on P-channels, a special kind of information representation which combines advantages of histograms and local linear models. Our approach is motivated by its similarity to information representation in biological systems but its main advantage is its robustness against common distortions such as clutter and occlusion. The recognition algorithm consists of three steps: (1) low-level image features for color and local orientation are extracted in each point of the image; (2) these features are encoded into P-channels by combining similar features within local image regions; (3) the query P-channels are compared to a set of prototype P-channels in a database using a least-squares approach. The algorithm is applied in two scene registration experiments with fisheye camera data, one for pose interpolation from synthetic images and one for finding the nearest view in a set of real images. The method compares favorable to SIFT-based methods, in particular concerning interpolation. The method can be used for initializing pose-tracking systems, either when starting the tracking or when the tracking has failed and the system needs to re-initialize. Due to its real-time performance, the method can also be embedded directly into the tracking system, allowing a sensor fusion unit choosing dynamically between the frame-by-frame tracking and the pose recognition. The proposed method has been developed in context of the MATRIS project 1 aimed at markerless real-time tracking of camera poses [39] . The MATRIS system applies a hybrid technique for estimating the pose dynamically by fusing position estimates of tracked image features 2 [37, 36] and inertia measurements [23] . For this process to start or to restart in case of failure, an initial registration of the current view in a database is required to acquire a coarse pose estimate. The proposed method allows the registration to be achieved by pose recognition. Pose recognition is a special case of image recognition. Most image recognition approaches are based on either of the following two paradigms: model-based recognition or view-based recognition. It is propounded in the literature that view-centered recognition has significant advantages compared to object-centered models (see, e.g., [18] , Sect. 5). Following this line of arguments, we focus on view-based representations. View-based representations can be global, i.e., the elements of the representation depend on the whole image, or they can be local, where the elements of the representation only depend on a sub-region of the image. Both kinds of representation can be either dense, i.e., all image pixels contribute to the representation, or sparse, i.e., only selected image pixels contribute.. The problem that we consider in this paper is the following: interpolate the camera pose for a previously unseen view with a system which has seen the scene from different poses before. Interpolation of camera poses results in a non-linear mapping on the space of previously seen images. The difference to view-based object recognition, see, e.g., [12] , is that object recognition aims at producing the most probable object class independent of the view angle, whereas in the present paper, we try to estimate the camera pose as accurate as possible. The different views might originate from a single physical scene (''object class'') or from several ones.. The solution that we propose belongs to the category of dense, local methods, i.e., all image pixels contribute to the view representation, but each element has a local region of support. Algorithms that work with local image regions are popular, see, e.g., [1, 2] , due to their ''robustness to geometric distortion'' [2] . The proposed method uses P-channels as a view representation, a relatively new technique [11] which is related to local histograms and is introduced in Sect. 2.3. The proposed recognition algorithm consists of three steps:. 1. Low-level image features for color and local orientation are extracted in each point of the image. 2. These features are encoded into P-channels by combining similar features within local image regions. 3. The query P-channels are compared to a set of prototype P-channels in a database using a leastsquares approach.. The last step is related to comparing local density estimates of the low-level features, as a local density estimate can be obtained from a linear combination of P-channels [12] . It has been shown in [12] that using least-squares techniques works slightly better than the (regularized) Kullback-Leibler divergence [7] of the kernel density estimate.. The least-squares method for estimating the camera pose from P-channels is the main contribution of this paper, i.e., the paper focuses on the view representation and its matching. In order to build a system including a large database of stored view representations, the data has to be organized cleverly, e.g., in tree structures, for achieving fast access, but this is considered as a separate problem not treated in this paper. The interested reader is referred to prominent papers as, e.g., [29, 33, 32] .. If pose recognition shall be applied for tracking re-initialization of video streams and live recordings, the method must work in video real-time, i.e., recognition in images with PAL resolution at 25 Hz, in order to avoid frames without pose estimates. For databases and video sequences, even higher average recognition speed might be desirable in order to analyze the data in sub-real-time. Real-time processing on up-to-date computer systems or on future wearable systems rules out current implementations of many powerful approaches for recognition, e.g., learningbased methods as [34, 35, 28] , image matching [6] , grouptheoretic global methods [13] , and eigen-space projections [40] . The proposed method for pose recognition runs in real-time on ordinary personal computers.. As we cannot guaranty that all views required for successful recognition of all poses are available prior to the tracking, it must be possible to add new views, e.g., from successful tracking, dynamically to the learning set. Requiring that learning has to be done on the fly excludes batch-learning methods as, e.g., [21, 31] . Our proposed method allows to add new view representations at any time.. For a method to be applicable in practice, it needs to be robust and stable. By robustness we refer to the property of a system or method to handle quantitative and qualitative deviations from the assumed model, e.g., occlusion or specular highlights. If an input to the system lies outside the modeled space, it should lead to some standard output, e.g., suppression of an input or re-initialization of a tracking system in case of lost tracking. To differentiate from general robustness, statistical robustness denotes the limited quantitative influence of input outliers to the output of an estimation process. We consider statistical robustness as a special case of general robustness, starting from the assumption of a linear model for the estimator which is then modified to achieve saturation of the estimate error for outliers.. Robustness is often mixed up with the term stability, by which we denote bounded output error for a bounded input error (bibo stability), or equivalently a finite operator norm. The latter is trivially fulfilled for finite linear operators. The proposed method is robust against intensity changes, i.e., we do not model intensity invariance, but the system's output is not influenced by changes caused by opening/ closing blinds, changing the aperture or shutter time. The pose estimates are robust against occlusion and specular highlights, which is shown in the experimental section. Finally, the method behaves stable under geometric distortions, i.e., introducing small geometric distortions leads to small additional errors in the pose estimate.. In the experiments section of the paper it is shown that P-channel representations perform well compared to stateof-the-art descriptors. Many recently published visual recognition methods make use of SIFT features [29] in one or the other way. The SIFT feature is computed by extracting the SIFT (keypoint) descriptor at SIFT keypoints with appropriate orientation and scale. P-channels can likewise be computed in a local frame [26] and therefore it makes sense to compare the SIFT descriptor (cf. Sect. 6 of [29] ) to the P-channel representation. The SIFT descriptor is similar to a linear-spline channel representation (cf. [10] ) of the gradient orientation weighted by the saturated gradient magnitude. The main differences of the here applied P-channels to SIFT descriptors are: disregard for the gradient magnitude, no spatial weighting, inclusion of hue and saturation, and finally using piecewise polynomials of order zero and one instead of linear interpolation. SIFT descriptors of the same dimensionality are significant slower to compute than P-channels. Comparing the descriptive power of both image descriptors shows that Pchannels perform equally well for nearest-neighbor matching and perform superior for the least-squares interpolation of poses, i.e., non-linear mappings on the image space. We have presented a novel approach to pose recognition and interpolation suitable for real-time applications. The method is based on a sampled kernel density estimate, computed from the P-channel representation of the considered image features. The density estimates from the test set are classified using a least-squares learning technique implemented using the SVD. It has been shown in two experiments with fisheye data that. • the method performs equally well as SIFT descriptor based recognition for finding the closest view despite its real-time capability, number indicates the matching score in %. As it can be seen in this example, the matching is robust to partial occlusion of the scene. • the method outperforms SIFT descriptor if the pose angle is interpolated using the matching function (SVD), • the method is robust against occlusion, changes of lighting conditions, and common distortions.. This makes the method a suitable tool for the initialization of pose tracking in the MATRIS system and similar applications as, e.g., visual navigation. We thank our project partners for providing the test data used in the experiments.

O O B I O O O O O O O O O O O O O O O O O B I O O B I O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O B O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O B O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O


Optimal insertion in deterministic DAWGs In this paper, we present an on-line algorithm for adding words (strings) in deterministic directed acyclic word graphs (DAWGs) i.e. acyclic deterministic ÿnite-state automata (DFAs). The proposed algorithm performs optimal insertion, meaning that if applied to a minimal DAWG, the DAWG after the insertion will also be minimal. The time required to add a new word is O(n) with respect to the size of the DAWG. Repetitive application of the proposed insertion algorithm can be used to construct minimal deterministic DAWGs incrementally, although the algorithm is not time-e cient for building minimal DAWGs from a set of words: to build a DAWG of n words this way, O(n 2 ) time is required. However, the algorithm is quite useful in cases where existing minimal DAWGs have to be updated rapidly (e.g. speller dictionaries), since each word insertion traverses only a limited portion of the graph and no additional minimization operation is required. This makes the process very e cient to be used on-line. This paper provides a proof of correctness for the algorithm, a calculation of its time-complexity and experimental results. The directed acyclic word graph (DAWG) is a very e cient data structure for lexicon representation [2, 18] and fast string matching [1, 5, 9] , with a great variety of applications ranging from Speech Processing [13] to DNA analysis [9] . An example of DAWG 1 is shown in Fig. 1 . It consists of nodes (states) and links (transitions) between nodes. Each link has a label. The words are stored as directed paths on the graph. They can be retrieved by traversing the graph from an initial node (source) to a terminal node (sink), collecting the labels of the links encountered. In this way, traversing the DAWG of Fig. 1 from the source (⊗) to the sink ( ) we retrieve the words dance, darts, start and smart. DAWGs constitute very compact representations of lexicons: common word preÿxes and su xes are represented by the same links. The DAWG representation facilitates content-addressable pattern matching (i.e. approximate and incomplete search).. The DAWG of Fig. 1 is called deterministic because no links exist that have the same labels and leave the same node. This property results in a very e cient search function (linear to the length of the word), since the number of links leaving any node of a deterministic DAWG is bound to the size of the alphabet.. There are many possible deterministic DAWGs expressing the same lexicon. Of them, the one with the least number of nodes is called the minimal DAWG. Several algorithms [1, 2, 12, 17] are known for the construction of the minimal DAWG, the most e cient being the algorithm by Revuz [18] working in linear time. However, all minimization algorithms are quite time-consuming because they have to check every node and link of the graph in order to perform the minimization. For this reason they are usually used o -line. The main practical drawback of the minimization approach is that if a change is made in the DAWG (even a slight one, such as the addition of a new word) the minimization process has to run again for the whole graph. For applications like spellers, which need to frequently update their lexicon, this is time-consuming and cumbersome.. Realizing the practical value of the solution to the above problem we have devised an on-line algorithm for adding words in a deterministic DAWG [20] . A new word is inserted by slightly altering the topology of the original DAWG, without performing a total traversal of it. However, the insertion is optimal, i.e. this process guarantees that if the original DAWG is minimal, the updated DAWG will also be minimal. This eliminates the need of minimization after the insertion is completed. The time complexity for the word insertion is O(n), in respect to the size of the DAWG. We can also use the algorithm to construct minimal DAWGs incrementally, by successive insertion of new words to an empty DAWG. This task requires O(n 2 ) time for n words. If a list of words is given beforehand, there are more time-e cient algorithms to produce a minimal DAWG from them (e.g. [18] ). But if the words are not all known beforehand, or if an initial DAWG is already available, or if the size of the intermediate structure is crucial (i.e. if we do not want to create a huge trie that will be later minimized to a DAWG), then the proposed algorithm can be very useful. In fact, the strong point of the algorithm is its usefulness in cases where existing minimal DAWGs have to be updated rapidly (like in speller dictionaries). Since each word insertion traverses only a limited portion of the graph and no additional minimization operation is used, this makes the process very e cient to be used on-line (faster than using minimization algorithms that have to access every node in the graph).. We ÿrst published this algorithm in [20] as a heuristic process, together with an analogous algorithm for non-deterministic DAWGs. In this paper, we provide a theoretical analysis of the algorithm, we provide some interesting lemmas concerning its function, we prove its optimality (i.e. that it actually produces minimal deterministic DAWGs), we calculate its time complexity and present experimental results for 230,000 words.. Several variations of the presented algorithm have been developed independently by di erent researchers. The ÿrst one by Aoe et al. [3] , although it does not mention the minimality of the resulted DAWGs, it also shows the process to delete words from an existing DAWG. Later, Park et al. [16] proved that the aforementioned algorithm produces minimal DAWGs. The same research team has also presented a method [4] for compacting tries in a structure that, unlike a DAWG, is able to associate speciÿc information to each word. More recent implementations of incremental algorithms have been reported by Mihov [14, 15] for sorted input lexicons, Daciuk et al. [10, 11] both for sorted and unsorted lexicons, Ciura and Deorowicz [7, 8] and Revuz [19] . 2 In Section 2 of this paper some basic deÿnitions are given that will be used throughout the paper. We have tried to deÿne appropriate concepts that simplify the proofs of the lemmas. The presentation of the algorithm follows in Section 3, where a step-bystep example is presented. In Section 4, a theoretical analysis is provided together with a set of interesting lemmas, resulting to a proof that the algorithm produces minimal DAWGs. The time complexity is calculated in Section 5, while implementation issues and experimental results are presented in Section 6. The paper conclusions follow in Section 7. We have presented an insertion algorithm for adding words (strings) in deterministic DAWGs and provided some interesting lemmas resulting to a proof for its optimal behavior, i.e. if this algorithm is applied to a minimal deterministic DAWG it will not damage its minimality. This optimal insertion algorithm provides an e cient and elegant way to update minimal deterministic DAWGs without the need to perform a minimization operation afterwards. However, the proposed algorithm does not require a minimal original DAWG in order to work properly. It can add words to non-minimal deterministic DAWGs as well, but the updated DAWGs are not guaranteed to be minimal.. The optimal insertion algorithm does not traverse every node in the DAWG but only a limited number of nodes, in the neighborhood of the path of the inserted word. Thus, adding a word with the proposed algorithm is faster than adding it in the classic way (i.e. put the word in the graph and perform a minimization process afterwards), because every minimization process needs to access every node in the graph. The time required for the insertion of a new word was shown to be O(n), in respect to the size of the DAWG. Moreover, if we use the algorithm repeatedly starting from an empty DAWG we can incrementally build minimal deterministic DAWGs. This process requires O(n 2 ) time for n words and (although it is not time-e cient) it could be handy if the size of the intermediate structure (the one to be minimized) is crucial or if part of the structure has been already constructed. The behavior of the algorithm has also been tested experimentally using a lexicon of 230,000 words. The results have veriÿed the theoretical expectations.. Apart from its theoretic interest, this algorithm has direct practical uses. On-line word insertion is highly desirable in every application where the data need to be updated regularly. Thus the proposed algorithm can be used to update the lexicon of a spellchecker on-line, or it can be used to add records in a DAWG-structured database. We have already used this algorithm to build morphological lexicons [22] and we are currently working on its incorporation to an experimental Web-Agent who will be able to automatically create lexical resources from the Internet [21] .

O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O B O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O B O O O O O O O O O O B O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O B O O O O B O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O


From

a

domain

analysis

to

the

specification

and

detection

of

code

and

design

smells

Abstract.

Code

and

design

smells

are

recurring

design

problems

in

software

systems

that

must

be

identified

to

avoid

their

possible

negative

consequences

on

development

and

maintenance.

Consequently,

several

smell

detection

approaches

and

tools

have

been

proposed

in

the

literature.

However,

so

far,

they

allow

the

detection

of

predefined

smells

but

the

detection

of

new

smells

or

smells

adapted

to

the

context

of

the

analysed

systems

is

possible

only

by

implementing

new

detection

algorithms

manually.

Moreover,

previous

approaches

do

not

explain

the

transition

from

specifications

of

smells

to

their

detection.

Finally,

the

validation

of

the

existing

approaches

and

tools

has

been

limited

on

few

proprietary

systems

and

on

a

reduced

number

of

smells.

In

this

paper,

we

introduce

an

approach

to

automate

the

generation

of

detection

algorithms

from

specifications

written

using

a

domain-specific

language.

This

language

is

defined

from

a

thorough

domain

analysis.

It

allows

the

specification

of

smells

using

high-level

domain-related

abstractions.

It

allows

the

adaptation

of

the

specifications

of

smells

to

the

context

of

the

analysed

systems.

We

specify

smells,

generate

automatically

their

detection

algorithms

using

templates,

and

validate

the

algorithms

in

terms

of

precision

and

recall

on

Xerces

and

GanttProject

two

open-source

object-oriented

systems.

We

also

compare

the

detection

results

with

those

of

a

previous

approach,

iPlasma.

Following

their

development

and

delivery

to

the

clients,

software

systems

enter

the

maintenance

phase.

During

this

phase,

systems

are

modified

and

adapted

to

support

new

user

requirements

and

changing

environments,

which

can

lead

to

the

introduction

of

"bad

smells"

in

the

design

and

code.

Indeed,

during

the

maintenance

of

systems,

their

structure

may

deteriorate

because

the

maintainer's

efforts

are

focused

on

bugs

under

cost

and

time

pressure,

thus

with

little

time

to

keep

the

code

and

design

"clean"..

Yet,

code

and

design

smells

are

costly

because

these

"bad"

solutions

to

common

and

recurrent

problems

of

design

and

implementation

are

a

frequent

cause

of

low

maintainability

and

can

impede

the

evolution

of

the

systems.

During

formal

technical

reviews,

quality

experts

may

detect

errors

and

smells

early,

before

they

are

passed

on

to

subsequent

software

development

and

maintenance

activities

or

released

to

customers.

However,

the

detection

of

code

and

design

smells

requires

important

resources

in

time

and

personal,

as

well

as

being

error-prone

Code

and

design

smells

are

problems

resulting

from

bad

design

practices

They

include

problems

ranging

from

high-level

and

design

problems,

such

as

antipatterns

[BMB

(that

we

will

designate

as

design

smells

in

the

rest

of

the

paper),

to

low-level

or

local

problems,

such

as

code

smells

Code

smells

are

in

general

symptoms

of

design

smells.

However,

software

engineers

can

define

their

own

code

and

design

smells

according

to

their

own

understanding

and

the

context

of

their

systems

and

organisations..

One

example

of

a

very

common

design

smell

is

the

Blob

[BMB

p.

also

known

as

God

Class

The

Blob

reveals

a

procedural

design

(and

thinking)

implemented

with

an

object-oriented

programming

language.

It

manifests

itself

through

a

large

controller

class

that

plays

a

God-like

role

in

the

program

by

monopolizing

the

processing,

and

which

is

surrounded

by

a

number

of

smaller

data

classes

providing

many

attributes

but

few

or

no

methods.

In

the

Blob,

the

code

smells

are

the

large

class

and

its

surrounding

data

classes..

Several

approaches

and

tools

have

been

proposed

in

the

literature

to

specify

and

detect

smells.

Although

showing

interesting

results,

these

approaches

have

the

following

limitations:.

-Problem

Lack

of

high-level

specifications

of

smells

adapted

to

analysed

systems.

These

approaches

propose

the

detection

of

a

set

of

predefined

hard-coded

smells.

The

detection

of

new

smells

requires

a

new

implementation

using

programming

languages.

The

detection

algorithms

are

defined

at

the

code

level

by

developers

rather

than

at

the

domain

level

by

quality

experts.

Moreover,

the

implementation

of

the

detection

algorithms

is

guided

by

the

services

of

the

underlying

detection

framework

rather

than

by

a

study

of

the

textual

descriptions

of

the

smells.

Lincke

et

al.

demonstrate

that

the

problem

is

even

worst,

in

particular

among

metrics-based

tools.

They

show

that

metrics-based

tools

not

only

interpret

and

implement

the

definitions

of

metrics

differently

but

also

deliver

tool-dependent

metrics

results,

and

these

differences

have

implications

on

the

analyses

based

on

the

metrics

results.

Consequently,

it

is

difficult

for

quality

experts

not

familiar

with

these

languages

and

services

to

evaluate

the

choices

made

by

the

developers,

to

adapt

the

algorithms

or

specify

new

detection

algorithms

to

take

into

account

the

contexts

of

the

analysed

systems..

-Problem

"Magical"

transition

from

the

specifications

of

smells

to

their

detection.

Most

of

the

approaches

do

not

explain

the

transition

from

the

specifications

of

smells

to

their

detection.

The

way

specifications

are

processed

or

manipulated

is

not

clear

and

the

definition

of

the

underlying

detection

platform

that

allows

the

detection

is

not

documented.

This

lack

of

transparency

prevents

replication

and

improvement

of

detection

techniques,

but

also

the

technical

comparison

of

the

implementation

of

these

techniques..

-Problem

Partial

validation

of

the

existing

detection

techniques.

The

results

of

the

detection

with

the

approaches

are

not

presented

on

a

representative

set

of

smells

and

on

available

systems.

Indeed,

available

results

concern

proprietary

systems

and

a

reduced

number

of

smells..

In

this

paper,

we

follow

the

principle

of

domain

analysis

to

propose

a

domain-specific

language

to

specify

code

and

design

smells

at

the

domain

level

and

generate

automatically

detection

algorithms

from

these

specifications.

A

shorter

version

of

this

paper

was

published

in

We

extend

this

previous

version

of

the

paper

with

a

more

significant

set

of

smells,

detection

results

on

a

second

open-source

system,

and

an

extended

description

of

the

domain

analysis

that

gives

a

new

research

point

of

view

with

respect

to

our

previous

work

Figure

illustrates

the

following

contributions:

-Contribution

We

describe

and

implement

a

domain-specific

language,

(Design

Defects

Domain

Specific

Langage)

based

on

a

unified

vocabulary

that

allows

quality

experts

to

specify

smells.

This

language

results

from

a

thorough

domain

analysis

of

smells,

allows

quality

experts

to

take

into

account

the

contexts

of

the

analysed

systems,

and

allows

the

generation

of

traceable

detection

algorithms.

We

propose

an

explicit

process

for

generating

detection

algorithms

automatically

using

templates.

We

recall

the

services

provided

by

our

underlying

detection

framework,

(Design

Defects

FrameWork),

which

allow

the

automatic

generation

of

detection

algorithms

from

the

specifications.

These

algorithms

correspond

to

Java

code

source

directly

compilable

and

executable

without

any

manual

intervention..

-Contribution

We

present

the

validation

of

our

process

including

the

first

study

of

both

precision

and

recall

on

two

large

open-source

software

systems,

GANTTPROJECT

and

XERCES

This

validation

constitutes

a

first

result

in

the

literature

on

both

the

precision

and

recall

of

a

detection

technique

on

open-source

systems

and

on

a

representative

set

of

ten

smells..

In

the

rest

of

this

paper,

Sect.

presents

the

domain

analysis

performed

on

the

literature

pertaining

to

smells.

Section

presents

and

Section

describes

the

generation

process

of

detection

algorithms.

Section

validates

our

contributions

with

the

specification

and

detection

of

ten

smells

including

the

antipatterns:

Blob,

Functional

Decomposition,

Spaghetti

Code,

and

Swiss

Army

Knife,

and

the

code

smells:

Large

Class,

Lazy

Class,

Long

Method,

Long

Parameter

List,

Refused

Parent

Bequest,

Speculative

Generality,

on

the

open-source

systems

Xerces

and

GanttProject

Section

surveys

related

work

and

explicitely

compares

our

approach

to

iPlasma,

the

current

state-of-the-art

tool.

Section

concludes

and

presents

future

work.

In

this

paper,

we

introduced

a

domain

analysis

of

the

key

concepts

defining

design

and

code

smells;

a

domainspecific

language

to

specify

smells,

and

its

underlying

detection

framework,

and

a

process

for

generating

detection

algorithms

automatically..

With

and

the

generation

process,

quality

experts

can

specify

smells

at

the

domain

level

using

their

expertise,

generate

detection

algorithms,

and

detect

smells

during

formal

technical

reviews.

We

implemented

and

the

generation

process

and

studied

the

precision

and

recall

of

generated

algorithms

on

GanttProject

and

Xerces

We

showed

that

the

detection

algorithms

are

efficient

and

precise,

and

have

a

recall

close

to

recall..

The

validation

in

terms

of

precision

and

recall

sets

a

landmark

for

future

quantitative

comparisons.

Thus,

we

plan

to

perform

such

a

comparison

of

our

work

with

previous

approaches

in

complement

to

the

comparison

with

iPlasma

described

here.

We

also

plan

to

integrate

the

WordNet

lexical

database

of

English

into

to

improve

the

current

DSL,

to

improve

the

generated

code

in

terms

of

quality

and

reusability,

and

to

compute

the

precision

and

recall

on

more

systems.

We

will

assess

the

flexibility

of

the

code

generation

offered

when

using

XML

technologies

[SPJ

We

will

also

perform

usability

studies

of

the

language

with

quality

experts.

Tables

and

report

detection

times,

numbers

of

suspicious

classes,

and

precisions

and

recalls,

respectively

for

the

GanttProject

and

Xerces

systems.

We

perform

all

computations

on

a

Intel

Dual

Core

at

with

of

RAM.

Computation

times

do

not

include

building

the

models

of

the

system

but

include

accesses

to

compute

metrics

and

check

structural

relationships

and

lexical

and

structural

properties.

Excluding

the

code

smells

Lazy

Class

and

Refused

Parent

Bequest,

the

recalls

of

the

generated

algorithms

range

from

to

for

code

smells

and

for

design

smells.

Precisions

range

from

to

providing

between

and

of

the

total

number

of

classes,

which

is

reasonable

for

quality

experts

to

analyse

by

hand,

with

respect

to

analysing

the

entire

system,

classes

GanttProject,

manually..

For

the

Spaghetti

Code,

we

found

suspicious

classes.

Out

of

these

suspicious

classes,

are

indeed

Spaghetti

Code

previously

identified

in

Xerces

manually

by

software

engineers

independent

of

the

authors,

which

leads

to

a

precision

of

and

a

recall

of

(see

third

line

in

Table

The

result

file

contains

all

suspicious

classes,

including

class

org.apache.xerces.xinclude.XIncludeHandler

declaring

methods.

Among

these

methods,

method

handleIncludeElement(XMLAttributes)

is

typical

of

Spaghetti

Code:

it

does

not

use

inheritance

and

polymorphism,

uses

excessively

global

variables,

and

weighs

LOC..

For

the

Large

Class,

Long

Parameter

List,

and

Speculative

Generality

code

smells,

we

obtained

optimum

recalls

because

the

generated

detection

algorithms

are

based

on

quite

simple

metrics

that

consist

in

counting

entities.

For

the

Long

Method,

the

same

kind

of

simple

metric,

the

number

of

lines

of

code,

has

been

used.

However,

this

metric

depends

on

the

experts'

definition

of

a

long

method,

which

explains

that

we

did

not

obtain

a

perfect

recall

We

encountered

another

ambiguity

with

Lazy

Class.

Indeed,

one

of

the

criteria

of

its

detection

is

method

complexity:

during

manual

detection,

software

engineers

must

appreciate

method

complexity,

which

is

inherently

subjective,

while

we

use

objective

metrics

(WMC,

Weighted

methods

per

class,

and

McCabe

Cyclomatic

Complexity)

during

the

automatic

detection..

Finally,

the

smell

Refused

Parent

Bequest

illustrated

the

inverse

problem:

it

is

very

difficult

for

software

engineers

to

identify

all

its

occurrences

because

they

must

appreciate

if

a

class

uses

enough

public

and

protected

methods/fields

of

any

of

its

superclasses.

Moreover,

the

software

engineers

consider

bequests

provided

by

API

classes

whereas

we

apply

our

detection

on

the

system

only,

excluding

libraries..

The

two

smells

Lazy

Class

and

Refused

Parent

Bequest

exhibit

poorer

precision

and

recall

because

of

the

lack

of

constraints

of

their

specifications.

A

Lazy

Class

could

be

any

class

with

few

simple

methods

while

a

Refused

Parent

Bequest

could

be

any

class

that

does

not

directly

use

some

of

its

parents

methods.

These

two

smells

illustrate

the

problems

of

interpreting

the

definitions

of

the

smells

and

of

translating

these

definitions

into

specifications.

Future

work

includes

studying

the

contexts

in

which

these

specifications

could

be

made

more

constraining..

The

results

depend

on

the

specifications

of

the

smells.

The

specifications

must

be

neither

too

loose,

not

to

detect

too

many

suspicious

classes,

nor

too

constraining,

and

miss

smells.

With

quality

experts

can

refine

the

specifications

of

the

smells

easily,

according

to

the

detected

suspicious

classes

and

their

knowledge

of

the

system

through

iterative

refinement.

Several

books

provide

in-breadth

views

on

pitfalls

heuristics

code

smells

and

antipatterns

[BMB

aimed

at

a

wide

audience

for

educational

purposes.

However,

they

describe

textually

smells

but

performed

a

complete

analysis

of

the

text-based

descriptions

of

smells.

Thus,

it

is

difficult

to

build

detection

algorithms

from

their

textual

descriptions

because

they

lack

precision

and

are

prone

to

misinterpretation.

Travassos

et

al.

introduced

a

process

based

on

manual

inspections

and

reading

techniques

to

identify

Marinescu

introduced

the

concept

of

detection

strategies

to

overcome

the

limitations

of

the

previous

literature.

We

present

a

detailed

comparison

of

our

approach

with

these

detection

strategies

in

the

following

subsection.

Munro

also

noticed

the

limitations

of

the

textual

descriptions

and

proposed

a

template

including

heuristics

to

describe

code

smells

more

systematically.

It

is

a

step

towards

more

precise

specifications

of

code

smells

but

code

smells

remain

nonetheless

textual

descriptions

subject

to

misinterpretation.

Munro

also

proposed

metric-based

heuristics

to

detect

code

smells,

which

are

similar

to

Marinescu's

detection

strategies.

Only

Marinescu

and

Munro

provide

some

results

of

their

detection

but

on

a

few

smells

and

only

on

proprietary

systems.

Alikacem

and

Sahraoui

proposed

a

description

language

of

quality

rules

to

detect

violations

of

quality

principles

and

smells

The

rules

include

quantitative

information

such

as

metrics

and

structural

information

such

as

inheritance

or

association

relationships

among

classes.

They

also

use

fuzzy

logic

to

express

the

thresholds

of

rules

conditions.

The

rules

are

interpreted

and

executed

using

an

inference

engine.

Although

their

detection

framework

is

explicit,

they

did

not

provide

any

validation

of

their

approach.

All

these

approaches

have

contributed

significantly

to

the

automatic

detection

of

smells.

However,

presents

a

complete

solution

including

a

specification

language,

explicit

detection

framework

detailed

processing,

and

validation

of

the

detection

technique..

Tools

also

allow

developers

to

write

detection

rules

using

Java

or

XPath.

However,

the

addition

of

new

rules

is

intended

for

engineers

familiar

with

Java

and

XPath,

which

could

limit

access

to

a

wider

range

of

software

engineers.

Crocopat

provides

an

efficient

language

to

manipulate

relations

of

any

arity

with

a

simple

and

expressive

query

and

manipulation

language.

However,

this

language

is

at

a

low-level

of

abstraction

and

requires

quality

experts

to

understand

the

implementation

details

of

its

underlying

model.

Therefore,

previous

tools

provided

low-level

languages

for

specifying

new

smells

while

we

defined

a

high-level

DSL

targeting

software

quality

experts.

O O O O O O O O B O O O B I O O O B I O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O B O O O O O B O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O B I O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O B O O O O O O O O B I O O O O O O O O O O O O O B I O O B I O O O O O B I O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O B O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O B O O O O B O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O B O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O B I O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O B O O O O O O O O O O O O B O O O O O O O O O O O B O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O B O O O O O B O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O B O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O B I O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O B I O B I O O O O O O O O O O O O O O B I O O O O O B O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O B O O O O O O O B O O O O O O O O B O O B O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O


Multiscale simulations of porous media flows in flow-based coordinate system In this paper, we propose a multiscale technique for the simulation of porous media flows in a flow-based coordinate system. A flow-based coordinate system allows us to simplify the scale interaction and derive the upscaled equations for purely hyperbolic transport equations. We discuss the applications of the method to two-phase flows in heterogeneous porous media. For two-phase flow simulations, the use of a flow-based coordinate system requires limited global information, such as the solution of single-phase flow. Numerical results show that one can achieve accurate upscaling results using a flow-based coordinate system. In this paper, multiscale methods for two-phase immiscible flow using flow-based coordinate system are considered. In particular, the upscaling of a convectiondominated transport equation is discussed. The flowbased coordinate system allows us to simplify the scale interaction and obtain an upscaled model for transport. Furthermore, this upscaled model is used to design a coarse-scale algorithm for two-phase flow. In our numerical methods, the shock front of the upscaled equation was resolved using a moving mesh. Numerical results show that one can achieve high accuracy using the proposed algorithms. The proposed methods are efficient when the solution is smooth in a new coordinate system (perhaps with the exception of some sharp moving fronts). However, if, under changing source terms or boundary conditions, the solution dramatically changes and no longer remains smooth, then one may need to introduce another coordinate system for accurate coarse-scale simulations.. Though the results presented in the paper are encouraging, there are possible extensions that are currently under investigation. The extension to three dimensions does not seem to be difficult. However, it fails when the coordinate transformation becomes degenerate. We conjecture (see [23] ) that, for most permeability fields, the regions of the flow where this occurs do not carry much fluid. It should then be possible to regularize the transformation and apply this method with only a small numerical error. Another direction of future research is the development of fast and accurate algorithms that perform interpolation from the Cartesian to pressure-streamline grid. In particular, our interest is in the development of such algorithms using coarse-scale information similar to multiscale finite element methods. The latter will speed-up the interpolation computations and make the method more desirable for multiphase flow and transport computations. The upscaling and multiscale methods for two-phase flow systems have been discussed by many authors. In most upscaling procedures, the upscaled quantities are computed on a coarse grid obtained from the underlying fine-grid. Because of strong scale interactions associated with complex spatial correlations, most upscaling and multiscale methods may require some type of global information or border regions to take into account nonlocal neighboring information. In the proposed work, multiscale, and upscaling techniques are used in a flow-based coordinate system. This coordinate system, which is based on limited global information, can provide additional smoothness for the solution, and it simplifies the scale interaction.. Next, we present the flow-based coordinate system and the modified equation and discuss some asymptotic properties of the modified equations in the flowbased coordinate system. We will restrict our analysis to the two-dimensional case and assume that the heterogeneous porous medium is isotropic, k(x) = k(x)I. In general, the stream function is defined as ∇ × ψ = v = (v 1 , v 2 ). In two dimensions, the stream function ψ reduces to a scalar field defined by. It can be easily shown that ∇ψ · ∇ p = 0, where p is initial pressure. Denote the initial stream function and pressure by ψ = ψ(x, t = 0) and p = P(x, t = 0). If we assume S = 0 at time zero, then (ψ, p) can be obtained from the pressure equation with λ(S ) = 1. Then, the equation for pressure and stream function can be written down in this curvilinear orthogonal coordinate system using standard coordinate transformation techniques (see [11, 23] ). As a result, we obtain. Applying the same change of variables to saturation equation, we get. Our objective is to present an upscaling method in pressure-streamline framework for two-phase flow equations. The cornerstone of our upscaling method is the fact that the pressure at later times is a smooth function of initial pressure and, thus, the upscaling of initial pressure-streamline framework is more robust and accurate. In Efendiev et al. [11] , the authors consider a special case when the permeability has strong nonlocal effects with a single high-permeability channel. The authors show that, in this case, the pressure evolution can be written as. where P 0 is the solution of. where λ 0 depends S 0 . If λ is a smooth function, then P 0 is a smooth function with respect to p. Here, h.o.t are related to the contrast in the permeability field, which is very high inside the channel. This expansion shows that, in porous media with strong channelized nonlocal effects, the initial pressure-streamline coordinate system can provide a better coordinate system for performing upscaling. First, this coordinate system can simplify the scale interaction and nonlocal effects can be modeled more accurately.. 4 Upscaling of saturation equation in flow-based coordinate system

B O O O O O O B I I O O O O O O B O O O O O O O O O O B I I O B I I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O B I I O O O O O O O O O O O O O O O O O O O B O O O B I I O O O B O O O O O O B I I O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O B O B O O B I O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O B O B O O O O O O O O O O O O O O O O O O O O O O B O B O O O O O B I I O O O O O O O O O O O O O O O O O O O O O O O O O O O B I I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O B I O O O O O B O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B O O O O O O O O O O O O O O O O O O B O O O O B I I


Avoiding Shared Clocks in Networks of Timed Automata Abstract. Networks of timed automata (NTA) are widely used to model distributed real-time systems. Quite often in the literature, the automata are allowed to share clocks, i.e. transitions of one automaton may be guarded by conditions on the value of clocks reset by another automaton. This is a problem when one considers implementing such model in a distributed architecture, since reading clocks a priori requires communications which are not explicitly described in the model. We focus on the following question: given an NTA A1 A2 where A2 reads some clocks reset by A1, does there exist an NTA Awithout shared clocks with the same behavior as the initial NTA? For this, we allow the automata to exchange information during synchronizations only, in particular by copying the value of their neighbor's clocks. We discuss a formalization of the problem and define an appropriate behavioural equivalence. Then we give a criterion using the notion of contextual timed transition system, which represents the behavior of A2 when in parallel with A1. Finally, we effectively build A Timed automata [AD94] are one of the most famous formal models for real-time systems. They have been deeply studied and very mature tools are available, like Uppaal [BDL04] , Epsilon [CGL93] and Kronos [BDM + 98].. Networks of Timed Automata (NTA) are a natural generalization to model real-time distributed systems. In this formalism, each automaton has a set of clocks that constrain its real-time behavior. But quite often in the literature, the automata are allowed to share clocks, which provides a special way of making the behavior of one automaton depend on what the others do. Actually shared clocks are relatively well accepted and can be a convenient feature for modeling systems. Imagine for instance several agents performing together a distributed task according to a predefined schedule. In a typical implementation the schedule would be sent to the agents at the beginning and every agent would store its own copy of the schedule. But for a (simplified) model of the system, it may be easier to have one timed automaton modeling a single copy of the schedule and every agent referring to it via shared clocks.. Since NTA are almost always given a sequential semantics, shared clocks can be handled very easily even by tools: once the NTA is transformed into a single timed automaton by the classical product construction, the notion of distribution is lost and the notion of shared clock itself becomes meaningless. Nevertheless, implementing a model with shared clocks in a multi-core architecture is not straightforward since reading clocks a priori requires communications which are not explicitly described in the model.. Here we are concerned with the expressive power of shared clocks according to the distributed nature of the system. We are aware of only one previous study about this aspect, presented in [LPW07] . Our purpose is to identify NTA where sharing clocks could be avoided, i.e. NTA which syntactically use shared clocks, but whose semantics could be achieved by another NTA without shared clocks. For simplicity, we look at NTA made of two automata A 1 and A 2 where only A 2 reads clocks reset by A 1 . The first step is to formalize which aspect of the semantics we want to preserve in this setting. Then the idea is essentially to detect cases where A 2 can avoid reading a clock because its value does not depend on the actions that are local to A 1 and thus unobservable to A 2 . To generalize this idea we have to compute the knowledge of A 2 about the state of A 1 . We show that this knowledge is maximized if we allow A 1 to communicate its state to A 2 each time they synchronize on a common action.. In order to formalize our problem we need an appropriate notion of behavioral equivalence between two NTA. We explain why classical comparisons based on the sequential semantics, like timed bisimulation, are not sufficient here. We need a notion that takes the distributed nature of the system into account. That is, a component cannot observe the moves and the state of the other and must choose its local actions according to its partial knowledge of the state of the system. We define the notion of contextual timed transition systems (contextual TTS) in order to formalize this idea.. Then we express the problem of avoiding shared clocks in terms of contextual TTS and we give a characterization of the NTA for which shared clocks can be avoided. Finally we effectively construct an NTA without shared clocks with the same behavior as the initial one, when it exists. A possible interest is to allow a designer to use shared clocks as a high-level feature in a model of a protocol, and rely on our transformation to make it implementable.. Related work. The semantics of time in distributed systems has already been debated. The idea of localizing clocks has already been proposed and some authors [ABG + 08, DL07, BJLY98] have even suggested to use local-time semantics with independently evolving clocks. Here we stay in the classical setting of perfect clocks evolving at the same speed. This is a key assumption that provides an implicit synchronization and lets us know some clock values without reading them.. Many formalisms exist for real-time distributed systems, among which NTA [AD94] and time Petri nets [Mer74] . So far, their expressiveness was compared [BCH + 05, BR08, CR06, Srb08] essentially in terms of sequential semantics that forget concurrency. In [BCH12] , we defined a concurrency-preserving translation from time Petri nets to networks of timed automata. This transformation uses shared clocks and the question whether these could be avoided remained open. A ′ 2 could achieve the same behavior as A 1 A 2 without using shared clocks.. A first remark is that our problem makes sense only if we insist on the distributed nature of the system, made of two separate components. On the other hand, if the composition operator is simply used as a convenient syntax for describing a system that is actually implemented on a single sequential component, then a simple product automaton would perfectly describe the system and every clock becomes local.. So, let us consider the example of Fig. 1 , made of two TA, supposed to describe two separate components. Remark that A 2 reads clock x which is reset by A 1 . But a simple analysis shows that this reading could be avoided: because of the condition on its clock y, A 2 can only take transition b before time 3; but x cannot reach value 2 before time 3, since it must be reset between time 1 and 2. Thus, forgetting the condition on x in A 2 would not change the behavior of the system. 2.2. Transmitting Information during Synchronizations. Consider now the example of Fig. 2 . Here also A 2 reads clock x which is reset by A 1 , and here also this reading could be avoided. The idea is that A 1 could transmit the value of x when synchronizing, and afterwards any reading of x in A 2 can be replaced by the reading of a new clock x ′ dedicated to storing the value of x which is copied on the synchronization. Therefore A 2 can be replaced by A ′ 2 pictured in Fig. 2 , while preserving the behavior of the NTA, but also the behavior of A 2 w.r.t. A 1 .. We claim that we cannot avoid reading x without this copy of clock. Indeed, after the synchronization, the maximal delay in the current location depends on the exact value of. Figure 2: A 2 reads x which belongs to A 1 and A ′ 2 does not.. x, and even if we find a mechanism to allow A ′ 2 to move to different locations according to the value of x at synchronization time, infinitely many locations would be required (for example, if s occurs at time 2, x may have any value in (1, 2]).. Coding Transmission of Information. In order to model the transmission of information during synchronizations, we allow A ′ 1 and A ′ 2 to use a larger synchronization alphabet than A 1 and A 2 . This allows A ′ 1 to transmit discrete information, like its current location, to A ′ 2 . But we saw that A ′ 1 also needs to transmit the exact value of its clocks, which requires a more general mechanism than the simple clock resets. For this we allow an automaton to copy its neighbor's clocks into local clocks during synchronizations. This is denoted as updates of the form x ′ := x in A ′ 2 (see Fig. 2 ). This feature is a bit unusual but has already been studied: it is a restricted class of updatable timed automata as defined in [BDFP04] . Moreover, as shown in [BDFP04] , the class we consider, without comparisons of clocks and with only equalities in the updates is not more expressive than classical TA for the sequential semantics (any updatable TA of the class is bisimilar to a classical TA), and the emptiness problem is PSPACE-complete, as in the case of classical TAs.. Semantics. TTS(A 1 A 2 ) can be defined as previously, with the difference that the synchronizations are now defined by:. where u is a partial function from. Here, we choose to apply the reset r 1 ∪ r 2 before the update u, because we are interested in sharing the state reached in A 1 after the synchronization, and r 1 may reset some clocks in C 1 ⊆ X 1 .. 2.3. Towards a Formalization of the Problem. We want to know whether A 2 really needs to read the clocks reset by A 1 , or if another NTA A ′ 1 A ′ 2 could achieve the same behavior as A 1 A 2 without using shared clocks. It remains to formalize what we mean by "having the same behavior" in this context. First, we impose that the locality of actions is preserved, i.e. A ′ 1 uses the same set of local actions as A 1 , and similarly for A ′ 2 and A 2 . For the synchronizations, we have explained earlier why we allow A ′ 1 and A ′ 2 to use a larger synchronization alphabet than . and A 2 . The correspondence between both alphabets will be done by a mapping ψ (this point will be refined later). Now we have to ensure that the behavior is preserved. The first idea that comes to mind is to impose bisimulation between ψ(TTS(. A ′ 2 ) with synchronization actions relabeled by ψ) and TTS(A 1 A 2 ). But this is not sufficient, as illustrated by the example of Fig. 3 (where ψ is the identity). Intuitively A 2 needs to read x when in q 1 (and similarly in q 2 ) at time 2, because this reading determines whether it will perform a or b, and the value of x cannot be inferred from its local state given by q 1 and the value of y. Anyway TTS(A 1 A ′ 2 ) is bisimilar to TTS(A 1 A 2 ), and A ′ 2 does not read x. For the bisimulation relation R, it is sufficient to impose (p 1 , q 1 ) R (p 1 , r 1 ) and (p 2 , q 1 ) R (p 2 , r 2 ).. What we see here is that, from the point of view of A 2 and A ′ 2 , these two automata do not behave the same. As a matter of fact, when A 2 fires one edge labeled by c, it has not read x yet, and there is still a possibility to fire a or b, whereas when A ′ 2 fires one edge labeled by c, there is no more choice afterwards. Therefore we need a relation between A ′ 2 and A 2 , and in the general case, a relation between A ′ 1 and A 1 also.. A ′ 2 satisfying items 2 and 3 of Definition 3.8,. . But, by Lemma 3.5, when A 2 is deterministic and TTS A 1 (A 2 ) has restrictions, TTS Q 1 (A 1 )⊗ TTS A 1 (A 2 ) is not timed bisimilar to TTS Q 1 (A 1 A 2 ) (not even weakly timed bisimilar since there are no ε-transitions). Hence any NTA A ′ 1 A ′ 2 satisfying items 2 and 3 of Definition 3.8, does not satisfy item 1. We remark from the proof that when there is a restriction in TTS A 1 (A 2 ), even infinite A ′ 1 and A ′ 2 would not help. Next section will be devoted to the constructive proof of the direct part of this theorem.. The counterexample in Fig. 4 also works here to argue that the conditions of Lemma 3.9 and Theorem 3.10 are not necessary when A 2 is not deterministic. Indeed A ′ 2 with only one unguarded edge labeled by a and A ′ 1 = A 1 satisfy the three items of Definition 3.8 but there is a restriction in TTS A 1 (A 2 ).

O B I O B I I I O B I I I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I I I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I I I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O B I O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I I I O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O B I O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O O