  Consider a communication network with a source, a relay and a destination.
Each time interval, the source may dynamically choose between a few possible
coding schemes, based on the channel state, traffic pattern and its own queue
status. For example, the source may choose between a direct route to the
destination and a relay-assisted scheme. Clearly, due to the difference in the
performance achieved, as well as the resources each scheme uses, a sender might
wish to choose the most appropriate one based on its status.
  In this work, we formulate the problem as a Semi-Markov Decision Process.
This formulation allows us to find an optimal policy, expressed as a function
of the number of packets in the source queue and other parameters. In
particular, we show a general solution which covers various configurations,
including different packet size distributions and varying channels.
Furthermore, for the case of exponential transmission times, we analytically
prove the optimal policy has a threshold structure, that is, there is a unique
value of a single parameter which determines which scheme (or route) is
optimal. Results are also validated with simulations for several interesting
models.
