Exemple #1
0
def generate_data(sample_size):
    data = []
    for i in range(sample_size):
        x = start.generate_random_graph(10, 0.8, 10)
        y = start.edmonds_karp(x)
        data.append((x, y))
    return data
Exemple #2
0
def generate_data(sample_size):
    data = []
    for i in range(int(sample_size / 4)):
        x = start.generate_random_graph(5, 0.8, 10)
        y = start.edmonds_karp(x)
        x.shape = ([1, 25])
        data.append((x, y))
    for i in range(int(sample_size / 4)):
        x = start.generate_random_graph(5, 0.6, 10)
        y = start.edmonds_karp(x)
        x.shape = ([1, 25])
        data.append((x, y))
    for i in range(int(sample_size / 4)):
        x = start.generate_random_graph(5, 0.4, 10)
        y = start.edmonds_karp(x)
        x.shape = ([1, 25])
        data.append((x, y))
    for i in range(int(sample_size / 4)):
        x = start.generate_random_graph(5, 0.2, 10)
        y = start.edmonds_karp(x)
        x.shape = ([1, 25])
        data.append((x, y))
    return data
Exemple #3
0
            v+=1
            for j in range(10):
                if self.reward_graph[i][j] > -1:
                    if self.q[i][j] > maxq:
                        maxq = self.q[i][j]
            self.q[self.current][i] = self.reward_graph[self.current][i]+self.gamma*maxq
            if i == self.sink:
                end = True
            else:
                self.current = i
            if v > 10:
                end = True

episodes = 500
ex_graph_1 = start.generate_random_graph(10, 0.4, 15)
print(start.edmonds_karp(ex_graph_1))
done = False
maxf = 0
while not done:
    graph = np.zeros([10, 10])
    for i in range(len(graph[0])):
        for j in range(len(graph[0])):
            if ex_graph_1[i][j] > 0:
                if j == 9:
                    graph[i][j] = 1
                else:
                    graph[i][j] = 0
            else:
                graph[i][j] = -1
    bond = agent(1, 0.9, graph)
    for i in range(episodes):