Ejemplo n.º 1
0
#    distributed under the License is distributed on an "AS IS" BASIS,
#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#    See the License for the specific language governing permissions and
#    limitations under the License.
#
# ================================================================================================
from __future__ import print_function
import dwave_networkx as dnx
import networkx as nx
import dimod

# Use basic simulated annealer
sampler = dimod.SimulatedAnnealingSampler()

# The definition of a minimum vertex cover set is that each edge in the graph
# must have a vertex in the minimum vertex cover set, and we also want the
# vertex cover set to be as small as possible.

# Set up a Networkx Graph
G = nx.Graph()
G.add_edges_from([(0, 1), (0, 2), (1, 3), (2, 3), (3, 5), (4, 5), (3, 6),
                  (4, 7), (5, 6), (5, 7), (6, 8), (7, 8), (8, 9)])

# Get the minimum vertex cover, which is known in this case to be of
# length 5
candidate = dnx.min_vertex_cover(G, sampler)
if dnx.is_vertex_cover(G, candidate) and len(candidate) == 5:
    print(candidate, " is a minimum vertex cover")
else:
    print(candidate, " is not a minimum vertex cover")
Ejemplo n.º 2
0
 def vertex_cover_check(self, G, cover):
     # each node in the vertex cover should be in G
     self.assertTrue(dnx.is_vertex_cover(G, cover))
Ejemplo n.º 3
0
print("g", file=main)
maximum_matching = nx.max_weight_matching(Main_graph)
maximum_matching_graph = gv.Graph()
print("Maximum matching:", maximum_matching, file=main)
print("maximum_matching.size =", len(maximum_matching), file=main)
color_the_edges(maximum_matching_graph, maximum_matching)
# maximum_matching_graph.view(filename='maximum_matching', quiet_view=True)
print("h", file=main)
part = []
minimum_vertex_cover_graph = gv.Graph()
min_vertex_cover = {
    'AL', 'KO', 'BG', 'GR', 'RS', 'HR', 'HU', 'RO', 'FI', 'NO', 'UA', 'RU',
    'LV', 'BY', 'SP', 'FR', 'BE', 'DE', 'PL', 'IT', 'SK', 'AT', 'CH'
}
print(min_vertex_cover, file=main)
print(dnx.is_vertex_cover(Main_graph, min_vertex_cover), file=main)
print("min_vertex_cover.size =", len(min_vertex_cover), file=main)
color_the_vertexes(minimum_vertex_cover_graph, min_vertex_cover)
# minimum_vertex_cover_graph.view(filename='minimum_vertex_cover', quiet_view=True)
print("i", file=main)
minimum_edge_cover = nx.algorithms.min_edge_cover(Main_graph)
minimum_edge_cover_graph = gv.Graph()
normalized_edge_cover = set(
    (a, b) if a <= b else (b, a) for (a, b) in minimum_edge_cover)
print("Minimum edge cover:", normalized_edge_cover, file=main)
print("minimum_edge_cover.size =", len(normalized_edge_cover), file=main)
color_the_edges(minimum_edge_cover_graph, normalized_edge_cover)
# minimum_edge_cover_graph.view(filename='minimum_edge_cover', quiet_view=True)
print("l", file=main)
block_cut_tree_graph = gv.Graph()
k = 0