Wireless Sensor and Actuator Networks (WSANs) employ mobile nodes in addition to stationary tiny sensors. Similarly, mobile sensors make it possible to have the flexibility of mobility in mobile sensor network (MSN) applications. Mobility can be exploited to connect partitioned WSANs and MSNs due to large scale damages or deployment problems. However, since mobility consume significant energy and it can be limited due to terrain constraints, the travel distance for the mobile nodes should be minimized in such a recovery effort. In this paper, we present a mathematical model which minimizes the total travel distance for connecting a given number of partitions. The idea is based on network flows and the problem is modeled as a mixed integer nonlinear program. The nonlinear terms in the model are linearized using a polygon approximation for computational efficiency. We evaluated the performance of the proposed approach in terms of total distance as well as the time to reconnect the partitions. The results show that our approach outperforms the heuristic approach in terms of total distance and delay and reveals various trade-offs involved in connecting multiple partitions.