• PA7 The Traveling Salesman Problem


    PA7 The Traveling Salesman Problem

    Due: Monday, December 5th, 11:59PM

    QQ1703105484

    Submission:

    • 🙄

      PA11Main.java - the main program
     

    seriously, for the autograder

    • DGraph.java - a weighted directed graph
    • README.md - results of timing experiments

    Overview

    The traveling salesman problem (TSP): given a set of cities and the distances between each, what is the shortest path that visits each city once and returns to the starting city? The problem is usually modeled with a weighted graph and has been studied extensively. The solution involves making a decision about which city to visit next and as such it belongs to a large class of combinatorial optimization problems that can be solved by searching for the optimal answer. The time complexity of such a search is exponential and only problems of modest size can be solved. Applications of the TSP include: vehicle routing, scheduling, integrated circuit design, DNA sequencing and the tracking of stars. This assignment involves the implementation of a program to experiment with some basic solutions to the TSP and to time their performance.

    Assignment

    A program is needed to take as input a directed weighted graph which represents a network of cities in a TSP. The graph is stored in a file and the filename is given to the program as a command line argument. The input files are in the matrix market (.mtx) format. An example input file is:

    %%MatrixMarket matrix coordinate real general

    3

    3

    6

    1

    2

    1.0

    2

    1

    2.0

    1

    3

    3.0

    3

    1

    4.0

    2

    3

    5.0

    3

    2

    6.0

    Also provided on the command line is a directive to indicate which algorithm should be used to solve the TSP and when timing should be performed:

    HEURISTIC - an approximate algorithm that uses a heuristic, BACKTRACK - an exact algorithm that uses brute-force search,

    MINE - a variation on the heuristic and backtracking approaches that improves performance, TIME - a measuring of the running time of the above approaches.

    An example of the output for the above input file using the HEURISTIC command is:

    cost = 10.0, visitOrder = [1, 2, 3]

    The assignment can be partitioned into five main tasks:

    1. The Graph

    A weighted directed graph is needed to represent the ‘cities’ and their distances. The graph should support operations that will be needed by the algorithms, mainly a method to find all vertices that are adjacent to a given vertex. The graph class should be in DGraph.java.

    🙄

    Code to read a .mtx file and store it in a DGraph should be in PA11Main.java.

    1. The Heuristic Approach

    A simple way to arrive at an approximate solution to the TSP is to traverse the graph and at each vertex that you arrive at, make a decision about which way to go based on the weights of the incident edges. A simple ‘heuristic’ or rule-of-thumb is to take the edge of lowest weight.

    The heuristic approach can be implemented as a method in the DGraph class.

    "

    this means you really, really should make

    1. The Backtracking Approach
     

    it a method in the DGraph class

    Recursive backtracking is a general approach to solving problems that can be represented with a graph. It involves exploring a possible solution, recording its value, and then backing up to the previous vertex to make a different decision and record the value of that solution, and so on.

    The backtracking approach can be implemented as a method in the DGraph class.

    this also means you really, really should

    1. "

      Your Own Variation
     

    make it a method in the DGraph class

    😎

    After working on steps 2 and 3 you will probably have some ideas about improving their performance. Here you can modify the heuristic or backtracking approach in some way so as to make it faster. Implement this as a method in the DGraph class.

    1. Timing

    The output for the TIME command should look as follows: heuristic: cost = 935.3299999999999, 0 milliseconds

    mine: cost = 935.3299999999999, 0 milliseconds

    backtrack: cost = 835.8799999999999, 5 milliseconds

     

    obviously

    Grading Criteria

    Testcases are provided for this PA. There will also be private grading testcases.

    You are encouraged to write your own JUnit testcases to ensure your classes work properly, but these test files will not be collected or graded.

    Your grade will consist of similar style and code clarity points as in earlier assignments.

  • 相关阅读:
    跨境电商卖家必知的9个圣诞节营销技巧
    ASP.NET猜数游戏的设计与开发(源代码+论文)
    笔试面试相关记录(10)
    Q4已来,DAO发新生|CyberDAO子DAO种子会议
    pytorch加载darknet权重文件
    载紫杉醇PTX的四氧化三铁Fe3O4/二氧化硅SiO2/二氧化钛TIO2/氧化锌ZNO/二氧化锰MnO2纳米粒
    自动化您的Instagram帐户的程序InstaBot Pro 7.0.2
    MySQL数据的完整性和多表查询
    STM32超声波传感器
    Java中使用alibaba easyexcel导出Excel,合并单元格
  • 原文地址:https://blog.csdn.net/qq_37064135/article/details/128057798