示例#1
0
文件: cnn.py 项目: swone/rlnf
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
示例#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
示例#3
0
"""class Memory():
    def __init__(self, max_size):
        self.buffer = deque(maxlen = max_size)

    def add(self, experience):
        self.buffer.append(experience)

    def sample(self, batch_size):
        buffer_size = len(self.buffer)
        index = np.random.choice(np.arange(buffer_size),
                size=batch_size, replace=False)
        return [self.buffer[i] for i in index]

memory = Memory(max_size=memory_size)
"""
fgraph = start.generate_random_graph(10, 0.6, 15)
rgraph = np.copy(fgraph)
for i in range(10):
    for j in range(10):
        if fgraph[i][j] > 0:
            if j == 9:
                rgraph[i][j] = 10
            else:
                rgraph[i][j] = 1
        else:
            rgraph[i][j] = -11
possible_actions = []

for i in range(10):
    actions = []
    for j in range(10):
示例#4
0
文件: gamenn.py 项目: swone/rlnf
            maxq = 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)