Autonomous multi-stage flexible optimal power flow