BitTorrent splits the files that are shared on a P2P network into fragments and then spreads these by giving the highest priority to the rarest fragment. We propose a mathematical model that takes into account several factors such as the peer distance, communication delays, and file fragment availability in a future period also by using a neural network module designed to model the behaviour of the peers. The ensemble comprising the proposed mathematical model and a neural network provides a solution for choosing the file fragments that have to be spread first, in order to ensure their continuous availability, taking into account that some peers will disconnect.