ML-Based Optimization of Large-Scale Systems: Case Study in Smart Microgrids and 5G RAN