|
5 | 5 | #include <sstream>
|
6 | 6 |
|
7 | 7 | class Edge
|
8 |
| -{ |
9 |
| - public: |
10 |
| - int fromNode; // Subscript of other endpoint in node array |
11 |
| - int toNode; // Subscript of one endpoint in node array. Nodes are stored as numbers, but printed as characters. |
12 |
| - int cycleID; // Cycle which the edge is a member of, -1 if it is included in no cycle |
13 |
| - int order; |
14 |
| - bool used; // true if edge is used in final tour |
| 8 | +{ |
| 9 | + public: |
| 10 | + int fromNode; // Subscript of other endpoint in node array |
| 11 | + int toNode; // Subscript of one endpoint in node array. Nodes are stored as numbers, but printed as characters. |
| 12 | + int cycleID; // Cycle which the edge is a member of, -1 if it is included in no cycle |
| 13 | + int order; |
| 14 | + bool used; // true if edge is used in final tour |
15 | 15 |
|
16 |
| - Edge(char f, char t): cycleID(-1), order(-1), used(false) { set(f, t); }//constructor with vertex letters |
17 |
| - Edge(int f, int t): cycleID(-1), order(-1), used(false) { set(f, t); }//constructor with vertex numbers |
| 16 | + Edge(char f, char t): cycleID(-1), order(-1), used(false) { set(f, t); }//constructor with vertex letters |
| 17 | + Edge(int f, int t): cycleID(-1), order(-1), used(false) { set(f, t); }//constructor with vertex numbers |
18 | 18 |
|
19 |
| - // Create a string version of Edge |
20 |
| - // Edge endpoints are stored as numbers, but printed as characters. |
21 |
| - std::string toString() const |
22 |
| - { |
23 |
| - std::ostringstream os; // allows string to act like stream to use stream operations |
24 |
| - char f = fromNode + 'A'; |
25 |
| - char t = toNode + 'A'; |
26 |
| - os << f << "-" << t << " (" << cycleID << ") (" << order << ") "; |
27 |
| - return os.str(); |
28 |
| - } |
| 19 | + // Create a string version of Edge |
| 20 | + // Edge endpoints are stored as numbers, but printed as characters. |
| 21 | + std::string toString() const |
| 22 | + { |
| 23 | + std::ostringstream os; // allows string to act like stream to use stream operations |
| 24 | + char f = fromNode + 'A'; |
| 25 | + char t = toNode + 'A'; |
| 26 | + os << f << "-" << t << " (" << cycleID << ") (" << order << ") "; |
| 27 | + return os.str(); |
| 28 | + } |
29 | 29 |
|
30 |
| - // if one Node is an endpoint, return other endpoint |
31 |
| - int getOther(int oneNode) const |
32 |
| - { |
33 |
| - if (fromNode == oneNode) return toNode; |
34 |
| - assert(toNode == oneNode); |
35 |
| - return fromNode; |
36 |
| - } |
| 30 | + // if one Node is an endpoint, return other endpoint |
| 31 | + int getOther(int oneNode) const |
| 32 | + { |
| 33 | + if (fromNode == oneNode) return toNode; |
| 34 | + assert(toNode == oneNode); |
| 35 | + return fromNode; |
| 36 | + } |
37 | 37 |
|
38 |
| - // Set initial values of an edge from Node f to Node t (char) |
39 |
| - void set(char f, char t) |
40 |
| - { |
41 |
| - fromNode = f - 'A'; |
42 |
| - toNode = t - 'A'; |
43 |
| - cycleID = -1; |
44 |
| - used = false; |
45 |
| - //std::cout << "creating Edge " << toString() << std::endl; |
46 |
| - } |
| 38 | + // Set initial values of an edge from Node f to Node t (char) |
| 39 | + void set(char f, char t) |
| 40 | + { |
| 41 | + fromNode = f - 'A'; |
| 42 | + toNode = t - 'A'; |
| 43 | + cycleID = -1; |
| 44 | + used = false; |
| 45 | + //std::cout << "creating Edge " << toString() << std::endl; |
| 46 | + } |
47 | 47 |
|
48 |
| - // Set initial values of an edge from Node f to Node t (int) |
49 |
| - void set(int f, int t) |
50 |
| - { |
51 |
| - fromNode = f; |
52 |
| - toNode = t; |
53 |
| - cycleID = -1; |
| 48 | + // Set initial values of an edge from Node f to Node t (int) |
| 49 | + void set(int f, int t) |
| 50 | + { |
| 51 | + fromNode = f; |
| 52 | + toNode = t; |
| 53 | + cycleID = -1; |
54 | 54 |
|
55 |
| - used = false; |
56 |
| - //std::cout << "creating Edge " << toString() << std::endl; |
57 |
| - } |
| 55 | + used = false; |
| 56 | + //std::cout << "creating Edge " << toString() << std::endl; |
| 57 | + } |
58 | 58 |
|
59 |
| - friend bool operator== (Edge const & a, Edge const & b) |
60 |
| - { |
61 |
| - return (a.fromNode == b.fromNode && a.toNode == b.toNode); |
62 |
| - } |
| 59 | + friend bool operator== (Edge const & a, Edge const & b) |
| 60 | + { |
| 61 | + return (a.fromNode == b.fromNode && a.toNode == b.toNode); |
| 62 | + } |
63 | 63 | };
|
64 | 64 |
|
65 | 65 | #endif
|
0 commit comments