# graph help

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

## 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 on other sites
Aren't you already representing them as graph edges? Or do I not understand the question?

##### 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 on other sites
Quote:
 Original post by JinJoSee 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.

1. 1
2. 2
Rutin
15
3. 3
4. 4
5. 5

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633724
• Total Posts
3013556
×