# Two-Stage Optimal Task Scheduling for Smart Home Environment Using Fog Computing Infrastructures
## 1 Introduction  
The modern era of the Internet of Things (IoT) has made our world connected in a smarter way. Here, a thing can be a person with a wearable device, an animal with a biochip, or any device with a built-in sensor that can be associated with an IP address to transfer the data over a network. The IoT has become one of the most-important technologies of the 21 st Century by which we can connect our home appliances, workstations, cars, baby monitors, and many other devices to the Internet and communicate with them. The IoT connects billions of devices, human beings, and computing elements in order to make decisions and act accordingly. The IoT has started a new industrial revolution worldwide known as Industry 4.0, which has changed the entire manufacturing industry. The emerging 5G technology is the key to Industry 4.0. The high speed and low latency of 5G is very effective for automation, healthcare, media, and entertainment. 5G will be responsible for critical communication in real-time, which means that data can be accessed reliably and securely in a wireless manner. The concept of the IoT has existed for a long time, but the advancement of technologies such as low-power sensor technology, cloud computing platforms, artificial intelligence, and machine learning has resulted in hands-on experience for the IoT. Cloud computing platforms for storing, processing, and analyzing the datagenerated from a large number of connected devices became a great innovation for the IoT, but this has brought many challenges with respect to their centralized architecture [1,2]. Due to the huge demand of IoT devices and location-aware services, applications are generating amounts of data that are almost inconceivable [3]. It has been estimated that the cloud alone may not be sufficient to handle the big data generated by IoT devices with respect to time-critical or emergency situations. Thus, the concept of fog computing was proposed by Cisco in 2012 to cope up with these situations [4]. This emerging paradigm of fog computing lies between the cloud and end users (IoT devices) and aims to bring storage, networking, and computation close to the end users. Fog computing extends the cloud environment to the edge of the network. Although the cloud and fog use the same types of mechanisms (virtualization, resource provisioning, task scheduling, and many others) on the same kinds of resources (storage, computations, networking, etc.), still, there are few differences between them. The fog environment is suitable for many services and applications for which cloud computing does not support them well [4,5] such as: traffic light monitoring systems, healthcare monitoring systems, connected vehicles, smart cities, homes, and many others. Sending high-velocity data to the cloud leads to the congestion of the cloud infrastructure, which further leads to high latency and violations of the QoS.  
Thus, these delay-sensitive applications need to be processed at the edge of the network or near the end devices, rather than the cloud, in order to provide the guaranteed QoS related to the reduced latency, increased throughput, and high bandwidth. Fog computing plays a very important role in supporting rapid decision-making during these time-critical applications [6]. This study proposes a machine-learning-based resource scheduling in a fog-cloud environment considering smart homes as a case study. Figure 1 shows the fog-cloud architecture for smart homes. The fog computing architecture is divided into three layers [7]: The end device (IoT) layer contains the end devices such as smart phones, computers, vehicles, smart equipment, wearables, and smart home appliances. The second layer is the fog layer (middle layer), which includes fog devices such as gateways, routers, switches, and workstations. Finally, the third layer, i.e., the cloud layer, which is also known as the upper layer, contains high-speed computers, servers, and data centers.