In this paper, an emergency ad‐hoc network based on cognitive radio is considered. It is assumed that secondary users (SUs) are moving agents in which some fixed agents namely distributed relays (DRs), forward the data gathered by SUs to destination. The main goal is to maximize the capacity of data gathering in destination with respect to the maximum interference tolerable by primary users (PU), and SU's and DR's power constraints. A mixed‐integer nonlinear model (MINLP) for joint relay assignment and power allocation is shown. Given that MINLP problems are NP‐Hard, a two interdependent solutions are proposed to achieve the relay assignment and power control. A social‐aware dynamic relay assignment algorithm (SADRA) based on many‐to‐one matching is proposed. In this matching, the preference list of DRs is the result of mean opinion scores ranking that two roulette wheel selection and random walk selection techniques are applied to eliminate the same priorities. In the second phase, a greedy adaptive algorithm for non‐convex power allocation problem that converges to the component‐wise minimal power is proposed. It is shown that the SADRA algorithm converges to a two‐sided exchange stable matching. The superior performance of the proposed SADRA algorithm is verified by the simulation results.