1
////////////////////////////////////////////////////////////////////////////////
3
// This file is part of Toolkit for Conceptual Modeling (TCM).
4
// (c) copyright 2001, Universiteit Twente.
5
// Author: Rik Eshuis (eshuis@cs.utwente.nl).
7
// TCM is free software; you can redistribute it and/or modify
8
// it under the terms of the GNU General Public License as published by
9
// the Free Software Foundation; either version 2 of the License, or
10
// (at your option) any later version.
12
// TCM is distributed in the hope that it will be useful,
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
// GNU General Public License for more details.
17
// You should have received a copy of the GNU General Public License
18
// along with TCM; if not, write to the Free Software
19
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21
////////////////////////////////////////////////////////////////////////////////
22
#include "hypergraph.h"
24
#include "hyperedge.h"
26
#include "outputfile.h"
28
HyperGraph::HyperGraph() {
29
nodes = new List<Node *>;
30
hedges = new List<HyperEdge *>;
31
nodeTypes = new int[static_cast<int>(MAX_TYPES)];
32
edgeTypes = new int[static_cast<int>(MAX_TYPES)];
37
connections [i][j][k]= False;
42
HyperGraph::~HyperGraph() {
54
void HyperGraph::AddNode(Node *node) {
55
if (!HasNode(node)) nodes->add(node);}
57
void HyperGraph::AddHyperEdge(HyperEdge *edge) {
58
if (!HasHyperEdge(edge)) hedges->add(edge);
61
void HyperGraph::WriteSubjects(OutputFile *f) {
62
(*f) << "# GRAPH NODES\n\n";
63
for (nodes->first(); !nodes->done(); nodes->next()) {
64
if (check(nodes->cur()))
65
nodes->cur()->Write(f);
67
(*f) << "# GRAPH HYPEREDGES\n\n";
68
for (hedges->first(); !hedges->done(); hedges->next()) {
69
if (check(hedges->cur()))
70
hedges->cur()->WriteMembers(f);
76
void HyperGraph::GetNodes(List <Subject *> *l){
77
for (nodes->first(); !nodes->done(); nodes->next()) {
78
if (check(nodes->cur() && !nodes->cur()->IsHyperEdge()))
84
void HyperGraph::GetNodes(List<Subject *> *l, int t) {
85
// int c = l->count();
86
for (nodes->first(); !nodes->done(); nodes->next()) {
87
Subject *s = nodes->cur();
88
if (check(s && !s->IsEdge())) {
89
if (s->GetClassType() == t)
95
void HyperGraph::RemoveNode(Node *node){
97
for (hedges->first();!hedges->done(); ) {
98
HyperEdge *e = hedges->cur();
100
List <Subject *> *n1=e->GetSubject1();
101
if (n1->contains(node)) hedges->removecur();
103
List <Subject *> *n2=e->GetSubject2();
104
if (n2->contains(node)) hedges->removecur();
112
void HyperGraph::GetHyperEdges(List <Subject *> *l){
113
for (hedges->first(); !hedges->done(); hedges->next()) {
114
HyperEdge *e = hedges->cur();
121
void HyperGraph::GetHyperEdgesFrom(List <Subject *> *l,Subject *s){
122
for (hedges->first(); !hedges->done(); hedges->next()) {
123
HyperEdge *e = hedges->cur();
125
if (e->IsDirected() && e->GetSubject1()->contains(s))
131
void HyperGraph::GetHyperEdgesTo(List <Subject *> *l,Subject *s){
132
for (hedges->first(); !hedges->done(); hedges->next()) {
133
HyperEdge *e = hedges->cur();
135
if (e->IsDirected() && e->GetSubject2()->contains(s))
143
void HyperGraph::GetHyperEdgesFrom(List <HyperEdge *> *l,List <Subject *> *cfg){
144
for (hedges->first(); !hedges->done(); hedges->next()) {
145
HyperEdge *e = hedges->cur();
146
if ((check(e)) && (e->IsDirected())){
147
List <Subject *> *source=e->GetSubject1();
149
for (source->first();!source->done();source->next()){
150
if (cfg->find(source->cur())<0) { // source->cur() not in cfg
152
break; // jump out of the for-loop
155
if (Found) // all sources of e are in cfg
161
bool HyperGraph::ExistsSimilarHyperEdge(HyperEdge *he){
162
for (hedges->first(); !hedges->done(); hedges->next()) {
163
HyperEdge *e = hedges->cur();
165
if (*e==*he) return True;