Introduction

Simple and low-cost sensors with limited processing power have gained significant popularity, especially in industrial and commercial systems, notably in Internet of Things (IoT) and Industrial IoT applications. These sensors are often used for detecting specific conditions and environmental monitoring, such as patient health monitoring1,2,3, early fire detection4, agriculture5,6 or UAV recognition7. One of the main advantages of these sensors is their low price and scalability, allowing for widespread deployment to create a network of precise data collection points8,9.

Sensors (e.g., DHT11 and MQ-2) are well-suited for simple and low-cost applications in IoT systems, providing reliable environmental data for temperature, humidity, and gas detection. These sensors are extensively used in healthcare monitoring, industrial applications, and fire detection systems. For example, heart rate and blood oxygen sensors (e.g., MAX30100) are used in healthcare systems for real-time patient monitoring. The system employs ESP8266 microcontrollers and Arduino boards to connect the sensors to networks for data transmission and processing10. These components are ideal for large-scale IoT projects, offering scalability to manage numerous sensors while maintaining low power consumption and efficient data communication. Block diagrams and flowcharts are included to illustrate the sensor-to-gateway communication flow and data aggregation, ensuring a clear understanding of the system’s architecture and its ability to scale effectively across various applications11,12,13.

Low-cost sensors and wireless networks play a critical role in healthcare systems, particularly for real-time localization and tracking of patients and medical equipment14. These technologies offer significant advantages in large hospitals and clinics, where efficient resource management and patient monitoring are crucial15. By deploying sensors or wireless tags, healthcare providers can track patients’ movements within the facility, ensuring timely interventions when needed. For instance, patients with Alzheimer’s conditions can be monitored and localized. Additionally, these systems are used for tracking essential equipment such as hospital beds, oxygen tanks, and wheelchairs. By leveraging low-cost sensors, healthcare facilities can improve efficiency, particularly in managing the movement of patients and medical assets in real-time.

Through observation, we have found that constructing corners of the shapes forging to reconstruction of binary images with disjoint components is an important problem16,17. This challenge can address many challenges in different fields such as accurate clustering of IoT devices in Industrial IoT (IIoT) ecology, digital/graphical games and so on. For all these applications, if we check them carefully, we would find that the main issue stems from the fact of detecting the minimum number of noises which could be removed and caused construction of some separate components.

To achieve our goal, as Fig. 1 illustrates, we consider an Industrial IoT environment where IIoT devices have spread in a field that tracks a UAV. In our scenario, IIoT devices are represented by + and - symbols, indicating the longitude and latitude of the moving autonomous vehicle (AV), respectively. In our scenario, two Convex Hulls have been created due to the existence of two kinds of IIoT devices. These convex hulls overlap, which also has a negative effect on the clustering issue of IIoT devices. They, generally, are without much complexity in a way that different sensing aspects can be applied in these systems to various targets such as temperature, light, sound, etc. The devices which generate information as little as one bit at each time result in providing inexpensive communication.

Fig. 1
figure 1

IIoT ecology where devices have shaped two Disjoint Convex hulls with overlap.

The goal is to minimize the number of IIoT devices required to achieve disjoint Convex Hulls, enabling accurate clustering.

In our scenario, each IIoT device detects and transfers one bit of information to the base station. These kinds of problems can be formulated as follows18. Having a set of m binary devices \(S = \{S_1,S_2,...,S_m\}\) with the consideration of a single sample \(s\in \{-1,+1\}^m\) of data, produced at time t. The following lemma illustrates an approximation for the location of the tracked UAV which is outside the convex hulls of both plus devices and minus devices.

Lemma 1

Let \(s \in \{ -1, +1 \}^m\) be a sample of the device values and X(t) be the location of the target UAV at the time t. Let \(A = \{S_i | s_i = +1 \}\), \(B = \{S_j | s_j = -1 \}\), and CH(A) and CH(B) their convex hulls. Then \(CH(A)\cap CH(B)=\emptyset\). Furthermore, \(X(t) \not \in CH(A) \cup CH(B)\)18.

