Exemplo n.º 1
0
def testGraphs(gs,output):
	lp.printMoreGraphs(gs)
	dense = cplex.Cplex("dense.lp")
	
	# Turn off cplex output
	if not output : 
		dense.set_log_stream(None)
		dense.set_error_stream(None)
		dense.set_warning_stream(None)
		dense.set_results_stream(None)

	os.remove("dense.lp")
	alg = dense.parameters.lpmethod.values
	dense.parameters.lpmethod.set(alg.barrier)
	dense.solve()
	nodes = getNodes(getNonZero(dense))
	t = getSolution(getNonZero(dense))
	(name,graph,density) = findSmallestGraph(nodes,gs)
	if abs(t-density) < 0.000005:
		return True
	else:
		return False 
Exemplo n.º 2
0
def testGraphs(gs, output):
    lp.printMoreGraphs(gs)
    dense = cplex.Cplex("dense.lp")

    # Turn off cplex output
    if not output:
        dense.set_log_stream(None)
        dense.set_error_stream(None)
        dense.set_warning_stream(None)
        dense.set_results_stream(None)

    os.remove("dense.lp")
    alg = dense.parameters.lpmethod.values
    dense.parameters.lpmethod.set(alg.barrier)
    dense.solve()
    nodes = getNodes(getNonZero(dense))
    t = getSolution(getNonZero(dense))
    (name, graph, density) = findSmallestGraph(nodes, gs)
    if abs(t - density) < 0.000005:
        return True
    else:
        return False
Exemplo n.º 3
0
def main(argv):

	if len(argv) < 1:
		usage()
	gs = []		
	for file in argv[1:]: gs.append(snap.LoadEdgeList(snap.PUNGraph, file, 0, 1))
	# Load and solve LP
	usr_in = ""
	print "Program: minimize..."
	print "use the following input"
	print "data/oregonFAULT-2/oregon2_010421.txt data/oregonFAULT-2/oregon2_010428.txt data/oregonFAULT-2/oregon2_010407.txt"
	print "1) minimize nodes wrt sys.argv[1:]"
	print "2) Does this input fail (sys.argv[1:]) yes/no"
	print "3) Run this: Example nodes"
	while  usr_in not in ["1","2","3"]:
		usr_in = raw_input(">") 

	print "You have Choosen " + usr_in +"!"

	if usr_in == "1":
		lp.printMoreGraphs(gs)
		dense = cplex.Cplex("dense.lp")
		os.remove("dense.lp")
		alg = dense.parameters.lpmethod.values
		dense.parameters.lpmethod.set(alg.barrier)
		dense.solve()

		# get the nodes for the LP
		nodes = getNodes(getNonZero(dense))
		print "size nodes:"+str(nodes)
		# minimize the nodes and respective graphs
		n,gs = ddmin(2,nodes,gs)
		gs0 = []
		for g in gs:
			gs0.append(getSubgraph(g,n))

		lp.printMoreGraphs(gs)
		dense = cplex.Cplex("dense.lp")
		os.remove("dense.lp")
		alg = dense.parameters.lpmethod.values
		dense.parameters.lpmethod.set(alg.barrier)
		dense.solve()

		t = getSolution(getNonZero(dense))
		
		(name,graph,density) = findSmallestGraph(n,gs)
		

		print "t* = "+str(t)
		print "density = "+str(density)
		print "t* =? density : " +str(abs(t - density) < 0.000005)
		print "Local minimal nodes: "+str(n)
		print "---"
		print "Would you like to save the fault inducing minimized graphs? y/n"
		while  usr_in not in ["y","n"]:
			usr_in = raw_input(">") 
		
		if usr_in == "y":
			
			data = sys.argv[1].split("/")[1]
			path = "results/snap/minimal/"
			if not os.path.exists(path) :
				os.makedirs(path)
			filename = raw_input('Enter a snapgraph name: ')
			print "saving graphs in: " + path +" under names "+filename+"i.txt"
			for i in range(0,len(gs)):
				snap.SaveEdgeList(gs[i],path+filename+str(i+1)+".txt","Minimal graph from" + data)		


		else:
			print "exiting..."


	if usr_in == "2":
		if testGraphs(gs,True):
			print "No, input does not fail, e.g t* = density"
		else:
			print "Yes, input does fail, e.g t* != density"
	if usr_in == "3":
		nodes = [5388, 6659, 13237, 5466, 9019, 9013, 5611]
		for g in gs:
			g = getSubgraph(g,nodes)
		
		lp.printMoreGraphs(gs)
		dense = cplex.Cplex("dense.lp")
		os.remove("dense.lp")
		alg = dense.parameters.lpmethod.values
		dense.parameters.lpmethod.set(alg.barrier)
		dense.solve()

		t = getSolution(getNonZero(dense))
		
		(name,graph,density) = fsg(nodes)
		
		print "t* = "+str(t)
		print "density = "+str(density)
		print "t* =? density : " +str(abs(t - density) < 0.000005)
		print "Local minimal nodes: "+str(nodes)
Exemplo n.º 4
0
def main(argv):

    if len(argv) < 1:
        usage()
    gs = []
    for file in argv[1:]:
        gs.append(snap.LoadEdgeList(snap.PUNGraph, file, 0, 1))
    # Load and solve LP
    usr_in = ""
    print "Program: minimize..."
    print "use the following input"
    print "data/oregonFAULT-2/oregon2_010421.txt data/oregonFAULT-2/oregon2_010428.txt data/oregonFAULT-2/oregon2_010407.txt"
    print "1) minimize nodes wrt sys.argv[1:]"
    print "2) Does this input fail (sys.argv[1:]) yes/no"
    print "3) Run this: Example nodes"
    while usr_in not in ["1", "2", "3"]:
        usr_in = raw_input(">")

    print "You have Choosen " + usr_in + "!"

    if usr_in == "1":
        lp.printMoreGraphs(gs)
        dense = cplex.Cplex("dense.lp")
        os.remove("dense.lp")
        alg = dense.parameters.lpmethod.values
        dense.parameters.lpmethod.set(alg.barrier)
        dense.solve()

        # get the nodes for the LP
        nodes = getNodes(getNonZero(dense))
        print "size nodes:" + str(nodes)
        # minimize the nodes and respective graphs
        n, gs = ddmin(2, nodes, gs)
        gs0 = []
        for g in gs:
            gs0.append(getSubgraph(g, n))

        lp.printMoreGraphs(gs)
        dense = cplex.Cplex("dense.lp")
        os.remove("dense.lp")
        alg = dense.parameters.lpmethod.values
        dense.parameters.lpmethod.set(alg.barrier)
        dense.solve()

        t = getSolution(getNonZero(dense))

        (name, graph, density) = findSmallestGraph(n, gs)

        print "t* = " + str(t)
        print "density = " + str(density)
        print "t* =? density : " + str(abs(t - density) < 0.000005)
        print "Local minimal nodes: " + str(n)
        print "---"
        print "Would you like to save the fault inducing minimized graphs? y/n"
        while usr_in not in ["y", "n"]:
            usr_in = raw_input(">")

        if usr_in == "y":

            data = sys.argv[1].split("/")[1]
            path = "results/snap/minimal/"
            if not os.path.exists(path):
                os.makedirs(path)
            filename = raw_input('Enter a snapgraph name: ')
            print "saving graphs in: " + path + " under names " + filename + "i.txt"
            for i in range(0, len(gs)):
                snap.SaveEdgeList(gs[i], path + filename + str(i + 1) + ".txt",
                                  "Minimal graph from" + data)

        else:
            print "exiting..."

    if usr_in == "2":
        if testGraphs(gs, True):
            print "No, input does not fail, e.g t* = density"
        else:
            print "Yes, input does fail, e.g t* != density"
    if usr_in == "3":
        nodes = [5388, 6659, 13237, 5466, 9019, 9013, 5611]
        for g in gs:
            g = getSubgraph(g, nodes)

        lp.printMoreGraphs(gs)
        dense = cplex.Cplex("dense.lp")
        os.remove("dense.lp")
        alg = dense.parameters.lpmethod.values
        dense.parameters.lpmethod.set(alg.barrier)
        dense.solve()

        t = getSolution(getNonZero(dense))

        (name, graph, density) = fsg(nodes)

        print "t* = " + str(t)
        print "density = " + str(density)
        print "t* =? density : " + str(abs(t - density) < 0.000005)
        print "Local minimal nodes: " + str(nodes)