1 Supplementary Material for the article: 2 3 Route optimisation and solving Zermelo’s navigation problem during long distance 4 migration in cross flows 5 Graeme C. Hays, Asbjørn Christensen, Sabrina Fossette, Gail Schofield, Julian Talbot, Patrizio 6 Mariani 7 Ecology Letters 8 9 Track analyses: We assumed that turtle motion is regulated by two components: (i) 10 swimming behaviour, and (ii) local ocean circulation. By combining individual swimming 11 velocity vector (w) and ocean surface velocity vector (u), we calculated the total velocity of 12 swimming turtles as: 13 v(x, t) = w + u 14 (Eq. S1) 15 16 17 The observed longitude and latitude (x, y) values along the trajectories of a turtle, x(t) , were used to calculate the velocity vector v using the equation: 18 v(x, t) = 19 R(x, t) Dt (Eq. S2) 20 21 where R is the vector for the distance covered between two consecutive points in time, 22 Dt = 4h . 1 1 We calculated u(x, t) through the linear interpolation of the tracks superimposed on 2 sea surface daily data at a spatial resolution of 1/16o using the Mediterranean Ocean 3 Forecasting System database (Pinardi et al. 2003; Tonani et al. 2009). 4 The swimming vector was then calculated as w(x, t) = v - u . Speed [ w º w ] and 5 direction [ q ] were used to analyse turtle swimming behaviour. To determine the relative 6 importance of local current circulation and turtle swimming behaviour in the observed path, 7 we projected u in the direction of w, using the equation: 8 9 Pu,w = u×w w 2 w (Eq. S3) 10 11 12 The above current speed is as defined negative if the angle uÙw > p . The vectors for the observed trajectories (v) were mainly directed southwest (Fig. 13 S1); however, other components following a north-northeast-northwest direction were also 14 present. The surface ocean currents interpolated on the tracks (u) were uniformly 15 distributed in all the directions while w peaked at around -110 oN (Fig. S1). 16 Turtle swimming speed has a Gaussian distribution with median w = 0.46 ms-1 , and 17 reached maximum values of w =1.0 ms-1 (Fig. S2). The projected ocean velocities ( Pu,w ) 18 appeared to follow a Poisson distribution, with a zero mean and a maximum magnitude of 19 0.2 m s-1 both with and against the swimming velocity (Fig. S2). 20 21 Simulations: We simulated individual trajectories using the modelled local surface ocean 22 circulation conditions and simple models for the behaviour of adult turtles. 23 24 For a single numerical particle, we integrated Eq. (1) with a fixed time step Dt = 4h using a Runge Kutta second order method. 2 1 Turtles are assumed to swim at a constant speed, w, toward the direction of an 2 assigned final destination, Xend º ( xend , yend , tend ) , matching the final position of the observed 3 trajectories, i.e. Xend Î x(t). Specifically, for each observed x(t) , we release numerical 4 particles in (xstart , ystart ,tstart ) Î x(t) , assuming a constant swimming speed and final target 5 Xend . Then the trajectory x S (t)was simulated until t = tend . 6 7 Computation of the travel distances: To assess the similarity between the observed track, 8 x(t) , and the simulated trajectories, x S (t), we calculated a set of distance metrics: (1) 9 Euclidean distance x ts - x t , (2) Hausdorff distance, and (3) straightness index distance. In 10 addition, we calculated (4) the theoretical migration time for each model (in days), and 11 compared those to the observed values. 12 All of the calculated distance metrics above, (1 – 3), were obtained after matching 13 the migration time for the observed and simulated tracks, using linear interpolation. For the 14 values of metric (3), we first calculated the straightness index (D/L, where D is the distance 15 between the final and starting point Xend - Xstart and L is the total path length travelled) for 16 x(t) and x S (t), then we computed the absolute difference between these two values. 17 Finally, the distances of metrics (1) and (2) were normalised by the total path length L. 18 Those geometric distance metrics are calculated for all the observed tracks (Fig. S3 a – h) 19 and the behavioural models considered in the study. 20 The values of (iv) are only showed for the simulations in which the behavioural 21 model reached the final destination, i.e. when the turtle headed directly toward target and 22 the Zermelo optimisation. 23 All of the algorithms for the analyses were developed in MATLAB© R2012. 24 25 3 1 2 Fig. S1. Distribution of the direction, q , for the three motion components: (i) ocean surface 3 velocity (u), and (ii) observed velocity (v) and (iii) turtle swimming velocity (w = v-u). 4 5 6 7 Fig. S2.Distribution of swimming speed (w) and surface velocity along the direction that 8 turtles swam ( Pu,w ). Note that the speed Pu,w has both positive and negative values, 9 which indicate whether the ocean surface velocity is with or against the swimming velocity. 4 Distance score 1 2 Fig. S3.Non-dimensional distance score for the eight observed turtle migratory tracks (a – h) 3 using the four different behavioural models: (i) heading to the goal, (ii) single heading (iii), 4 optimal Zermelo route, (iv) course correction. The three metrics shown are: distance in 5 straightness index (black bar), Euclidean average distance (grey bar), Hausdorff distance 6 (white bar), with the latter two normalised by the observed total length of the track. 5 1 2 Optimal swimming behaviour: A complementary approach for simulating behavioural rules 3 to explain the observed animal migration paths is the use of optimal behaviour models. 4 Such models shift the focus from the behavioural response mechanisms to the pay-off. The 5 major weakness of optimal behaviour models is the assumptions of (i) perfect knowledge 6 about the ambient conditions that influence the pay-off and (ii) perfectly adapted response 7 patterns to the behavioural problem. The major advantage of such models is that one avoids 8 the overt parameterisation of the behavioural rules. In this way, optimal behaviour models 9 indicate the upper limits of the pay-offs that might be achieved by adapting behaviour. 10 In the present study, the behavioural problem was formulated as a horizontal (i.e. 11 2D) travel problem between an observed initial point π0 and an observed final point ππΈ . The 12 subsequent sections present the mathematical and computational details of the 13 implementation of the models. In an optimal behaviour model the turtle chooses a travel 14 path between π0 and π±π that minimises a hypothesised cost functional. A functional is the 15 mathematical term for a function that takes a function as argument - in this case the 16 swimming path x(t). The cost functional is then the price the turtle pays when choosing x(t). 17 Examples of cost functionals include swimming time (corresponding to the original Zermelo 18 problem) or swimming energy expenditure. The behavioural scope of the turtle is to select 19 its swimming velocity vector (both speed and direction), π°(π‘), as a function of time along 20 the swimming path. Swimming velocity is understood with respect to water, so that the 21 effective velocity v in the earth coordinate system is v = u + w, where u is the local water 22 current vector. The challenge for the turtle is to use prevailing hydrographic current 23 patterns and variability optimally, by swimming along the current where possible and 24 avoiding swimming against the current, if not necessary. The minimisation of the cost 25 function is formulated in the time domain, and involves solving the corresponding Euler- 26 Lagrange equations, which are a set of coupled ordinary differential equations for π°(π‘). The 27 initial conditions of π°(π‘) must be reverse engineered so that the path ends at ππ¬ , given that 28 it starts at π0 . If only the swimming direction is variable or currents u are stationary, 29 additional mathematical transformations are possible to reduce the problem (Comincioli, 30 2004). This approach is technically challenging with time-varying currents, especially when 31 the behavioural scope has more than one dimension (e.g., swimming speed and direction). 6 1 Alternatively, the problem may be formulated in the space domain. In this case, the 2 problem is simplified by local optimality, which eliminates π°(π‘) from the problem (this is 3 elaborated on later in this text). In this approach, the optimal swimming path is obtained by 4 minimising the general functional: 5 6 ππ (Eq. S4) πΈ[π₯] = ∫ π (π(π‘), , π‘) ππ₯ ππ‘ 7 8 directly over all (valid) paths between π0 and ππΈ . Here, E is the overall cost functional and ε 9 is the corresponding local cost function (with unit cost per length) that depends on the ππ 10 pathπ(π‘), which is parameterised by time t and the effective velocity vector 11 vector with respect to a stationary coordinate system). The local cost function ε has clearly 12 delineated time dependence, because water currents vary with time. Computationally, this 13 approach involves relaxing a guessed initial path between π0 and ππΈ using an iterative 14 minimisation technique, in which the swim path is used as an independent variable. ππ‘ (i.e. velocity 15 16 Examples of cost functions: When the local cost function is: 17 1 π£ = 1 (Eq. S5) 18 π= 19 we resolve the Zermelo problem, where v is the effective velocity in the earth coordinate 20 system. Informally, since v=dx/dt, this means the integrand in Eq. S4 εdx = dx/v = dt is the 21 time used to travel a small piece dx of the travel path, so that the integral Eq. S4 sums up 22 the total travel time. To have a well-posed problem, the swimming speed w must be a 23 constant, so the turtle only has the option of swimming direction, otherwise minimisation 24 obviously leads to infinitely fast swimming speeds to achieve the minimal travel time. The 25 construction of the effective velocity v is indicated in Fig. S4a, where the swimming 26 direction is constrained by the preferred swimming direction t in the earth coordinate 27 system (corresponding to the local path tangent vector). Therefore, the positive solution w ππ | | ππ‘ 7 1 shown in Figure S4a represents the locally optimal swimming direction. In this way, by 2 applying local optimality, the cost functional does not depend on π°(π‘), but only the path 3 x(t). Figure S4b indicates the minimal cruising speed required to (i) cancel the transversal 4 current component, and (ii) acquire a positive definite effective velocity v along the path 5 tangent. This requirement is met by: 6 7 π€ ≥ √π’2 − π’2π‘ π€ ≥ |π’| π’π‘ > 0 π’π‘ < 0 (Eq. S6) 8 9 If this inequality is not satisfied, the cruising speed w is too small to allow the turtle to swim 10 in all directions locally, because the current is too strong. In this instance, a forbidden cone 11 of directions is present locally, which constrains how the travel paths may cross this area of 12 strong currents. Fig. S4c illustrates the construction of the effective velocity v when an 13 energetic cost function ε(w) with a positive slope is applied. This would normally be the 14 case, because travel cost is expected to increase with swimming speed, e.g. the water drag 15 force. In this case, to have a well-posed problem, a certain minimal effective velocity π£πππ is 16 required; otherwise, the minimisation of travel costs would obviously lead to an infinitely 17 slow swimming speed at path segments that oppose the current, which is biologically 18 irrelevant. In the case of the energetic cost functions, there is no imposed upper limit on 19 swimming speed w (only a high cost). In this case, there are no forbidden cones, as in the 20 Zermelo problem, with a constant cruising speed. Fig. S4d indicates the minimal cruising 21 speeds required to compensate the transversal current component, and to acquire a 22 positive definite effective velocity π£πππ along the path tangent. If a biological limit is imposed 23 on the swimming speed, this would be represented as a diverging cost at the limiting 24 swimming speed. In this case, there would also be forbidden cones in areas of very strong 25 opposing currents. In this work, we only focus on the Zermelo problem, Eq. S5, when 26 calculating the optimal travel path. 27 8 1 2 3 Fig. S4: Construction of the local optimal effective velocity v and minimal swimming velocity 4 w to realise swimming in the preferred direction t, when the current vector is u for the 5 Zermelo problem (a + b), where the turtle controls swimming direction, and the energetic 6 problem (c + d), where the turtle controls both swimming direction and speed. (a) The 7 decision circle for cruising speed w, with the arrow indicating optimal swimming direction. 8 (b) The minimal cruising speed w required to compensate the transversal current 9 component, and obtain the positive effective velocity v for swimming direction. (c) Local 10 optimal effective velocity when there is a required minimal effective velocity π£πππ . (d) 11 Minimal swimming speed w required to compensate the transversal current component, 12 and obtain the positive effective velocity π£πππ for swimming direction. 13 14 Minimising cost functions: When using numerics, the path integral Eq. S4 is evaluated by 15 sampling the travel path with nodes {xi}. In this study, around 20 nodes per travel path 16 provided sufficiently meaningful representation. Hence, the functional derivative of Eq. S4 9 1 was mapped onto a finite dimensional gradient with respect to the nodal points {xi}. For the 2 Zermelo problem, the travel time becomes: 3 πΈ = ∫ ππ‘ ~ ∑π−2 π=0 π(ππ , ππ+1 ) (Eq. S7) 4 5 where M is the number of nodes in the path and τ the time to travel between points xi and 6 xi+1. When the path sampling is sufficiently dense, it is assumed that the effective velocity v 7 varies linearly between ππ and ππ+1 . Under this assumption we can analytically calculate τ: 8 9 | ππ+π − ππ | ππ π£(π ) π(ππ , ππ+1 ) = ∫0 = |ππ+π − ππ | π£ ln( π£π+1 ) π£π+1 − π£π π (Eq. S8) 10 ππ 11 The spatial derivatives of τ also involve the current shear components 12 for v, constructed as indicated in Fig S4(a+c). A consistent choice for time points π‘π where the 13 turtle arrives to each node π₯π is: ππ via the chain rule 14 15 π‘π = π‘0 + ∑π−1 π=0 π(ππ , ππ+1 ) (S9) 16 17 which is used to interpolate the time dependent current vectors ππ = π(ππ , π‘π ) as elaborated 18 below. This update of the set of times {ti} also applies to the energetic cost functionals. In 19 the model implementations, we applied lazy update of the set of times {ti} above. This 20 means that π‘π is considered to be parametric when taking the derivative of τ in Eq. S9. Then, 21 the update of {ti} Eq. S9 is only performed after a minimisation step. This approach localises 22 the cost function, and simplifies the complexity and load of the gradient evaluation, because 23 the strict enforcement of Eq. S9 implies that a variation in ππ affects all points on the path 24 after i in Eq. S9. The self- consistency of the set of times {ti} is obtained through iterative 25 updates using Eq.S9 during the minimisation of the cost functional E, so that it converges 10 1 with the proper minimum. This approach is similar to the Car and Parrinello scheme (1985), 2 which simplified molecular dynamics in computational materials science. 3 To evaluate Eq. S7–S9, a smooth current field interpolation was needed for arbitrary 4 time and space points (x,t) in the Mediterranean. The current fields obtained from the 5 circulation model described in Methods are stored as gridded data ππππ = π(πππ , π‘π ) on a 6 regular longitude/latitude grid πππ at regular time intervals π‘π . Bilinear spatial interpolation 7 of π’πππ at arbitrary positions x was found to cause kinks in the gradients of the cost 8 functional (via current shear terms ππ), which hindered the minimisation of the cost 9 functional close to a minimum. Therefore, each time frame π‘π , ππππ was Fourier transformed ππ 10 spatially into πΌπππ , and the corresponding wave representation was used to generate a 11 smooth spatial representation: 12 13 π(π, π‘π ) = ∑ππ πΌπππ πππππ π (Eq. S10) 14 15 where {πππ } is the set of wave vectors associated with {πππ } by the Fourier transformation. 16 Finally, a piece-wise linear interpolation in time was applied between adjacent space 17 interpolations, to generate time interpolation π(π, π‘) for arbitrary time and space points 18 (π, π‘), π‘π < π‘ < π‘π+1 , in the Mediterranean: 19 π(π, π‘) = π(π, π‘π ) + π‘− π‘π ((π(π, π‘π+1 ) − π(π, π‘π )) π‘π+1 −π‘π (Eq. S11) 20 21 A pertinent problem generated by minimising the discretely sampled functional Eq. S7 is 22 that, under certain conditions, the value of the cost functional may decrease slightly due to 23 coalescence of certain sampling points along the travel path; thus, lowering the path 24 resolution. This is a problem that arises at the end phase of the minimisation process, where 25 weak modes are also relaxed. To overcome this problem, three parallel stabilizing measures 26 were implemented. First, close-lying points were removed from the initial path; specifically, 27 if adjacent points were separated by less than 25 km, the latter point was removed from the 11 1 initial path (unless it was the observed end point). Second, gradients of the cost functional 2 ∇πΈ supplied to the minimisation algorithm were projected onto path-normals (i.e. unit 3 vectors perpendicular to the swimming path): 4 5 ππ¬ ← π π«(π΅π ππ¬) (Eq. S12) 6 7 where N is a matrix with path-normals in its columns, ππ¬ is a matrix with nodal gradients in 8 its columns and D() is a matrix function that sets the off-diagonal elements to zero. This 9 equation directly prevents sampling point coalescence. Third, to avoid certain conditions 10 causing zig-zag features in the final travel path, the highest modes were removed by Fourier 11 filtering. Here, the reference is a linear path L between π0 and ππΈ . If the matrix B contains 12 included modes in its columns and c is a vector describing how much each mode is excited, 13 the transformation between the Cartesian path and the mode representation would be: 14 15 πΏ π = = π π©π π© π³ + π©π π©π (πΏ − π³) (Eq. S13) 16 17 and gradients would be transformed using: 18 19 ππ π¬ = π©π ππ¬ (Eq. S14) 20 21 Minimisation is then performed in excitation space c. Consequently, the first measure 22 (pruning of initial path) would be applied once, whereas the second (normal projection of 23 gradients) and third (mode transformation) measures would be applied in this order for 24 each minimisation step. 12 Many observed turtle tracks pass close to land; hence, to avoid artificial land 1 2 crossings during minimisation runs, a predictor-corrector scheme was applied after each 3 minimisation step, to retain the path in the sea, if it was displaced by the minimization 4 algorithm onto land. The geography of the Mediterranean region was represented by a land 5 mask: 6 0 πππ = { 1 ππ πππ ππ π€ππ‘ ππ πππ ππ πππ¦ } (Eq. S15) 7 8 A continuous topography function d(x) was constructed through the bilinear interpolation of 9 πππ on the grid πππ . The land areas were then defined by π(π) > 1⁄2. This coastal 10 representation provides a softer coastline for the given spatial resolution πππ compared to 11 other frequently used procedures, like looking on whether the closest grid point xij is wet or 12 dry. 13 14 Several standard algorithms are available to minimise functions over a continuous 15 space x. There are, however, a few features associated with the present problem that 16 complicate the application of standard minimisers. First, these features assume an 17 unrestricted (or at least convex/square) domain of the function; this assumption is not 18 satisfied, because many potential paths connecting observed end points are invalid, as the 19 paths artificially pass over land. Second, for the travel time functional, there are forbidden 20 cones in certain areas of strong currents for realistic cruising speeds. These two issues are 21 not easy to remove by suitable transformations to unrestricted domains. Third, the cost 22 functional is not strictly a unique functional of paths x, due to the lazy evaluation of the 23 current time evaluation points (Eq. S9), but depends slightly on search history during the 24 minimisation, even though the cost functional approximation converges with the proper 25 value and path at the end of the minimisation. This minor non-uniqueness of Eq. S4, due to 26 lazy time evaluation, is sufficient to confuse many standard algorithms based on iterative 27 line searches. Therefore, we applied a Newtonian annealing algorithm QuickMin (Stoltze 28 1997), which only depends on local conditions around the focal path; thus, it is insensitive to 13 1 the non-uniqueness issue. Furthermore, it is relatively easy to capture the two technical 2 issues (land crossing/forbidden swim directions and non-uniqueness) in this algorithm by 3 using a predictor-corrector amendment that ensures the path remains in the valid domain 4 following initialisation. 5 The landscape of πΈ[π] is generally governed by several local minima. For a given 6 initial path, π0 , the Quickmin algorithm (like other standard algorithms) only localises a 7 proximal minimum to π0 . To ensure that the global minimum was localized, an ensemble of 8 initial paths {π0 } was produced by generating a random perturbation to the straight line 9 between ππ and ππ¬ . In the presented runs, an ensemble size of 50 initial paths was applied, 10 which seemed sufficient for the travel time cost functional. The presented cost functional minimisation is implemented as a class library in 11 12 Python. Automatic derivatives were found to be too slow numerically; hence, gradients 13 were coded by hand. Numerical consistency between the functional and (lazy) gradients was 14 tested. 15 16 17 References 18 1. Car, R., Parrinello, M. (1985). Unified approach for molecular dynamics and density- 19 20 functional theory. Phys. Rev. Lett. 55 (22), 2471-2474 2. Pinardi, N., Allen, I., Demirov, E., De Mey, P., Korres, G., Lascaratos, A., et al.(2003). The 21 Mediterranean ocean forecasting system: first phase of implementation (1998-2001). 22 Ann. Geophys.21(1), 3-20. 23 24 3. Comincioli, V (2004): Biomatematica (interazioni tra le. Scienze della Vita e la Matematica),Universita' degli Studi di Pavia, 14 1 4. Tonani, M., Pinardi, N., Fratianni, C., Pistoia, J., Dobricic, S., Pensieri, S., et al.(2009). 2 Mediterranean forecasting system: forecast and analysis assessment through skill 3 scores. Ocean Sci. 5, 649-660. 4 5 5. Stoltze, P. (1997). Simulation Methods in Atomic-scale Materials Physics. Polyteknisk Forlag, Lyngby, Denmark. 6 15