Exemplo n.º 1
0
def main():
	G_in=get_graph.edge_list()	# read the input instance
	G=copy.deepcopy(G_in)
	k=int(input("Enter k:"))
	d=int(input("Enter d:"))
	G,k,kernel_solution=kernel.kernelization(G,k) # do kernelization
	print("Kernelization",k,kernel_solution)
	search_solution=search(G,[],[],G.nodes(),[],k,d,[0],[])
	print("No Solution")
Exemplo n.º 2
0
def main():
    G = get_graph.edge_list()  # read the input instance
    print_graph.input(G)  # construct input graph for display
    k = int(input("Enter k:"))
    G, k, solution = kernel.kernelization(G, k)  # do kernelization
    print("Kernelization", k, solution)
    if not branching(G, k, solution, []):
        print("No Solution")
    else:
        G.remove_nodes_from(sol)
        print_graph.output(G)  # construct output graph for display
Exemplo n.º 3
0
def main():
    G = get_graph.edge_list()  # read the input instance
    print_graph.input(G)
    k = int(input("Enter k:"))
    G, k, solution = kernel.kernelization(G, k)  # do kernelization
    print("Kernelization", k, solution)
    p3s = kernel.get_p3(G)
    if not three_way_branching(p3s, k, solution):
        print("No Solution")
    else:
        G.remove_nodes_from(sol)
        print_graph.output(G)
        print_graph.show()
Exemplo n.º 4
0
def main():
    G = get_graph.edge_list()  # read the input instance
    print_graph.input(G)
    k = int(input("Enter k:"))
    d = int(input("Enter d:"))
    G, k, kernel_solution = kernel.kernelization(G, k)  # do kernelization
    print("Kernelization", k, kernel_solution)
    if not branching(G, [], k, d, []):
        print("No Solution")
    else:
        print("CVD solution: ", sol)
        G.remove_nodes_from(sol)
        print_graph.output(G)
        print_graph.show()
Exemplo n.º 5
0
def main():
	G=get_graph.edge_list()	# read the input instance
	print_graph.input(G)
	k=int(input("Enter k:"))
	G,k,kernel_solution=kernel.kernelization(G,k) # do kernelization
	print("Kernelization",k,kernel_solution)
	brute_solution=brute(G,k) # do brute force
	if k>0 and brute_solution == []:	
		print ("No Solution")
	else:
		solution=list(set(kernel_solution)|set(brute_solution)) # combine kernelization and brute force approach results
		print("CVD solution: ",solution)
		G.remove_nodes_from(solution)
		print_graph.output(G)
		print_graph.show()
Exemplo n.º 6
0
                #print("rr1:",rr1)
                rr2 = reduction_rule2(G_guess, out, G_S)  # reduction rule 2
                G_S.remove_nodes_from(rr2)
                G_guess.remove_nodes_from(rr2)
                #print("rr2:",rr2)
                solution_d = construct_G(G_guess, out,
                                         G_S)  # weighted bipartite matching
                if len(solution_d) + len(rr1) + len(rr2) + len(
                        guess) <= k:  # check for a k- sized solution
                    # return the k sized solution
                    return list(set().union(solution_d, rr1, rr2, list(guess)))
    # return the k+1 sized solution
    return solution


G_input = get_graph.edge_list()  # get the input instances
k = int(input("Enter K:"))
print_input_graph(G_input)  # display the input graph

G, k, solution = kernel.kernelization(G_input, k)  # do kernelization
print("Kernelization", k, solution)
G.remove_nodes_from(solution)
for nodes in itertools.combinations(G.nodes(),
                                    k + 2):  # to get a k+2 number of nodes
    break
nodes = list(nodes)
G_induced = G.subgraph(nodes).copy()  # induce a graph with k+2 nodes

for solution in itertools.combinations(
        G.nodes(),
        k + 1):  # get a k+1 solution for the graph induced with k+2 nodes