This application enables the definition of new geometric problems, the logical versions of which are \(NP-hard.\) The “Almost 2SAT” problem, which serves as the foundational problem in this paper, is NP-hard. However, we do not attempt to solve this problem in its general form. The main contribution of this paper is the definition and solution of its geometric variant. In this work, we prove that when the problem is constrained to geometric data, it no longer remains computationally intractable, and we are able to solve it by a polynomial-time algorithm. Furthermore, we present two algorithms and discuss their details.

Section “Two disjoint convex hulls” includes some subsections which represents results19 about these logical problems. In the next subsection, a new problem related to the convex hull is introduced, which is applicable to shape modeling and the IIoT environment, which we will solve it in polynomial time. As a result, a naive \(O(n^3)\) algorithm is also presented, and in the next part, to address this issue, we propose a novel solution which is \(O(n^2)\). Finally, Section “Conclusion and future work” concludes this study and suggests several open problems.

Two disjoint convex hulls

As it is mentioned before, this problem is similar to a version of \(2-SAT\) problem, which would be discussed in the following.

Variable deletion almost \(2-SAT\)

There are some basic hard problems in computational complexity, which are \(NP-hard\). Although \(2-SAT\) problem belongs to class P, some versions of that like “Max \(2-SAT\)”, “Almost \(2-SAT\)” and “Variable Deletion Almost \(2-SAT\)” are all \(NP-hard\). The last problem is known in theoretical computer science under the terms \(Almost 2-SAT\), \(All-but-k\) \(2-SAT\), \(2-CNF\) deletion, and \(2-SAT\) deletion20.

In the “Almost \(2-SAT\)” problem, there are a \(2-CNF\) formula \(\phi\), an integer k, and the question of whether one can delete at most k clauses from \(\phi\) to make it satisfiable. In “Variable Deletion Almost \(2-SAT\)” (variable-deletion variant), instead, it is allowed to detect at most k variables. Each variable is deleted along with all clauses containing it. One can think of deleting a variable as setting it both to true and false at the same time. These two problems are NP-hard, and in this regard, the following lemma has been proved19,21.

Lemma 2

Variable Deletion Almost \(2-SAT\) can be solved in \(4^kn^{O(1)}\) time.

The main problem

Detecting and testing the intersection between objects are among the most important applications of computational geometry in the Network domain. This problem has many other applications in text mining, and NLP in which we need to separate the given data set into some disjoint subsets22. It is one of the main questions addressed in Shamos’ article that lays the groundwork for computational geometry23, the first application of the plane sweep technique24. It is hard to overstate the importance of finding efficient algorithms for intersection testing or collision detection as this class of problems has many applications in Robotics, Computer Graphics, Computer-Aided Design, and VLSI design25,26,27. In the plane, Shamos23 presents an optimal linear algorithm to construct the intersection of a pair of convex polygons. Another linear time algorithm is later presented by O Rourke et al.28.

For the testing version of the problem, Lemma 3 has been proved29.

Lemma 3

Let P and Q be two convex polygons with n and m vertices, respectively. The 2D-algorithm determines if P and Q intersect in \(O(\log n + \log m)\) time29.

As discussed earlier, the problems are applicable to binary sensor networks and target tracking. Assume that some of the sensors do not work properly in a binary sensor network; these sensors send incorrect signs. Clearly, if two convex hulls overlap, it means that some of the sensors are making mistakes (Fig. 1), but the reverse is not necessarily right.

In some applications, the minimum sensors are ignored because they are prone to make a wrong sign at the moment. This problem is summarized as Problem 1.

Problem 1

Minimum Sign to Remove There are a plus set \(P_1\) and a minus set \(P_2\) of points on the plane. For an integer \(K\le min\{|P_1|, |P_2|\}\), are there K points in \(P_1\cup P_2\) whose removing yields two disjoint convex hulls for \(P_1\) and \(P_2\)?

At first glance, it seems that the problem is \(NP-hard\) and structurally very similar to Variable Deletion Almost \(2-SAT\) problem. For some geometric reasons, however, the problem can be solved in polynomial time. The following observations can be considered easily about two disjoint convex hulls of given points in the 2D plane.

Observation 1

For two given sets A and B of points in Problem 1, the minimum points which should be removed might be located outside of \(CH(A)\cap CH(B)\) (Fig. 2).

Observation 2

Removing each pair of points on convex hull forces to remove all the points between them (either clockwise or counterclockwise), which are on the convex hull (Fig. 3).

Observation 3

If we know the regions containing only plus (minus) signs, the problem may become simpler (Fig. 4).

Fig. 2
figure 2

Removing only two (minimum) IIoT devices yields two disjoint convex hulls.

Fig. 3
figure 3

Removing points (a) and (d) forces to remove either (e) or (b, c).

To decide whether two convex polygons are intersecting, the Separating Axis Theorem can be used30,31. Clearly, for two not-intersecting convex polygons, there exists a line passing between them. Obviously, such a line exists if and only if an edge of one of the polygons forms that line. The closest point of this line to the other polygon is one of its corners which is closest to the first polygon (Fig. 5). This edge will then form a separating axis between the polygons. And also, if two middle edges of two polygons are parallel, both of them are separating axes. These are summarized in Lemma 4, and the idea has been used in the algorithm of this study30,32.

Lemma 4

(Hyperplane Separation Theorem) Let A and B be two disjoint nonempty convex subsets of \(R^n\). Then there exist a nonzero vector v and a real number c such that \(<x, v> \ge c\) and \(<y, v> \le c\) for all x in A and all y in B; i.e., the hyperplane \(<., v> = c\), v the normal vector, separates A and B30.

Fig. 4
figure 4

All the sensors in region A (B) are plus (minus) and we can remove only from region C.

Fig. 5
figure 5

Dividing axis for two convex hulls.

For every two arrays \(A_{2*n}\) and \(B_{2*m}\) of points in the plane, Algorithm 1 computes a cost for each line segment made by a pair of points. It chooses the pair with the minimum cost and returns the points that should make the separating axis. As a result, the minimum number of removing signs (plus or minus) of Problem 1 will be represented. So, a glance at the algorithm reveals that Theorem 1 is clear.

Algorithm 1
figure a

A Naive Algorithm for Two Disjoint Convex Hulls

Theorem 1

Algorithm 1 solves Two Disjoint Convex Hulls in \(O(m+n)^3.\)

An \(O(m+n)^2\) algorithm

As mentioned earlier, in this section, a new fast algorithm is presented for the problem that uses the duality of given points. As illustrated in Fig. 6, if the dual space is drawn, \((m+n)^2\) regions appear in which \(m=|A|\) and \(n=|B|\). In order to find the optimal line \(l_{opt}\) in the primal space, an optimal cell \(cell_{opt}\) and a point \(v_{opt}\) in it should be found in dual space that \(v_{opt}\) demonstrates the dual of \(l_{opt}\) which has been depicted in Fig. 9.

Fig. 6
figure 6

Primal Plane, red points \(\{r_1, r_2,..., r_7\}\) and blue points \(\{b_1, b_2,..., b_8\}\).

For this purpose, firstly, the dual line of all the given points in A (plus signs) and B (minus signs) is drawn in the dual space. Red and blue colors are assigned to dual lines of set A and B, respectively (Lines 2–3). There appear \(O(m+n)^2\) segments and half-lines in two colors in the dual space. The dual space is stored in a Doubly Connected Edge List (DCEL) in which the edge list contains the color of every edges as well. This process takes \(O(m+n)^2\) time. At this time, a planar graph G(VE) (Lines 4–6) can be generated as follow. The starting cell to which vertex \(v_1\) is assigned to that is the cell above the upper envelope (Fig. 7). A vertex \(v_i\) is assigned to every other cell in any order. There is an edge between two vertices if those are adjacent, so E contains all the edges between every two adjacent vertices (Line 6) (Fig. 8). The resulting graph has \(O(m+n)^2\) vertices and edges, each of which processes once (Fig. 9).

Fig. 7
figure 7

Vertex \(V_1\) is assigned to the starting cell in the upper envelope.

Fig. 8
figure 8

Every other cell is labeled in any order and there is an edge between two vertices if and only if their corresponding cells are adjacent.

Fig. 9
figure 9

