Exemplo n.º 1
0
def main():
  rails_environment = sys.argv[1]
  connection = dbf.connect_to_database(rails_environment)
  connection.autocommit = True

  database_row_id=sys.argv[2]

  cur = connection.cursor()
  cur.execute ("SELECT * FROM metalics WHERE id=\'"+database_row_id+"\' LIMIT 1;")
  database_row = cur.fetchone()
  database_row_id = database_row[0]
  params = database_row[1]
  algorithm = database_row[2]
  solver = None

  if algorithm == "MD Solver":
    solver = md.MDSolver(params)
  elif algorithm =="Genetics":
    solver = gas.GeneticSolver(params)
  elif algorithm == "Simulated Annealing":
    solver = san.simulatedAnnealingNano(params)
  elif algorithm == "Basin Hopping":
    solver = sbh.randomSolver(params)

  if solver is None:
    print "ERROR: Invalid solver!"
  else:
    solver.cur = cur
    solver.database_row_id=database_row_id
    solver.setStatusDone("Calculating solution...")
    solution = solver.solve()
    solver.setSolution(solution)
    solver.setDone('y')
    print solution
def main():
  minPoints = 10
  maxPoints = 1500
  pointInterval = 6
  iteration = 1

  n = open('nul','w')
  sys.stdout=n

  output=""

  for points in xrange(minPoints,maxPoints,pointInterval):
      output+=str(points) + "\n\r"
      distances = [0,0,0,0,0,0,0,0,0,0,0]
      times =[0,0,0,0,0,0,0,0,0]
      for iterations in xrange(iteration):

        solver = []
        #solver.append(md.MDSolver()) WE NEVER RAN A TEST CASE WITH THIS
        #solver.append(san.simulatedAnnealingNano()) THIS WAS INCLUDED IN THE FIRST FOUR POINTS
        solver.append(sbh.randomSolver())
        solver.append(gas.GeneticSolver())

        for solves in xrange(len(solver)):
            solver[solves].numberOfAtoms = points
            string = "Al" + str(points/2) + "Ni" + str(points/2)
            solver[solves].definingString = string
            timer = time.time()
            solution = solver[solves].solve()
            timer = time.time()-timer
            times[solves] += timer
            distances[solves] += solver[solves].bestEnergy
            print"a",str(points)
      for solves in xrange(len(solver)):
        output+=str(times[solves]/iteration) + "\n\r"
        output+=str(distances[solves]/iteration) + "\n\r"
        f = open("output.txt", "w")
        #if points % 4 == 2:
#            f = open("output.txt", "w")
#        else:
#            f = open("output1.txt", "w")
        f.write(output)
        f.close()