def main():
  minPoints = 10
  maxPoints = 300
  pointInterval = 5
  iteration = 2
  for points in xrange(minPoints,maxPoints,pointInterval):
      print points
      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):
        string = generateRandomString(points,50)


        solver = []
        solver.append(ab3d.alpha_beta_3d(string))
        solver.append(ab.alpha_beta(string))
        solver.append(ss.SlitheringSnakeSolver(string))
        #solver.append(abai3d.alpha_beta_ai_3d(string))

        for solves in xrange(len(solver)):
            timer = time.time()
            solution = solver[solves].solve()
            timer = time.time()-timer
            times[solves] += timer
            distances[solves] += getPotentialEnergy(solution)
           # print"a"
      for solves in xrange(len(solver)):
        print times[solves]/iteration
        print distances[solves]/iteration
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 proteins WHERE id=\'"+database_row_id+"\' LIMIT 1;")
  database_row = cur.fetchone()
  database_row_id = database_row[0]
  params = database_row[3]
  algorithm = database_row[4]
  solver = None

  if algorithm == "Alpha Beta":
    solver = ab.alpha_beta(params)

  if algorithm =="Slithering Snake":
    solver = ss.SlitheringSnakeSolver(params)

  if algorithm == "Alpha Beta 3D AI":
    solver = ab_3d_ai.alpha_beta_ai_3d(params)

  if algorithm == "Alpha Beta 3D":
    solver = ab3d.alpha_beta_3d(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
Esempio n. 3
0
    return float(solution[i:len(solution)-1])

def generateRandomString(length, percent_h):
    ph = float(percent_h)
    hs = 0
    string = ""
    for i in xrange(length):
        rand = random.random()
        if rand <= float(length*ph - hs)/float(length - i):
            string += "H"
            hs += 1
        else:
            string += "P"
    return string

percent_h = .5
length = 50
string = generateRandomString(length,percent_h)
print string
solver = ss.SlitheringSnakeSolver(string)
solution = solver.solve()
print getPotentialEnergy(solution)

solver = ab.alpha_beta(string)
solution = solver.solve()
print getPotentialEnergy(solution)

solver = ab3d.alpha_beta_3d(string)
solution = solver.solve()
print getPotentialEnergy(solution)