Optimal control of networked systems using reinforcement learning