예제 #1
0
 def __init__(self,solver,input):
     self.solver = solver
     self.input  = input
     self.graph = nx.read_graphml(input)
     self._make_groups_to_dwave_nodes()
     self.network = self.make_network_from_graph()
     self.embedding = social.Embedding(self.solver,self.network)
예제 #2
0
 def from_input(cls, solver, input):
     obj = cls()
     obj.solver = solver
     obj.input = input
     obj.graph = nx.read_graphml(input)
     obj._make_groups_to_dwave_nodes()
     obj.network = obj.make_network_from_graph()
     obj.embedding = social.Embedding(obj.solver, obj.network)
     return obj
예제 #3
0
    # pr.enable()

    fout = open(output, 'wb')
    fout.write('nnodes,tembedding,tsolve,tqpu\n')
    try:
        for nn in range(nmin, nmax + 1):
            # Make a random graph of  nodes.
            g = sc.make_random_graph(nn, gtype)
            ne = len(g.edges())

            # Create a social network from the graph.
            socnet = sc.make_social_network(g)

            # Get an embedding for the graph.
            start_time = time.time()
            embedding = soc.Embedding(solver, socnet)
            end_time = time.time()
            tembedding = end_time - start_time
            print('Total embedding time = ' + str(tembedding) + ' seconds.')

            # Solve the embedded problem.
            start_time = time.time()
            solution = socnet.solve(solver, embedding)
            end_time = time.time()
            tsolve = end_time - start_time
            print('Total solution time = ' + str(tsolve) + ' seconds.')
            qpuval = 'n/a'
            if use_dwave == True:
                qpu_access_time = solution._orig_results['timing'][
                    'qpu_access_time']
                qpuval = str(qpu_access_time * 1.e-6)
예제 #4
0
    # Use the D Wave machine or local solver.
    if not use_dwave:
        conn = local.local_connection
        solver = conn.get_solver("c4-sw_sample")
    else:
        # token = os.environ['DWAVE_TOKEN']
        token = settings.DWAVE_TOKEN
        print token
        os.environ['no_proxy'] = 'localhost'
        # print os.environ
        conn = remote.RemoteConnection('https://localhost:10443/sapi', token)
        solver = conn.get_solver("DW2X")

    # Create a network from the GraphML file.
    g = nx.read_graphml(input)
    net = make_network_from_graph(g)

    print(input + ' initial problem read in.')

    # Create an embedding.
    embedding = social.Embedding(solver, net, verbose=1)

    # Perform the initial solve.
    solution = net.solve(solver, embedding, s=.25, num_reads=1000)

    # Examine results.
    results = solution.results()
    results_not_broken = [x for x in results if not x['broken']]
    delta = results_not_broken[0]['delta']
    print('delta = ' + str(delta))
예제 #5
0
        print ' ', r


if True:
    conn = local.local_connection
    solver = conn.get_solver("c4-sw_sample")
else:
    token = os.environ['DWAVE_TOKEN']
    print token
    os.environ['no_proxy'] = 'localhost'
    #print os.environ
    conn = remote.RemoteConnection('https://localhost:10443/sapi', token)
    solver = conn.get_solver("DW2X")

net = fig1A4()
emb = social.Embedding(solver, net, verbose=0)
solve(net, emb)

# change the network values without changing the topology,
# and therefore the embedding
net.friend(A, B)
solve(net, emb, verbose=0)

# change the network values without changing the topology,
# and therefore the embedding
net.friend(B, C)
solve(net, emb, verbose=0)

net = fig1B()
emb = social.Embedding(solver, net, verbose=0)
solve(net, emb)
예제 #6
0
 def _make_embedding(self):
     # use the fully connected total graph to set the embedding
     # from groups to dwave nodes
     grph = self.graphs[-1]
     net = self._create_network(grph)
     self.embedding = social.Embedding(self.solver, net, verbose=0)