def MCTS(): start = Node() Agent_id = 2 User3_id = 3 AgentPosts = algo.Post_on_feed(Agent_id) User3Posts = algo.Post_on_feed(User3_id) AgentOperators = RA.Get_Possible_Operators(Agent_id,AgentPosts) User3Opeators = RA.Get_Possible_Operators(User3_id,User3Posts) start.data.append(AgentOperators) start.data.append(User3Opeators) myPath = [] myPath.append(start) while True: node = myPath.pop() if node.countParents > 2: print("Final Path = ",node.operator) print("TrueScoreAgent = ",node.TrueScoreAgent) break operators = getChlids(node.data) j = 0 SimulateMax = -100 AgentMaxOperation = '' User3RanOperation = '' MaxNode = node RandomStatusID_1 = RA.getStatusToPostID() RandomStatusID_2 = RA.getStatusToPostID() for i in operators: l = list(operators[j]) n = NodeP(node,l,RandomStatusID_1,RandomStatusID_2) SimulateScore = Simulate(l[0]) n.SimulateScore = n.TrueScoreAgent + SimulateScore if n.SimulateScore > SimulateMax: MaxNode = n SimulateMax = n.SimulateScore AgentMaxOperation = l[0] User3RanOperation = l[1] j+=1 myPath.append(MaxNode) print(operators) print("AgentMaxOperation = ",AgentMaxOperation, "User3RanOperation = ",User3RanOperation) move1,value1 = RA.MakeMove(Agent_id,AgentMaxOperation,AgentOperators) move2,value2 = RA.MakeMove(User3_id,User3RanOperation,User3Opeators) AgentPosts = algo.Post_on_feed(Agent_id) User3Posts = algo.Post_on_feed(User3_id) AgentOperators = RA.Get_Possible_Operators(Agent_id,AgentPosts) User3Opeators = RA.Get_Possible_Operators(User3_id,User3Posts) MaxNode.data.append(AgentOperators) MaxNode.data.append(User3Opeators)
def BFS(): start = Node() Agent_id = 2 User3_id = 3 count = 0 startr = timer() start = Node() MaxNode = start Q = Queue() Q.put(start) while(not Q.empty()): node = Q.get() AgentPosts = algo.Post_on_feed(Agent_id) User3Posts = algo.Post_on_feed(User3_id) AgentOperators = RA.Get_Possible_Operators(Agent_id,AgentPosts) User3Opeators = RA.Get_Possible_Operators(User3_id,User3Posts) node.data.append(AgentOperators) node.data.append(User3Opeators) print(node.countParents) if node.countParents > 3: print(node.operator) break validOperator = getChlids(node.data) j = 0 RandomStatusID_1 = RA.getStatusToPostID() RandomStatusID_2 = RA.getStatusToPostID() MaxValueChilds = -100 for o in validOperator: l = list(validOperator[j]) n = NodeP(node,l,RandomStatusID_1,RandomStatusID_2) Q.put(n) count+=1 j+=1 AgentMaxOperation,User3RanOperation = getRandomOpeartion2Players(validOperator) print("AgentMaxOperation = ",AgentMaxOperation, "User3RanOperation = ",User3RanOperation) move1,value1 = RA.MakeMove(Agent_id,AgentMaxOperation,AgentOperators) move2,value2 = RA.MakeMove(User3_id,User3RanOperation,User3Opeators) print("total chlids = ",count) end = timer() print((end-startr)/60) print(count)
def home(request): posts = algo.Post_on_feed(request.user.id) posts.sort(reverse=True, key=sortbyTime) user_liked = posts_user_liked(request.user.id) people_may_know = helper(request) list_friend_req = myreqest(request.user.id) context = { 'posts': posts, 'mystatus': Status.objects.all(), # 'friends' : Friends.objects.filter(userid_id=request.user.id).first().myfriends, 'friends_requst': list( set( Friend_req.objects.filter( userid_id=request.user.id).first().myfriends_req)), 'people_my_know': people_may_know, 'users': User.objects.all(), 'posts_user_liked': user_liked, 'list_friend_req': list_friend_req } return render(request, 'facebook/feed.html', context)
if (DEBUG): print("move from the waiting room to Create Post Page") ''' in the Create Post page. ''' if (DEBUG): print("Create Post in Create post page") # ini the status to list status = Status.objects.all() for i in status: PostsIUsed.update({i.id: i.sumWithOutBenefit}) # Create The First Round! algo.Post_on_feed(agent.id) time.sleep(2) current_path = site_path + 'create_post' AgentTimeStart = timer() key = max(PostsIUsed, key=PostsIUsed.get) StatusToPost = getStatusToPost(key) AgentRequest = MyRequest(method='POST', path=current_path, params={'user_option': StatusToPost}) create_post_Agent(AgentRequest) AgentTimeEnd = timer() AgentTimeTook = (AgentTimeEnd - AgentTimeStart) / 60 mylog = Log.objects.filter(id_user=agent_id).last() mylog.TimeTookInSec = AgentTimeTook mylog.save()
validOperator = getChlids(node.data) j = 0 RandomStatusID_1 = RA.getStatusToPostID() RandomStatusID_2 = RA.getStatusToPostID() MaxValueChilds = -100 for o in validOperator: l = list(validOperator[j]) n = NodeP(node,l,RandomStatusID_1,RandomStatusID_2) Q.put(n) count+=1 j+=1 AgentMaxOperation,User3RanOperation = getRandomOpeartion2Players(validOperator) print("AgentMaxOperation = ",AgentMaxOperation, "User3RanOperation = ",User3RanOperation) move1,value1 = RA.MakeMove(Agent_id,AgentMaxOperation,AgentOperators) move2,value2 = RA.MakeMove(User3_id,User3RanOperation,User3Opeators) print("total chlids = ",count) end = timer() print((end-startr)/60) print(count) if __name__ == '__main__': agentPosts = algo.Post_on_feed(2) AgentOperators = RA.Get_Possible_Operators(2,agentPosts) print(list(AgentOperators.keys()))