本文整理汇总了Python中graphillion.GraphSet.dumps方法的典型用法代码示例。如果您正苦于以下问题:Python GraphSet.dumps方法的具体用法?Python GraphSet.dumps怎么用?Python GraphSet.dumps使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类graphillion.GraphSet
的用法示例。
在下文中一共展示了GraphSet.dumps方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_io
# 需要导入模块: from graphillion import GraphSet [as 别名]
# 或者: from graphillion.GraphSet import dumps [as 别名]
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))
示例2: GraphSet
# 需要导入模块: from graphillion import GraphSet [as 别名]
# 或者: from graphillion.GraphSet import dumps [as 别名]
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]
示例3: range
# 需要导入模块: from graphillion import GraphSet [as 别名]
# 或者: from graphillion.GraphSet import dumps [as 别名]
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()