Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [henshin-user] Nested application conditions in Henshin diagrams?

hi,


I thought that the multi-rule levels were meant for this: Place and Token are matched by the same multi-rule (remove), so I thought that would mean it finds only the one match. I thought if I wanted to find the matches separately, I had to use nested multi-rules to loop. When I saw the effect, I did wonder whether that was exactly my misunderstanding. So, is there any way at all to do in Henshin what I want to do?

honestly, i am not 100% sure about the semantics of nested-multi-rules.

Anyway, i typically avoid to do too many things in one rule. In another example (an interpreter for a hierarchical state machine with prioritiers and with incoming and outgoing messages), i simply use different rules.

1) Mark all transitions which are enabled
2) select the transition with the highest priority according to the semantics
3) execute the transition
4) set all marking attributes to false

I use labels for information exchange. The first rule sets the boolean attribute enabled for all enabled transitions, the second rule only considers transitions with that attribute set to true and sets an attribute firing, the third rule executes the transition with that attribute.

I think this makes the rules much easier to understand as well.

See attached the concrete example.

I think this could be applied to the petri net case as well.

As for the textual syntax: I don't have this available in the Wizard. Does it come as part of the standard Henshin installation or do I need to get it from somewhere else?

If it is not in the current stable build, we should consider making a new stable build. I always use the HEAD in the git, so i dont know what is in the stable build ;)

Cheers,

Matthias

--
Prof. Dr. Matthias Tichy
Institute of Software Engineering and Programming Languages
Faculty of Engineering, Computer Science and Psychology
Ulm University
89069 Ulm, Germany

Tel.:  +49 731 50-24160
Fax:   +49 731 50-24162
email: matthias.tichy@xxxxxxxxxx
ePackageImport hfsm

rule firstLevelCalc ()
{
	graph {
		preserve node hfsm:HFSM {
		}
		multiRule forAllChildrenOfHFSM {
			graph {
				preserve node state:State {
					create level=1
				}
				edges [(hfsm ->	state : states)] 	
			}
		}
	}
}

unit levelcalc(l:EInt, k:EInt)
{
    
	firstLevelCalc()
	while {
		calculateNextLevel(l,  k)
	}
}

rule calculateNextLevel(l:EInt, k:EInt)
{
	graph {
		preserve node composite:CompositeState {
			level = l
		}
		preserve node child:State {
			level = k
			set level = l + 1
		}
		edges [(composite -> child : children)]
	}
	conditions [(k == 0)]
}

rule enableTransitions()
{
	graph {
		node hfsm:HFSM
		node currentStateRef:CurrentState
		node currentState:State
		edges [(hfsm->currentStateRef:currentState), (currentStateRef->currentState:currentState)]
		
		multiRule forAllTransitions {
			graph {
				reuse hfsm
				reuse currentState
				node nextState:State
				node transition:Transition {
					create enabled = true
				}
				edges [(hfsm->transition:transitions), (transition->currentState:source), (transition->nextState:target)]
				matchingFormula{
				formula !checkMessagesAvailable
				conditionGraph checkMessagesAvailable {
					reuse transition
					node messageType:MessageType
					edges[(transition->messageType:receive)]
					
					matchingFormula {
						formula !checkQueue
						conditionGraph checkQueue {
							reuse messageType
							node message:Message
							edges [(message->messageType:queuedMessages)]
						}
					}
					
				}
				}
			}
		}
	}	
}

rule resetTransitions()
{
	graph {
		node hfsm:HFSM
		multiRule forAllTransitions {
			graph {
				reuse hfsm
				node transition:Transition {
					create enabled = false
					create firing = false
				}
				edges [(hfsm->transition:HFSM.transitions)]
			}
		}
	}
}

rule selectTransitions(p1:EInt, p2:EInt, l1s:EInt, l1t:EInt, l2s:EInt, l2t:EInt)
{
	graph {
		node hfsm:HFSM
		node transition:Transition {
			prio = p1
			enabled = true
			create firing = true
		}
		edges [(hfsm->transition:transitions)]
		
		matchingFormula {
			formula !(sameHierachy OR differentHierarchy)
			conditionGraph sameHierachy {
				reuse hfsm
				reuse transition {
					prio = p1
					enabled = true
				}
				node otherTransition:Transition{
					prio = p2
					enabled = true
				}
				edges [(hfsm->otherTransition:transitions)]
			}
			conditionGraph differentHierarchy {
				reuse hfsm
				reuse transition {
					prio = p1
					enabled = true
				}
				node source:State {
					level = l1s
				}
				node target:State {
					level = l1t
				}
				node otherTransition:Transition{
					prio = p2
					enabled = true
				}
				node otherSource:State {
					level = l2s
				}
				node otherTarget:State {
					level = l2t
				}
				
				edges [(transition->source:source), (transition->target:target), (hfsm->otherTransition:transitions), (otherTransition->otherSource:source), (otherTransition->otherTarget:target)]
			}
		}
		
	}
	conditions [(p1 > p2), (l1s < l2s OR l1s < l2t OR l1t < l2s OR l1t < l2t)]

}

rule executeFireTransition()
{
	graph {
		node hfsm:HFSM
		node firingTransition:Transition {
			firing = true
		}
		node currentStateRef:CurrentState
		node currentState:State
		node nextState:State
		edges [(hfsm->firingTransition:transitions),
			   (firingTransition->currentState:source), (firingTransition->nextState:target),
			   (hfsm->currentStateRef:currentState),
			   (delete currentStateRef->currentState:currentState),
			   (create currentStateRef->nextState:currentState)
		]
		multiRule deleteConsumedMessages {
			graph {
				reuse firingTransition
				reuse currentStateRef
				node messageType:MessageType
				delete node message:Message
				edges [(firingTransition->messageType:receive), (delete message->messageType:queuedMessages), (delete currentStateRef->message:type)]
			}
		}
		multiRule createSendMessages {
			graph {
				reuse firingTransition
				reuse currentStateRef
				node messageType:MessageType
				create node message:Message
					edges [(firingTransition->messageType:receive), (create message->messageType:queuedMessages), (create currentStateRef->message:type)]
				
			}
		}
	}
}

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature


Back to the top