Dual plane of Fig. 6, dual of points (lines) and a black point in a region that separates blue and red lines with minimum error (only \(D(b_7)\) and \(D(r_8)\) are at the wrong side of black point.

The next step is computing a pair of numbers \(w_1\) and \(w_2\) as weights of the vertices (7–25). Firstly, set \(w_1(v_1)=m\) and \(w_2(v_1)=0\), then set weights of the adjacent vertices according to the segment between them, so that if the segment is red decrease \(w_1\) without any change in \(w_2\) and if the segment is blue reduce \(w_1\) and \(w-1\) stay without change. Therefore, for each vertex v, \(w_1(v)\) and \(w_2(v)\) show the number of red lines under v and the number of blue lines above it respectively. Using a queue structure Q, the weight for all the vertices (Lines 8–25) is computed. In each step, when an unweighted vertex appears by crossing a red (blue) segment, \(w_1\) (\(w_2\)) is decreased (increased) by one. Computing the weight for a new vertex takes constant time; hence, in \(O((m+n)^2)\) time, the weighted planar graph can be computed in which the weights \(w_1(v)\) and \(w_2(v)\) demonstrate the red lines below and blue lines above the cell containing vertex v. In both sensor network applications and finding two disjoint convex hulls, if the separation line is the dual line of vertex v, then \(w_1(v)\) plus signs and \(w_2(v)\) minus signs should be removed. Algorithm 2 find the optimal vertex \(v_{opt}\) with \(min\{w_1+w_2\}\) and line \(l_{opt}\) in Lines (26–27) in \(O((m+n)^2)\) time. We can conclude all the results in Theorem 2.

Theorem 2

Let A and B be two sets of points in the plane, \(|A|=m\) and \(|B|=n\). Then Algorithm 2 finds the minimum number of removal points in order to have two disjoint convex hulls in \(O(m+n)^2\).

Algorithm 2
figure b

Two Disjoint CHs by Dual Space

Note to practitioners

This paper has been inspired by a real challenge in the world: imperfect IoT device detection. Specifically, the challenge stems from the fact that we need to leverage existing generated data of a variety of IoT devices to find imperfect ones. This problem literally is NP-hard which means there is no solution that can solve this issue in a logical polynomial time. In this paper, we have extracted the geometric version of IoT devices data forging an accurate and fast algorithm for it. We demonstrate that the geometric version of the problem is not NP-hard. To the best of our knowledge, this is the first study to address this complex challenge. Moreover, we address this geometric version through two novel fast algorithms for a large number of IoT devices in \(O(n^2)\). The achieved result demonstrates we can address this important challenge in a short time. To show the superior performance of our solution, we have implemented it in an IoT environment and evaluated it from several evaluation metrics.

Conclusion and future work

In this paper, we addressed the accurate clustering issue in the Industrial IoT environment by addressing a big challenge which is “Almost \(2-SAT\)” problem. In this case, at first, we have depicted it in a geometric environment. Then, we solved it via two different algorithms, while the first one is a naive and simple but slower approach with \(O(n^3)\) time complexity. However, the second algorithm uses dual space and is faster with \(O(n^2)\) time complexity. Beyond mathematical proof, we showed the effectiveness of our solution in the Industrial IoT environment. We showed that through our solution, we could remove the minimum number of IoT devices in the Industrial IoT ecology and perform accurate clustering of IoT devices.

As highlighted throughout the paper, the two algorithms presented in this paper fall within class P and exhibit polynomial computational complexity, ensuring high execution speed and making them suitable for real-time applications. However, the system’s scalability and adaptability to diverse healthcare scenarios could face limitations, particularly in environments with higher complexity or a larger number of IoT devices. While the algorithms perform well in real-time localization using low-cost devices, further optimization may be necessary to enhance their robustness and scalability in more demanding settings, such as large-scale hospital networks or disaster response scenarios. Future work will focus on improving system adaptability to various healthcare applications, optimizing the algorithms for even greater scalability, and addressing any constraints related to real-time performance. Additionally, future research may explore integrating advanced machine learning models to detect sensor malfunctions more effectively and expanding the system’s applicability to other fields, such as drones, wildfire detection, and smart city infrastructure.