def _process(json_data, use_cloud, quit_on_first=True, ignore_pickle=False, debug_info=None): slv = Solver(quit_on_first=quit_on_first, use_cloud=use_cloud, ignore_pickle=ignore_pickle, debug_info=debug_info) st = State() st.load_from_json(json_data) slv.set_state(st) filelist = [] if use_cloud: # fetch remote pickle if exists filelist = cloud.files.list() pf = '%s.pickle' % st.__hash__() pffull = os.path.join('var', 'graphs', pf) if pf in filelist: cloud.files.get(pf, pffull) slv.solve() if use_cloud: # upload solution cloud.files.put(pffull, pf) # the image, save it to cloud png = '%s.png' % st.__hash__() pngfull = os.path.join('var', 'graphs', png) if png not in filelist: # irrelevent? FIXME , pngfull does not exist, since we never synced it. slv.draw_graph(filename=pngfull) if use_cloud: cloud.files.put(pngfull, png) else: print "Graph Image %s already exists" % pngfull ret = (slv.l_shortest) return ret
class _SolverThread(Thread): def __init__(self,state,draw_graph,quit_on_first,debug_info): Thread.__init__(self) self.t = time.time() self.draw_graph = draw_graph from src.solve.solver import Solver self.solver = Solver(debug_info=debug_info,quit_on_first=quit_on_first) self.solver.set_state(state) def run(self): self.solver.solve() if self.draw_graph: self.solver.draw_graph("data/graphs/graph-%s.png" % self.solver.state.__hash__()) #FIXME remove graph- prefix for consistency print "Took %d seconds" % int(time.time() - self.t)