Exemplo n.º 1
0
def preprocess(graph, input_format='dot'):
    graph_file = io.StringIO(pygraphviz.AGraph(graph).to_string())
    print(graph_file)
    G = gt.load_graph(graph_file, fmt='dot')
    G = gt.lattice([5, 5])
    d = distance_matrix(G)
    return G, d
Exemplo n.º 2
0
def square_grid_ts_pcoloring(size):
    g = gt.lattice([size, size])
    dist_mat = get_distance_matrix(g)
    prob = GraphProblem(dist_mat)

    p_col1 = tabu_pack_col(prob, k_count=5, tt_a=10, tt_d=0.6, max_iter=1000)

    max_col = p_col1.get_max_col()

    print(np.max(p_col1))
    print(p_col1)
Exemplo n.º 3
0
def square_grid_rpartcol_pcoloring(m, n, nbr_it):
    g = gt.lattice([m, n])
    setattr(g, "name", "G_{0}x{1}".format(m, n))
    kwargs = {"k_count": 5, "tt_a": 20, "tt_d": 0.6,
              "max_iter": 2000, "iter_period": 50, "tenure_inc": 5}
    return benchmark_function(g, nbr_it, react_partial_pack_col, **kwargs)
#! /usr/bin/env python
# -*- coding: utf-8 -*-
"""
@author: lockheed
Information and Electronics Engineering
Huazhong University of science and technology
E-mail:[email protected]
Created on: 3/13/14 9:06 PM

Copyright (C)  lockheedphoenix

"""

import graph_tool.all as gt

"""
20140320 nig
g = gt.load_graph('BA_networks.xml.gz')
pos = gt.arf_layout(g)
g.vertex_properties['pos'] = pos
g.save('BA_networks_2.xml.gz')
"""

g = gt.lattice([40, 40], True)
pos = gt.sfdp_layout(g, cooling_step=0.99, epsilon=1e-3)
g.vertex_properties['pos'] = pos
g.save('3Dlattice.xml.gz')
gt.graph_draw(g, pos)

Exemplo n.º 5
0
    def discover_vertex(self,u):
        self.visited.add(int(u))

Lx = args.N
Ly = Lz = Lx

l = Lx*Ly*Lz

rm = 1.0
gm = args.gm

num_bonds = (Lx-1)*Ly*Lz + Lx*(Ly-1)*Lz + Lx*Ly*(Lz-1)

log.info("generating graph")
g = gt.lattice([Lx,Ly,Lz])

assert(g.num_edges() == num_bonds)

p = args.probability

if args.maskfile:
    log.info("loading %s" % args.maskfile)
    mask = np.load(args.maskfile)
    p = np.sum(mask)/mask.shape[0]
    vals = mask
else:
    vals = binomial(1,p,num_bonds).astype('bool')

prop = g.new_edge_property('bool',vals=vals)
g.set_edge_filter(prop)
Exemplo n.º 6
0
import graph_tool.all as gt
N = 99
'''
g = gt.lattice([15, 15])
Pin = g.new_vertex_property('bool')
Pin.a = False
Pin[g.vertex(1)] = True
Pin[g.vertex(0)] = True
assert isinstance(Pin, object)
pos = gt.sfdp_layout(g, epsilon=0.2)
pos[g.vertex(1)][0] = pos[g.vertex(0)][0]
pos = gt.sfdp_layout(g)
g.vertex_properties['pos'] = pos
g.save('S2Dlattice.xml.gz')
'''
g = gt.lattice([N, N])
Pin = g.new_vertex_property('bool')
Pin.a = False
Pin[g.vertex(1)] = True
Pin[g.vertex(0)] = True
assert isinstance(Pin, object)
pos = gt.sfdp_layout(g, epsilon=0.2)
pos[g.vertex(1)][0] = pos[g.vertex(0)][0]
pos = gt.sfdp_layout(g)
g.vertex_properties['pos'] = pos
g.save('2Dlattice.xml.gz')

'''

g = gt.lattice([N, N])
pos = gt.sfdp_layout(g, epsilon=0.000000001, C=1)
Exemplo n.º 7
0
#! /usr/bin/env python
# -*- coding: utf-8 -*-
"""
@author: lockheed
Information and Electronics Engineering
Huazhong University of science and technology
E-mail:[email protected]
Created on: 4/29/14 3:21 PM

Copyright (C)  lockheedphoenix

"""

import graph_tool.all as gt
g = gt.lattice([60, 60])
pos = gt.sfdp_layout(g)
g.vertex_properties['pos']=pos
K = 2
'''
for k in range(2, K):
    for v in g.vertices():
        g.add_edge(v, g.vertex((g.vertex_index[v]+k)%(g.num_vertices())))
