1 |
//####//------------------------------------------------------------ |
2 |
//####//------------------------------------------------------------ |
3 |
//####// MAGiC |
4 |
//####// Jean Christophe Cuilliere et Vincent FRANCOIS |
5 |
//####// Departement de Genie Mecanique - UQTR |
6 |
//####//------------------------------------------------------------ |
7 |
//####// MAGIC est un projet de recherche de l equipe ERICCA |
8 |
//####// du departement de genie mecanique de l Universite du Quebec a Trois Rivieres |
9 |
//####// http://www.uqtr.ca/ericca |
10 |
//####// http://www.uqtr.ca/ |
11 |
//####//------------------------------------------------------------ |
12 |
//####//------------------------------------------------------------ |
13 |
//####// |
14 |
//####// hypergraphlib_arc.cpp |
15 |
//####// |
16 |
//####//------------------------------------------------------------ |
17 |
//####//------------------------------------------------------------ |
18 |
//####// COPYRIGHT 2000-2024 |
19 |
//####// jeu 13 jun 2024 11:54:00 EDT |
20 |
//####//------------------------------------------------------------ |
21 |
//####//------------------------------------------------------------ |
22 |
#include <iostream> |
23 |
|
24 |
#pragma hdrstop |
25 |
|
26 |
#include "hypergraphlib_platform.h" |
27 |
#include "hypergraphlib_arc.h" |
28 |
#include "hypergraphlib_graph.h" |
29 |
#include "hypergraphlib_node.h" |
30 |
|
31 |
|
32 |
namespace HypergraphLib { |
33 |
|
34 |
Arc::Arc(Graph * __owner, int __id) |
35 |
: GraphObject (__owner, __id) |
36 |
{ |
37 |
} |
38 |
|
39 |
Arc::Arc(const Arc &__from, Graph * __owner) |
40 |
: GraphObject(__from, __owner) |
41 |
{ |
42 |
for (Arc::MultimapNodesById::const_iterator it = __from._nodes.begin(); |
43 |
it != __from._nodes.end(); |
44 |
it++) |
45 |
{ |
46 |
Node * n = _owner->GetNode(it->first); |
47 |
if (n) |
48 |
{ |
49 |
Add (n); |
50 |
} |
51 |
} |
52 |
} |
53 |
|
54 |
Arc::~Arc() |
55 |
{ |
56 |
|
57 |
} |
58 |
|
59 |
void Arc::Add (Node * __node) |
60 |
{ |
61 |
_nodes.insert ( Int_Node_Pair ( __node->Id(), __node )); |
62 |
} |
63 |
|
64 |
int Arc::Remove (Node * __node) |
65 |
{ |
66 |
return Remove (__node->Id()); |
67 |
} |
68 |
|
69 |
int Arc::Remove (int __id) |
70 |
{ |
71 |
int result=0; |
72 |
MultimapNodesById::iterator it; |
73 |
for (it = _nodes.find ( __id ); |
74 |
it != _nodes.end(); |
75 |
it = _nodes.find ( __id ), result++) |
76 |
_nodes.erase ( it ); |
77 |
|
78 |
/*while(it!=_nodes.end()) |
79 |
{ |
80 |
_nodes.erase ( it ); |
81 |
it = _nodes.find ( __id ); |
82 |
}*/ |
83 |
|
84 |
return result; |
85 |
} |
86 |
|
87 |
int Arc::Rank () const |
88 |
{ |
89 |
return _nodes.size(); |
90 |
} |
91 |
|
92 |
int Arc::NodeCount(int __id) const |
93 |
{ |
94 |
return _nodes.count(__id); |
95 |
} |
96 |
|
97 |
Arc::MultimapNodesById & Arc::Nodes() |
98 |
{ |
99 |
return _nodes; |
100 |
} |
101 |
|
102 |
Node * Arc::First() const |
103 |
{ |
104 |
MultimapNodesById::const_iterator it = _nodes.begin(); |
105 |
return it->second; |
106 |
} |
107 |
|
108 |
Node * Arc::Last() const |
109 |
{ |
110 |
MultimapNodesById::const_iterator it = _nodes.end(); |
111 |
it--; |
112 |
return it->second; |
113 |
} |
114 |
|
115 |
bool Arc::IsLoopOfNode(int __NodeId) |
116 |
{ |
117 |
return (NodeCount(__NodeId ) == 2); |
118 |
} |
119 |
|
120 |
bool Arc::IsLoop() |
121 |
{ |
122 |
return (_nodes.size() == 2 && First() == Last() ); |
123 |
} |
124 |
|
125 |
} |
126 |
|