Huxi campus tour guide system

Source: Internet
Author: User

Problem description design a campus tour guide program to provide information query services for visitors. Basic requirements (1) design the campus plan of the school. There are no less than 10 scenic spots included in the plan. The vertices in the chart represent all scenic spots in the school, and store the scenic spot name, code name, profile, and other information, the path is represented by edges, and relevant information such as the path length is stored. (2) provide visitors with information about any scenic spots in the diagram; (3) provide visitors with information about the routes from the school gate to any scenic spots in the diagram; the representation of the algorithm IDEA graph is represented by the most basic adjacent matrix. The A (I, j) value in the matrix indicates the weight between vertex I and j in the graph, A (I, i) it is recorded as 0. If no path exists, it is recorded as infinity = 10000. Ignore unnecessary details in graph data structure implementation and only provide the most basic functions, including [cpp] int get_count (); // obtain the number of vertices in the graph; void read (char * fname); // read from the file and set the weight of the Vertex adjacent matrix in the graph; void write (); // output the critical matrix void set_distances (Vertex source, weight distance [], Vertex ways [13] [13]) const; // obtain the shortest path and value single-source shortest path algorithm from the specified point to the graph using the classic Krim algorithm, first, initialize the path from each point to the source point as the direct path, and the path value is the source point to each vertex weight. Then select the vertex with the shortest path value (set to vertex k) and record the information of each vertex through the array found [n. After selecting a vertex, traverse each unfound vertex. If the path value from the Source Vertex to a vertex is shorter than the PATH value of the original record, update the Source Vertex to its path to go through k, the path value is the path value from the source point to the k PATH value plus the PATH value from the k point to this point, and then select the vertex with the shortest path value in the new path array. Repeat the operation until all vertices in the graph are found. [Cpp] template <class Weight, int graph_size> void Digraph <Weight, graph_size >:: set_distances (Vertex source, Weight distance [], Vertex ways [13] [13]) const // output: array is used to record the value of the shortest path from the source point to each point // two-dimensional array ways is used to record the Vertex (that is, the arrival method) that the shortest path goes through from the source point to each point {Vertex v, w; bool found [graph_size]; // store Vertex minways [graph_size]; // store the path of the currently found Shortest Path // initialize the information of each vertex // each vertex is not found, and its shortest path starts to be set as the path from the Source Vertex To This vertex, // go to the source point directly to this point for (v = 0; v <coun T; v ++) {found [v] = false; distance [v] = adjacency [source] [v]; ways [v] [0] = 0; ways [v] [1] = v; minways [v] = infinity; for (w = 2; w <count; w ++) ways [v] [w] = infinity;} // initialize the source Vertex. By default, it is a locate vertex, and the shortest path is 0 found [source] = true; distance [source] = 0; // The outermost loop finds a vertex for (int I = 0; I <count-1; I ++) {Weight min = infinity at each cycle; minways [0] = 0; // This cycle determines the Shortest Path of the currently found vertex // then sets this vertex as the located vertex, its path is set to min, and its path is set to minways // note that the key here is because every The "Shortest Path" of the unfound vertex changes accordingly to the new set for (w = 0; w <count; w ++) {if (! Found [w]) if (distance [w] <min) {v = w; min = distance [w]; for (int j = 0; j <count; j ++) minways [j] = ways [v] [j] ;}} found [v] = true; // This cycle is used to modify the shortest path of an unfound vertex. // If min + the path from the just found vertex to this vertex is smaller than the original Shortest Path, // change the shortest path value and shortest path. // after the new vertex, the new set-to-point path is optimized to the original path. Then, the shortest path value is changed to for (w = 0; w <count; w ++) if (! Found [w]) if (min + adjacency [v] [w] <distance [w]) {distance [w] = min + adjacency [v] [w]; int a = 0; while (minways [a] <infinity) {ways [w] [a] = minways [a]; a ++ ;} ways [w] [a] = w ;}} single-source shortest path Krim algorithm flow for the interface, because the function is not complex, we use the Ezwin class library. The implementation idea is very simple. First, a window with the Huxi campus plane as the background is generated, and the Scenic Spot button is on the right. click the button to generate the Scenic Spot introduction window, and the corresponding button to load the introduction pictures of the corresponding scenic spots, at the same time, the path of the original window is loaded. The best program may not use the most complex code. We believe that streamlining is better than complicated, and the purpose of implementation is king! Our campus attraction query system contains only about 200 lines of code! Module division 1. classDigraph definition graph, the single-source shortest path algorithm is the most member function implementation 2. The main function implements graph initialization and window generation and Event Response Data Structure [cpp] typedef int Vertex; // infinity is used to indicate the value of const int infinity = 10000, which does not have the same path between two ways. // create a Diagrah class to indicate the graph template <class Weight, int graph_size> class Digraph {public: digraph (); void read (char * fname); void write (); int get_count (); void set_distances (Vertex source, Weight distance [], vertex ways [13] [13]) const; protected: int count; // Number of vertices in the graph Weight adjacency [graph_size] [graph_size]; // weights between neighboring points}; test cases 1. Open the program start interface: 2. query the scenic spots "library" to display the scenic spots introduction window, at the same time, the original path map shows the shortest path from the north gate to the library. 3. query the introduction and shortest path of the "first teaching building" scenic spot. 4. Project Demonstration of detailed information on the scenic spot paths

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.