1
//////////////////////////////////////////////////////////////////////////////////
2
// This file is part of Toolkit for Conceptual Modeling (TCM).
3
// (c) copyright 2001, Universiteit Twente.
4
// Author: Rik Eshuis (eshuis@cs.utwente.nl).
6
// TCM is free software; you can redistribute it and/or modify
7
// it under the terms of the GNU General Public License as published by
8
// the Free Software Foundation; either version 2 of the License, or
9
// (at your option) any later version.
11
// TCM is distributed in the hope that it will be useful,
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
// GNU General Public License for more details.
16
// You should have received a copy of the GNU General Public License
17
// along with TCM; if not, write to the Free Software
18
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20
////////////////////////////////////////////////////////////////////////////////
21
#include "adsvaluation.h"
22
#include "adspropertyvaluation.h"
25
#include "outputfile.h"
26
#include "adshypergraph.h"
28
#include "adsclockconstraint.h"
31
ADSValuation::ADSValuation(ADSCks *c, StateType s): Node(c){
34
cm.SetInterval(c->GetADSHyperGraph()->GetNrTimeouts()+1);
38
ADSValuation::~ADSValuation(){
42
ADSValuation::ADSValuation(const ADSValuation ©): Node (copy.GetGraph()) {
50
qtermlist=copy.qtermlist;
59
ADSValuation::ADSValuation(const ADSValuation ©, StateType s) : Node(copy.GetGraph()) {
68
qtermlist=copy.qtermlist;
77
bool ADSValuation::operator==( ADSValuation &comp) {
78
if (st!=comp.st) return False;
79
if (cfg.length()!= comp.cfg.length()) return False;
81
// compare the configurations
82
if (!cfg.contains(comp.cfg)) return False;
83
if (!comp.cfg.contains(cfg)) return False;
85
// compare the terminated list nodes
86
if (tlist.length()!= comp.tlist.length()) return False;
87
if (!tlist.contains(comp.tlist)) return False;
88
if (!comp.tlist.contains(tlist)) return False;
90
// compare the property valuations
91
int plistlen=plist.count();
92
int compplistlen=comp.plist.count();
94
for (i=0;i<plistlen;i++){
96
for (j=0;j<compplistlen;j++){
97
if ( (* (plist[i])) == (* ( comp.plist[j])) ){
102
if (!found) return False;
104
for (j=0;j<compplistlen;j++){
106
for (i=0;i<plistlen;i++){
107
if ( (* (plist[i])) == (* ( comp.plist[j])) ) {
112
if (!found) return False;
115
// compare the clock constraints
116
int clistlen=clist.count();
117
int compclistlen=comp.clist.count();
118
for (i=0;i<clistlen;i++){
120
for (j=0;j<compclistlen;j++){
121
if ( (* (clist[i] ) ) == (* ( comp.clist[j]) )) {
126
if (!found) return False;
128
for (j=0;j<compclistlen;j++){
130
for (i=0;i<clistlen;i++){
131
if ( (* (clist[i] ) ) == (* ( comp.clist[j])) ){
136
if (!found) return False;
139
// compare the clock manager
140
if (!(cm==comp.cm)) return False; // check is needed to ensure that all clock constraints are eventually met
142
// ADDD CHECKS FOR ILS!!!!!
146
// compare the queue clock constraints
147
int qclistlen=qclist.count();
148
int compqclistlen=comp.qclist.count();
149
for (i=0;i<qclistlen;i++){
151
for (j=0;j<compqclistlen;j++){
152
if ( (* (qclist[i] ) ) == (* ( comp.qclist[j]) )) {
157
if (!found) return False;
159
for (j=0;j<compqclistlen;j++){
161
for (i=0;i<qclistlen;i++){
162
if ( (* (qclist[i] ) ) == (* ( comp.qclist[j])) ){
167
if (!found) return False;
171
plistlen=queue.count();
172
compplistlen=comp.queue.count();
174
for (i=0;i<plistlen;i++){
176
for (j=0;j<compplistlen;j++){
177
if ( (* (queue[i])) == (* ( comp.queue[j])) ){
182
if (!found) return False;
184
for (j=0;j<compplistlen;j++){
186
for (i=0;i<plistlen;i++){
187
if ( (* (queue[i])) == (* ( comp.queue[j])) ) {
192
if (!found) return False;
195
if (!qtermlist.contains(comp.qtermlist)) return False;
196
if (!comp.qtermlist.contains(qtermlist)) return False;
211
void ADSValuation::GetConfig(Bag <Subject *> *b){
215
void ADSValuation::SetConfig(Bag <Subject *> c){
218
for (l.first();!l.done();l.next()){
219
cfg.add(l.cur(),c.count(l.cur()));
223
void ADSValuation::GetPropList(List <PropVal *> *pl){
227
void ADSValuation::SetPropList(List <PropVal *> p){
234
void ADSValuation::GetTerminated(Bag <ATDActionStateNode *> *tl){
238
void ADSValuation::AddTerminated(Bag <ATDActionStateNode *> t){
239
List <ATDActionStateNode *> l;
241
for (l.first();!l.done();l.next()){
242
tlist.add(l.cur(),t.count(l.cur()));
248
void ADSValuation::GetClockConstraints(List <ClockConstraint *> *cl){
252
void ADSValuation::SetClockConstraints(List <ClockConstraint *> c){
258
ClockManager ADSValuation::GetClockManager(){
262
void ADSValuation::SetClockManager(ClockManager &c){
268
void ADSValuation::Write(OutputFile *ofile) {
269
(*ofile) << "location ID:\t"<< GetId() <<"\t";
270
if (st==stable) {(*ofile) << "stable\n";}
271
else {(*ofile) << "unstable\n";}
274
for (l.first();!l.done();l.next()){
275
(*ofile) << "cfg element =\n" ;
276
(*ofile) << (*(l.cur()->GetName()));
277
(*ofile) << "\t:\t count = " << cfg.count(l.cur()) << "\n";
281
(*ofile) << "TermList:\n";
282
List <ATDActionStateNode *> l2;
284
for (l2.first();!l2.done();l2.next()){
285
(*ofile) << "term el:" <<l2.cur()->GetId() <<":\t" << tlist.count(l2.cur()) <<"\n";
288
(*ofile) << "PropValList:\n";
289
for (plist.first();!plist.done();plist.next()){
290
plist.cur()->Write(ofile);
292
(*ofile) <<"Time outs:\n";
293
for (clist.first();!clist.done();clist.next()){
294
clist.cur()->Write(ofile);
299
(*ofile) << "END of valuation\n";
303
void ADSValuation:: WriteScreen() {
305
(std::cout) << "location ID:\t"<< GetId() <<"\t";
306
std::cout << "\t\tkey\t" << ComputeKey() << "\n";
307
if (st==stable) {(std::cout) << "stable\n";}
308
else {(std::cout) << "unstable\n";}
311
for (l.first();!l.done();l.next()){
312
(std::cout) << "cfg element =\n" ;
313
(std::cout) << (*(l.cur()->GetName()));
314
(std::cout) << "\t:\t count = " << cfg.count(l.cur()) << "\n";
317
(std::cout) << "TermList:\n";
318
List <ATDActionStateNode *> l2;
320
for (l2.first();!l2.done();l2.next()){
321
(std::cout) << "term el:" <<l2.cur()->GetId() <<":\t" << tlist.count(l2.cur()) <<"\n";
324
(std::cout) << "PropValList:\n";
325
for (plist.first();!plist.done();plist.next()){
326
plist.cur()->Write();
329
(std::cout) << "END of valuation\n";
334
void ADSValuation::SetNumber(int i){
338
int ADSValuation::GetNumber(){
343
int ADSValuation::ComputeKey(){
348
for (l.first();!l.done();l.next()){
349
key = key * (7*(l.cur()->GetId()) * (cfg.count(l.cur())));
351
List <ATDActionStateNode *> l2;
353
for (l2.first();!l2.done();l2.next()){
354
key = key + (1 * (l2.cur()->GetId()) * (tlist.count(l2.cur()) )) ;
356
for (plist.first();!plist.done();plist.next()){
357
if (plist.cur()->GetBool())
358
key=key + ((1) * (plist.cur()->GetProp()->GetId()));
360
if (st!=stable) key=key+1;
365
bool ADSValuation::hassameconfig( ADSValuation &comp){
371
for (sl.first();!sl.done();sl.next()){
372
if (cfg.count(sl.cur())!=comp.cfg.count(sl.cur()))
383
void ADSValuation::GetQueue(List <PropVal *> *q){
387
void ADSValuation::SetQueue(List <PropVal *> q){
391
void ADSValuation::GetQClockConstraints(List <ClockConstraint *> *cl){
395
void ADSValuation::SetQClockConstraints(List <ClockConstraint *> c){
399
void ADSValuation::GetQTerminated(Bag <ATDActionStateNode *> *tl){
403
void ADSValuation::AddQTerminated(Bag <ATDActionStateNode *> t){
404
List <ATDActionStateNode *> l;
406
for (l.first();!l.done();l.next()){
407
qtermlist.add(l.cur(),t.count(l.cur()));