Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to solve the problem with a simple algorithm?

How to solve the problem with a simple algorithm?

Scheduled Pinned Locked Moved C / C++ / MFC
questionsysadminalgorithmsdata-structureshelp
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tianzhili4399
    wrote on last edited by
    #1

    There are a total of P levels. For any level p, there are Jp nodes. Any two nodes on the same level are not connected. And the unidirectional path weight between any two nodes Ai and Bj is D(i,j). What is the shortest distance required from the first layer to the _P_th layer? (** Note that P is generally large and it is not recommended to traverse all possible situations **) If this problem is abstracted as a graph, then what is actually required is the shortest path from the first layer to the last layer of a fully connected network. What I have tried: Use deep search, Dijkstra algorithm, Floydw algorithm, etc. to search the shortest path from all J1 nodes in the first layer to the last layer in turn, and select the minimum value from the J1 values. What I want to know is if there is a simpler algorithm to solve this problem?

    Greg UtasG CPalliniC S 3 Replies Last reply
    0
    • T tianzhili4399

      There are a total of P levels. For any level p, there are Jp nodes. Any two nodes on the same level are not connected. And the unidirectional path weight between any two nodes Ai and Bj is D(i,j). What is the shortest distance required from the first layer to the _P_th layer? (** Note that P is generally large and it is not recommended to traverse all possible situations **) If this problem is abstracted as a graph, then what is actually required is the shortest path from the first layer to the last layer of a fully connected network. What I have tried: Use deep search, Dijkstra algorithm, Floydw algorithm, etc. to search the shortest path from all J1 nodes in the first layer to the last layer in turn, and select the minimum value from the J1 values. What I want to know is if there is a simpler algorithm to solve this problem?

      Greg UtasG Offline
      Greg UtasG Offline
      Greg Utas
      wrote on last edited by
      #2

      If I understand this correctly, you're looking for a unidirectional path from the first layer to the _p_th layer, a path that includes each layer only once. I would start with the second layer. Assign each node its shortest distance from the first layer, and record the first layer node whose edge was selected. Then proceed through each layer in the same way: for each node, find its shortest distance from the nodes in the previous layer (the current weight of a previous node plus its edge to the current layer). Eventually you will find the shortest distances to nodes in the _p_th layer, and thus the shortest path to that layer.

      Robust Services Core | Software Techniques for Lemmings | Articles

      <p><a href="https://github.com/GregUtas/robust-services-core/blob/master/README.md">Robust Services Core</a>
      <em>The fox knows many things, but the hedgehog knows one big thing.</em></p>

      1 Reply Last reply
      0
      • T tianzhili4399

        There are a total of P levels. For any level p, there are Jp nodes. Any two nodes on the same level are not connected. And the unidirectional path weight between any two nodes Ai and Bj is D(i,j). What is the shortest distance required from the first layer to the _P_th layer? (** Note that P is generally large and it is not recommended to traverse all possible situations **) If this problem is abstracted as a graph, then what is actually required is the shortest path from the first layer to the last layer of a fully connected network. What I have tried: Use deep search, Dijkstra algorithm, Floydw algorithm, etc. to search the shortest path from all J1 nodes in the first layer to the last layer in turn, and select the minimum value from the J1 values. What I want to know is if there is a simpler algorithm to solve this problem?

        CPalliniC Offline
        CPalliniC Offline
        CPallini
        wrote on last edited by
        #3

        Simulated Annealing[^] could be effective. I don't know if it belongs to the 'simple algorithm' category. :-)

        In testa che avete, signor di Ceprano?

        S 1 Reply Last reply
        0
        • T tianzhili4399

          There are a total of P levels. For any level p, there are Jp nodes. Any two nodes on the same level are not connected. And the unidirectional path weight between any two nodes Ai and Bj is D(i,j). What is the shortest distance required from the first layer to the _P_th layer? (** Note that P is generally large and it is not recommended to traverse all possible situations **) If this problem is abstracted as a graph, then what is actually required is the shortest path from the first layer to the last layer of a fully connected network. What I have tried: Use deep search, Dijkstra algorithm, Floydw algorithm, etc. to search the shortest path from all J1 nodes in the first layer to the last layer in turn, and select the minimum value from the J1 values. What I want to know is if there is a simpler algorithm to solve this problem?

          S Offline
          S Offline
          Stefan_Lang
          wrote on last edited by
          #4

          Simpler than Dijkstra? Seriously? Dijkstra is the obvious choice. You may be able to find a faster algorithm, but not a simpler one, unless you use brute force. P.S.: I wasn't familiar with the Floyd-Warshall algorithm[^] (assuming that is what you were referring to). It seems like it is simply a specialiced version of Dijkstra applied to a weighted graph. Sounds like it's a perfect fit for this problem.

          GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)

          1 Reply Last reply
          0
          • CPalliniC CPallini

            Simulated Annealing[^] could be effective. I don't know if it belongs to the 'simple algorithm' category. :-)

            S Offline
            S Offline
            Stefan_Lang
            wrote on last edited by
            #5

            Unfortunately it can in general not guarantee that it will find the global optimum. You can find a good guess very quickly, or you can slow the annealing to the pace of continental drifts and have a higher chance to find the correct answer, but you can never be 100% sure unless you test all options, i. e. brute force.

            GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)

            CPalliniC 1 Reply Last reply
            0
            • S Stefan_Lang

              Unfortunately it can in general not guarantee that it will find the global optimum. You can find a good guess very quickly, or you can slow the annealing to the pace of continental drifts and have a higher chance to find the correct answer, but you can never be 100% sure unless you test all options, i. e. brute force.

              GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)

              CPalliniC Offline
              CPalliniC Offline
              CPallini
              wrote on last edited by
              #6

              You are right, of course. If the problem needs an exact solution, Simulated Annealing is not the right algorithm.

              In testa che avete, signor di Ceprano?

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups