1 Introduction

A device to device (D2D) communication is typically an organization of two or more intelligent devices to communicate without the involvement or partial involvement of communication infrastructure [1,2,3]. A device has no information regarding other devices in its transmission coverage and aims to communicate with its proximal devices in the network. Therefore, proximal device discovery is a key initial phase for the initialization of D2D communication in the cellular system. Device proximal knowledge is essential for data routing algorithms, medium access control algorithms, and D2D network formation algorithms to work correctly and efficiently [4, 5]. Many device discoveries schemes have been proposed in D2D communication, but the main issues are discovered device synchronization, discovery delay, energy consumption, and discovery accuracy. Proximal device discovery is a non-trivial problem for several reasons and needs an optimized solution [6]. First, proximal device discovery must manage collisions in randomized proximal device discovery; second, when devices are heterogeneous in nature; and third, when devices are asynchronous.

Proximal device discovery algorithms can be categorized into two methods: randomized and deterministic [7,8,9,10]. In randomized proximal device discovery, every device transmits at a random time and discovers its proximal devices with high probability at each time. In deterministic proximal discovery, every device transmits as per an encoded transmission schedule that enables it to discover every one of its proximal devices with maximum probability. In a distributed network, discovery time increases, so the network needs the synchronization and a priori knowledge of the proximal devices. In an asynchronous system, devices can start discovery at random and may miss transmissions from each other. Furthermore, when the proximal users are unknown, devices do not know when or how to finish the proximal discovery process [11]. To guarantee fast device discovery, the authors in [12] projected a quick pairing methodology by utilizing an inverse popularity matching order strategy rather than traditionally utilized Kuhn-Munkres algorithm in [13]. A Signature-based device discovery technique was suggested in [14]. The paper gives a proficient method to limit the collisions during the discovery stage while utilizing the least physical resources. The autonomous device discovery technique dependent on FlashLinQ [15] was offered in [16]. Noteworthy power consumption of devices is a genuine worry during the device discovery phase. Besides, anyhow continual searching, this issue turns out to be more basic. Hence, the researchers in [17,18,19] have been given energy efficiency device discovery schemes while enhancing the performance of the system.

The hunting space search-based bats algorithm is most prominent in discovering their prey. Therefore, due to these motivations bat echolocation-based algorithm is proposed to solve device discovery issues. The discovery procedure is separated into two phases: investigation and the manipulation phase. The optimizer must incorporate devices globally to investigate the search space, and movements ought to be randomized. The manipulation phase follows the investigation phase and can be characterized as the process of exploring in detail the promising areas of the pursuit space. Manipulation thus relates to the neighborhood seeking ability in the promising areas of configured space found in the investigation phase. Finding a legitimate synchronization among investigation and manipulation is the most difficult assignment in the advancement of any meta-heuristic technique because of the stochastic idea of the optimization discovery procedure. Therefore, the bat echolocation-based algorithm is ideal to discover (investigation and manipulation) the proximal devices efficiently and has the capability to discover the heterogeneous devices even in poor coverage zoon. Echolocation is used to detect distance and recognizes prey and barriers, flying haphazardly. Therefore, the discovery signal strength adaptation of bat echolocation is used for proximal device discovery. These are good features for computational geometry applications for device discovery. All the idealization characteristics are incorporated in the bat echolocation-based algorithm to solve the discovery issue. The main discovery issues are exact device discovery, energy consumption and routing between devices for D2D communication. The bat echolocation-based algorithm addresses all these issues and gives better performance in terms of discovery, energy utilization, and routing. To verify this algorithm, a device mobility pattern is defined based on human movements. Using the Euclidean distance equation, distance is calculated between the responding devices in a mobility pattern by the bat echolocation algorithm. The discovery probability is calculated using contact duration and meeting probability frequency and verified by the Coupon Collector’s Problem [20].

The rest of this paper is organized as follows: basic bat algorithm is explained in Sect. 2 and echolocation characteristics are presented in Sect. 3. Section 4 defines the device mobility pattern. In Sect. 5 device discovery mechanism is explained and results are discussed with the coupon collector problem in Sect. 6. In the end, the paper is concluded in Sect. 7.

2 Basic bat algorithms

Heuristic and meta-heuristic algorithms with evolutionary and swarm techniques are currently becoming effective for solving numerous optimization issues, particularly real-world engineering issues because of reliability [21]. These algorithms have been derived from the behavior of physical and biological systems in nature. Bats are fascinating, and they have the innovative capability of echolocation [22]. Using echolocation capabilities, bats identify different attributes for both moving and stationary prey in their echo environment. Each prey has many features, and bats have capabilities to manipulate these features including distances, subtended angle, absolute size, azimuth, elevation, and velocity. Using idealization characteristics of the echolocation, the bat-inspired algorithm is proposed for device discovery. Echolocation allows bats to sense the distance between prey and barriers in a magical way. Bats fly haphazardly with velocity \(v_{i}\) at location \(x_{i}\) with frequency \(f_{i}\), varying \(\lambda\) and loudness \(A^{\text{t}}\) to discover the prey. They can adjust \(\lambda\) of echo signal and pulse emission rate \(r\) at the limit \(\left[ {0, 1} \right],\) depending upon the proximity of their prey. Loudness \(A^{t}\) can diverge in many ways but in this proposed algorithm is considered to be high \(A^{t}\) to minimum \(A^{0} \left( {A_{ \hbox{min} } } \right).\)

Bat echolocation can perceive the area of the devices (prey) and enclose them. Since the location of the search space is not known from the earlier efforts, the bat algorithm expects that the present best contender solution is the objective device or is near to optimum. After the best search, the bat (discoverer) transmits the other inquiry signal that will henceforth attempt to refresh their positions towards the best search discoveries [23]. This phenomenon is represented by the accompanying conditions:

$$D = \left| {CX'\left( t \right) - X\left( t \right)} \right|$$
(1)
$$X\left( {t + 1} \right) = X'\left( t \right) - A\;\cdot\;D$$
(2)

where \(t\) is the present iteration; \(A\), \(C,\) and \(D\) are coefficient vectors; \(X'\left( t \right)\) is the discovery position vector; \({\text{X}}\left( {\text{t}} \right)\) is the discoverer position vector; \(||\) is the absolute value; and \(\cdot\) is the dot product. \(X^{\prime}\left( t \right)\) ought to be refreshed in every iteration to get the best solution. The vectors \(A\) and \(C\) in (2) are ascertained as \(A = 2a \;\cdot\;r {-} a\) and \(C = 2 \cdot r\) where \(a\) is linearly diminished through the span of iterations in both investigation and exploitation phases. Figure 1 shows the justification behind (2) where the location \(\left( {X, Y} \right)\) of a search mediator can be refreshed by the position of the present best record \(\left( {X^{\prime}, Y^{\prime}} \right)\). Better positions can be expected to improve the present position by modifying the estimation of \(A\) and \(C\) vectors. By characterizing the random discovery vector, it is conceivable to achieve any position in the inquiry space situated between the key-foci appearing in Fig. 1. Hence, (2) enables any search operator to refresh its position in the proximal current best arrangement and encircle the location of the devices.

Fig. 1
figure 1

2D position vectors and their possible next locations

3 Echolocation characteristics

The basic Bat algorithm does not much depend upon the power of the devices, while echolocation-based Bat algorithm depends upon the power of the devices. In our propose model devices power has significant role in device discovery in D2D communication. There are two phases to disseminate the echolocation signal for discovery: manipulation and estimation.

Manipulation phase Two approaches exist in the manipulation phase to determine the bat echolocation behavior-based device discovery model describes as follows:

(1) Growing echo mechanism This mechanism is accomplished by decreasing the estimation of \(a,\) and it is noted that the variance range of vector \(A\) is additionally decreased by \(a\). At the end of the day, vector \(A\) will be an irregular incentive in the interval \(\left[ { - a, a} \right],\) where \(a\) is diminished through the span of emphases. Setting random consequences for vector \(A\) in \(\left[ { - 1, 1} \right]\), the new location of a device can be characterized at any place between the first position of the device and the present position. Figure 1 demonstrates the conceivable positions from \(X, Y\) towards \(\left( {X^{\prime},Y^{\prime}} \right)\) that can be accomplished by \(0 \le A \le 1\) in 2-dimensional space. (2) Echo updating position mechanism an echo equation is built between the position of discoverer and discovery to imitate the echo-shaped movement of bats as follows:

$${\text{X}}\left. {\left( {t + 1} \right.} \right) = D'e^{bt} \cdot\cos (2\pi l + {\text{X'}}\left. {\left( t \right.} \right)$$
(3)
$$D' = \left| {\left. {X'\left( t \right.} \right) - X\left. {\left( t \right.} \right)} \right|$$
(4)

This approach initially figures the separation between the discoverer device situated at \(\left( {X,Y} \right)\) and the discovery devices situated at \(\left( {X^{\prime},Y^{\prime}} \right),\) also indicating the separation of the \(i{\text{th}}\) discoverer devices from the discovery device, \(b\) is a constant to define the state of the logarithmic, \(l\) is an arbitrary number in \(\left[ { - 1,1} \right]\), and \(\cdot\) is a dot product [24].

3.1 Estimation phase

A similar approach considering the variation of the vector \({\text{A}}\) can be used to search for devices (investigation). Discoverer devices look haphazard as indicated by their relative positions. Therefore, \(A\) with the arbitrary esteem is more noteworthy than 1 or under − 1 to constrain the search device to move far from a reference point. Compared with the manipulation phase, the position of a device in the estimation stage is refreshed as indicated by a haphazardly picked searching operator rather than the best search operator discovered so far. This method and \(\left| A \right| > 1\) accentuate the investigation and allow the bat optimization algorithm to work for global search. The bat optimization algorithm can be represented on the mathematical model below:

$$D = \left| {C\;\cdot\;X_{rand} - X} \right|$$
(5)
$$X\left( {t + 1} \right) = X_{rand} - A\;\cdot\;D$$
(6)

where \(X_{rand}\) is the random position of discovery devices chosen from the existing population.

4 Devices mobility pattern

The devices mobility pattern is designed in Fig. 2 to clarify the random movement of the devices. The devices mobility pattern is defined by 200m × 200m coverage area and the device mobility pattern may assume an imperative part to decide the discovery ratio and routing algorithm performance. It is utilized to mimic the mobility pattern of focused real-life applications sensibly [25]. Consequently, while assessing the device discovery algorithm, it is important to pick the correct underlying mobility pattern. Random device mobility pattern is considered in this research and is the benchmark of the mobility pattern to evaluate the device discovery routing algorithm because it is simple and widely available [11]. To make the random waypoint device discovery model, the MATLAB tool including network simulator is used and lets the underlying position of the device \(Rs\) and \(Ds\) be \(\left( {x_{n} , y_{n} } \right)\). correspondingly at a time, as explained in Fig. 3. Random movement allows the devices to communicate with each other when they are in coverage of each other by the consent of the access point.

Fig. 2
figure 2

Discovered devices mobility pattern in 200 × 200 m2

Fig. 3
figure 3

Energy base discovery route for device discovery

The \(Rs\) and \(Ds \;{\text{of}}\;{\text{the}}\;{\text{device}}\) change with variable speeds in a specific direction with angles \(\theta_{1}\) and \(\theta_{2}\) regarding the positive x-axis, correspondingly. Device \(R\) covers a distance \(d_{1}\), and device \(D\) covers a distance \(d_{2}\) in spa \({\text{n }}0 \to t\). At time t, after movement, the devices \(R\) and \(D\) change to position \(\left( {x_{k} , y_{k} } \right)\) and \(\left( {x_{n} , y_{n} } \right)\) separately, as shown in Fig. 4. The Euclidean distance \(\left( {d\left( {RD,0} \right)} \right)\) between the device \(R\left( {x_{1} , y_{1} } \right)\) and \(D \left( {x_{2} , y_{2} } \right)\) at time \(t = 0\;{\text{is}}\) given by

Fig. 4
figure 4

The new position of the device after mobility

$$d\left( {RD, 0} \right) = \sqrt {\left| {x_{1} - x_{2} } \right|^{2} + \left| {y_{1} - y_{2} } \right|^{2} }$$
(7)

Let the devices \(R\) and \(D\) change with the variable speed \(v_{R}\) and \(v_{D}\) forming an angle \(\theta_{1}\) and \(\theta_{2}\) with the cluster, separation \(d_{1}\) and \(d_{2}\) crossed by the cluster in a specific time \(t\) is given by \(d_{1} = v_{R} \times t\) and \(d_{2} = v_{D} \times t\). At time \(t\), when device \(R\left( {x_{1} , y_{1} } \right) \;{\text{has}}\) traveled distance \(d_{1}\) with angle \(\theta_{1}\) and the x-axis, then the new location of the device will be \(D\left( {x_{6} , y_{6} } \right),\) as depicted in Fig. 4. The estimation of \(x_{6}\) and \(y_{6}\) as far as speed and time t is given as

$$x_{6} = x_{1} + v_{R} \times t \times \cos \left( \theta \right)$$
(8)
$$y_{6} = y_{1} + v_{R} \times t \times { \sin }\left( \theta \right)$$
(9)

Thus, when device \(D\left( {x_{2} , y_{2} } \right)\) transport is at a distance \(d_{2}\), assembling \(\theta_{2}\) angle along the x-axis in the new location of the device will be \(D\left( {x_{3} , y_{3} } \right).\) The coordinate estimation of \(x_{3}\) and \(y_{3}\) as far as speed and time \(t\) is given as

$$x_{3} = x_{2} + v_{D} \times t \times \cos \left( \theta \right)$$
(10)
$$y_{3} = y_{3} + v_{D} \times t \times { \sin }\left( \theta \right)$$
(11)

when a device \(R\) and \(D\) shifts to a new location \(R\left( {x_{6} , y_{6} } \right)\) and \(D\left( {x_{3} , y_{3} } \right)\), correspondingly. The new distance \(\left( {d\left( {RD,t} \right)} \right)\) among the devices \(R\left( {x_{6} , y_{6} } \right)\) and \(D\left( {x_{3} , y_{3} } \right)\) at \(t\) is given by

$$d_{{\left( {RD,t} \right)}} = \sqrt {\left| {x_{6} - x_{3} } \right|^{2} + \left| {y_{6} - y_{3} } \right|^{2} }$$
(12)

The reliability factor \((R_{Factor} )\) with constant \(w\) of device discovery

$$R_{Factor} = w\frac{{{ \hbox{min} }\,\left( {remaining \;energy\;of\; p, remaining\;energy\;of\;q} \right)}}{{distance \left( {{\text{RD}}, t} \right)}}$$
(13)

5 Device discovery mechanism

All the discussions in the previous sections have formed the background for the device discovery. Manipulation, estimation, and mobility pattern are included for efficient device discovery and based on these parameters; the bat echolocation-based algorithm is applied for device discovery. The proposed scheme is more reliable than whale optimization and other related algorithms [21].

5.1 Bat echolocation-based discovery algorithm

By using the idealization of the echolocation, the bat echolocation-based algorithm has the capability of discovering the heterogeneous devices even in the poor coverage zone. The following idealized rules are utilized for efficient device discovery. (1) All bats utilize echolocation to detect distance, and they additionally know prey and barriers. (2) Bats fly haphazardly with speed \(v_{i}\) at position \(x_{i}\) with varying wavelength and use different discovery signal strength \(A^{t}\) to scan for prey. They can adjust the frequency of their transmitted discovery signal automatically and change the rate of signal \(r \in \left[ {0,1} \right]\), contingent upon the proximity of their prey. (3) Although the discovery signal strength can change in many ways, it is always expected that the signal strength varies positively. Therefore, these are good features for computational geometry applications for device discovery, and all the characteristics are incorporated into the bat echolocation-based algorithm to solve the discovery issues. The bat echolocation-based algorithm gives better performance in terms of fast discovery, energy utilization, and routing. To verify this algorithm, the device mobility pattern is defined based on human movements. Using the Euclidean distance equation, distance is calculated between responding devices in a mobility pattern by the bat echolocation algorithm. The discovery probability is calculated using contact duration and meeting probability frequency and verified by the Coupon Collector’s Problem.

The bat algorithm is based on mimicking the nourishing behavior of bats and transmits natural waves to identify the position of the prey, accordingly, changing its position to pursue the prey. With the departure of the prey getting nearer, the loudness steadily lessens, and the frequency of emanation becomes quicker [26]. The frequency of natural waves and the span of prey are connected. The bat additionally assaults the prey with the echolocation methodology as described in Fig. 5. In the echolocation methodology, the bat transmits sound waves and wait for reflection or echo. When the bat receives echo and based on echo characteristics it decides the location of prey. The same concept is implemented for the device discovery algorithm in a specific search space. A discoverer device sends a signal or takes help from the base station to get the position of the proximal devices. Discoverer devices and proximal devices give the response via a base station or directly to the discovery devices. Depending on the network configuration, it may be device-centric or centralized. A device movement pattern is saved in the pattern table, which helps to discover the devices with minimum delay. This technique is numerically detailed as follows: suppose at time \(t\), \(X\) demonstrates the position of a bat, and \(v\) addresses speed, which implies the level of the difference in the positions. Then, the position-refreshing technique of the bat can be calculated as follows:

Fig. 5
figure 5

Bat echolocation methodology for prey discovery

$$X_{i} \left( t \right) = x_{i} \left( {t + 1} \right) + v_{i} \left( t \right)$$
(14)

As indicated by the qualities of bats, bats modify their flight speed as per their separation from prey [27], which is detailed as

$$v_{i} \left( t \right) = v_{i} \left( {t + 1} \right) + \left( {X_{i} \left( t \right) - X^{\prime}} \right) *f_{i}$$
(15)

where \(f\) addresses the frequency of natural waves, \(X'\) addresses the position of the prey. To emulate the irrational actions of bats, for example, flight straying from a known prey with the level of deviation in the scope of loudness, the equation is as follows:

$${\text{X}}_{\text{new}} = {\text{X}}_{\text{old}} +\upvarepsilon*{\text{A}}^{\text{t}}$$
(16)

where \(\varepsilon\) between \(\left[ { - 1 1} \right]\) follows a uniform distribution, and \(A^{t}\) signifies signal strength, the loudness appraisal formula is

$$A_{i} \left( {t + 1} \right) = \propto *A_{i} \left( t \right)$$
(17)

where \(A_{i} \left( {t + 1} \right) \to 0 {\text{as t}} \to \infty\) and \(\propto\) is the empirical value. Bats estimate the separation from the prey by switching the frequency of emanation. The frequency of emanation update is as follows:

$$r_{i} \left( {t + 1} \right) = r_{i} \left( 0 \right)\left[ {1 - e^{{\left( { - \gamma *t} \right)}} } \right]$$
(18)

while \(r_{i} \left( t \right) \to r_{i} \left( 0 \right) as t \to \infty ,\) and \(\gamma\) is the empirical constant and is explained in the Pseudocode of the bat algorithm in Fig. 6.

Fig. 6
figure 6

Pseudocode of the Bat echolocation like algorithm

When a source device needs to send multicast discovery information to a cluster of destination devices, multicast paths have been made utilizing a reliable neighboring device assortment scheme. In this plan, the next device is chosen, considering the estimation of the quality pair factor. The framework works in the accompanying steps: (1) computation of \(R_{Factor}\) among the devices and expulsion of those devices having less dependability esteem in contrast with the threshold quality esteem factor \(R_{Factor} < R_{{th\left( {Factor} \right)}}\). (2) Finding of the multicast courses utilizing path request and path answer signal. (3) A multicast path has been allotted based on maximum \(R_{Factor}\) of the path. The information has been exchanged from the source device to a group of connected destination devices with the help of the device information table, which is associated with each device in the system. When the source device transmits the discovery request across the network, the devices listen to the request which is near to the source device. The discovery request contains such information in its header as the address of the source device, the cluster address, the reliability factor, the destination address and the battery power ratio. Each device in the network contains two tables which are updated regularly: the proximal information table and the routing information table. The proximal information table keeps the address of the proximal devices that are joining in the transmission area of the device with their \(R_{Factor} ,\) and the routing information table provides the flow of signal intelligently.

5.2 Discovery reply mechanism

Whenever destination devices cluster receives the discovery request, they initiate the discovery reply phase as is presented in Fig. 3. The receiver devices generate a reply (or acknowledgment) that is routed back to the source devices through the adapted path using the path information field attached to a source request. The reply message contains the following data in its header: source address, receiver device path information, reverse path, and cluster head address. Suppose the destination cluster devices \(D_{1}\), \(D_{2}\), and \(D_{3}\) produce the reply signal and transmit it to the up-devices \(R_{7}\) and \(R_{5} ,\) correspondingly. After accepting the reply, device \(R_{7}\) again sends the reply to its proximal device, called relay \(R_{2} ,\) and saves in its header. This operation is done until the source device \(S1\) has gotten the answer from the destination device. Similarly, the upstream device \(R_{5}\) also replies toward the source device \(S1\) until it receives the answer. Finally, the source \(S1\) receives the two answer messages by means of two unique paths. Hence, two unique paths are set up for data transmission.

5.3 Discovery route maintenance mechanism

The route maintenance mechanism monitors communication operation and reports errors to source device \(S1\) (refer to Fig. 3). When the device mobility expands, the routes might be inaccessible between the devices. When a source device \(S1\) needs to send information to another device, and the connections among the devices are not working, then the direct solution is to transmit an error signal back to the source device \(S1\). For this situation, the source device starts the route discovery procedure once again, which has been explained in the flow chart of Fig. 7. There is a route from source device \(S1\) to the destination devices \(D2: S1 \to R_{3} \to R_{6} \to R_{7} \to D_{2}\). If the device \(R_{6}\) goes out from the coverage area of the device \(R_{3} ,\) then a communication link separates between the devices \(R_{3}\) and \(R_{7}\). In this situation, the device \(R_{3}\) transmits the information data to the device \(R_{6}\) and waits for an acknowledgment from \(R_{6}\). If the device \(R_{3}\) will not get the acknowledgment from \(R_{6}\), then device \(R_{6}\) is considered out of coverage, showing that no transmission link exists between the device \(R_{3}\) and \(R_{6}\).

Fig. 7
figure 7

Flow chart of cluster devices mobility management

Consequently, the device \(R_{3}\) transmits a route error to source device \(S1,\) and the source device initiates the route discovery procedure once again to build up the new route. A constant bit rate model is used as a data traffic type, and in this model, the source device \(S1\) transmits a certain amount of signal for discovery. Some fixed parameters are utilized as a part of the simulation, and the performance evaluation parameters used in the simulation are explained as follows:

Discovery signal delivery ratio (DSDR) DSDR is the ratio of the discovery received signal at the destination to the transmitted discovery signal from the source.

$$DSDR = \frac{sum\;of\;received\;signal}{sum\;of\;transmitted\;signal}$$
(19)

Discovery signal delivery delay (DSDD) DSDD is the average time to send the discovery signal from the source device to the cluster receiver devices.

$$DSDD = \frac{sum\;of\;distance\;from\;source\;S\;devices\;to\;cluster\;devices}{frequency}$$
(20)

Signaling overhead (SO) SO is the average discovery signal exchange between the reliable devices and the proximal devices at any time.

$$SO = \mathop \sum \limits_{reliability = 1}^{R} \left[ {\mathop \sum \limits_{i = 1}^{M} \left( {signals} \right)} \right]$$
(21)

where \(R\) is a reliable device on the network, and \(M\) is proximal to each reliable device; signals are the messages exchanged among every reliable device and its proximal devices.

Control overhead (CO) CO is the number of control signals that are required to establish a steady routing path from the source device to the cluster device receivers.

6 Results and discussion

In this section, the results are evaluated with discussion in terms of device discovery probability ratio and discovery signal probability, and results are compared with the Coupon Collector’s Problem. The MATLAB simulator is used to execute the algorithm, and the proposed system model has been developed. We simulate a cell of length 100 × 100 m2, with a single base station placed in the middle of the cell, and a variable number of scheduled and uncoordinated devices that are uniformly and randomly distributed in the cell. All devices have omnidirectional antennas. There are 50 devices out of which 45 are blind devices (uncoordinated or random devices) and work at 5G frequencies. The reference power of each device is 2.2 mW. The standard (AWGN) channel is considered in this scenario and multipath scenarios is added because there are 50 random devices are deployed in simulation setup.

6.1 Discovery meeting probability

Let \(P\left( {S,D} \right)\) be the meeting probability between any two devices such as the source devices \(S\) and the destination device \(D\). For example, when device \(S\) and device \(D\) or \(R\) meet each other and make a connection with each other, they will interchange their meeting probability tables individually to the devices. Provided that the met device relay \(R\) has a greater probability to the \(D\), device \(S\) will convey the proposed signal to device \(D\). However, if \(D\) has a lesser probability, device \(S\) will not transmit the proposed signal to \(D\) (refer to Fig. 3). The meeting probability [28] is given as follows if device \(S\) meets device \(D\):

$$P\left( {S,D} \right) = P\left( {S,D} \right)_{previous} + \left( {\left( {1 - P\left( {S, D} \right)_{previous} } \right) \times P_{orignal} } \right)$$
(22)

If device \(S\) does not meet device \(D\) in a period, then

$$P\left( {S,D} \right) = P\left( {S, D} \right)_{previous} \times \gamma^{k}$$
(23)

\(P_{orignal}\) is an initialization, \(\gamma\) is a constant between \(0\;{\text{and }}\;1\) and \(k\) is the interval since the previous meeting until now. If device \(S\) meets device \(R\) regularly and device \(R\) meets device \(D\) regularly, then the meeting probability of device \(S\) and device \(D\) will be updated as follows:

$$P\left( {S,D} \right) = P\left( {S,D} \right)_{previous} + \left( {1 - P\left( {S,D} \right)_{previous} } \right) \times P\left( {S, R} \right) \times P\left( {R, D} \right) \times \beta$$
(24)

where \(\beta \;{\text{is}}\) a signal transfer factor, which signifies the effect of meeting probability by signal transfer. From (22) to (24), if device \(S\) and device \(D\) encounter each other more regularly in the network, the meeting probability among them becomes larger. When two devices encounter each other in the network, the discovery signal will be redirected to the device that meets more regularly with the destination device. To get better results from this algorithm when two devices meet, the discovery signal will be redirected successfully, and signal delivery probability is equal to encounter probability.

6.2 Discovery signal delivery probability

Meeting probability means the probability that a relay device meets with the destination device during mobility. In this algorithm, the forwarded discovery signal to the relay node is chosen by the difference in the value of the meeting probability. Signal delivery probability is symbolized as \(P\left( {R, D} \right)\), which shows the probability of the signal being successfully delivered to device \(D\) from device \(R\). Updating of the discovery message delivery probability \(P\left( {R,D} \right)\) is given in the following steps: discovery signal probability increases as meeting frequency and contact time increase. When two devices meet, they will update the discovery signal sending a probability table using the given mathematical model:

$$P\left( {R,D} \right) = P\left( {R, D} \right)_{Previous} + \left( {1 - P\left( {R,D} \right)_{Previous} } \right) \times P_{orignal} \times z^{{\frac{{T_{RD} }}{{\left( {T_{R} + T_{D} } \right)/2}}}}$$
(25)

and

$$T_{RD} = \mathop \sum \limits_{j = 1}^{m} t_{RD} \left( i \right) = \mathop \sum \limits_{j = 1}^{m} \left( {t_{{RD_{end} }} \left( j \right) - t_{{RD_{start} }} \left( j \right)} \right)$$
(26)

\(T_{RD}\) denotes the total contact duration between the relay device \(R\) and destination device \(D\). \(t_{{RD_{end} }} \left( j \right) \;{\text{is}}\;{\text{the}}\) end time of the \(j{\text{th}}\) link between relay device \(R\) and destination device \(D\), and \(t_{{RD_{start} }} \left( j \right) \;{\text{is}}\;{\text{the}}\) start time of the \(j{\text{th}}\) link between device \(R\) and destination \(D\). In addition, \(T_{R} = \mathop \sum \limits_{{{\text{i}} = 1}}^{n} t_{Ri}\) is the time where the relay device \(R\) is in contact with other devices in the network, and \(T_{D} = \sum\nolimits_{k = 1}^{n} {t_{Dk} }\) is the total time that device \(D\) is in contact with other devices in the network. \(\frac{{T_{RD} }}{{\left( {T_{R} + T_{D} } \right)/2}}\) is the amount of contact time between devices \(R\) and \(D\) in the average of contact time \(\left( {T_{r} + T_{d} } \right)/2\).

6.3 Neighbor discovery as Coupon Collector’s Problem

First, the proximal device discovery problem transforms into the Coupon Collector’s Problem [29], and the probability of successful discovery transmission by device \(X_{i}\) in a given time is:

$${\text{P}} = P_{x} \left( {1 - P_{x} } \right)^{n - 1}$$
(27)

\(P\) is normally distributed for each device \(i, 1 \le i \le n.\) The procedure of proximal device discovery translates into a Coupon Collector’s Problem as follows: consider Coupon Collector \(C\) depicting coupons with substitution from a vase containing \(n\) different coupons, with every coupon comparing to a device in the clique. In every time, C discovers proximal devices by coupon draw with probability \(p\) and remains idle with probability \(\left( {1 - np} \right)\). Therefore, if \(C\) gathers \(n\) different coupons regarding the discovery event, each device in the clique has discovered the greater part of its \(\left( {n - 1} \right)\) neighbors.

Discovery time The derivation of \(E\left[ W \right]\), where \(W\) is an arbitrary variable that means the time required for every device to discover its proximal devices. The proximal device discovery procedure can be considered as comprising a sequence of discovery periods, every discovery period comprising at least one period. Suppose \(W_{m}\) denotes discovery time length \(\left( {m, 0 \le m \le \left( {n - 1} \right)} \right)\); discovery time length begins when the \(m{\text{th}}\) device is discovered and finishes when the \(m + 1{\text{st}}\) device is discovered. Therefore, in the \(m{\text{th}}\) time slot, there are \(\left( {n - m} \right)\) devices still to be discovered and all have probability \(p\) to be discovered in each time span. The discovery time length \(W_{m}\) is geometrically scattered with parameter \(\left( {n - m} \right)p\). Therefore, taking note that \(W = W_{0} + \cdots + W_{n - 1}\), we get

$$E\left[ W \right] = \mathop \sum \limits_{m = 0}^{n - 1} \frac{1}{{\left( {n - m} \right)p}}$$
(28)

Unknown number of neighbors By reduction, suppose that every device belongs to a clique. The bat echolocation-based algorithm works in stages, with each stage comprising at least one discovery time slot. In the \(r{\text{th}}\) stage, which endures for \(2^{r + 1} \;\cdot\;e\;\cdot\;ln2^{r}\) discovery slots, every device transmits the discovery signal with probability \(1/2^{r}\). Therefore, the devices geometrically diminish their transmission probabilities until they join an execution suitable for the cluster size, which occurs when devices enter the \(\log n{\text{th}}\) stage, and during this stage, every device sends with probability \(1/n\) for an interval of \(2\;\cdot\;n\;\cdot\;e\;\cdot\;ln n\) time slots. So

$$\frac{n\;\cdot\;e\;\cdot\;ln n}{2} \le W \le 2\;\cdot\;n\;\cdot\;e\;\cdot\;ln n$$
(29)

From (29), all \(n\) devices will be found by the \(\log n{\text{th}}\) stage with high probability. The aggregate number of discovery time slots, \(W\), until all n devices are found with high probability can be described as

$$W = \mathop \sum \limits_{r = 1}^{\log n } 2^{r + 1} e\ln 2^{r} \le 4neln n.$$
(30)

Compared to (29), the absence of the information of \(n\) outcomes slow down no more than twice. The coupon transmission by the devices in the clusters is presented in Fig. 8. If the value of the coupon is greater than the threshold value (5 in this case), then these devices are eligible for discovery and qualify for D2D communication. As the value of the coupon is high, it has more probability for discovery. The same holds in the bat echolocation-based algorithm. First, if the loudness of the signal is high, then more devices will be discovered. Second, if the bat signal is spread over a large area, there is a smaller chance to capture the prey. Therefore, in this case, four quadrants are proposed for device discovery, and each quadrant utilizes the minimum power and receives the best response from the discovery devices (RSSI), as presented in Fig. 9.

Fig. 8
figure 8

Bat echolocation like algorithm is like Coupon Collector’s Problem. Each device has his coupon value which helps to discovery

Fig. 9
figure 9

Power consumption of devices and response of the device in term of RSSI

Discovered devices in the given area have its own coverage area in the clusters and get information directly or via a relay of the proximal devices when they are under the coverage of each other. During relay services, if some devices are not eligible for D2D communication because of low power, then destination devices will be affected. There are many cases in which devices not eligible for D2D. Therefore, in this proposed methodology based on these facts, simulation results using regression, discovered devices and failure devices are shown in Fig. 10.

Fig. 10
figure 10

Discovery ratio in the proposed model

As the number of devices in the cluster increases in our proposed model, the relative energy consumption decreases as explained in Fig. 11. The bat echolocation-based algorithm works efficiently when devices form the clusters. When 10 devices are in the cluster, devices consume more energy (in dBm) compared to 20 to 50 devices in the cluster. The bat echolocation-based algorithm converges rapidly compared to other techniques presented in [30] and is shown in Fig. 12. In an 8th iteration, maximum devices discover with minimum power consumption in milli watts.

Fig. 11
figure 11

Energy consumption (dBm) using bat echolocation like algorithm

Fig. 12
figure 12

The convergence of the proposed algorithm with power consumption in milli watts and time in milli seconds

7 Conclusions

A D2D communication is typically organized for two or more intelligent devices to communicate without or with partial involvement of wireless communication infrastructure. To initiate D2D communication, proximal device discovery is the primary issue. It is a non-trivial problem due to the collision, heterogeneity, a-synchronicity, and completion of the discovery process. Therefore, an intelligence optimization solution for proximal device discovery is needed. The bat echolocation-based algorithm for device discovery is proposed in this work has the capability of discovering the heterogeneous devices even in the poor coverage zone. Using the invention of echolocation characteristics of bats, the device knows the barriers and varies the loudness that is used for proximal device discovery. The bat echolocation-based algorithm is applied, and it has the intelligence to discover maximum devices with minimum energy consumption regardless of whether the number of devices increases. This work can be further enhanced for data routing and resource allocation for device discovery and for large geographical area.