~ubuntu-branches/ubuntu/intrepid/tcm/intrepid

« back to all changes in this revision

Viewing changes to src/dg/hyperedge.c

  • Committer: Bazaar Package Importer
  • Author(s): Otavio Salvador
  • Date: 2003-07-03 20:08:21 UTC
  • Revision ID: james.westby@ubuntu.com-20030703200821-se4xtqx25e5miczi
Tags: upstream-2.20
ImportĀ upstreamĀ versionĀ 2.20

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
////////////////////////////////////////////////////////////////////////////////
 
2
//
 
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).
 
6
//
 
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.
 
11
//
 
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.
 
16
//
 
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
 
20
// 02111-1307, USA.
 
21
////////////////////////////////////////////////////////////////////////////////
 
22
#include "inputfile.h"
 
23
#include "outputfile.h"
 
24
#include "util.h"
 
25
#include "assoclist.h"
 
26
#include "hypergraph.h"
 
27
#include "hyperedge.h"
 
28
#include "string.h"
 
29
 
 
30
 
 
31
HyperEdge::HyperEdge(HyperGraph *g, List<Subject *> *n1, List<Subject *> *n2): Subject(g) {
 
32
  subject1 = n1; 
 
33
  subject2 = n2;
 
34
  directed = True;
 
35
}
 
36
 
 
37
HyperEdge::HyperEdge(HyperGraph *g,Edge *e): Subject(g) {
 
38
  subject1= new List<Subject *>();
 
39
  subject1->add(e->GetSubject1()); 
 
40
  subject2= new List<Subject *>();
 
41
  subject2->add(e->GetSubject2());
 
42
  directed = True;
 
43
}
 
44
 
 
45
HyperEdge::HyperEdge(HyperGraph *g): Subject(g){
 
46
  subject1= new List <Subject *>;
 
47
  subject2= new List <Subject *>; 
 
48
  directed = True;
 
49
}
 
50
 
 
51
bool HyperEdge::operator==(HyperEdge &comp){
 
52
  // compare the configurations
 
53
  // compare the property valuations
 
54
  int sourcelen=subject1->count();
 
55
  int compsourcelen=comp.subject1->count();
 
56
  int i,j;
 
57
  for (i=0;i<sourcelen;i++){
 
58
    if (!comp.subject1->contains((*subject1)[i])) return False;
 
59
  }
 
60
  for (j=0;j<compsourcelen;j++){
 
61
    if (!subject1->contains((*(comp.subject1))[j])) return False;
 
62
  }
 
63
 
 
64
  int targetlen=subject2->count();
 
65
  int comptargetlen=comp.subject2->count();
 
66
 
 
67
  for (i=0;i<targetlen;i++){
 
68
    if (!comp.subject2->contains((*subject2)[i])) return False;
 
69
  }
 
70
  for (j=0;j<comptargetlen;j++){
 
71
    if (!subject2->contains((*(comp.subject2))[j])) return False;
 
72
  }
 
73
 
 
74
  return (label==comp.label);
 
75
}
 
76
 
 
77
 
 
78
 
 
79
 
 
80
HyperEdge::~HyperEdge() {
 
81
  delete subject1;
 
82
  delete subject2;
 
83
}
 
84
 
 
85
 
 
86
bool HyperEdge::InGraph() const {
 
87
  return GetHyperGraph()->HasHyperEdge((HyperEdge *)this);
 
88
}
 
89
 
 
90
 
 
91
void HyperEdge::WriteMembers(OutputFile *ofile) {
 
92
  Subject::WriteMembers(ofile);
 
93
  for (subject1->first();!subject1->done();subject1->next()){
 
94
    (*ofile) << "\t{ Subject1 " << (check(subject1->cur())? 
 
95
                                    subject1->cur()->GetId():0) << " }\n";
 
96
  }
 
97
  for (subject2->first();!subject2->done();subject2->next()){
 
98
    (*ofile) << "\t{ Subject2 " << (check(subject2->cur())? 
 
99
                                    subject2->cur()->GetId():0) << " }\n";
 
100
  }
 
101
  (*ofile) << "\t{ Label: " << label <<"\n";
 
102
  (*ofile) << "}\n";
 
103
}
 
104
 
 
105
 
 
106
void HyperEdge::AddSubject1(Subject *s){
 
107
  subject1->add(s);
 
108
}
 
109
 
 
110
void HyperEdge::AddSubject2(Subject *s){
 
111
  subject2->add(s);
 
112
}
 
113
 
 
114
 
 
115
 
 
116
string HyperEdge::GetLabel(){ 
 
117
  return label;
 
118
}
 
119
 
 
120
void HyperEdge::SetLabel(string s){ 
 
121
  label=s;
 
122
}
 
123
 
 
124
 
 
125
string HyperEdge::GetEvent(){
 
126
  string txt="";
 
127
  unsigned i=0;
 
128
  while (i<label.length()){
 
129
    if (label[i]=='[') return txt;
 
130
    else {
 
131
      txt= txt +label[i]; 
 
132
      i++;
 
133
    }
 
134
  }
 
135
  return txt;
 
136
}
 
137
 
 
138
string HyperEdge::GetGuard(){
 
139
  string txt="";
 
140
  unsigned i=0;
 
141
  while ((i<label.length()) && (label[i]!='[')) i++;
 
142
  if (i==label.length()) return txt;
 
143
  else {
 
144
    while (i<label.length()){
 
145
      txt = txt + label[i];
 
146
      i++;
 
147
    }
 
148
    return txt;
 
149
  }
 
150
}
 
151
 
 
152
 
 
153
 
 
154
bool HyperEdge::HasEmptyEvent(){
 
155
  return (GetEvent()=="");
 
156
}
 
157
 
 
158
 
 
159
 
 
160
 
 
161
bool HyperEdge::HasEmptyGuard(){
 
162
  return (GetGuard()=="");
 
163
}
 
164
 
 
165