def answer(flow_id, question_id, answer_id): flow = graph.flow(flow_id) question = graph.question(flow_id, question_id) answer = first([answer for answer in question.answers if answer["id"] == answer_id]) rewards = [rel.end for rel in answer.relationships.outgoing(["Reward"])] next_question = first([rel.end for rel in answer.relationships.outgoing(["Next"])]) return render_template( "answer.html", flow=flow, question=question, answer=answer, rewards=rewards, next_question=next_question )
def mlpt(): ''' Multi-power Topology Contorl Algorithm ''' G_mlpt = copy.deepcopy( Node.interconnect_matrix) # innerconnect matrix of mia nodes = copy.deepcopy(Node.nodes) ############################################################## M = 0 H = graph.flow(G_mlpt, Node.n) for i in range(Node.n): nei = nodes[i].double_neighbor n = [x[0] for x in nei] # id of beighbor of node-i d = [x[1] for x in nei] tempM = 0 e = [None] * len(d) for j in range(len(d)): e[j] = H[i][n[j]] * Simulator.dis_to_power(d[j]) tempM += e[j] V = [] for k in range(len(d)): V.append([n[k], d[k], e[k]]) nodes[i].neighbor = V nodes[i].neighbor.sort(key=lambda x: x[2], reverse=True) if tempM > M: M = tempM ################################################################ flag = True # is the power of node (game theory result) the NE? cnt = 0 # number of games while flag: flag = False cnt += 1 for i in range(Node.n): # N->0 (u, G_mlpt) = mlpt_utility(i, nodes, G_mlpt, M) if u != nodes[i].power: flag = True nodes[i].power = u print("Number of iterations of MLPT:", cnt) # print(nodes[0].neighbor) # print(nodes[0].power) # print(nodes[1].power) # print(nodes[Node.n-1].power) return G_mlpt, nodes
f = open('sections.txt', 'r') section_data = f.read().split('\n') f.close() mods = [] sections = [] # All names of the sections/the way strings are concatenated are due to the format I am using for my own implementation # Moderator names are animals. Why? Because why not. Also, because public git for m in moderator_data: line = m.split(',') exist_mod = find_moderator(line[0], mods) if exist_mod: exist_mod.add_to_prefs(line[1].strip() + '-' + line[2].strip()) else: new_mod = moderator(line[0], [line[1].strip() + '-' + line[2].strip()]) mods.append(new_mod) for s in section_data: new_section = section(s) sections.append(new_section) # Each moderator can teach 2 sections, each section needs three moderators (three rooms) flo = flow(2, mods, 3, sections) flo.get_max_flow() print(flo.max_flow_value()) print(flo.get_all_b_matches()) print print(flo.get_all_a_matches())
def question(flow_id, question_id): flow = graph.flow(flow_id) question = graph.question(flow_id, question_id) return render_template("question.html", flow=flow, question=question)
def flow(flow_id): flow = graph.flow(flow_id) questions = [rel.end.properties for rel in flow.relationships.outgoing(["Question"])] first_question = first([rel.end for rel in flow.relationships.outgoing(["First"])]) return render_template("flow.html", flow=flow, questions=questions, first_question=first_question)