ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/addin/outil/src/hypergraphlib_node.cpp
Revision: 1156
Committed: Thu Jun 13 22:02:48 2024 UTC (14 months, 2 weeks ago) by francois
File size: 4037 byte(s)
Log Message:
compatibilité Ubuntu 22.04
Suppression des refeences à Windows
Ajout d'une banière

File Contents

# Content
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_node.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
28 #include "hypergraphlib_node.h"
29 #include "hypergraphlib_arc.h"
30
31
32 namespace HypergraphLib {
33
34 Node::Node (Graph * __owner, int __id)
35 : GraphObject(__owner, __id)
36 {
37
38 }
39
40 Node::Node (const Node & __from, const Graph * __owner)
41 : GraphObject (__from, __owner)
42 {
43 }
44
45 void Node::Add (Arc *__incidentArc)
46 {
47 _arcs.insert( IntArc_Pair(__incidentArc->Id(), __incidentArc) );
48 }
49
50 int Node::Remove (int __id)
51 {
52 int result=0;
53 MultimapArcsById::iterator it = _arcs.find ( __id );
54 result = (it != _arcs.end());
55 if (result)
56 {
57 _arcs.erase ( it );
58 }
59 else
60 {
61 std::cout << "Error: Graph::RemoveArc ( "<<__id<<" )"<<std::endl;
62 std::cout << "\t the arc was not found !\n"<<__id<<" )"<<std::endl;
63 }
64 return result;
65 }
66
67 unsigned int Node::ArcCount (int __id)
68 {
69 return _arcs.count ( __id );
70 }
71
72
73 void Node::AdjacentNodes ( std::set < int > & __adjacentNodes )
74 {
75 for ( MultimapArcsById::const_iterator itArcs = _arcs.begin();
76 itArcs != _arcs.end();
77 itArcs++ )
78 {
79 Arc * arc = itArcs->second;
80 for (Arc::MultimapNodesById::const_iterator itNodes = arc->Nodes().begin();
81 itNodes != arc->Nodes().end();
82 itNodes++)
83 {
84 int id = itNodes->first;
85
86 if ( id != _id && __adjacentNodes.find(id) == __adjacentNodes.end() )
87 __adjacentNodes.insert(id);
88 }
89 }
90 }
91
92 void Node::AdjacentNodes ( std::set < Node * > & __adjacentNodes )
93 {
94 for ( MultimapArcsById::const_iterator itArcs = _arcs.begin();
95 itArcs != _arcs.end();
96 itArcs++ )
97 {
98 Arc * arc = itArcs->second;
99 for (Arc::MultimapNodesById::const_iterator itNodes = arc->Nodes().begin();
100 itNodes != arc->Nodes().end();
101 itNodes++)
102 {
103 int id = itNodes->first;
104
105 if ( id != _id && __adjacentNodes.find(itNodes->second) == __adjacentNodes.end() )
106 __adjacentNodes.insert(itNodes->second);
107 }
108 }
109 }
110
111
112 Arc *
113 Node::IsAdjacentToNode ( Node * __n )
114 {
115 return IsAdjacentToNode(__n->Id());
116 }
117
118 Arc *
119 Node::IsAdjacentToNode ( int __nodeId )
120 {
121 for ( MultimapArcsById::const_iterator itArcs = _arcs.begin();
122 itArcs != _arcs.end();
123 itArcs++ )
124 {
125 Arc * arc = itArcs->second;
126
127 if (arc->Nodes().find(__nodeId ) != arc->Nodes().end())
128 return arc;
129 }
130 return 0;
131 }
132
133 int
134 Node::GetNbArcsToNode(Node * __other)
135 {
136 int result = 0;
137 int __nodeId = __other->Id();
138 for ( MultimapArcsById::const_iterator itArcs = _arcs.begin();
139 itArcs != _arcs.end();
140 itArcs++ )
141 {
142 Arc * arc = itArcs->second;
143
144 if (arc->Nodes().find(__nodeId ) != arc->Nodes().end())
145 result++;
146 }
147 return result;
148 }
149
150 } // end namespace HypergraphLib
151