📄 adssemantics.c
字号:
} int acount = a.count(); unsigned long int subsetsa = 1<<acount; int ccount=0; if ((adk->GetClockManager().ExistScheduled())&&(!(adk->GetClockManager().ExistTimeouts()))) ccount=1; unsigned long int subsetsc = 1<<ccount; // PLEASE NOTE: I ASSUME THAT THERE ARE NO CHANGE EVENTS List <Prop *> notinq=extproplist; // the set of properties not in queue List <PropVal *> q; // existing q, it can only contain events adk->GetQueue(&q); for (q.first();!q.done();q.next()){ if (q.cur()->GetBool()) notinq.remove(q.cur()->GetProp()); // remove properties that are in queue } for (notinq.first();!notinq.done();){ if (notinq.cur()->GetType()!=EVENT){ notinq.removecur(); } else notinq.next(); } // notinq now only contains events not in q int pnotinq_len=notinq.count(); // unsigned long int subsets_pnotinq_len = 1 << pnotinq_len; // fill newq int index; for ( index=0;index<subsets_pnotinq_len;index++){ List <PropVal *> newq; // the new queue for (q.first();!q.done();q.next()){ if (q.cur()->GetBool()) newq.add(q.cur()); // put old events in new queue } for (int j=0;j<pnotinq_len;j++){ if ((1<<j) & index){ PropVal *pvt=new PropVal(notinq[j],True); // only for events newq.add(pvt); } else{ PropVal *pvf=new PropVal(notinq[j],False); newq.add(pvf); } } // NOTE // assumption: now every event has valuation true or false in newq // END OF NOTE unsigned long int c2; for (c2=0;c2<subsetsa;c2++){ // for all possibe subsets of a // compute the terminated queue activity instances Bag <ATDActionStateNode *> newqterm; // newqterm.join(qterm); niet nodig vanwege AddQTerminated procedure for (int ctemp=0;ctemp<acount;ctemp++){ if ((1<<ctemp) & c2) { newqterm.add(a[ctemp]); } } unsigned long int c3; ClockManager cmnew=adk->GetClockManager(); for (c3=0;c3<subsetsc;c3++){ // for all possibe subsets of c (1) if (c3){ if (!cmnew.Tick()) std::cout << "I cannot tick in state " << adk->GetId() << "\n";; } List <ClockConstraint *> timeout; if ((adk->HasClockConstraints()) || ((cmnew.ExistTimeouts()))) cmnew.GetTimeouts(&timeout); // timeout can be empty if !ExistScheduled if ((index==0) && (c2==0) && (c3==0) && (adk->isStable())) continue; // no change is no change if (adk->isStable()){ // router is not busy processing any event // either (a) an external event from newq or (b) a termination event from newqterm is processed or (c) a temporal event is processed // case (a) for (newq.first();!newq.done();newq.next()){ if (!newq.cur()->GetBool()) continue; List <PropVal *> newproplist; newproplist.add(newq.cur()); // pick a random event if event is true // preserve the old internal properties (data). List <PropVal *> oldpropvallist; adk->GetPropList(&oldpropvallist); for (oldpropvallist.first();!oldpropvallist.done();oldpropvallist.next()){ if (oldpropvallist.cur()->GetProp()->isInternal()) newproplist.add(oldpropvallist.cur()); } List <PropVal *> newnewq; newnewq=newq; newnewq.remove(newq.cur()); PropVal *pvf=new PropVal(newq.cur()->GetProp(),False); newnewq.add(pvf); ADSValuation *adknew=new ADSValuation(*adk,unstable); // make new state adknew->SetQueue(newnewq); adknew->AddQTerminated(newqterm); adknew->SetPropList(newproplist); adknew->SetQClockConstraints(timeout); adknew->SetClockManager(cmnew); ADSValuation *oldadk=c->FindSimilarNode(adknew); if (!oldadk){ // adknew does not yet exist in c // if (!c->ExistsSimilarNode(adknew)){ // adknew does not yet exist in c c->AddNode(adknew); // so add it to c unprocessed.add(adknew); // and to unprocessed ADSTransition *ktnew = new ADSTransition(c,adk,adknew); // make a new transition c->AddEdge(ktnew); string str; if (c->GrowsInfinite(adknew,str)){ string s="The activity diagram is infinite (state "+ str + " is unbounded)!\n"; char s1[100]; strcpy(s1,s.getstr()); error(s1); return; } // std::cout << "\nAFDDSF"; // eadkl.next(); // next in list } else{ // ADSValuation *old=c->FindSimilarNode(adknew); // adknew exists already, so find this old copy ADSTransition *ktnew = new ADSTransition(c,adk,oldadk); // make a transition if (!c->ExistsSimilarEdge(ktnew)){ c->AddEdge(ktnew); } else delete ktnew; } } // case (b) List <ATDActionStateNode *> qtermlist; qterm.GetSet(&qtermlist); if (qtermlist.count()==0){ newqterm.GetSet(&qtermlist); } for (qtermlist.first();!qtermlist.done();qtermlist.next()) { Bag <ATDActionStateNode *> newterm; adk->GetTerminated(&newterm); newterm.add(qtermlist.cur()); // pick a random event, insert into newterm newqterm.add(qtermlist.cur(),-1); // and remove from qterm term.add(qtermlist.cur()); // only needed for inspection of `canbeupdated' ADSActivity *act=qtermlist.cur()->GetActivity(); List <ADSVar *> varl; act->GetUpdateList(varl); unsigned long int c4; // depending upon c2 (computing al) !!!!! unsigned long int subsetsvarl = 1 << varl.count(); for (c4=0; c4<subsetsvarl;c4++) { List <PropVal *> ipl; int ctemp; for (ctemp=0;ctemp<varl.count();ctemp++){ if ((1<<ctemp) & c4) { for (ip.first();!ip.done();ip.next()){ if (ip.cur()->GetVar()==varl[ctemp]){ PropVal *pv=new PropVal(ip.cur(),True); ipl.add(pv); } } } else{ for (ip.first();!ip.done();ip.next()){ if (ip.cur()->GetVar()==varl[ctemp]){ PropVal *pv=new PropVal(ip.cur(),False); ipl.add(pv); } } } } List <PropVal *> oldproplist; adk->GetPropList(&oldproplist); for (ip.first();!ip.done();ip.next()){ if (!varl.contains(ip.cur()->GetVar())){ // retrieve old value PropVal *pv=getPropVal(&oldproplist,ip.cur()); // take old value if (pv!=NULL) ipl.add(pv); } } ADSValuation *adknew=new ADSValuation(*adk,unstable); // make new state adknew->SetPropList(ipl); adknew->SetQueue(newq); adknew->AddQTerminated(newqterm); adknew->AddTerminated(newterm); adknew->SetQClockConstraints(timeout); adknew->SetClockManager(cmnew); ADSValuation *oldadk=c->FindSimilarNode(adknew); if (!oldadk){ // adknew does not yet exist in c // if (!c->ExistsSimilarNode(adknew)){ // adknew does not yet exist in c c->AddNode(adknew); // so add it to c unprocessed.add(adknew); // and to unprocessed ADSTransition *ktnew = new ADSTransition(c,adk,adknew); // make a new transition if (!c->ExistsSimilarEdge(ktnew)){ // if the transition did not yet exist c->AddEdge(ktnew); } else delete ktnew; // else delete the transition string str; if (c->GrowsInfinite(adknew,str)){ string s="The activity diagram is infinite (state "+ str + " is unbounded)!\n"; char s1[100]; strcpy(s1,s.getstr()); error(s1); return; } // std::cout << "\nAFDDSF"; // eadkl.next(); // next in list } else{ // ADSValuation *old=c->FindSimilarNode(adknew); // adknew exists already, so find this old copy ADSTransition *ktnew = new ADSTransition(c,adk,oldadk); // make a transition if (!c->ExistsSimilarEdge(ktnew)){ c->AddEdge(ktnew); } else delete ktnew; } } } // case (c) temporal event for (timeout.first();!timeout.done();timeout.next()){ ADSValuation *adknew=new ADSValuation(*adk,unstable); // make new state List <ClockConstraint *> newtimeout; newtimeout.add(timeout.cur()); List <ClockConstraint *> newqtimeout; newqtimeout=timeout; newqtimeout.remove(timeout.cur()); adknew->SetQueue(newq); adknew->AddQTerminated(newqterm); adknew->SetQClockConstraints(newqtimeout); adknew->SetClockConstraints(newtimeout); adknew->SetClockManager(cmnew); ADSValuation *oldadk=c->FindSimilarNode(adknew); if (!oldadk){ // adknew does not yet exist in c // if (!c->ExistsSimilarNode(adknew)){ // adknew does not yet exist in c c->AddNode(adknew); // so add it to c unprocessed.add(adknew); // and to unprocessed ADSTransition *ktnew = new ADSTransition(c,adk,adknew); // make a new transition if (!c->ExistsSimilarEdge(ktnew)){ // if the transition did not yet exist c->AddEdge(ktnew); } else delete ktnew; // else delete the transition string str; if (c->GrowsInfinite(adknew,str)){ string s="The activity diagram is infinite (state "+ str + " is unbounded)!\n"; char s1[100]; strcpy(s1,s.getstr()); error(s1); return; } // std::cout << "\nAFDDSF"; // eadkl.next(); // next in list } else{ // ADSValuation *old=c->FindSimilarNode(adknew); // adknew exists already, so find this old copy ADSTransition *ktnew = new ADSTransition(c,adk,oldadk); // make a transition if (!c->ExistsSimilarEdge(ktnew)){ c->AddEdge(ktnew); } else delete ktnew; } } } else if (!adk->isStable()){ // HET GAAT MIS OMDAT terminated BIJ BEREKENEN STAP. MOET TERMINATED ALS F BESCHOUWEN // gerepareerd // if (!adk->isStable()){ // adk is unstable, but step is not yet finished // only set the new queue // CASE 1 if (!((index==0) && (c2==0))){ // only if there is some change ADSValuation *adknew=new ADSValuation(*adk,unstable); adknew->SetQueue(newq); adknew->AddQTerminated(newqterm); adknew->SetQClockConstraints(timeout); ADSValuation *oldadk=c->FindSimilarNode(adknew); if (!oldadk){ // adknew does not yet exist in c // code repeated , make separate procedure someday // if (!c->ExistsSimilarNode(adknew)){ // adknew does not yet exist in c c->AddNode(adknew); // so add it to c unprocessed.add(adknew); // and to unprocessed ADSTransition *ktnew = new ADSTransition(c,adk,adknew); // make a new transition c->AddEdge(ktnew); string str; if (c->GrowsInfinite(adknew,str)){ string s="The activity diagram is infinite (state "+ str + " is unbounded)!\n"; char s1[100]; strcpy(s1,s.getstr()); error(s1); return; } // std::cout << "\nAFDDSF"; // eadkl.next(); // next in list } else{ // ADSValuation *old=c->FindSimilarNode(adknew); // adknew exists already, so find this old copy ADSTransition *ktnew = new ADSTransition(c,adk,oldadk); // make a transition if (!c->ExistsSimilarEdge(ktnew)){ c->AddEdge(ktnew); } else delete ktnew; } } // CASE 2 // adk is unstable, hence a reaction (step) can be taken Bag <ADSHyperEdge *> enab; // the bag of enabled hyperedges ComputeEnabled(h,adk,&enab); // fill enab with enabled hyperedges List<Bag<ADSHyperEdge *> *> steplist; // the list of all possible steps Step(h,adk,&enab,&steplist); // compute steplist (list of steps) // not every step in the steplist is maximal // therefore the maximal steps are filtered out next int slength=steplist.count(); for (int ii=0;ii<slength;ii++){ ADSValuation *klnew=TakeStep(h,c,adk,steplist[ii]); // take the step. This results in a unique next valuation, could be stable or unstable. // TODO // // make this next valuation unstable // DO NOT DO ADSValuation *oldadk=c->FindSimilarNode(klnew); if (!oldadk){ // if (!c->ExistsSimilarNode(klnew)){ c->AddNode(klnew); unprocessed.add(klnew); ADSTransition *ktnew = new ADSTransition(c,adk,klnew,steplist[ii]); // make a transition in which a step is taken c->AddEdge(ktnew); string str; if (c->GrowsInfinite(klnew,str)){ string s="The activity diagram is infinite (state "+ str + " is unbounded)!\n"; char s1[100]; strcpy(s1,s.getstr()); error(s1); return; } } else{ // there exists already a similar node // ADSValuation *old=c->FindSimilarNode(klnew); delete klnew; ADSTransition *ktnew = new ADSTransition(c,adk,oldadk,steplist[ii]); if (!c->ExistsSimilarEdge(ktnew)){ c->AddEdge(ktnew); } else delete ktnew; } } } // end else } } } unprocessed.remove(adk); // adk is processed so remove it } }*/// }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -