Meet User’s Service Requirements in Smart Cities Using Recurrent Neural Networks and Optimization Algorithm

Despite significant advancements in Internet of Things (IoT)-based smart cities, service discovery, and composition continue to pose challenges. Current methodologies face limitations in optimizing Quality of Service (QoS) in diverse network conditions, thus creating a critical research gap. This study presents an original and innovative solution to this issue by introducing a novel three-layered recurrent neural network (RNN) algorithm. Aimed at optimizing QoS in the context of IoT service discovery, our method incorporates user requirements into its evaluation matrix. It also integrates long short-term memory (LSTM) networks and a unique black widow optimization (BWO) algorithm, collectively facilitating the selection and composition of optimal services for specific tasks. This approach allows the RNN algorithm to identify the top- $K$ services based on QoS under varying network conditions. Our methodology’s novelty lies in implementing LSTM in the hidden layer and employing backpropagation through time (BPTT) for parameter updates, which enables the RNN to capture temporal patterns and intricate relationships between devices and services. Further, we use the BWO algorithm, which simulates the behavior of black widow spiders, to find the optimal combination of services to meet system requirements. This algorithm factors in both the attractive and repulsive forces between services to isolate the best candidate solutions. In comparison with existing methods, our approach shows superior performance in terms of latency, availability, and reliability. Thus, it provides an efficient and effective solution for service discovery and composition in IoT-based smart cities, bridging a significant gap in current research.

Abstract-Despite significant advancements in Internet of Things (IoT)-based smart cities, service discovery, and composition continue to pose challenges.Current methodologies face limitations in optimizing Quality of Service (QoS) in diverse network conditions, thus creating a critical research gap.This study presents an original and innovative solution to this issue by introducing a novel three-layered recurrent neural network (RNN) algorithm.Aimed at optimizing QoS in the context of IoT service discovery, our method incorporates user requirements into its evaluation matrix.It also integrates long short-term memory (LSTM) networks and a unique black widow optimization (BWO) algorithm, collectively facilitating the selection and composition of optimal services for specific tasks.This approach allows the RNN algorithm to identify the top-K services based on QoS under varying network conditions.Our methodology's novelty lies in implementing LSTM in the hidden layer and employing backpropagation through time (BPTT) for parameter updates, which enables the RNN to capture temporal patterns and intricate relationships between devices and services.Further, we use the BWO algorithm, which simulates the behavior of black widow spiders, to find the optimal combination of services to meet system requirements.This algorithm factors in both the attractive and repulsive forces between services to isolate the best candidate solutions.In comparison with existing methods, our approach shows superior performance in terms of latency, availability, and reliability.Thus, it provides an efficient and effective solution for service discovery and composition in IoT-based smart cities, bridging a significant gap in current research.Index Terms-Black widow optimization (BWO) algorithm (BWO), Internet of Things (IoT), recurrent neural network (RNN), service discovery, smart cities.

I. INTRODUCTION
S MART cities are becoming popular as cities around the world want to improve their infrastructure and services [1].The Internet of Things (IoT) combines different technologies and is essential for making smart cities work [2].IoT-based smart cities leverage sensors, connectivity, and automation to optimize infrastructure and resource consumption.By gathering data from connected devices and sensors in the city, IoT technology is used to improve sustainability, optimize energy consumption, and enhance residents' quality of life [3].In addition, the IoT is vital in connecting various devices within intelligent wearable devices and agriculture.While traditional mobile networks have mainly been developed for human communication, IoT networks aim to link multiple objects without human intervention [4].Examples of IoT network applications include control systems, intelligent recognition, positioning, and monitoring.
In IoT, service discovery and composition involve connecting different IoT devices, which requires using various technologies, such as the semantic Web, service-oriented architecture, and cloud computing [5].These technologies enable the development of a flexible and adaptable service infrastructure, that can meet the changing requirements of the smart city [6].Service discovery and composition can be used in traffic management systems [7], air pollution evaluation [8], and environmental monitoring applications [9].One of the main challenges of service discovery and composition in IoT is to ensure that the services selected meet the user's requirements in terms of Quality of Service (QoS) [10].
The main goal of this research is to present a unique method for selecting the services that will best satisfy the consumers' QoS expectations.Discovering IoT smart cites services based on existing circumstances with human input is an NP-hard issue [11].The user's needs significantly impact the service discovery, and QoS values, and that impact vary for each service.The recurrent neural network (RNN) [12] algorithm estimates the QoS of each service based on the number of connected devices, traffic load, network topology, using historical data and learned patterns.Black widow optimization (BWO) [13] selects the best services according to the fitness function of spiders and compounds these services.In Section IV, the proposed method is discussed deeply.Briefly, the current article's contributions are as follows.
c 2023 The Authors.This work is licensed under a Creative Commons Attribution 4.0 License.
For more information, see https://creativecommons.org/licenses/by/4.0/Authorized licensed use limited to the terms of the applicable license agreement with IEEE.Restrictions apply.
1) To achieve the most suitable integration of QoS, that fits best with the users' needs.2) To optimize the latency, energy consumption, availability, and reliability.3) To perform a series of analyses to assess the functionality of the method across different services.The structure of this article is organized as follows.Section II offers a review of the relevant recent literature.In Section IV, the problem statement is presented, and the proposed method is discussed in detail.The simulation setup and the results are presented in Section IV, and in section IV several interesting conclusions are highlighted, as well as recommendations for future research.

II. RELATED WORKS
Service discovery and composition are critical challenges in the field of IoT, as they enable the efficient and effective use of the diverse set of services and devices available in IoT environment.This study divided the related work into deterministic and nondeterministic algorithms.
Deterministic algorithms are the ones that suggest service discovery and composition algorithms for IoT that guarantee a deterministic outcome.Such algorithms use well-defined rules and procedures to match services with consumers' requirements, ensuring the same output every time the algorithm is run [14].
Hayyolalam et al. [15] proposed three phases for developing such algorithms, namely, service description, service composition, and service execution.The framework of the system is selecting the best candidate services that match the user's QoS and Quality of Experience (QoE) requirements in the first phase.The second phase combines the selected services into a composite service that meets the user's requirements while considering the resource constraints and dependencies between services.Finally, the composite service is executed and monitored at the desired QoS and QoE levels.The advantage of this approach is its reliability, availability, and user satisfaction by considering QoS and QoE; however, it is suffering from high-programming complexity and low number of users.
Deng et al. [16] introduced a framework for service discovery utilizing the sentence bidirectional encoder representations from transformers (SBERT) model and the graph attention network (GAT) algorithm.By embedding service descriptions into a high-dimensional vector space, the SBERT model enables efficient comparison and similarity evaluations between services.The GAT algorithm aids in constructing a service graph based on the semantic resemblance between service descriptions, thereby improving service discovery and selection efficiency.While this method facilitates selforganizing collaboration among diverse IoT devices without the need for a computing infrastructure, enhancing both security and scalability, it suffers from lengthy execution times and increased latency.
Mohana et al. [17] proposed a method for discovering services in a Social Internet of Things (SIoT) environment using semantic rules.SIoT refers to the integration of IoT with social networks, where people can interact with smart devices and services through social networks.The proposed method consists of two main components: 1) a service discovery engine (SDE) and 2) a semantic rule engine (SRE).The SDE is responsible for discovering available services in the SIoT environment, while the SRE applies semantic rules to filter and prioritize the discovered services based on user preferences and requirements.The SRE uses ontologies to represent user preferences and requirements.This technique provides good efficiency with respect to personalization and scalability, but may face challenges related to complexity, semantic interoperability, and resource requirements.
Mezni et al. [18] proposed a framework for smart monitoring of water environments using a combination of sensors, cloud computing, and service-oriented architecture.The proposed framework consists of three main layers: 1) the physical layer; 2) the network layer; and 3) the application layer.This article combines knowledge graph technology and network representation learning (NRL) for water quality control and drinking water consumption optimization by using intelligent corrective measures and management strategies.The knowledge graph-like water information network (WIN) is mapped incrementally into a lower dimensional vector space that is constantly readjusted to take into account all changes or problems that appeared in monitored water zones, which facilitates decision-making on appropriate management actions.This technique provides real-time monitoring and high scalability but may face high cost, complexity, as well as issues related to data privacy and security challenges.
Urbieta et al. [19] suggested a service composition framework that uses an abstract service model called wEASEL, which allows for dynamic reasoning on user tasks and service behavior.Its main objective is to enable mobile users to integrate IoT-based services available in their vicinity.The framework is evaluated using a new testbed based on OWLS-TC4.In the service selection step, the method selects the most appropriate services based on the user requests and on the services available in the smart city environment.In the second step, the selected services create a composite service that fulfills the user request.The proposed method has the potential to provide personalized and relevant services to users but does not address potential privacy or security concerns with the collection and processing of user context data.
Nondeterministic algorithms are the ones that allow multiple outcomes or paths to a solution rather than a single deterministic outcome.Nondeterministic algorithms are used in specific fields of computer science, such as computational complexity theory and cryptography.In addition, these algorithms are often used for optimization problems, where the goal is to find the best or optimal solution [20].
Bidi et al. [21] proposed a method, called GA-based QoEaware service composition (GQSC), that is used in solutions for service composition in smart city environment.In this article, the authors use a fog computing platform that provides resources and services for smart cities.In addition, the fog computing platform is designed to be fault-tolerant, which means that it can continue to provide services even in the event of a failure or outage.The proposed method also considers the QoE of the services, measured based on user satisfaction.The proposed method provide high reliability and high accuracy, but may face challenges related to high-energy consumption and high latency.
Hosseinzadeh et al. [22] proposed a method called hybrid artificial neural network-based particle swarm optimization (ANN-PSO) for the service composition issue.In this article the method proposed uses a decision-making process that considers both the QoS requirements and the available resources in the cloud-edge computing environment.Furthermore, it considers the context of the IoT devices and services in the cloud-edge computing environment, which can help providing personalized and relevant services to users.This technique has a high availability, reliability, and low cost but suffers from high-energy consumption and high complexity in programming.
Neiat et al. [23] proposed an IoT service composition technique that uses deep reinforcement learning (DRL) approach, that learns from user experience to improve the service composition process.The authors consider the mobility of IoT devices and the QoS requirements of the services in each process.This approach also uses dynamic programming to optimize the service composition process and to handle the IoT environment's uncertainty and randomness.This technique proves to have high scalability and accuracy but it suffers from long execution time and high-convergence time.
Namoun et al. [24] proposed a two-phase machine learning (ML) algorithm that considers the context of the user and the QoS requirements of the selected services.The first phase of the framework involves training a ML model on historical data to predict the QoS of the services.The second phase involves using the predicted QoS values to select the most appropriate services for the user.The proposed method also considers the user's context, including their disabilities, preferences, and location.It is shown that this technique has a high scalability and accuracy, but it is suffering from low latency and low reliability.
Sefati and Navimipour [25] proposed a service composition technique that uses a hidden Markov model (HMM) and ant colony optimization (ACO) to improve QoS.First, the HMM model is trained to anticipate QoS, while the Viterbi algorithm improves the emission and transition matrices.Then, the ACO algorithm is employed to assess the QoS and to select the most appropriate route.The method proposed has a good efficiency in availability, response time, cost and reliability but it needs high energy use and high complexity for the HMM algorithm.
Table I shows the advantages and disadvantage of the methods proposed in this paper discussed above.

