Advertisement

Priority Queue Search Algorithm Solve the Traveling Salesman Problem (TSP)

阅读量:

问题描述

复制代码
    import numpy as np
    import heapq
    
    
    class VertexNode(object):  # 顶点类
    def __init__(self, path=None, cost=None):
        self.path = path  # 到当前结点为止已经走过的路径
        self.cost = cost  # 到当前结点为止的费用
    
    def __lt__(self, other):
        return int(self.cost) < int(other.cost)
    
    
    def tst_dfs(w_array, s_index):
    # 初始化最优值和最优路径
    best_cost = np.inf
    best_path = None
    
    vex_num, _ = w_array.shape
    # 初始化起点结点和栈,将起始节点加入栈
    start_node = VertexNode(path=[s_index], cost=0)
    # open_queue = q.LifoQueue()
    open_queue = []
    start_node = Ver

全部评论 (0)

还没有任何评论哟~