<reponame>Ryhax/aco
from ants import Ant
from models import Dim3Env, plt
from utils import distance

# hyper-param
BATCH = 8
GEN = 64
# PHEROMONES = 100

# 交互模式
plt.ion()


if __name__ == '__main__':
    size = (12, 12, 12)     # 空间模型大小 12*12*12
    start = (0, 0, 0)       # 起点坐标
    end = (11, 11, 11)      # 终点坐标
    env = Dim3Env(size, start, end)     # 生成空间
    for b in range(BATCH):      # 批次迭代
        for g in range(GEN):    # 蚁群迭代
            agent = Ant('%d-%d' % (b, g), start, end, env.direct, *env.get_txd())   # 生成蚂蚁
            while True:
                step = agent.choose_action()    # 动作决策，每次移动一步
                # print('step to %s' % step.__str__())
                if distance(step, end, env.DIM) <= env.unit:
                    # 抵达终点
                    break
            env.distribution = agent.feedback(100) * 0.9    # 更新信息素分布
            print('ant %s step %d' % (agent.ant_id, len(agent.route)))
            env.render(agent.route)     # 渲染路径
            plt.pause(0.01)
    plt.ioff()
    plt.show()


from ants import Ant
from models import Dim3Env, plt
from utils import distance

# hyper-param
BATCH = 8
GEN = 64
# PHEROMONES = 100

# 交互模式
plt.ion()


if __name__ == '__main__':
    size = (12, 12, 12)     # 空间模型大小 12*12*12
    start = (0, 0, 0)       # 起点坐标
    end = (11, 11, 11)      # 终点坐标
    env = Dim3Env(size, start, end)     # 生成空间
    for b in range(BATCH):      # 批次迭代
        for g in range(GEN):    # 蚁群迭代
            agent = Ant('%d-%d' % (b, g), start, end, env.direct, *env.get_txd())   # 生成蚂蚁
            while True:
                step = agent.choose_action()    # 动作决策，每次移动一步
                # print('step to %s' % step.__str__())
                if distance(step, end, env.DIM) <= env.unit:
                    # 抵达终点
                    break
            env.distribution = agent.feedback(100) * 0.9    # 更新信息素分布
            print('ant %s step %d' % (agent.ant_id, len(agent.route)))
            env.render(agent.route)     # 渲染路径
            plt.pause(0.01)
    plt.ioff()
    plt.show()
# hyper-param # PHEROMONES = 100 # 交互模式 # 空间模型大小 12*12*12 # 起点坐标 # 终点坐标 # 生成空间 # 批次迭代 # 蚁群迭代 # 生成蚂蚁 # 动作决策，每次移动一步 # print('step to %s' % step.__str__()) # 抵达终点 # 更新信息素分布 # 渲染路径