## 2 Algorithm
### Phase 2: Estimated Location Refinement  
After phase 1, a coarse location estimate of all sensor locations is provided. Applying the same spring-relaxation technique in a different domain, phase 2 works on phase 1 estimates to refine the results in a cooperative way. In phase 2, \(Sensor_{i},i\in\mathbb{S}\) ranges to \(Node_{p},p\in\mathbb{S}\cup\mathbb{B}\), _i.e._, not only visible beacons but also neighboring sensors, to adjust cooperatively their locations according to the net force exerted. It is expected that with the contribution of location information from its neighboring sensors besides that from its visible beacons, a sensor will refine its location estimate in this phase. Meanwhile, similarly to the robot equipped with odometric equipment that moves around to provide appropriate initial coordinates to beacons that discussed in [20], the constant presence of beacons in known locations will impose constrains or rigidity on the available room for force-directed optimizations, and thus avoids the convergence to severe false minima. During the algorithm execution, each sensor will receive position updates from its neighbors, and broadcast its newly updated position to its neighbors. In lightly utilized networks, sensors can manage to use the idle channel to broadcast their position information. In heavily utilized networks, sensors can piggy-back their position information to on-going transmissions. In other words, bandwidth consumption is not a critical issue for the algorithm. ```
//For \(Sensor_{i}\)  INPUT: received signal strengths \(s_{i,p}\), estimated distances \(d_{i,p}\), \(\overrightarrow{V_{p}}\) (including beacon locations \(\overrightarrow{V_{j}}\) and phase 1 estimate of \(\overrightarrow{V_{i}}\))  OUTPUT: phase 2 refined estimate of \(\overrightarrow{V_{i}}\) \(\overrightarrow{F_{i}}=\tau_{2}\) while\(\parallel\overrightarrow{F_{i}}\parallel\geq\tau_{2}\)do \(\overrightarrow{F_{i}}=0\) for all\(Node_{p}\)do if\(Node_{p}\) is visible to \(Sensor_{i}\)then \(\overrightarrow{F_{i,p}}=(d_{i,p}-\parallel\overrightarrow{V_{i}}- \overrightarrow{V_{p}}\parallel)\times u(\overrightarrow{V_{i}}- \overrightarrow{V_{p}})\) \(\overrightarrow{F_{i}}=\overrightarrow{F_{i}}+\overrightarrow{F_{i,p}}\) endif endfor \(\overrightarrow{V_{i}}=\overrightarrow{V_{i}}+\delta_{2}\cdot\overrightarrow{F _{i}}\)  Update the \(s_{i,p}\), and \(d_{i,p}\) endwhile
```  
**Algorithm 2** Estimated Location Refinement  
Algorithm 2 describes the procedure for \(Sensor_{i}\) to obtain a more accurate location estimate by refining the coarse location estimate from phase 1. Since phase 2 is also based on the spring-relaxation technique, the algorithm also possesses two design parameters where one describes the tolerance, \(\tau_{2}\) and another describes the step size, \(\delta_{2}\). Due to different consideration in the design, phase 2 shall use a different setting for the parameters. In details, since the second phase follows a cooperative approach, a sensor will gather information not only from visible beacons, but also from other neighboring sensors for the location estimation. With the spring-relaxation technique for localization, the contribution of thenet force is much higher for a cooperative approach than that of a non-cooperative approach used in Algorithm 1. Thus, an appropriate setting for Algorithm 2 is where \(\tau_{2}>\tau_{1}\). In this phase, the algorithm updates the signal strength and estimation location in every iteration. Due to the noise in the signal strength measures, this constant update causes fluctuation in the computed location. A tighter control in \(\delta_{2}\) is necessary in this phase to maintain the stability of the location estimation. A study on the stability of the location estimation and the influence by \(\delta_{2}\) is given in the following analysis and simulation. Algorithm 2 can be executed in a continuation manner by excluding the terminate expression of the _while_ loop.