Ejemplo n.º 1
0
def cograph_editing(IG):
	if not IG._is_cograph:

		IG._count_dG_not_cograph += 1

		if not IG._is_compatible:
			IG._count_dG_notCograph_notConsistent += 1
		else:
			IG._count_dG_notCograph_consistent += 1

		# check that the edited graph is a cograph, properly colored and has a set of triples that is compatible.
		edited_G = IG.cograph_editing()
		edited_G_is_cograph = is_cograph(edited_G)
		edited_G_is_properly_colored = is_properly_colored(edited_G, IG._G)
		edited_G_is_compatible = is_compatible(edited_G, IG._G)


		if edited_G_is_cograph:
			
			IG._count_cographEdit_success += 1

			if edited_G_is_properly_colored:
				IG._count_cographEdit_remain_properly_colored += 1

			if edited_G_is_compatible and IG._is_compatible:
				IG._count_cographEdit_remained_consistent += 1
			elif edited_G_is_compatible and not IG._is_compatible:
				IG._count_cographEdit_fixed_consistency += 1
			elif not edited_G_is_compatible and IG._is_compatible:
				IG._count_cographEdit_broke_consistency += 1

			if edited_G_is_compatible and edited_G_is_properly_colored:
				IG._count_cographEdit_to_LDT += 1
				number_edges_remaining = len(edited_G.edges())
				edit_dist = gt.symmetric_diff(IG._G_perturbed, edited_G)
				return edited_G, True, number_edges_remaining, edit_dist

	return None, False, None, None
Ejemplo n.º 2
0
    }), (4, {
        "color": 0
    })]
    G_edges = [(0, 1), (1, 2), (2, 3), (2, 4)]

    G.add_nodes_from(G_nodes)
    G.add_edges_from(G_edges)

    solver = LDTEditor(G)
    solver.build_model()
    solver.optimize(time_limit=None)

    sol_graph, sol_distance = solver.get_solution()
    # sol_distance will be 2*symmetric_diff if using obj func for directed graph since we're counting xy edges and yx edges in the objective function. the graph is undirected so only xy or yx is needed

    edit_dist = gt.symmetric_diff(G, sol_graph)
    print(
        "------------------------------------------------------------------------------------------------------------------------"
    )
    print("The symmetric difference between G and G* is: {}".format(edit_dist))
    print("The value for the objective function is: {}".format(sol_distance))
    #print("------------------------------------------------------------------------------------------------------------------------")
    #print("The edges of the solution graph: {}".format(sol_graph.edges()))
    print(
        "------------------------------------------------------------------------------------------------------------------------"
    )
    print("Runtime: {}".format(solver.get_solve_time()))
    print("Saving data...")
    solver._save_ILP_data(G,
                          sol_graph,
                          solver.get_solve_time(),