ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/outil/src/hypergraphlib_arc.cpp
Revision: 1019
Committed: Tue Jun 4 21:16:50 2019 UTC (6 years ago) by francois
File size: 1745 byte(s)
Log Message:
restructuration de magic
outil est sorti de lib pour pouvoir etre utiliser en dehors de lib
template est merge avec outil
poly_occ et un sous projet de magic qui utilise le nouveau outil

File Contents

# User Rev Content
1 francois 283 #include <iostream>
2    
3     #pragma hdrstop
4    
5 francois 481 #include "hypergraphlib_platform.h"
6     #include "hypergraphlib_arc.h"
7     #include "hypergraphlib_graph.h"
8     #include "hypergraphlib_node.h"
9 francois 283
10    
11     namespace HypergraphLib {
12    
13     Arc::Arc(Graph * __owner, int __id)
14     : GraphObject (__owner, __id)
15     {
16     }
17    
18     Arc::Arc(const Arc &__from, Graph * __owner)
19     : GraphObject(__from, __owner)
20     {
21     for (Arc::MultimapNodesById::const_iterator it = __from._nodes.begin();
22     it != __from._nodes.end();
23     it++)
24     {
25     Node * n = _owner->GetNode(it->first);
26     if (n)
27     {
28     Add (n);
29     }
30     }
31     }
32    
33     Arc::~Arc()
34     {
35    
36     }
37    
38     void Arc::Add (Node * __node)
39     {
40     _nodes.insert ( Int_Node_Pair ( __node->Id(), __node ));
41     }
42    
43     int Arc::Remove (Node * __node)
44     {
45     return Remove (__node->Id());
46     }
47    
48     int Arc::Remove (int __id)
49     {
50     int result=0;
51     MultimapNodesById::iterator it;
52     for (it = _nodes.find ( __id );
53     it != _nodes.end();
54     it = _nodes.find ( __id ), result++)
55     _nodes.erase ( it );
56    
57     /*while(it!=_nodes.end())
58     {
59     _nodes.erase ( it );
60     it = _nodes.find ( __id );
61     }*/
62    
63     return result;
64     }
65    
66     int Arc::Rank () const
67     {
68     return _nodes.size();
69     }
70    
71     int Arc::NodeCount(int __id) const
72     {
73     return _nodes.count(__id);
74     }
75    
76     Arc::MultimapNodesById & Arc::Nodes()
77     {
78     return _nodes;
79     }
80    
81     Node * Arc::First() const
82     {
83     MultimapNodesById::const_iterator it = _nodes.begin();
84     return it->second;
85     }
86    
87     Node * Arc::Last() const
88     {
89     MultimapNodesById::const_iterator it = _nodes.end();
90     it--;
91     return it->second;
92     }
93    
94     bool Arc::IsLoopOfNode(int __NodeId)
95     {
96     return (NodeCount(__NodeId ) == 2);
97     }
98    
99     bool Arc::IsLoop()
100     {
101     return (_nodes.size() == 2 && First() == Last() );
102     }
103    
104     }
105