コード例 #1
0
def progress(G):
    S = nx.DiGraph()
    S.add_edges_from(
        (x, y) for x, y in S.edges() if S.edge[x][y]["codeblock"] != "fire")
    scc = len(list(nx.strongly_connected_components(S)))
    if scc > 0:
        log.err("found %s SCC without a fire" % scc)
    else:
        log.info("no SCC without a fire")
コード例 #2
0
 def __init__ (self, net) :
     self.last = net.get_marking()
     if PRAGMAS["LOGS"] :
         log.info("init with %s" % self.last)
     if PRAGMAS["STATS"] :
         self.stats = collections.defaultdict(int)
         self.count = 0
     if PRAGMAS["CHECKS"] :
         self.net = net
     if PRAGMAS["FAIR"] :
         self.trans = collections.defaultdict(int)
コード例 #3
0
 def simul (cls, net, nprocs=4, timeout=None) :
     netserver = Net(nprocs, net)
     players = cls.build(net, netserver)
     if PRAGMAS["LOGS"] :
         log.info("start simulation for %r" % net.name)
     cls.startup(players)
     if timeout :
         gevent.sleep(timeout)
         if PRAGMAS["FAIR"] :
             print "fairness:", dict(players[0].trace.trans)
         if PRAGMAS["CHECKS"] :
             players[0].reportstat()
         if PRAGMAS["BENCHS"] :
             print "bench:", cls.reportstat()
         netserver.kill()
         gevent.sleep(1)
         sys.exit(0)
コード例 #4
0
def deadlocks(G):
    states = G.graph["substates"]
    count = 0
    deadlocks = set()
    for node in G:
        if G.node[node]["dead"]:
            count += 1
            mark = G.node[node]["marking"]
            state = states._state[mark]
            deadlocks.add(mark)
            if list(states.successors(state)):
                log.error("invalid dealock", node, "=> %s=%s" % (state, mark))
    if count == 0:
        log.info("no deadlock found")
    else:
        log.info("checked %s deadlock(s)" % count)
    for state in states:
        if not list(states.successors()):
            mark = states.net.get_marking()
            if mark not in deadlocks:
                log.err("missing deadlock: %s" % mark)
    return count
コード例 #5
0
 def fire (self, trans, succ) :
     "Extend the trace with an event"
     if PRAGMAS["LOGS"] :
         log.info("fire %s:  %s => %s" % (trans, self.last, succ))
     if PRAGMAS["CHECKS"] :
         pred = self.last
     self.last = succ
     if PRAGMAS["STATS"] :
         self.count += 1
     if PRAGMAS["FAIR"] :
         self.trans[trans] += 1
     if PRAGMAS["CHECKS"] :
         self.net.set_marking(pred)
         for t in self.net.transition() :
             for m in t.modes() :
                 t.fire(m)
                 if t.name == trans and self.net.get_marking() == succ :
                     return
                 self.net.set_marking(pred)
         log.err("invalid firing of %s => %s (does not exist)"
                 % (trans, succ))
         self.netserver.kill()
         sys.exit(0)
コード例 #6
0
def correctness(G):
    def match(a, b):
        return a == b

    return nx.is_isomorphic(tau_star_reduce(lts(G.graph["states"])),
                            lts(G.graph["substates"]),
                            node_match=match,
                            edge_match=match)


if __name__ == "__main__":
    log.verbosity = log.ALL
    for path in glob.glob("nets/*.py"):
        g = make(path)
        d = deadlocks(g)
        progress(g)
        if nx.is_strongly_connected(g):
            log.info("strongly connected")
        elif d:
            if nx.is_strongly_connected(remove_dead(g)):
                log.info("strongly connected (except deadlocks)")
            else:
                log.err("not strongly connected (even without deadlocks)")
        else:
            log.err("not strongly connected but without deadlocks")
        if correctness(g):
            log.info("checked tau*-bisimilarity")
        else:
            log.err("marking graphs are not tau*-bisimilar")
        print