## 1 Introduction  
With the development of the Internet of Things (IoT), WSNs have become a primary technology for monitoring railway tunnels [1, 2, 3]. WSNs consist of numerous sensors with sensing, computing, and communication capabilities [4, 5, 6, 7, 8]. During monitoring, nodes are randomly deployed within the railway tunnel and periodically send data to the base station. Since internal batteries supply the energy for sensors, nodes will fail once the battery is depleted [9]. Therefore, if energy consumption is imbalanced in the network, nodes may fail prematurely, leading to the network's death [10].  
Researchers have conducted extensive studies to address this issue. One approach involves clustering the network, where many nodes are divided into multiple clusters, with specific nodes acting as cluster heads. These cluster heads are responsible for forwarding data to the base station, reducing direct communication between nodes and the base station, lowering network energy consumption, and extending the network lifespan [11]. The key to clustering lies in how to elect cluster heads [12], and current methods mainly rely on factors such as the remaining energy of nodes and the distance to the base station for election [13, 14]. Furthermore, researchers have designed routing protocols to identify the optimal paths for data transmission, aiming to reduce energy consumption [15, 16, 17].  
In most cases, when monitoring railway tunnels, the nodes are arranged linearly, resulting in a linear topology known as an LWSN [18, 19]. Compared with other types of WSNs, LWSNs exhibit fewer data transmission paths and lower network reliability due to their unique linear structure. Even the failure of a few nodes can lead to network disruption, especially in high-security railway tunnel monitoring scenarios. Therefore, traditional clustering and routing protocols based on WSNs are unsuitable for LWSNs. This paper proposes a self-organizing network and routing method based on an LWSN. After discovering the network topology, this method balances network energy consumption by optimizing network clustering and routing.  
The main contributions of this paper are as follows:  
1. Network topology discovery is achieved using a small number of anchor nodes. By the triangular relationship between two anchor nodes and an unknown node, the position of the unknown node can be uniquely determined. We also identify the minimum number of anchor nodes required, reducing packet redundancy and network costs;
2. Set different communication radii for nodes to achieve unequal clustering, reducing the reconstruction energy of clusters closer to the sink. Moreover, a timing mechanism is used to select the optimal cluster head;
3. In routing, cluster heads closer to the sink transmit data directly to the sink in a single hop, and cluster heads further away from the sink calculate a selection value based on the energy factor, distance factor, and load factor of candidate cluster heads. Based on the computed selection values, choose the next-hop cluster head for multi-hop transmission.  
The remainder of this paper is organized as follows. Section 2 summarizes the related work. Section 3 introduces the system model of this study. Section 4 provides a detailed description of the implementation of the self-organizing method, including network topology discovery and clustering. Section 5 elaborates on the design details of the routing protocol. Section 6 compares the proposed method with the existing routing protocols. Section 7 concludes the paper.