Multi-class Learning Based Temporal Decomposition and Distributed Optimization