Jump to content
  • Advertisement
Sign in to follow this  
JinJo

graph help

This topic is 4856 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

This is related to homework but i am not asking how to implement a solution. I have a graph class, an adjacency wighted graph, in Java. I have to represent flights of an airline company e.g Edinburgh to Heathrow, Cost £100 Heathrow to Amsterdam, Cost £120 Heathrow to Boston, Cost £230 etc. Now in my program I have to represent these direct flights with the costs as a graph, all flights go in both directions. Now an example here of how the graph is used: g.putEdge(new WeightedEdge(2, 4, new Integer(1))); where g is the graph, the inputs for the weighted edge constructor are vertex 1 and 2 of the edge and then the weight. Now weight can be any object, string, int etc. How do you suggest I represent the flights then?

Share this post


Link to post
Share on other sites
Advertisement
Aren't you already representing them as graph edges? Or do I not understand the question?

Share this post


Link to post
Share on other sites
well yeah I guess they would be graph edges, I havnt started the actual program yet, just thinking of how to store the info in the data structure I already have.

See the towns are strings, should I associate a number with each? also would the cost be represented as a weight?

Also I need to search through the graph to find a possible route between two cities.

Should I be looking at a map and do a basic diagram of where the cities are then labeling each city as an edge number? Just make up reasonable values for the vertices so that they all join up properly?

Share this post


Link to post
Share on other sites
Quote:
Original post by JinJo
See the towns are strings, should I associate a number with each? also would the cost be represented as a weight?


Yes to both, unless you can directly stick the city names in the vertices.

Quote:
Also I need to search through the graph to find a possible route between two cities.


There are plenty of algorithms to do that.

{/quote]Should I be looking at a map and do a basic diagram of where the cities are then labeling each city as an edge number? Just make up reasonable values for the vertices so that they all join up properly?[/quote]

No, the graph is an abstraction of the map. You aren't concerned by the actual location of each city, only how much the flight between two of them costs.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!