⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 adshypergraph.c

📁 这个工具集提供以下结构化分析和UML分析中所用的图形化绘图工具:ER-diagrams, data and event flow diagrams and state-transition diagr
💻 C
📖 第 1 页 / 共 3 页
字号:
//////////////////////////////////////////////////////////////////////////////////// This file is part of Toolkit for Conceptual Modeling (TCM).// (c) copyright 2001, Universiteit Twente.// Author: Rik Eshuis (eshuis@cs.utwente.nl).//// TCM is free software; you can redistribute it and/or modify// it under the terms of the GNU General Public License as published by// the Free Software Foundation; either version 2 of the License, or// (at your option) any later version.//// TCM is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the// GNU General Public License for more details.//// You should have received a copy of the GNU General Public License// along with TCM; if not, write to the Free Software// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA// 02111-1307, USA.////////////////////////////////////////////////////////////////////////////////#include "adshypergraph.h"#include "code.h"#include "atdactionstatenode.h"#include "adsactivity.h"#include "adshyperedge.h"#include "adsvariable.h"#include "adsproperty.h"#include "outputfile.h"#include "adsclock.h"#include "node.h"#include "adsclockconstraint.h"#include "util.h"#include "adssemantics.h" extern string replace(string s); // defined in adscksADSHyperGraph::ADSHyperGraph() :HyperGraph() {  timeoutnumber=0;}ADSHyperGraph::~ADSHyperGraph(){}void ADSHyperGraph::ComputeInternalProperties(){  intproplist.empty();  for (updatedinactivities.first();!updatedinactivities.done();updatedinactivities.next()){    for (propl.first();!propl.done();propl.next()){      if (propl.cur()->GetVar()==updatedinactivities.cur()){ // note == on addr	  switch (propl.cur()->GetType()) {	  case ::INT :     propl.cur()->SetType(::INTERNAL_INT);break;	  case ::PROP :    propl.cur()->SetType(::INTERNAL_PROP);break;	  case ::STRING :  propl.cur()->SetType(::INTERNAL_STRING);break;	  default : ;	  }	  intproplist.add(propl.cur());      }    }  }  int length=propl.count();  for (int i=0;i<length;i++){    if (propl[i]->GetType()==EVENT){       List <Subject *> edges;      GetHyperEdges(&edges);      for (edges.first();!edges.done();edges.next()){		Prop *p=((((ADSHyperEdge *)edges.cur())->GetSendEvent()));	if ((p) && (*p==*propl[i])){ // EVENT is triggered by SENDEVENT	  propl[i]->SetType(::SENDEVENT); // then set EVENT to SENDEVENT	  continue;	}      }	    }  }}void ADSHyperGraph::ComputeInternalHyperEdges(){  List <Subject *> edges;  GetHyperEdges(&edges);  for (edges.first();!edges.done();edges.next()){	    List <Prop *> proplist;    ((ADSHyperEdge *)edges.cur())->GetPropList(proplist);    for (proplist.first();!proplist.done();proplist.next()){      if (proplist.cur()->GetType()==::SENDEVENT){	((ADSHyperEdge *)edges.cur())->SetInternal();      }    }  }}	  void ADSHyperGraph::ComputeExternalProperties(){  extproplist.empty();  for (propl.first();!propl.done();propl.next()){    if (!(propl.cur()->isInternal())){	extproplist.add(propl.cur());      }      }}void ADSHyperGraph::ComputeActivities(){  actlist.empty();  updatedinactivities.empty();  for (nodes->first();!nodes->done();nodes->next()){    if (((ATDActionStateNode *)nodes->cur())->GetClassType()==Code::ATD_ACTION_STATE_NODE){      string s=*(nodes->cur()->GetName());      ADSActivity *newact=new ADSActivity(s); // create new activity      // insert newact into actlist, if it was not in it already      bool b=True;      for (actlist.first();!actlist.done();actlist.next()){	if (*actlist.cur()==*newact) {	  b=False; 	  delete newact;	  newact=actlist.cur();	  break;	}      }      if (b) actlist.add(newact);      ((ATDActionStateNode *)nodes->cur())->SetActivity(newact);           List <Subject *> *l=new List <Subject *>;      GetHyperEdgesFrom(l,nodes->cur());      for (l->first();!l->done();l->next()){	List <ADSVar *> vl;	((ADSHyperEdge *)l->cur())->GetVarList(vl);	for (vl.first();!vl.done();vl.next()){	  newact->AddUpdate(vl.cur());	  	  // update updatedinactivities	  bool found=False;	  for (updatedinactivities.first();!updatedinactivities.done();updatedinactivities.next()){		   	    if (*updatedinactivities.cur()==*vl.cur()){	      found=True;	      break;	    }	  }	  if (!found) updatedinactivities.add(vl.cur());	}      }              }  }}void ADSHyperGraph::ComputeInterferences(){  int count=actlist.count();  int i,j;  // Begin computation of conflicts  for (i=0;i<count;i++){    List <ADSVar *> l1;    actlist[i]->GetUpdateList(l1);        for (j=i;j<count;j++){      List <ADSVar *> l2;      actlist[j]->GetUpdateList(l2);      interference[i][j]=0;      for (l1.first();!l1.done();l1.next()){	bool b=False;	for (l2.first();!l2.done();l2.next()){	  ADSVar *v1=l1.cur();	  ADSVar *v2=l2.cur();	  if (*v1==*v2){	    interference[i][j]=1;	    b=True;	    break;	  }	}	if (b) break; // conflict[i][j] already found      }    }  }}bool ADSHyperGraph::GetInterference(ADSActivity *a1,ADSActivity *a2){ // action state node???  int i1=actlist.find(a1);  int i2=actlist.find(a2);  if ((i1==-1) || (i2==-1)) return False;  if (i1<i2)     return interference[i1][i2];  else     return interference[i2][i1];}bool ADSHyperGraph::GetInterference(ATDActionStateNode *a1, ATDActionStateNode *a2){  string a1name=*a1->GetName();  string a2name=*a2->GetName();  ADSActivity *a1new= new ADSActivity(a1name);  ADSActivity *a2new= new ADSActivity(a2name);  ADSActivity *a1old=0, *a2old=0;  bool b1=False;  bool b2=False;  for (actlist.first();!actlist.done();actlist.next()){    if (*a1new==*actlist.cur()) {a1old=actlist.cur();b1=True;}    if (*a2new==*actlist.cur()) {a2old=actlist.cur();b2=True;}    if (b1&&b2) break;  }  if (b1&&b2)     return GetInterference(a1old,a2old);  else // not found? I'm confused!    return False;}void ADSHyperGraph::Initialise(){  ComputeActivities();  ComputeInterferences();  ComputeConflicts();  ComputeInternalProperties();  ComputeExternalProperties();  ComputeInternalHyperEdges();  ComputeNrTimeouts();  SetInitialFinalNames();  InitialiseBounds();}void ADSHyperGraph::Finalise(){   UnSetInitialFinalNames();}bool ADSHyperGraph::AddProp(Prop *p){  for (propl.first();!propl.done();propl.next()){    if (*propl.cur()==*p) return False;  }  propl.add(p);  return True;}bool ADSHyperGraph::AddVar(ADSVar *v){  for (varl.first();!varl.done();varl.next()){    if (*varl.cur()==*v) return False;  }  varl.add(v);  return True;}void ADSHyperGraph::RemoveProp(Prop *p){   propl.remove(p);}void ADSHyperGraph::GetPropList(List <Prop *> &p){  p=propl;}void ADSHyperGraph::GetExtPropList(List <Prop *> &p){  p=extproplist;}void ADSHyperGraph::GetIntPropList(List <Prop *> &p){  p=intproplist;}void ADSHyperGraph::GetVarList(List <ADSVar *> &v){  v=varl;}Prop *ADSHyperGraph::FindSimilarProp(Prop *p){  for (propl.first();!propl.done();propl.next()){    if (*propl.cur()==*p) return propl.cur();  }  return 0;}  ADSVar *ADSHyperGraph::FindSimilarVar(ADSVar *p){  for (varl.first();!varl.done();varl.next()){    if (*varl.cur()==*p) return varl.cur();  }  return 0;}  Node *ADSHyperGraph::FindNode(string name){  //  List <Subject *> nodes;  //  GetNodes(&nodes);  for (nodes->first();!nodes->done();nodes->next()){    if (replace(*(nodes->cur()->GetName()))==replace(name)){      return (Node*)(nodes->cur());    }  }  return NULL;}//ADSActivity *ADSHyperGraph::FindAct(string s){//  ADSActivity *a = new ADSActivity(s);//  for (actlist.first();!actlist.done();actlist.next()){//    if (*actlist.cur()==*a) return actlist.cur();//  }//  return 0;//}// The now following procedure is old, since we now discretise // all clocks with 1, not with 1/nr of timeoutsvoid ADSHyperGraph::ComputeNrTimeouts(){  //  List <Subject *> amhedges;  //  GetHyperEdges(&amhedges);  // for (amhedges.first(); !amhedges.done(); amhedges.next()) {  //    if (((ADSHyperEdge *)amhedges.cur())->hasClockConstraint()) timeoutnumber++;  //  }  timeoutnumber=0; // discretisation with 1}void ADSHyperGraph::WriteSubjects(OutputFile *f) {  HyperGraph::WriteSubjects(f);  (*f) << "INTERNAL PROPERTY LIST \n";  for (intproplist.first();!intproplist.done();intproplist.next()){    intproplist.cur()->Write(f);  }  (*f) << "EXTERNAL PROPERTY LIST \n";  for (extproplist.first();!extproplist.done();extproplist.next()){    extproplist.cur()->Write(f);  }  List <Subject *> amhedges;  GetHyperEdges(&amhedges);  int actcount=actlist.count();  for (int i=0;i<actcount;i++){    (*f) << i << ":\t";    actlist[i]->Write(f);    for (int j=i+1;j<actcount;j++){      if (GetInterference(actlist[i],actlist[j])){	(*f) << "1";;      }      else (*f) << "0";    }    (*f) << "\n";  } }void ADSHyperGraph::UpdateBounds(Bag <Subject *> *cfg){  List <Subject *> ls;  cfg->GetSet(&ls);  List <Node *> ahnodes;  GetNodes((List <Subject *> *)&ahnodes);  int count=ahnodes.count();  for (int i=0;i<count;i++){     int c=cfg->count(ahnodes[i]);    if (c>bound[i]) bound[i]=c;  }}void ADSHyperGraph::InitialiseBounds(){  List <Node *> ahnodes;  GetNodes((List <Subject *> *)&ahnodes);  int ahnodescount=ahnodes.count();  int i;  for (i=0;i<ahnodescount;i++){    bound[i]=0;  }}int ADSHyperGraph::GetBound(Subject *s){  List <Subject *> ahnodes;  GetNodes(&ahnodes);  int index=ahnodes.find(s);  if (index==-1) error ("A node that does not exist cannot have a bound!\n");  return bound[index];}void ADSHyperGraph::ComputeConflicts(){  List <ADSHyperEdge *> hyperedges;  GetHyperEdges((List <Subject *> *)&hyperedges);  int hedgescount = hyperedges.count();  for (int i=0;i<hedgescount;i++){

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -