An optimization approach to Petri net monitor design