Exemplo n.º 1
0
    def test_io(self):
        gs = GraphSet()
        st = gs.dumps()
        self.assertEqual(st, "B\n.\n")
        gs = GraphSet.loads(st)
        self.assertEqual(gs, GraphSet())

        gs = GraphSet([g0])
        st = gs.dumps()
        self.assertEqual(st, "T\n.\n")
        gs = GraphSet.loads(st)
        self.assertEqual(gs, GraphSet([g0]))

        v = [g0, g1, g12, g123, g1234, g134, g14, g4]
        gs = GraphSet(v)
        st = gs.dumps()
        gs = GraphSet.loads(st)
        self.assertEqual(gs, GraphSet(v))

        # skip this test, becasue string is treated as an element
#        gs = GraphSet(st)
#        self.assertEqual(gs, GraphSet(v))

        with tempfile.TemporaryFile() as f:
            gs.dump(f)
            f.seek(0)
            gs = GraphSet.load(f)
            self.assertEqual(gs, GraphSet(v))
Exemplo n.º 2
0
    def test_io(self):
        gs = GraphSet()
        st = gs.dumps()
        self.assertEqual(st, "B\n.\n")
        gs = GraphSet.loads(st)
        self.assertEqual(gs, GraphSet())

        gs = GraphSet([g0])
        st = gs.dumps()
        self.assertEqual(st, "T\n.\n")
        gs = GraphSet.loads(st)
        self.assertEqual(gs, GraphSet([g0]))

        v = [g0, g1, g12, g123, g1234, g134, g14, g4]
        gs = GraphSet(v)
        st = gs.dumps()
        gs = GraphSet.loads(st)
        self.assertEqual(gs, GraphSet(v))

        # skip this test, becasue string is treated as an element
        #        gs = GraphSet(st)
        #        self.assertEqual(gs, GraphSet(v))

        f = tempfile.TemporaryFile()
        gs.dump(f)
        f.seek(0)
        gs = GraphSet.load(f)
        self.assertEqual(gs, GraphSet(v))
GraphSet.set_universe(universe)

ng = 20

g_univ = GraphSet({})

g1 = []
i = 1
for sg in g_univ.rand_iter():
  g1.append(sg)
  if i == ng: break
  i += 1

G1 = GraphSet(g1)
print(G1.dumps())

data = map (lambda x:x.split(" "),G1.dumps().strip().split("\n"))
data.pop()


data_fl = list(chain.from_iterable(data))

len_data_fl = len(data_fl)
num_v = len_data_fl/4

v_id = data_fl[::4]
v_lab = data_fl[1::4]
v_lo = data_fl[2::4]
v_hi = data_fl[3::4]
universe = []
for i in range(marker):
    universe.append((i, i + 1))

GraphSet.set_universe(universe)

g1 = []
i = 1
for i in range(n):
    tmp = []
    for j in range(marker):
        if haps[i][j] == 1:
            tmp.append(universe[j])
    if i == 0:
        g1 == [tmp]
    else:
        g1.append(tmp)

G1 = GraphSet(g1)
print "haps"
print haps
print "\nuniverse"
print universe
print "\ng1"
print g1
print "\nG1"
print G1
print "\nG1.dumps()"
print G1.dumps()