Ejemplo n.º 1
0
 def testCritical(self):
     critical = self.dal.k4_codiamond_critical()
     self.assertEqual(critical, True)
     self.dal = DalGraph(make_cycle(4))
     critical = self.dal.k4_codiamond_critical()
     self.assertEqual(critical, False)
     self.dal = DalGraph(make_cycle(5))
     self.dal._g.add_node(5)
     self.dal._g.add_edge(0, 5)
     self.dal._g.add_edge(1, 5)
     self.dal._g.add_edge(2, 5)
     self.dal._g.add_node(6)
     self.dal._g.add_edge(2, 6)
     self.dal._g.add_edge(3, 6)
     self.dal._g.add_edge(4, 6)
     critical = self.dal.k4_codiamond_critical()
     self.assertEqual(critical, True)
     self.dal = DalGraph(make_cycle(5))
     self.dal._g.add_node(5)
     self.dal._g.add_edge(0, 5)
     self.dal._g.add_edge(1, 5)
     self.dal._g.add_edge(2, 5)
     self.dal._g.add_node(6)
     self.dal._g.add_edge(1, 6)
     self.dal._g.add_edge(2, 6)
     self.dal._g.add_edge(3, 6)
     critical = self.dal.k4_codiamond_critical()
     self.assertEqual(critical, False)
Ejemplo n.º 2
0
def check_critical_file(mypath, logger):
    # mypath = os.path.join(os.getcwd(),"critical")
    onlyfiles = [ f for f in listdir(mypath) if isfile(join(mypath,f)) ]
    pp.pprint(onlyfiles)
    result = {}
    total = len(onlyfiles)
    index = 0
    print("Total Files: %d" % total)
    for file in onlyfiles:
        try:
            print("{0:.2%}".format(index / total))
            index += 1
            logger.info("Checking file %s" % file)
            d = DalGraph(file=os.path.join(mypath,file), logger=logger)
            critical = d.critical_aprox()
            logger.info("File %s is %r" %(file, critical))
            result[file] = critical
        except:
            result[file] = "Invalid File"
    pp.pprint(result)
    logger.info("Results:")
    logger.info("-----------------")
    for file, critical in result.items():
        logger.info("File %s is %r" %(file, critical))
    logger.info("-----------------")
    send_email(CRITICAL_MESSAGE, TO_ADDRESS)
Ejemplo n.º 3
0
 def testUnionNeighbors(self):
     g = DalGraph(make_claw())
     result = g.union_neighbors([0])
     expect = [1, 2, 3]
     self.assertEqual(result, expect)
     g._g.add_node(4)
     g._g.add_edge(3, 4)
     result =g.union_neighbors([4, 2])
     expect = [3, 0]
     self.assertEqual(result, expect)
Ejemplo n.º 4
0
def consume(lock, graphs, done, critical):
    while done.empty():
        try:
            g = graphs.get(block=True, timeout=5)
            d = DalGraph(graph=g, logger=LOGGER)
            if d.critical_aprox():
                f = File(DIRECTORY, G=g, logger=LOGGER)
                fp = f.save()
                if fp is not None:
                    critical.put(fp)
        except Empty:
            #print("Empty")
            pass
    return
Ejemplo n.º 5
0
class testK4CoDiamond(unittest.TestCase):
    def setUp(self):
        self.dal = DalGraph(make_cycle(5))

    def tearDown(self):
        pass

    def testDelete2(self):
        k = {'i,i+1,i+2': 1, 'i,i+1,i+4': 1}
        result = self.dal.delete_2(k)
        self.assertEqual(k, result)
        k = {'i,i+4': 1, 'i,i+1': 2, 'i+1,i+2': 1}
        result = self.dal.delete_2(k)
        expect = {}
        self.assertNotEqual(k, result)
        self.assertEqual(expect, result)

    def testCoverC5(self):
        covered = self.dal.cover_c5("i,i+1,i+2", "i+2,i+3,i+4")
        self.assertEqual(covered, True)
        covered = self.dal.cover_c5("i,i+1,i+2", "i+1,i+2,i+3")
        self.assertEqual(covered, False)

    def testCritical(self):
        critical = self.dal.k4_codiamond_critical()
        self.assertEqual(critical, True)
        self.dal = DalGraph(make_cycle(4))
        critical = self.dal.k4_codiamond_critical()
        self.assertEqual(critical, False)
        self.dal = DalGraph(make_cycle(5))
        self.dal._g.add_node(5)
        self.dal._g.add_edge(0, 5)
        self.dal._g.add_edge(1, 5)
        self.dal._g.add_edge(2, 5)
        self.dal._g.add_node(6)
        self.dal._g.add_edge(2, 6)
        self.dal._g.add_edge(3, 6)
        self.dal._g.add_edge(4, 6)
        critical = self.dal.k4_codiamond_critical()
        self.assertEqual(critical, True)
        self.dal = DalGraph(make_cycle(5))
        self.dal._g.add_node(5)
        self.dal._g.add_edge(0, 5)
        self.dal._g.add_edge(1, 5)
        self.dal._g.add_edge(2, 5)
        self.dal._g.add_node(6)
        self.dal._g.add_edge(1, 6)
        self.dal._g.add_edge(2, 6)
        self.dal._g.add_edge(3, 6)
        critical = self.dal.k4_codiamond_critical()
        self.assertEqual(critical, False)
