def RL_forwarding(data, src, dst): graph = get_dict(data) A = graph["A"] Z = graph["Z"] weight = graph["weight"] links = graph["links"] R = initial_R(A,Z,weight,links) Q = initial_Q(R) alpha = 0.9 # learning rate epsilon = 0.8 #greedy policy n_episodes = 300 return get_result(R,Q,alpha,epsilon,n_episodes,src,dst)
def find_nodes(csv_file, start_node, end_node): data = pd.read_csv(csv_file) graph = get_dict(data) A = graph["A"] Z = graph["Z"] weight = graph["weight"] A_Z_dict = graph["A_Z_dict"] start = int(start_node) end = [int(end_node)] R = initial_R(A, Z, weight, A_Z_dict) Q_init = initial_Q(R) Q = copy.deepcopy(Q_init) # print("The WEIGHT-TABLE from a NODE A TO NODE B : ") # print(R) # print("The Q-TABLE after initialisation : ") # print(Q) alpha = 0.7 # learning rate epsilon = 0.1 #greedy policy n_episodes = 900 # print("The final Q table : ") # time0 = time.time() result = get_result(R, Q, alpha, epsilon, n_episodes, start, end) # print("time is:",time.time() - time0) # print(result["ends_find"]) # print(result["cost"]) # print(result["routes_number"]) # print(result["all_routes"]) return R, Q_init, result["all_routes"], result["final_Q"]
import pandas as pd import time data = pd.read_csv("graph.csv") graph = get_dict(data) A = graph["A"] Z = graph["Z"] weight = graph["weight"] A_Z_dict = graph["A_Z_dict"] ## start = 1 end = [9] R = initial_R(A, Z, weight, A_Z_dict) Q = initial_Q(R) alpha = 0.7 # learning rate epsilon = 0.1 #greedy policy n_episodes = 1000 time0 = time.time() result = get_result(R, Q, alpha, epsilon, n_episodes, start, end) print("time is:", time.time() - time0) print(result["ends_find"]) print(result["cost"]) print(result["routes_number"])