Sign in to follow this  
JinJo

graph help

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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this