コード例 #1
0
ファイル: greedy.py プロジェクト: antongt/DenseProject
from greedy import DCSGreedy, utils, preprocessGreedy

if(len(sys.argv) < 2):
  sys.exit("Usage: python " + sys.argv[0] + " <file1> <file2> ...")
  
utils.timer() # Start the timer.
if(sys.argv[1] == "-d"):
    graphs = preprocessGreedy.loadDirGraphs()
else:
    graphs = preprocessGreedy.loadGraphs()

print("Imported " + str(len(graphs)) + " graphs in " + utils.timer())
# Don't remove, this isn't the deep preprocessing that takes time.
numberOfNodes = preprocessGreedy.simplePreprocessing(graphs)

# If multiple graphs, do some preprocessing to make sure they are over the same
# set of nodes.
# Make sure all graphs have the same amount of nodes.
# There could be a deeper check here.

print("Preprocessing took " + utils.timer())
startTime = time.clock()
(nodes,density) = DCSGreedy.getDCS_Greedy(graphs,numberOfNodes)
runTime = time.clock()-startTime

utils.saveResults(nodes,str(runTime) + " seconds",density)

# printQuickStats(g2)
print("The greedy algorithm completed in " + str(runTime) + " seconds")
#saveResults(g2, runTime, density)
コード例 #2
0
ファイル: greedy.py プロジェクト: antongt/DenseProject
from greedy import DCSGreedy, utils, preprocessGreedy

if (len(sys.argv) < 2):
    sys.exit("Usage: python " + sys.argv[0] + " <file1> <file2> ...")

utils.timer()  # Start the timer.
if (sys.argv[1] == "-d"):
    graphs = preprocessGreedy.loadDirGraphs()
else:
    graphs = preprocessGreedy.loadGraphs()

print("Imported " + str(len(graphs)) + " graphs in " + utils.timer())
# Don't remove, this isn't the deep preprocessing that takes time.
numberOfNodes = preprocessGreedy.simplePreprocessing(graphs)

# If multiple graphs, do some preprocessing to make sure they are over the same
# set of nodes.
# Make sure all graphs have the same amount of nodes.
# There could be a deeper check here.

print("Preprocessing took " + utils.timer())
startTime = time.clock()
(nodes, density) = DCSGreedy.getDCS_Greedy(graphs, numberOfNodes)
runTime = time.clock() - startTime

utils.saveResults(nodes, str(runTime) + " seconds", density)

# printQuickStats(g2)
print("The greedy algorithm completed in " + str(runTime) + " seconds")
#saveResults(g2, runTime, density)
コード例 #3
0
ファイル: lag.py プロジェクト: antongt/DenseProject
prev_t    = dense0.solution.get_values(0)
prev_xijm = dense0.solution.get_values(range(1,len(xijm)+1))
prev_val  = dense0.solution.get_objective_value()
printResults.save(dense0)
print "time taken: " + str(iter0_time)
sys.exit()
print "Iteration 0 ("+str(iter0_time)+" sec.): " + str(prev_val)

# initial value of all lamdas are -1.
lamda = [-1]*len(Graphs)

times = []
times.append(iter0_time)
usedNodes = preprocessGreedy.simplePreprocessing(Graphs)
(nodes, LB) = DCSGreedy.getDCS_Greedy(Graphs,usedNodes)
scalar = 1.0
dense = cplex.Cplex("dense.lp")
j = 0
while(j<5):
    #remove all output from cplex:
    dense.set_results_stream(None)

    oldlamda = lamda[:]
    #calculate (sub)gradients:
    grads = []
    start = 1
    for i in range(0,len(lamda)):
      # split up prev_xijm
      end = start+len(allEdges[i])
      prev_xijm_sum = sum(prev_xijm[start:end])