Dynamic Spectrum Allocation for Cognitive Radio Networks: A Comprehensive Optimization Approach