'''

g.save('RG.xml.gz')

Exemplo n.º 8
0
Nphys = 25 # number of cubes on an edge in physical space
Nres = args.N # number of lattice sites on an edge
M = 2 # edge length (w.r.t. Nphys) of cubes to be removed, total vol removed is M**3
p = args.p # volume fraction
tol = 1e-3 # desired tolerance on volume fraction for generation

log.info("Nphys = %d, Nres = %d, M = %d, p = %f" % (Nphys,Nres,M,p))

flags = resnet.discrete_pore_space(Nphys,M,p,tol)

# generate a matrix with True volume fraction close to desired value

log.info("generating lattice")

g = gt.lattice([Nres,Nres,Nres])

mat = triu(gt.adjacency(g))

bonds = np.vstack([mat.row,mat.col])

r1 = 8e-9
r2 = 25e-9

log.info("warping lattice")
x,y,z = resnet.bonds_to_xyz(bonds,Nres,r1,r2)

# coordinates inside a certain radius
# inner = np.argwhere(np.sqrt(x**2 + y**2 + z**2) < (r1 + 0.2*(r2-r1))).flatten()

# fit lattice into space of 'physical matrix' indices
Exemplo n.º 9
0
#! /usr/bin/env python
# -*- coding: utf-8 -*-
"""
@author: lockheed
Information and Electronics Engineering
Huazhong University of science and technology
E-mail:[email protected]
Created on: 3/13/14 9:06 PM

Copyright (C)  lockheedphoenix

"""

import graph_tool.all as gt
"""
20140320 nig
g = gt.load_graph('BA_networks.xml.gz')
pos = gt.arf_layout(g)
g.vertex_properties['pos'] = pos
g.save('BA_networks_2.xml.gz')
"""

g = gt.lattice([40, 40], True)
pos = gt.sfdp_layout(g, cooling_step=0.99, epsilon=1e-3)
g.vertex_properties['pos'] = pos
g.save('3Dlattice.xml.gz')
gt.graph_draw(g, pos)
Exemplo n.º 10
0
def square_grid_rlf_pcoloring(m, n, nbr_it):
    g = gt.lattice([m, n])
    setattr(g, "name", "G_{0}x{1}".format(m, n))
    return benchmark_function(g, nbr_it, rlf_algorithm)
Exemplo n.º 11
0
N = 99
'''
g = gt.lattice([15, 15])
Pin = g.new_vertex_property('bool')
Pin.a = False
Pin[g.vertex(1)] = True
Pin[g.vertex(0)] = True
assert isinstance(Pin, object)
pos = gt.sfdp_layout(g, epsilon=0.2)
pos[g.vertex(1)][0] = pos[g.vertex(0)][0]
pos = gt.sfdp_layout(g)
g.vertex_properties['pos'] = pos
g.save('S2Dlattice.xml.gz')
'''
g = gt.lattice([N, N])
Pin = g.new_vertex_property('bool')
Pin.a = False
Pin[g.vertex(1)] = True
Pin[g.vertex(0)] = True
assert isinstance(Pin, object)
pos = gt.sfdp_layout(g, epsilon=0.2)
pos[g.vertex(1)][0] = pos[g.vertex(0)][0]
pos = gt.sfdp_layout(g)
g.vertex_properties['pos'] = pos
g.save('2Dlattice.xml.gz')
'''

g = gt.lattice([N, N])
pos = gt.sfdp_layout(g, epsilon=0.000000001, C=1)
#pos = gt.sfdp_layout(g)
Exemplo n.º 12
0
#! /usr/bin/env python
# -*- coding: utf-8 -*-
"""
@author: lockheed
Information and Electronics Engineering
Huazhong University of science and technology
E-mail:[email protected]
Created on: 4/29/14 3:21 PM

Copyright (C)  lockheedphoenix

"""

import graph_tool.all as gt
g = gt.lattice([60, 60])
pos = gt.sfdp_layout(g)
g.vertex_properties['pos'] = pos
K = 2
'''
for k in range(2, K):
    for v in g.vertices():
        g.add_edge(v, g.vertex((g.vertex_index[v]+k)%(g.num_vertices())))
'''

g.save('RG.xml.gz')