Real-time Monitoring and Optimal Control for Smart Additive Manufacturing