def experimentSceleton(dimension, nameFile): f = open(nameFile, 'r') for i in f: i = i.split() vertex = int(i[0]) facet = int(i[1]) break m = Matrix(vertex, facet) m.values = np.zeros(shape=[int(vertex), 0]) firstLine = True for line in f: incedence = list() # if firstLine: # firstLine = False # else: line = line.split() for k in range(vertex): if (str(k) in line): incedence.append(1) else: incedence.append(0) m.addCol(incedence) graph = Hasse(m) start = time.time() graph.building() finish = time.time() graph.printGraph() timeRun = finish - start return timeRun
def test_AddString(self): m = Matrix(2, 2) m.addString([1, 0]) print(m.values) print(np.shape(m.values)) self.assertEqual(1, np.shape(m.values)[0]) self.assertEqual(2, np.shape(m.values)[1])
def test_Constructor(self): m = Matrix(2, 3) m.addString([1, 1, 1]) m.addString([0, 1, 1]) graph = Hasse(m) self.assertEqual(2, len(graph.builtNodes)) self.assertEqual(3, len(graph.AllNodes))
def test_Building2(self): m = Matrix(7, 7) m.addString([0, 1, 1, 1, 1, 1, 1]) m.addString([1, 1, 0, 0, 0, 0, 1]) m.addString([1, 1, 1, 0, 0, 0, 0]) m.addString([1, 0, 1, 1, 0, 0, 0]) m.addString([1, 0, 0, 1, 1, 0, 0]) m.addString([1, 0, 0, 0, 1, 1, 0]) m.addString([1, 0, 0, 0, 0, 1, 1]) # piramide graph = Hasse(m) graph.building() graph.printGraph() self.assertEqual(28, graph.graphSize)
def experiment(dimension, nameFile, vertex, facet): m = Matrix(vertex, facet) f = open(nameFile, 'r') for line in f: m.addString(line) graph = Hasse(m) start = time.time() graph.building() finish = time.time() graph.printGraph() timeRun = finish - start return timeRun
def experimentRandom(dimension, vertex, facet): m = Matrix(vertex, facet) adding = list() for i in range(vertex): adding.clear() for j in range(facet): adding.append(random.randint(0, 1)) m.addString(adding) graph = Hasse(m) start = time.time() graph.building() finish = time.time() graph.printGraph() timeRun = finish - start return timeRun
def test_FindFacetInVertex2(self): m = Matrix(4, 3) m.addString([0, 1, 1]) m.addString([1, 0, 1]) m.addString([1, 0, 1]) m.addString([0, 0, 1]) self.assertTrue(m.findFacetInVertex(1, 0)) self.assertTrue(m.findFacetInVertex(2, 3)) self.assertFalse(m.findFacetInVertex(0, 0))
def test_ConvertedFacetArray(self): m = Matrix(3, 2) m.addString([1, 0]) m.addString([1, 0]) m.addString([1, 1]) m.convertedFacetArray() self.assertEqual(0, m.facetInc[0]) self.assertEqual(1, m.facetInc[1]) self.assertEqual(2, m.facetInc[2]) self.assertEqual(2, m.facetInc[3]) self.assertEqual(0, m.arrFacet[0]) self.assertEqual(3, m.arrFacet[1])
def test_Constructor(self): m = Matrix(2, 2) self.assertEqual(0, np.size(m.values)) self.assertEqual(2, m.vertexVal) self.assertEqual(2, m.facetVal) self.assertEqual(0, m.incVal) self.assertEqual(0, np.size(m.arrVertex)) self.assertEqual(0, np.size(m.vertexInc)) self.assertEqual(0, np.size(m.arrFacet)) self.assertEqual(0, np.size(m.facetInc))
def test_Building(self): m = Matrix(4, 4) m.addString([1, 1, 0, 1]) m.addString([0, 1, 1, 1]) m.addString([1, 1, 1, 0]) m.addString([1, 0, 1, 1]) # tetrahedra graph = Hasse(m) graph.building() graph.printGraph() self.assertEqual(16, graph.graphSize)
def test_ComputingNextLevelNodes(self): m = Matrix(4, 4) m.addString([1, 1, 0, 1]) m.addString([0, 1, 1, 1]) m.addString([1, 1, 1, 0]) m.addString([1, 0, 1, 1]) # tetrahedra graph = Hasse(m) workNode = Node({0}) newSet = graph.computingNextLevelNodes(workNode) self.assertEqual(3, len(newSet))
def test_VfromT(self): m = Matrix(4, 4) m.addString([1, 1, 1, 0]) m.addString([0, 1, 1, 1]) m.addString([1, 1, 1, 1]) m.addString([1, 0, 1, 1]) graph = Hasse(m) newSet = graph.VfromT([0, 3]) self.assertEqual([2], newSet[0]) self.assertEqual([3], newSet[1])
def test_FfromS(self): m = Matrix(4, 3) m.addString([1, 1, 1]) m.addString([0, 1, 1]) m.addString([1, 0, 1]) m.addString([1, 0, 1]) graph = Hasse(m) newSet = graph.FfromS([0, 2, 3]) self.assertEqual([0], newSet[0]) self.assertEqual([2], newSet[1])
def test_Closure(self): m = Matrix(4, 4) m.addString([1, 1, 1, 1]) m.addString([0, 0, 1, 1]) m.addString([1, 1, 0, 1]) m.addString([1, 0, 1, 1]) graph = Hasse(m) node = Node({0, 3}) expectedNode = Node({0, 2, 3}) newNode = graph.closure(node, 2) self.assertSetEqual(expectedNode.getElements(), newNode.getElements())
def test_ConvertedVertexArray(self): m = Matrix(2, 3) m.addString([1, 1, 1]) m.addString([0, 0, 1]) m.convertedVertexArray() self.assertEqual(0, m.vertexInc[0]) self.assertEqual(1, m.vertexInc[1]) self.assertEqual(2, m.vertexInc[2]) self.assertEqual(2, m.vertexInc[3]) self.assertEqual(0, m.arrVertex[0]) self.assertEqual(3, m.arrVertex[1])
def test_FindVertexInFacet2(self): m = Matrix(3, 3) m.addString([1, 0, 1]) m.addString([0, 0, 1]) m.addString([0, 1, 1]) self.assertTrue(m.findVertexInFacet(0, 0)) self.assertTrue(m.findVertexInFacet(0, 2)) self.assertTrue(m.findVertexInFacet(1, 2)) self.assertTrue(m.findVertexInFacet(2, 1)) self.assertTrue(m.findVertexInFacet(2, 2)) self.assertFalse(m.findVertexInFacet(0, 1)) self.assertFalse(m.findVertexInFacet(1, 0)) self.assertFalse(m.findVertexInFacet(1, 1)) self.assertFalse(m.findVertexInFacet(2, 0))
def test_CountingIncedenceError(self): m = Matrix(2, 3) m.addString([0, 2, 1]) self.assertRaises(ValueError, m.countingIncedence())
def test_CountingIncedence(self): m = Matrix(2, 2) m.addString([1, 0]) m.addString([0, 1]) self.assertEqual(2, m.countingIncedence())
def test_AddTwoStrings(self): m = Matrix(2, 2) m.addString([1, 0]) m.addString([0, 1]) self.assertEqual(2, np.shape(m.values)[0]) self.assertEqual(2, np.shape(m.values)[1])