from sts.invariant_checker import InvariantChecker
import sys

def bail_on_connectivity(simulation):
  result = InvariantChecker.python_check_connectivity(simulation)
  if not result:
    print "Connectivity established - bailing out"
    sys.exit(0)
  return []

def check_for_loops_or_connectivity(simulation):
  result = InvariantChecker.check_loops(simulation)
  if result:
    return result
  return bail_on_connectivity(simulation)

def check_for_loops_blackholes_or_connectivity(simulation):
  for check in [InvariantChecker.check_loops, InvariantChecker.check_blackholes]:
    result = check(simulation)
    if result:
      return result
  return bail_on_connectivity(simulation)

# Note: make sure to add new custom invariant checks to this dictionary!
name_to_invariant_check = {
  "check_for_loops_or_connectivity" : check_for_loops_or_connectivity,
  "check_for_loops_blackholes_or_connectivity" : check_for_loops_blackholes_or_connectivity,
  "InvariantChecker.check_liveness" :  InvariantChecker.check_liveness,
  "InvariantChecker.check_loops" :  InvariantChecker.check_loops,
  "InvariantChecker.python_check_connectivity" :  InvariantChecker.python_check_connectivity,
  "InvariantChecker.check_connectivity" :  InvariantChecker.check_connectivity,
  "InvariantChecker.check_blackholes" :  InvariantChecker.check_blackholes,
  "InvariantChecker.check_correspondence" :  InvariantChecker.check_correspondence,
}

@@ -683,16 +683,221 @@
 ation)%0A%0A
+def check_for_loops_blackholes(simulation):%0A  for check in %5BInvariantChecker.check_loops, InvariantChecker.check_blackholes%5D:%0A    result = check(simulation)%0A    if result:%0A      return result%0A  return %5B%5D%0A%0A
 # Note: 
@@ -1145,32 +1145,93 @@
 r_connectivity,%0A
+  %22check_for_loops_blackholes%22 : check_for_loops_blackholes,%0A
   %22InvariantChec

Add a new invariant check