Resource Allocation And Precoding In Cognitive Radio And Relay Networks