Ejemplo n.º 6
0
 def testFindCoClaw(self):
     g = DalGraph(make_co_claw())
     # add some noise
     g._g.add_node(4)
     g._g.add_node(5)
     g._g.add_node(6)
     g._g.add_node(7)
     g._g.add_edge(3, 4)
     g._g.add_edge(2,5)
     g._g.add_edge(1, 6)
     g._g.add_edge(3, 7)
     result = g.find_co_claw()
     expect = [2, 3, 1, 0]
     self.assertEqual(result, expect)
     # no triangle
     g = DalGraph(make_claw())
     # add some noise
     g._g.add_node(4)
     g._g.add_node(5)
     g._g.add_node(6)
     g._g.add_node(7)
     g._g.add_edge(0, 4)
     g._g.add_edge(0, 5)
     g._g.add_edge(0, 6)
     g._g.add_edge(0, 7)
     result = g.find_co_claw()
     expect = None
     self.assertEqual(result, expect)
     g = DalGraph(make_wheel(6))
     result = g.find_co_claw()
     self.assertEqual(result, expect)
Ejemplo n.º 7
0
 def testCriticalAprox(self):
     # is_critical graphs
     g = nx.Graph()
     g.add_node(0)
     g = join(g, g)
     g = join(g, g)
     d = DalGraph(g)
     result = d.critical_aprox()
     self.assertEqual(result, True)
     g = make_wheel(6)
     d = DalGraph(g)
     result = d.critical_aprox()
     self.assertEqual(result, True)
     d = DalGraph(make_cycle(5))
     result = d.critical_aprox()
     self.assertEqual(result, True)
     # test non is_critical
     d = DalGraph(make_claw())
     result = d.critical_aprox()
     self.assertEqual(result, False)
     d = DalGraph(make_co_claw())
     result = d.critical_aprox()
     self.assertEqual(result, False)
Ejemplo n.º 8
0
 def testKColor(self):
     g = DalGraph(make_cycle(3))
     c = g.k_color()
     self.assertEqual(3, c, "KColor: K3 case")
     g = DalGraph(make_cycle(4))
     c = g.k_color()
     self.assertEqual(None, c, "KColor: C4 case")
     g = DalGraph(make_wheel(6))
     c = g.k_color()
     self.assertEqual(4, c, "KColor: W6 case")
     c5 = make_cycle(5)
     c5_2 = make_cycle(5)
     c = join(c5,c5_2)
     g = DalGraph(c)
     c = g.k_color()
     self.assertEqual(c, 6, "KColor: C5 joined with a C5")
Ejemplo n.º 9
0
 def testCycleNodes(self):
     g = DalGraph(make_cycle(3))
     c = g.cycle_nodes()
     self.assertEqual(c, [], "Cycle Nodes Failed: found cycle less than 3")
     g = DalGraph(make_cycle(5))
     c = g.cycle_nodes()
     self.assertEqual(c, [0, 1, 2, 3, 4 ,0], 
                      "Cycle Nodes Failed: did not find C5")
     c5 = make_cycle(5)
     c5.add_edge(2,4)
     g = DalGraph(c5)
     c = g.cycle_nodes()
     self.assertEqual(c, [], "Cycle Nodes Failed: did found non-induced C5")
Ejemplo n.º 10
0
 def testCheckSmallerCycle(self):
     c3 = make_cycle(3)
     g = DalGraph(c3)
     c = g.check_smaller_cycle([], 1, 0)
     self.assertEqual(c, [0, 1], "Failed the simple C2 case")
     c3 = make_cycle(3)
     g = DalGraph(c3)
     c = g.check_smaller_cycle([0], 0, 1)
     self.assertEqual(c, [0, 1], "Failed the simple C2 case")
     c5 = make_cycle(5)
     g = DalGraph(c5)
     c = g.check_smaller_cycle([0, 1, 2], 4, 3)
     self.assertEqual(c, [0, 1, 2, 3 , 4, 0], "Failed the simple C5 Case")
     c4 = make_cycle(4)
     g = DalGraph(c4)
     c = g.check_smaller_cycle([0, 1, 2], 0 ,3)
     self.assertEqual([], c, "Failed the simple C4 case")
     c5 = make_cycle(5)
     c5.add_edge(2, 4)
     g = DalGraph(c5)
     c = g.check_smaller_cycle([0, 1, 2], 4, 3)
     self.assertEqual([], c, "Failed to find back track node in C5 Case")
     c = g.check_smaller_cycle([2], 4, 3)
     self.assertEqual([], c, "Failed to find back track node in C5 Case")
Ejemplo n.º 11
0
 def setUp(self):
     self.dal = DalGraph(make_cycle(5))