def create_supports(self): for i, pce_id in enumerate(self.pieces): for row in db.callproc('orders_for_piece', pce_id): dst = row['destination'] order_type = int(row['order_type']) if dst and order_type == 2: operands = db.callproc('operands_for_piece', pce_id) if len(operands) == 1: sup_pce = operands[0]['ter_id'] if not self.loc_pce.has_key(sup_pce): continue sup_pce = self.loc_pce[sup_pce] sup_orders = db.callproc('orders_for_piece', self.pieces[sup_pce]) if not sup_orders: continue sup_dst = sup_orders[0]['destination'] if sup_dst != dst or sup_pce == i: continue self.pce_m[i][sup_pce] = 2 #print order_type, len(db.callproc('orders_for_piece', pce_id)), pce_id #if self.loc_pce.has_key(dst) and self.loc_pce[dst] != i: #self.pce_m[i][self.loc_pce[dst]] = 1 #for o in self.orders: #if o['destination'] == dst and o['order_type'] == 2\ #and self.piece_map[int(o['pce_id'])] != i: #self.pce_m[i][self.piece_map[int(o['pce_id'])]] = 2 #print i, self.dst_pce[dst], len(self.pce_m[i]) graph_algorithms._print_matrix(self.pce_m)
def create_moves(self): for i, pce_id in enumerate(self.pieces): for row in db.callproc('orders_for_piece', pce_id): dst = row['destination'] order_type = int(row['order_type']) if dst and order_type == 1: #print order_type, len(db.callproc('orders_for_piece', pce_id)), pce_id if self.loc_pce.has_key(dst) and self.loc_pce[dst] != i: self.pce_m[i][self.loc_pce[dst]] = 1 for o in self.orders: if o['destination'] == dst and o['order_type'] == 1\ and self.piece_map[int(o['pce_id'])] != i: self.pce_m[i][self.piece_map[int(o['pce_id'])]] = 1 #print i, self.dst_pce[dst], len(self.pce_m[i]) graph_algorithms._print_matrix(self.pce_m)
#print for v in xrange(len(self.pce_m)): #print v, color[v], path[v], self.adj(v) if color[v] == 0: dfs_visit(v) print path print exe - dislodged for pce in list(exe - dislodged): if not dont: execute(self.pieces[pce]) for pce in list(dislodged): if not dont: dislodge(self.pieces[pce], self.pieces_info[self.pieces[pce]]['ter_id'], [self.pieces[p] for p in list(exe - dislodged)]) print dislodged def resolve(gam_id): g = graph(gam_id) g.step_one() #graph_algorithms._print_matrix(g.pce_m) g.step_two() if __name__ == '__main__': pass #dislodge(1, 5) g = graph(1) g.step_one() graph_algorithms._print_matrix(g.pce_m) g.step_two(True) #g.create_order_graph()