A. Comparative Outlook
An examination of related work reveals the extensive use of deterministic and nondeterministic algorithms in the realm of IoT service discovery and composition.Deterministic algorithms have proven their worth in terms of reliability and user satisfaction, despite challenges related to programming complexity and user capacity.Conversely, nondeterministic algorithms offer excellent optimization capabilities but are marked by high-energy consumption, extended execution time, and complexity.A closer look reveals a gap in the current literature, with few studies considering the dynamic QoS expectations of consumers across diverse services.Crucial issues, such as latency, energy consumption, and availability, are either not fully addressed or are tackled at the expense of other significant parameters.The research presented here bridges this gap by proposing an innovative approach that fuses RNN and black widow optimization (BWO) for efficient service discovery in smart cities' IoT systems.Our method considers the dynamic QoS expectations of consumers and optimizes service selection accordingly.Emphasizing reducing latency and energy consumption, it also enhances availability and reliability.Moreover, the presented research evaluates the functionality of our method across various services, adding to its robustness.This unique aspect allows for an optimized and comprehensive approach to service discovery and composition in smart city environments.In doing so, it considers consumers' dynamic QoS expectations and the complex tradeoffs between different performance metrics.

III. PROPOSED METHOD
The technique proposed in this work aims to anticipate the QoS for different services.It uses RNN and BWO algorithms to provide users with the best achievable services.RNN is a Authorized licensed use limited to the terms of the applicable license agreement with IEEE.Restrictions apply.type of neural network appropriate for analyzing sequential data and can be utilized to predict QoS values based on historical data [26].The BWO algorithm is a swarm intelligence algorithm inspired by the behavior of black widow spiders that can be used to optimize the selection and composition of services based on user needs [27].One potential advantage of this approach is that it could help reduce the time and effort required for users.However, it is essential to note that the effectiveness of this approach will depend on various factors, such as the quality of the data, used for training the RNN and the accuracy of the QoS predictions, made by the model.

A. Problem Statement
The problem statement of service discovery and composition involves the challenge of identifying and integrating services from various sources in a smart city environment.These issues include heterogeneity of service interfaces, lack of standardization, scalability, security, and automated methods.Solutions for this problem require the development of innovative technologies that can support the seamless integration and orchestration of services across different domains.Service discovery requires a mechanism to find services provided by IoT devices and assess their availability and capabilities.This can be a complex issue since the IoT devices may have limited computing resources and connectivity.Service composition in IoT requires a flexible approach to handle many devices and services involved and to ensure real-time collaboration.As shown in Fig. 1, the IoT device layer is connected to the service layer, and, with the help of the RNN algorithm, we discover the QoS of services; then, with the use of the BOW algorithm, we composite these services.An atomic service in IoT discovery and composition refers to a basic, indivisible service that provides a specific function or capability.These services can be combined or orchestrated to create more complex and valuable services for IoT applications [28].
QoS-aware service composition and discovery can fulfill the customer requirements through a quadruple of (WF, QP, QC, and TC).WF stands for workflow, which represents the practical requirements with multiple tasks.QP stands for QoS performance, representing the users' priorities for each QoS factor.QC stands for QoS constraints, which represent the universal QoS constraints for each factor.Finally, TC stands for transactional constraints, and represents the users' need for the transactional conduct of the composite service.
The composition engine searches for candidate services for each job in the workflow by matching the functional requirements with the service details.The main goal is to create a composite service that satisfies users' end-to-end QoS and transactional constraints.For each task, a set of candidate services is identified and bound to create the composite service.
1) The practical requirements of the users are denoted by WF, which is composed of multiple tasks that are interconnected through composition structures.2) QP is a set (P 1 , . . ., P d ) that reflects the user's priorities for each QoS factor.3) QC is a collection (c 1 , . . ., c d ) that represents the universal QoS constraints of the users for each QoS parameter.
It defines an upper limit constraint for negative factors and a lower limit constraint for positive factors.If a constraint, c d , is null, it indicates that there is no constraint for the corresponding.4) TC reflects the user's need for the transactional conduct of the composite service.The final operator can recognize the transactional characteristic of the composite service, as well as the user need not specify this constraint.A composite service can combine the existing services in order to provide a new, value-added composite service.

B. QoS of Service Discovery and Composition
Integrating QoS into service composition and discovery is an essential aspect of service oriented computing (SOC).A significant challenge in achieving this goal is selecting the most suitable combination of services that meet the user's defined global QoS requirements.This challenge becomes even more pronounced in dynamic service environments, where two additional problems arise.
Cost: The cost in service discovery and composition refers to the overall expense or effort required to discover, select, and compose different services in order to fulfill a specific task or goal.Equations ( 1) and ( 2) demonstrate the overall cost of a service where C sp (S i ) represents the cost of selecting the service provider (SP) for the service S i , D(S i,m ) is the set of data required by service S i , C dp (D i,m ) represents the cost of accessing the required, and C LD (D i,m ) represents the total cost of transferring over the network Authorized licensed use limited to the terms of the applicable license agreement with IEEE.Restrictions apply.
Equation (2) determine the total cost that is calculated as the sum of the cost of each service in the set {P}, denoted by C service (S i ), and the cost of each link in the set C L , denoted by C L (l, k) [29].
Reliability: In IoT systems reliability is a critical factor for ensuring the efficient operation of connected devices and the delivery of valuable services to end-users.Equation (3) determines the reliability of the IoT services where R(t) represents the probability density function (PDF) of the time t that it takes for a system to fail (i.e., the time between service discovery and system failure), and a controls the degree of skewness or asymmetry of the PDF.A larger value of a indicates a more symmetric distribution, while a smaller value of a leads to a more skewed distribution.The λ parameter is the failure probability at t time [4].Equation ( 4) determines the expected value, E(t) that represents the average time until failure, also known as the mean time to failure (MTF).Here, t represents the time until failure, f (t) is taken over the entire range of possible failure times By calculating the expected value we can estimate the average time until failure, which can be used to make decisions regarding maintenance, repair, and replacement of IoT devices and systems.
Availability: In the context of service discovery in IoT, the availability represents the proportion of time in which a service or system is operational and accessible.Equations ( 5) and ( 6) evaluates the availability, as follows: where λ represents the failure rate and μ repair rate.As the operating time t trends to infinity the availability A(t) trends to the probability of availability.These formulas can be used to determine the MTF and mean time to repair (MTR) [4].
Latency: In IoT systems, the latency refers to the time necessary for a device or an application to discover available services or resources on the network.Equation ( 7) determines the latency of IoT as follows: where τ 1 shows the total end-to-end latency, where τ t is the time necessary to transmit the data over the network, τ prop is the propagation delay (i.e., the time it takes for the data to get from the transmitter to the receiver), τ proc is the processing delay time, which is the time it takes for the receiver to process the data once it has been received, τ ret is the queuing delay to be processed, and τ sig is the time necessary to send and receive control signals for synchronization message and error control checking [30].
Energy Consumption: IoT service discovery involves searching for available services, which can be energy intensive process, since the devices are frequently sending and receiving messages to maintain an up-to-date service directory.Equation ( 8) determines the energy usage of IoT-capable devices where E init is representing the initial energy of each node and E c is representing the current energy of each node [30].

C. Standardization of Qualitative Attributes
Standardization of qualitative attributes refers to the way in which nonnumeric characteristics of a product, service, or process can be measured and defined consistently and objectively.This can include attributes, such as usability, reliability, and user satisfaction, which are essential for evaluating the quality of a product or service.There are several standardization organizations that have developed guidelines and frameworks for measuring and evaluating qualitative attributes.Overall, standardization of qualitative attributes can help ensure consistency and reliability in evaluating product and service quality, which can be benefic for both producers and consumers.A solution for standardization was proposed in [31] where q k si shows to the k th quality of the i th service, while Max(q k si ) and Min(q k si ) are the high values of the k th for the i th service [31].

