I think what you need is just a simple sofware which reads the telemeteries of the Tie lines flows (P & Q ) and sends a commands to your controllers ( Co-Generating units , and transformers taps, ...ets) to prevent the export of the flow and return the system to the base case within seconds...