def main(args): rid = args[1].decode("gb18030").encode("utf8"); if len(args)==1: depth = 3 else: depth = int(args[2].decode("gb18030").encode("utf8")); #points traversal: nodes = [] p = MudRoomSearchProblem(rid,None) # nodes = depthFirstTraversalList(p,nodes,depth) nodes = breadthFirstTraversalList(p,nodes,depth) nodes.append(nodes[0]) # print [node.status for node in nodes] i = 0 ret = "" while i<len(nodes)-1: init_rid = nodes[i].status goal_rid = nodes[i+1].status p = MudRoomSearchProblem(init_rid,goal_rid) actions,_,_=bfs(p) for act in actions: ret = ret + act + ";" i = i + 1 retlist = ret.split(";") for a in retlist[:-1]: print a
def getAreaRooms(area, exp_depth=2): arooms = [] brooms = [] conn = getconn() cursor = conn.cursor() cursor.execute( 'SELECT t2.rid FROM area_name_map t1,(select rid,rname,ifnull(t_area,area) as tarea from v_traversal_roominfo) t2 where t1.area=t2.tarea and t1.cname=?', (area.decode("utf8"), )) rows = cursor.fetchall() for row in rows: arooms.append(row[0]) cursor.execute( 'SELECT t2.rid FROM area_name_map t1,(select rid,rname,ifnull(t_area,area) as tarea from v_traversal_roominfo) t2,v_roomrel_nextarea t3 where t2.rid=t3.rid and t1.area=t2.tarea and t3.next_area<>? and t1.cname=?', (area.decode("utf8"), area.decode("utf8"))) rows = cursor.fetchall() conn.close() for row in rows: if row[0] not in brooms: brooms.append(row[0]) if len(brooms) > 0: nodes = [] for rid in brooms: p = MudRoomSearchProblem(rid, None) # nodes = depthFirstTraversalList(p,nodes,depth) nodes = breadthFirstTraversalList(p, nodes, exp_depth) for node in nodes: if node.status not in arooms: arooms.append(node.status) return (arooms, brooms)
def main(args): ref_rid = args[1].decode("gb18030").encode("utf8") rname = args[2].decode("gb18030").encode("utf8") if len(args) == 2: depth = 5 else: depth = int(args[3].decode("gb18030").encode("utf8")) # ref_rid = "978dd91452cfa9ca80d8816822786374" # rname = "北大街" # depth =0 # rids = get_room_list_byRName(ref_rid, rname) # print rids #test: # print area,rname # print ridlist ##### #points traversal: if len(rids) > 0: nodes = [] for rid in rids: p = MudRoomSearchProblem(rid, None) # nodes = depthFirstTraversalList(p,nodes,depth) nodes = breadthFirstTraversalList(p, nodes, depth) nodes.append(nodes[0]) # print [node.status for node in nodes] i = 0 ret = "" while i < len(nodes) - 1: init_rid = nodes[i].status goal_rid = nodes[i + 1].status p = MudRoomSearchProblem(init_rid, goal_rid) actions, _, _ = bfs(p) for act in actions: ret = ret + act + ";" i = i + 1 retlist = ret.split(";") for a in retlist[:-1]: print a
def main(args): loc = args[1].decode("gb18030").encode("utf8") if len(args) == 1: depth = 3 else: depth = int(args[2].decode("gb18030").encode("utf8")) # loc='扬州打铁铺' # depth=2 (area, rname) = loc_split(loc) ridlist = get_room_list(area, rname) #test: # print area,rname # print ridlist ##### if len(ridlist) > 0: nodes = [] for rid in ridlist: p = MudRoomSearchProblem(rid, None) nodes = depthFirstTraversalList(p, nodes, depth) nodes.append(nodes[0]) # print [node.status for node in nodes] i = 0 ret = "" while i < len(nodes) - 1: init_rid = nodes[i].status goal_rid = nodes[i + 1].status p = MudRoomSearchProblem(init_rid, goal_rid) actions, _, _ = bfs(p) for act in actions: ret = ret + act + ";" i = i + 1 retlist = ret.split(";") for a in retlist[:-1]: print a
def walk_stepbystep2(ref_rid,goal_rid): #return action and next ref_rid if len(ref_rid)==0 or ref_rid == "0": return ("0","0") else: p = MudRoomSearchProblem(ref_rid,goal_rid) actions,cost,nodes = breadthFirstTCSearch(p) if len(actions)==0 or len(nodes)<1: return ("0","0") else: return (actions[0],nodes[1].status)
def main(args): #2d5c8daa1b737d97509231fda8c49d05 9834ec789ab9f8f08c46c50678f66f3a init_rid = args[1].decode("gb18030") goal_rid = args[2].decode("gb18030") pre = int(args[3].decode("gb18030")) # init_rid = '2d5c8daa1b737d97509231fda8c49d05' # goal_rid = '9834ec789ab9f8f08c46c50678f66f3a' p = MudRoomSearchProblem(init_rid, goal_rid) _, _, nodes = ucs(p) pre_rid = "0" ret = pre_rid + ";" if len(nodes) > pre: pre_rid = nodes[-1 * pre].status p1 = MudRoomSearchProblem(pre_rid, goal_rid) actions, _, _ = ucs(p1) ret = pre_rid + ";" for act in actions: ret = ret + act + ";" retlist = ret[:-1].split(";") for a in retlist: print a
def main(args): #2d5c8daa1b737d97509231fda8c49d05 9834ec789ab9f8f08c46c50678f66f3a init_rid = args[1].decode("gb18030"); goal_rid = args[2].decode("gb18030"); # init_rid = '2d5c8daa1b737d97509231fda8c49d05' # goal_rid = '9834ec789ab9f8f08c46c50678f66f3a' p = MudRoomSearchProblem(init_rid,goal_rid) actions,cost,nodes = ucs(p) ret = str(cost) + ";" for act in actions: ret = ret + act + ";" retlist = ret.split(";") for a in retlist: print a
def get_room_list_byRName(ref_rid, rname): depth = 15 nodes = [] p = MudRoomSearchProblem(ref_rid, None) nodes = breadthFirstTraversalList(p, nodes, depth) conn = getconn() cursor = conn.cursor() cursor.execute('SELECT rid from roominfo where rname=?', (rname.decode("utf8"), )) rows = cursor.fetchall() conn.close() if len(rows) == 0: return [] rids = [] for n in nodes: for row in rows: if row[0] == n.status: rids.append(n.status) return rids
def sortNodes(nodes): if len(nodes) > 15: return nodes sortedNodes = [] sortedNodes.append(nodes[0]) init_rid = nodes[0].status del nodes[0] while len(nodes) > 0: min_cost = 999999 min_index = 0 i = 0 while i < len(nodes): goal_rid = nodes[i].status p = MudRoomSearchProblem(init_rid, goal_rid) _, cost, _ = bfs(p) if cost < min_cost: min_cost = cost min_index = i i = i + 1 sortedNodes.append(nodes[min_index]) init_rid = nodes[min_index].status del nodes[min_index] return sortedNodes
def main(args): loc = args[1].decode("gb18030").encode("utf8") if len(args) == 1: depth = 0 else: depth = int(args[2].decode("gb18030").encode("utf8")) # loc='灵鹫密道' # depth=0 (area, rname) = loc_split(loc) (ridlist, arooms, brooms) = get_room_list(area, rname) #test: # print area,rname # print ridlist ##### #points traversal: if len(rname) > 0 and len(ridlist) > 0: nodes = [] for rid in ridlist: p = MudRoomSearchProblem(rid, None) # nodes = depthFirstTraversalList(p,nodes,depth) nodes = breadthFirstTraversalList(p, nodes, depth) # print [node.status for node in nodes] nodes = sortNodes(nodes) # print [node.status for node in nodes] i = 0 ret = "" while i < len(nodes) - 1: init_rid = nodes[i].status goal_rid = nodes[i + 1].status p = MudRoomSearchProblem(init_rid, goal_rid) actions, _, _ = bfs(p) for act in actions: ret = ret + act + ";" i = i + 1 retlist = ret.split(";") # print retlist[:-1] for a in retlist[:-1]: print a #area traversal: if len(rname) == 0: #use brooms[0] as start point startp = ridlist[0] if len(brooms) > 0: startp = brooms[0] nodes = [] p = MudRoomSearchProblem(startp, None) nodes = depthFirstTraversalList_inArea(p, arooms) # print [node.status for node in nodes] nodes = sortNodes(nodes) i = 0 ret = "" while i < len(nodes) - 1: init_rid = nodes[i].status goal_rid = nodes[i + 1].status p = MudRoomSearchProblem(init_rid, goal_rid) actions, _, _ = bfs(p) for act in actions: ret = ret + act + ";" i = i + 1 retlist = ret.split(";") for a in retlist[:-1]: print a
def main(args): loc = args[1].decode("gb18030").encode("utf8"); if len(args)==1: depth = 3 else: depth = int(args[2].decode("gb18030").encode("utf8")); # loc='扬州打铁铺' # depth=2 ss = re.split("\s+",loc) (area,rname) = ("","") if len(ss) == 1: area = ss[0] if len(ss) > 1 : (area,rname) = (ss[0],ss[1]) (ridlist,arooms,brooms) = get_room_list_bypy(area,rname) #points traversal: if len(rname)>0 and len(ridlist)>0: nodes = [] for rid in ridlist: p = MudRoomSearchProblem(rid,None) # nodes = depthFirstTraversalList(p,nodes,depth) nodes = breadthFirstTraversalList(p,nodes,depth) nodes.append(nodes[0]) # print [node.status for node in nodes] i = 0 ret = "" while i<len(nodes)-1: init_rid = nodes[i].status goal_rid = nodes[i+1].status p = MudRoomSearchProblem(init_rid,goal_rid) actions,_,_=bfs(p) for act in actions: ret = ret + act + ";" i = i + 1 retlist = ret.split(";") for a in retlist[:-1]: print a #area traversal: if len(rname)==0: #use brooms[0] as start point startp = ridlist[0] if len(brooms)>0: startp = brooms[0] nodes = [] p = MudRoomSearchProblem(startp,None) nodes = depthFirstTraversalList_inArea(p,arooms) nodes.append(nodes[0]) # print [node.status for node in nodes] i = 0 ret = "" while i<len(nodes)-1: init_rid = nodes[i].status goal_rid = nodes[i+1].status p = MudRoomSearchProblem(init_rid,goal_rid) actions,_,_=bfs(p) for act in actions: ret = ret + act + ";" i = i + 1 retlist = ret.split(";") for a in retlist[:-1]: print a