Last change
on this file since 8308 was
8300,
checked in by spimming, 12 years ago
|
#1894:
- graph data structures added
- method to get the ways for a specific node
|
File size:
1.2 KB
|
Rev | Line | |
---|
[8300] | 1 |
|
---|
| 2 | namespace HeuristicLab.Problems.RoutePlanning.Graph {
|
---|
| 3 | public class Vertex<T> {
|
---|
| 4 | private static long idCounter = 0;
|
---|
| 5 |
|
---|
| 6 | private long id;
|
---|
| 7 | public long Id {
|
---|
| 8 | get { return id; }
|
---|
| 9 | }
|
---|
| 10 |
|
---|
| 11 | private T node;
|
---|
| 12 | public T Node {
|
---|
| 13 | get { return node; }
|
---|
| 14 | }
|
---|
| 15 |
|
---|
| 16 | public Vertex(T node) {
|
---|
| 17 | this.node = node;
|
---|
| 18 | this.id = idCounter++;
|
---|
| 19 | }
|
---|
| 20 |
|
---|
| 21 | public static bool operator ==(Vertex<T> v1, Vertex<T> v2) {
|
---|
| 22 | if ((object)v1 == null) {
|
---|
| 23 | if ((object)v2 == null) {
|
---|
| 24 | return true;
|
---|
| 25 | }
|
---|
| 26 | return false;
|
---|
| 27 | }
|
---|
| 28 | if ((object)v1 == null && (object)v2 != null) {
|
---|
| 29 | return false;
|
---|
| 30 | }
|
---|
| 31 | return v1.Equals(v2);
|
---|
| 32 | }
|
---|
| 33 |
|
---|
| 34 | public static bool operator !=(Vertex<T> v1, Vertex<T> v2) {
|
---|
| 35 | return !(v1 == v2);
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | public override bool Equals(object obj) {
|
---|
| 39 | if (obj is Vertex<T>) {
|
---|
| 40 | Vertex<T> graph = (obj as Vertex<T>);
|
---|
| 41 | return this.Equals(graph);
|
---|
| 42 | }
|
---|
| 43 | return false;
|
---|
| 44 | }
|
---|
| 45 |
|
---|
| 46 | public override int GetHashCode() {
|
---|
| 47 | return typeof(T).GetHashCode() ^ this.Node.GetHashCode();
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | public override string ToString() {
|
---|
| 51 | return string.Format("{0}", this.Node);
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 |
|
---|
| 55 | }
|
---|
| 56 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.