D. Proposed Method
It is computationally challenging to discover IoT intelligent city services that match current circumstances and incorporate human input.The user's needs significantly impact service discovery, and QoS values vary for each service.The RNN algorithm estimates [32] the QoS of each service based on the number of connected devices, traffic load, and network topology, using historical data to predict QoS based on learned patterns [33].The BWO algorithm can be applied to service composition in the second step.The proposed method will be described in more detail in the following section.
In the RNN algorithm, there are three levels (input layer, recurrent layer, and output layer).The input layer for the method proposed in this work consists of the users preferences, number of users, number of services, target services, and top-K services.The RNN algorithm could be used to find the top-K services by processing data based on different services QoS and under different network conditions.The RNN could make predictions with respect to different services QoS and determine the top-K services to be used for a particular task.Top-K can be helpful in a variety of IoT scenarios, such as in resource-constrained environment, where it is essential to minimize the overhead of service discovery, or in situations where there is a large number of possible services to choose from, Authorized licensed use limited to the terms of the applicable license agreement with IEEE.Restrictions apply.
and it is impractical to evaluate all of them.Equation (10) determines the RNN input as the formula in this proposed method ) A particular set of RNN layers uses nonlinear learning to acquire the concept of x s .Here, R T S represents a row matrix containing the QoS values between the top-K source services (S) and target services (T) in the context of IoT service discovery.The top-K services refer to the highest ranked services based on specific QoS criteria.The QoS values provide a method to evaluate and compare different IoT services, essential for service discovery, ranking, and selection.The elements of the R T S matrix are the individual QoS values between each top-K source service and target service pair.These values can include various performance metrics, such as response time, throughput, reliability, availability, and energy consumption.The matrix aims to provide a more efficient and manageable representation of the most relevant services for the service discovery task by focusing on the top-K services.The importance of the R T S matrix lies in its role as input data for the RNN for discovering and ranking IoT services.By processing the QoS values in the R T S matrix, the model can learn complex patterns, relationships, and dependencies between the top-K services and the target services.The nth layer of the model uses the variables w n , b n , and f n .Here, w n is the weight of service discovery in IoT, used to adjust the influence of various inputs on the prediction of the QoS provided by different services.By adjusting the weights, the RNN can learn the relationships between the inputs and the QoS provided by different services and make more accurate predictions about the best service to use for a particular task.b n denotes the bias, which is a variable in charge to deal with the systematic errors in the network conditions data.By adjusting the biases, the RNN can improve the overall accuracy of predictions about the best service.We denote by f n the activation function in an RNN for service discovery in IoT.This function can have a significant impact on the performance of the network and determines how inputs are transformed into outputs.
The hidden layer long short-term memory (LSTM) is trained give as answer the solution according to the input function.
During training, the backpropagation through time (BPPT) technique is used to update the RNN parameters.Equations ( 11) and (12) shows how the first training in hidden states is performed where h t represents the hidden state at time step t, namely, the internal state of the RNN, showing the relevant temporal patterns and relationships between devices and services up to the current time step.σ shows the nonlinear activation function, usually a sigmoid or hyperbolic tangent (tanh) function.It introduces nonlinearity into the model, allowing it to learn complex patterns in the data.Wshows the input of hidden weight matrix, that contains the weights that control how the input data at each time step x t influences the hidden state h t .In IoT service discovery, these weights assist in determining the importance of input features, such as device attributes or sensor readings, in predicting device behavior or service requirements.U is the hidden-to-hidden weight matrix, that contains the weights that control the way in which the hidden state from the previous time step h t−1 influences the current hidden state h t .In IoT service discovery, these weights help the RNN model capture the temporal relationships and dependencies between devices and services.h t−1 shows the hidden state at the previous time step (t − 1), and it represents the internal state of the RNN at the previous time step, encoding the temporal patterns and relationships between devices and services up to that point.Equation (11) shows the output of the node at time step t, where y t is the output, and multiplying the weight matrix W with the final hidden state h t .The product of the weight matrix W and the hidden state h t generates the output at time step t.Equation (12) shows that the length of a data sequence (number of services, number of users, and top-K services) significantly impacts how long an RNN takes to train.
RNNs' ability to remember previous states makes them suitable for IoT service discovery, allowing them to consider previous inputs and make informed decisions about service selection.The forget gate in RNNs can control the influence of previous selections on the current decision.The forget gate formula, given in (13), determines how previous selections should be considered or ignored where f t represents the forget gate activation, σ is the activation function, and W f is the forget gate weight matrix.In IoT service discovery, W f elements are specific to the problem and learned during RNN training.The matrix is initialized randomly and updated iteratively through backpropagation to minimize error.Values depend on input data and RNN architecture, optimized during training for improved prediction accuracy.In the context of IoT, the forget gate weight matrix can be used to help the RNN model to predict time series data.This can help the RNN to learn long-term dependencies and make accurate predictions over longer time horizons.h t−1 x t represents the chain of the previous hidden state h t−1 and the current input x t , and b f is the forget gate bias.
To minimize the impact of bias in RNNs, it is important to carefully consider the training data used to develop the network and to use representative and unbiased data [34].To verify that the network is producing accurate predictions, tracking the network's performance over time and modifying weights is crucial In ( 14) i t is a input gate activation and calculating the sigmoid function σ , which determines how much of the new input information x t should be let into the cell state c t at time step t.The variable i t ranges from 0 to 1, where 0 means that no information from the current input x t is let into the new cell state c t , and 1 means that all of the information from Authorized licensed use limited to the terms of the applicable license agreement with IEEE.Restrictions apply.
x t is let in.In the context of IoT and service discovery, this can be used to incorporate new information obtained from IoT sensors into the RNN model to make predictions about future events or states.W i is typically used to represent the weight matrix of maps concatenation of the previous hidden state and the current input to the current hidden state h t−1 .For example, considering an IoT application that uses sensor readings to predict air quality levels in a city.The concatenation of the previous hidden state and the current input could include information about the air quality levels at previous time steps and other factors that could affect air quality, such as temperature, humidity, and wind speed.The weight matrix W i could then be used to map this concatenated input to the current hidden state, allowing the RNN to learn patterns in the data and make predictions about future air quality levels.b i represents the bias term for the input gate.The bias term allows the network to learn a shift in the activation function, which can be useful for improving the model's predictions.The value of b i is learned during training and can be modified through backpropagation to minimize the error between the predicted output and the actual output.In the context of IoT service discovery, the value of b i would be specific to the problem being addressed and would be optimized during the training process to improve the accuracy of the model's predictions.W c represents the weight matrix of candidate hidden state.The candidate hidden state represents the updated state of the system based on the current input and the previous hidden state.The tanh activation function maps its input to the range of [−1, 1], which makes it particularly well suited for use in RNNs.b c is a learnable parameter that helps adjust the candidate's hidden state and improve the accuracy of the model's predictions.It helps to shift the activation function of the tanh nonlinearity to better fit the input data, leading to better performance of the RNN model.C t is the updated value of the memory cell at time step t The current hidden state h t is computed by multiplying o t and the hyperbolic tangent of c t .The output gate activation o t is a parameter in the LSTM network used for processing sequence data.
Normalization is a typical preprocessing step RNNs for IoT service discovery.Normalization helps to standardize the input data and to ensure that the input values are within a consistent range [35].This can help to prevent numerical instability and improve the performance and accuracy of the RNN.LSTM is being used to update the hidden state of the RNN at each time step t.The LSTM processes is used input gate, forget gate, and output gate, which allow it to selectively remember or forget information from previous time steps and update the hidden state based on the current input [36].Normalization is typically performed on the input data before it is fed into the RNN and can significantly impact the network's performance and accuracy.By normalizing the input data, it is possible to improve the robustness and stability of the network and to ensure that the network is making accurate predictions for IoT service discovery where t = 1, 2, . . ., n (18) where x i−1 t refers to the input data for time step t in the (i−1)th iteration.
LN is a technique that can be used to normalize the inputs to each layer of a neural network, which can help to improve the training and performance of the network.The function of LN is to normalize the inputs to each layer of the RNN by subtracting the mean and dividing by the standard deviation of the inputs.This can help to reduce the impact of differences in scale and distribution between the input features, which can improve the training and performance of the RNN, where x i t represents the output of the normalization layer at time step t in the ith iteration, h i t represents to the hidden state of the RNN at time step t in the ith iteration.At the end input h The following equations describe the normalization at the t time instant: The above expressions represent mathematically the normalization layer applied to the hidden state of an RNN, with the normalization function being a combination of three functions f , g, and the activation function .The function f scales the hidden state h t .g is a trainable scale parameter, and μ t is the mean of the hidden state h t .The activation function is applied elementwise to h t − μ t , and b is a trainable bias term.H demonstrates the hidden components in LSTM.The hidden state is a vector that represents the output of the LSTM at a particular time step, while the cell state is a vector that represents the internal memory of the LSTM.Fig. 2 shows the normalization steps in RNN.
After discovering the services, the BWO algorithm combines this service for answering the user's demand.In the context of IoT service composition, BWO can be used to find the optimal combination of services that meet the requirements of a given system.The algorithm simulates the behavior of a black widow spider in selecting its prey by exploiting the attractive and repulsive forces between different services.The attractive forces represent the benefits of selecting a particular service, while the repulsive forces represent the costs or limitations of that service [37].The BWO algorithm starts with a population of candidate solutions, each representing a different combination of services.The algorithm then evaluates the fitness of each candidate solution using a fitness function that takes into account the attractive and repulsive forces.The best candidate solutions are then selected as "spiders" and used to Authorized licensed use limited to the terms of the applicable license agreement with IEEE.Restrictions apply.explore the search space.Over time, the algorithm iteratively improves the candidate solutions until an optimal combination of services is found.
Equation (24) shows the initial solution of the BWO population.The jth request for the service composition and ith "spider" might have the following random (rand) initialization function: where S lbi and S ubi are the initial and final available services.SS i determines the available service in the set of services for the user's demands.rand() is a random number generated within the range [0,1].In the context of service discovery in IoT, SS i represents the set of available services that meet the user's demands for service i.This set can be determined mathematically based on the user's requirements and the QoS metrics of the available services.For example, if a user requires a service that provides a response time of less than 1 s, and there are three available services with response times of 0.5, 1.2, and 1.5 s, then SS i would be the set containing the first service that meets the user's response time requirement.The mathematical definition of SS i could be expressed as follows: let S = {S 1 , S 2 , . . ., S n } be the set of available services, and let QoS sj = {q 1 , q 2 , . . ., q m } be the vector of QoS metrics for Service sj .The user's demands for service i can be specified as a vector d i = {d i1 , d i2 , . . ., d im } of desired QoS metrics for service i.Then SS i , the set of available services that meet the user's demands for service i, can be defined as We consider both positive and negative QoS requirements and each spider is assigned a place for adjusting value based on the service level agreement (SLA).Additionally, the user's priority has to be indicated in the fitness function.Equations ( 25) and (26) show the positive and negative QoS criteria, respectively.These QoS must be used to normalize as follows: where c − i and c + i represents the QoS of ith services and Sq − i , Sq + i are QoS limitations determined in the SLA.Positive QoS criteria should be increased while negative QoS criteria should be decreased in order to prevent SLA.In calculating the fitness values, we also need to take the into account the user's preferences.
Parameter ∂ i represent the sensitivity of the cost function concerning the predicted QoS metrics and is used to update the predicted QoS metrics to improve the overall performance of the system.c i represent the learned weights in the BWO algorithm, which are used to extract meaningful features from the input data.f (BWO) is the fitness function of services and select the optimal combination that meets the user's QoS requirements, where o is the quantity of QoS requirements.The suggested algorithm aims to find composite services with a high-fitness value.Equations ( 27) and ( 28) represent the fitness function as follows: The positions of the "spider" and the considering food are essential for the best composition answers.
Algorithm 1 shows the service discovery composition using the RNN and BWO algorithm.

IV. EXPERIMENTAL RESULTS
The proposed method is compared to various algorithms, such as GQSC [21], ANN-PSO [22], DRL [23], and ML [24] algorithm, which is mainly used for service discovery and composition.All algorithms showed identical fitness values for all data sets.The study examined the variables and their amounts, as well as the simulation factors and outcomes.

A. Characteristics of the Data Set
Our urban context-based approach was evaluated using the Cooja simulator for mobile applications.We used a simulated smart city environment where service providers and citizens interacted with a network of gateways that managed services.Providers, citizens, and gateways could be either static or mobile, and the gateways could perform service registration, distribution, and discovery.We implemented the overlay maintenance process for both models to adapt them to the large and Authorized licensed use limited to the terms of the applicable license agreement with IEEE.Restrictions apply.11), ( 12)); Pass the hidden state through the fully connected layer to get the predicted output for this time step (Eq.( 14)-( 18)); Normalization data (Eq.( 19)-( 22   points of interests (POIs) and their domains as a reference.
Each POI is automatically annotated with domain information based on its location and tags in open street maps.City services are defined using Dublin POIs [38] and their domains.
The simulation is based on Dublin city and includes 500 gateways, of which 250 are mobile and 250 static.The experiments were conducted with different numbers of services, and various parameters were varied for each approach [38].Table II summarizes the essential information for the setup, while Table III presents the parameters used for training.

B. Results
The study's results revealed essential insights into the performance of various algorithms used for service discovery and composition in IoT.Specifically, the developed RNN-BOW algorithm performances were compared with other popular techniques, such as GQSC, ANN-PSO, DRL, and ML techniques.In addition, the study focused on a range of performance metrics, including the rate of solved requests, average availability, reliability, cost, energy consumption, and latency.The distinct performance attributes observed in our study for the RNN-BOW, GQSC, ANN-PSO, and DRL algorithms can be traced back to their unique computational architectures and operational principles.Our proposed method, the RNN-BOW algorithm, capitalizes on the predictive prowess of RNN for forecasting the QoS and synergizes it with the BWO to enable effective service composition.This combination propels the RNN-BOW to outperform the other algorithms Authorized licensed use limited to the terms of the applicable license agreement with IEEE.Restrictions apply.
on certain metrics, such as the rate of solved requests and reliability.However, our algorithm's and others' performance characteristics are influenced by the diversity and distinct QoS attributes of the IoT services in our data set.This aspect needs to be taken into account.The superior performance of the RNN-BOW on certain metrics comes with tradeoffs.While its integrated structure allows for efficient modeling and predicting of the diverse service characteristics, resulting in improved reliability and solved request rate, this comes at a cost.The increased computational demands and resources necessitated by the two-pronged RNN-BOW approach lead to a rise in energy consumption and overall costs.
Furthermore, the role of hyperparameters in the performance of the algorithms should be noted.Different settings, particularly within our proposed method's RNN and BWO components, could influence learning rates, the number of epochs, and the balance between exploration and exploitation in the BWO.These results bear practical implications for real-world IoT service discovery and composition scenarios.While the high reliability and success rate of the RNN-BOW algorithm make it a compelling choice for applications where these factors are crucial, its higher energy usage and costs must be considered.More straightforward algorithms, such as ML or DRL, could be better suited for applications where energy efficiency or cost-effectiveness are primary considerations.Therefore, understanding the inherent tradeoffs and mapping them to the specific requirements of IoT applications can guide us in making more informed algorithmic choices.
The integrated nature of the RNN-BOW increases computational demands, which results in a spike in energy consumption and overall costs.The implications of these findings extend to real-world applications of IoT service discovery and composition.RNN-BOW's high reliability and solved request rate make it a strong contender for applications where these factors are critical.But its higher energy consumption and costs may be a deterrent for scenarios where energy efficiency or costeffectiveness are crucial, suggesting that simpler algorithms like ML or DRL could be more suitable.This underlines the importance of understanding these tradeoffs to make informed decisions when choosing an algorithm for specific IoT applications.Additionally, the effect of hyperparameters on the performance of algorithms, especially in our method's RNN and BWO components, cannot be ignored.Variations in these settings can impact learning rates, the number of epochs, and the balance between exploration and exploitation in the BWO, thus influencing the overall performance.Analyzing these metrics allowed us to identify the strengths and weaknesses of each algorithm and compare them against each other.Fig. 3 shows the performance of different algorithms for IoT service discovery and composition, based on the percentage of successfully solved requests.The y-axis, which ranges from 0% to 100%, shows the proportion of successfully resolved requests, while the x-axis indicates the number of services.The proposed method has the best performance, with a success rate of 0%, 40%, 60%, 70%, 75%, and 80% for 20 000, 40 000, 60 000, 80 000, and 100 000 services, respectively.The "ML algorithm" has a success rate of 0%, 35%, 55%, 65%, 68%, and 72%, respectively.GQSC has lower percentage of performance largely depends on the quality and quantity of training data available.On the other hand, DRL, a subfield of reinforcement learning that integrates deep learning, excels in situations where a clear reward signal can be maximized over time.The ANN-PSO algorithm's ability to optimize complex systems can be utilized in IoT service discovery.In contrast, the GQSC algorithm's quantum-inspired metaheuristic approach offers a unique perspective on the IoT service discovery problem.The primary objective of the study was to assess the efficiency of the RNN-BWO algorithm in IoT service discovery and composition within the context of smart cities.The results confirmed the superior performance of this model in meeting user service requirements across a wide range of network conditions.Despite its superiority, the algorithm's high-computational demands lead to increased energy consumption and costs, creating a significant tradeoff that needs careful consideration.It was also discovered that the performance of the RNN-BWO algorithm is heavily influenced by hyperparameters, indicating potential areas for future research to optimize these parameters.

V. CONCLUSION
The IoT-based smart cities can significantly enhance the quality of life for their citizens by leveraging advanced technologies, such as sensors, connectivity, and automation to optimize infrastructure, services, and sustainability.Service discovery and composition in IoT-based smart cities are crucial for meeting the changing requirements of citizens and ensuring that the services selected meet their QoS expectations.This article introduces a novel approach for solving the service composition problem in IoT using RNN and BWO algorithms.The system uses RNN-LSTM to predict the QoS of different services and, then, employs the BWO algorithm to combine them in order to satisfy the user's request.The use of RNN and BWO algorithms leads to higher accuracy in service composition, which can enhance the overall performance of IoT systems.The study evaluated a simulated smart city environment using an urban context-based approach with various parameters and performance metrics, including rate of solved requests, reliability, cost, energy consumption, and latency.The simulation results revealed that the method proposed in this work performed well for important metrics, such as latency, reliability, availability, and solved requests, indicating its effectiveness in IoT service discovery and composition.However, the method achieved higher energy consumption and cost, suggesting that more research may be needed to optimize these factors for practical implementation in real-world scenarios.In the future, it would be interesting to test the proposed approach in a real smart city environment to validate the simulation results.Additionally, deep learning techniques could be used to improve the accuracy of QoS prediction further, and metaheuristic algorithms could be explored to optimize the composition process.Finally, new metrics for evaluating energy consumption and cost could be introduced to make the proposed approach more efficient and cost-effective.

Fig. 1 .
Fig. 1.Service discovering and composition in smart city.

TABLE I PROS
AND CONS OF RELATED WORKS

Algorithm 1
Pseudo Code of Service Discovery: A Fusion of RNN and BWO Algorithm Input: Historical service data, Users need QoS, Number of services, Number of users (Eq.(10)); The simulations were run on a Linux OS, Corie i7 Intel Processor, and 32 GB of RAM.The service, which falls under the government and planning domain, generates a street dashboard based on inputs of street video, temperature, and water level.The service uses Dublin