Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: flightpaths, finding lowest cost -- lowest amount of crossovers

  1. #1
    Member
    Join Date
    Jan 2012
    Posts
    33
    My Mood
    Confused
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default flightpaths, finding lowest cost -- lowest amount of crossovers

    I have a college assignment.
    I already have it working with a depth first search on the data structure [it's not a tree since there are loops]
    Basically, the professor just wants the program to find A path and the price of said path.
    I have that basically worked out. But I want to bring it a step further and offer "Lowest total price" option
    and "lowest amount of crossover flights" and perhaps if I'm feeling up to it "lowest total price" although that would use
    the same algorithm for the lowest total price.
    Basically, I was thinking about using iterative deepening depth first search but I heard that's only usable on data trees.
    What algorithm would I need to implement.?
    Basically what I have now:

    City class
    --String of name
    --Hashmap of cities that it connects to, price per connection
    --getname()
    --getDestMap()
    --addDest()
    --depthFirstSearch(City start, goalfunction isGoal, stack<City> result)
    Goalfunction is an interface

    Main class
    --hashmap of cities and theyre name

    scanner
    to add to the tree
    CODE REMOVED Since it's not needed anymore
    Last edited by CjStaal; May 7th, 2012 at 11:47 PM. Reason: removed code in case anyone in my java class decides to look on this


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: flightpaths, finding lowest cost -- lowest amount of crossovers

    Try looking at Dijkstra's Algorithm.

  3. The Following User Says Thank You to helloworld922 For This Useful Post:

    CjStaal (May 7th, 2012)

  4. #3
    Member
    Join Date
    Jan 2012
    Posts
    33
    My Mood
    Confused
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: flightpaths, finding lowest cost -- lowest amount of crossovers

    That's exactly what I need! Thanks so much!! My "Graph" would be the hashmap I have in the main class? I've encapsulated it to be its own class.
    Here's the entire code

    deleted code since it's no longer needed

    The algorithm would work with the finding lowest cost, finding lowest time
    and if I set all distances to "1" it will find lowest amount of hops, correct?
    Would there be a faster algorithm to find the latter of the 3 situations?

    City.java would be the vertex class, and FlightInfo.java's hashmap would be the graph?
    Last edited by CjStaal; May 8th, 2012 at 12:38 AM.

  5. #4
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: flightpaths, finding lowest cost -- lowest amount of crossovers

    Sounds right to me. There are other path-finding algorithms you can investigate, but they're all more or less based off of Dijkstra's algorithm with some sort of heuristic, or guess strategy.

  6. #5
    Member
    Join Date
    Jan 2012
    Posts
    33
    My Mood
    Confused
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: flightpaths, finding lowest cost -- lowest amount of crossovers

    I've looked up examples online of the algorithm, and I've decided to rework the entire project, AGAIN lol. Well, It's going to be right this time.

Similar Threads

  1. Set weight (cost) to edges.
    By andreas90 in forum Java Theory & Questions
    Replies: 1
    Last Post: March 18th, 2012, 04:49 PM
  2. Is Amazon RDS Cost-Effective?
    By KevinWorkman in forum JDBC & Databases
    Replies: 7
    Last Post: March 7th, 2012, 09:07 PM
  3. Lowest Term Function Help
    By thisbeme in forum What's Wrong With My Code?
    Replies: 5
    Last Post: August 2nd, 2011, 06:33 AM
  4. Replies: 1
    Last Post: December 4th, 2010, 05:26 PM
  5. Loop to note position of lowest number
    By fortune2k in forum Loops & Control Statements
    Replies: 3
    Last Post: November 23rd, 2010, 10:05 AM