-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
76 changed files
with
12,044 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
|
||
from t_core.composer import Composer | ||
from tc_python.frule import FRule | ||
from HGiveRuleLHS import HGiveRuleLHS | ||
from HGiveRuleRHS import HGiveRuleRHS | ||
from HReleaseRuleLHS import HReleaseRuleLHS | ||
from HReleaseRuleRHS import HReleaseRuleRHS | ||
from HRequestSimpleRuleLHS import HRequestSimpleRuleLHS | ||
from HRequestSimpleRuleRHS import HRequestSimpleRuleRHS | ||
from HTakeRuleLHS import HTakeRuleLHS | ||
from HTakeRuleRHS import HTakeRuleRHS | ||
|
||
|
||
class AsLongAsPossible(Composer): | ||
def __init__(self, N, debug_folder=''): | ||
super(AsLongAsPossible, self).__init__() | ||
self.length = 0 | ||
self.debug_suffix = 'alap' | ||
self.debug_folder = debug_folder | ||
self.N = N | ||
self.ReleaseRule = FRule(HReleaseRuleLHS(), HReleaseRuleRHS(), max_iterations=N, ignore_resolver=True) | ||
self.GiveRule = FRule(HGiveRuleLHS(), HGiveRuleRHS(), max_iterations=N, ignore_resolver=True) | ||
self.RequestSimpleRule = FRule(HRequestSimpleRuleLHS(), HRequestSimpleRuleRHS(), max_iterations=N, ignore_resolver=True) | ||
self.TakeRule = FRule(HTakeRuleLHS(), HTakeRuleRHS(), max_iterations=N, ignore_resolver=True) | ||
|
||
def packet_in(self, packet): | ||
if self.debug_folder: packet.graph.draw(label='name', debug=True).save(self.debug_folder + '/%s%d.png' % (self.debug_suffix, self.length)) | ||
|
||
# Release | ||
packet = self.ReleaseRule.packet_in(packet) | ||
packet.clean() | ||
if not self.ReleaseRule.is_success: | ||
if self.ReleaseRule.exception is not None: | ||
self.exception = self.ReleaseRule.exception | ||
return packet | ||
self.length += self.ReleaseRule.I.iterations | ||
if self.debug_folder: packet.graph.draw(label='name', debug=True).save(self.debug_folder + '/%s%d.png' % (self.debug_suffix, self.length)) | ||
|
||
# Give | ||
packet = self.GiveRule.packet_in(packet) | ||
packet.clean() | ||
if not self.GiveRule.is_success: | ||
if self.GiveRule.exception is not None: | ||
self.exception = self.GiveRule.exception | ||
return packet | ||
self.length += self.GiveRule.I.iterations | ||
if self.debug_folder: packet.graph.draw(label='name', debug=True).save(self.debug_folder + '/%s%d.png' % (self.debug_suffix, self.length)) | ||
|
||
# Request | ||
packet = self.RequestSimpleRule.packet_in(packet) | ||
packet.clean() | ||
if not self.RequestSimpleRule.is_success: | ||
if self.RequestSimpleRule.exception is not None: | ||
self.exception = self.RequestSimpleRule.exception | ||
return packet | ||
self.length += self.RequestSimpleRule.I.iterations | ||
if self.debug_folder: packet.graph.draw(label='name', debug=True).save(self.debug_folder + '/%s%d.png' % (self.debug_suffix, self.length)) | ||
|
||
# Take | ||
packet = self.TakeRule.packet_in(packet) | ||
packet.clean() | ||
if not self.TakeRule.is_success: | ||
if self.TakeRule.exception is not None: | ||
self.exception = self.TakeRule.exception | ||
return packet | ||
self.length += self.TakeRule.I.iterations | ||
if self.debug_folder: packet.graph.draw(label='name', debug=True).save(self.debug_folder + '/%s%d.png' % (self.debug_suffix, self.length)) | ||
|
||
self.is_success = True | ||
return packet | ||
|
||
|
240 changes: 240 additions & 0 deletions
240
tcore_package/tcore_package/examples/mutex/HBlockedRuleLHS.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,240 @@ | ||
|
||
|
||
from core.himesis import Himesis, HimesisPreConditionPatternLHS | ||
import cPickle as pickle | ||
|
||
class HBlockedRuleLHS(HimesisPreConditionPatternLHS): | ||
def __init__(self): | ||
""" | ||
Creates the himesis graph representing the AToM3 model HBlockedRuleLHS. | ||
""" | ||
# Create the himesis graph | ||
EDGE_LIST = [(1, 0), (0, 4), (2, 1), (3, 2)] | ||
|
||
super(HBlockedRuleLHS, self).__init__(name='HBlockedRuleLHS', num_nodes=5, edges=EDGE_LIST) | ||
self.is_compiled = True # now this instance has been compiled | ||
|
||
# Set the graph attributes | ||
self["mm__"] = pickle.loads("""(lp1 | ||
S'MT_pre__Mutex' | ||
p2 | ||
aS'MoTifRule' | ||
p3 | ||
a.""") | ||
self["MT_constraint__"] = pickle.loads("""S"#===============================================================================@n# This code is executed after the nodes in the LHS have been matched.@n# You can access a matched node labelled n by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression:@n# returning True enables the rule to be applied,@n# returning False forbids the rule from being applied.@n#===============================================================================@n@nreturn True@n" | ||
p1 | ||
.""").replace("@n", "\n") | ||
self["name"] = pickle.loads("""S'' | ||
.""") | ||
self["GUID__"] = pickle.loads("""ccopy_reg | ||
_reconstructor | ||
p1 | ||
(cuuid | ||
UUID | ||
p2 | ||
c__builtin__ | ||
object | ||
p3 | ||
NtRp4 | ||
(dp5 | ||
S'int' | ||
p6 | ||
L25781605398516429218136079497349662553L | ||
sb.""") | ||
# Set the node attributes | ||
self.vs[0]["MT_subtypeMatching__"] = pickle.loads("""I00 | ||
.""") | ||
self.vs[0]["MT_label__"] = pickle.loads("""S'5' | ||
.""") | ||
self.vs[0]["MT_subtypes__"] = pickle.loads("""(lp1 | ||
.""") | ||
self.vs[0]["mm__"] = pickle.loads("""S'MT_pre__held_by' | ||
p1 | ||
.""") | ||
self.vs[0]["MT_dirty__"] = pickle.loads("""I00 | ||
.""") | ||
self.vs[0]["GUID__"] = pickle.loads("""ccopy_reg | ||
_reconstructor | ||
p1 | ||
(cuuid | ||
UUID | ||
p2 | ||
c__builtin__ | ||
object | ||
p3 | ||
NtRp4 | ||
(dp5 | ||
S'int' | ||
p6 | ||
L189113243710121451020345705446107178214L | ||
sb.""") | ||
self.vs[1]["MT_subtypeMatching__"] = pickle.loads("""I00 | ||
.""") | ||
self.vs[1]["MT_label__"] = pickle.loads("""S'2' | ||
.""") | ||
self.vs[1]["MT_subtypes__"] = pickle.loads("""(lp1 | ||
.""") | ||
self.vs[1]["mm__"] = pickle.loads("""S'MT_pre__Resource' | ||
p1 | ||
.""") | ||
self.vs[1]["MT_dirty__"] = pickle.loads("""I00 | ||
.""") | ||
self.vs[1]["MT_pre__name"] = pickle.loads("""S"@n#===============================================================================@n# This code is executed when evaluating if a node shall be matched by this rule.@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node 'n' by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression.@n#===============================================================================@n@nreturn True@n" | ||
p1 | ||
.""").replace("@n", "\n") | ||
self.vs[1]["GUID__"] = pickle.loads("""ccopy_reg | ||
_reconstructor | ||
p1 | ||
(cuuid | ||
UUID | ||
p2 | ||
c__builtin__ | ||
object | ||
p3 | ||
NtRp4 | ||
(dp5 | ||
S'int' | ||
p6 | ||
L207744363826058715471754082471395483563L | ||
sb.""") | ||
self.vs[2]["MT_subtypeMatching__"] = pickle.loads("""I00 | ||
.""") | ||
self.vs[2]["MT_label__"] = pickle.loads("""S'4' | ||
.""") | ||
self.vs[2]["MT_subtypes__"] = pickle.loads("""(lp1 | ||
.""") | ||
self.vs[2]["mm__"] = pickle.loads("""S'MT_pre__request' | ||
p1 | ||
.""") | ||
self.vs[2]["MT_dirty__"] = pickle.loads("""I00 | ||
.""") | ||
self.vs[2]["GUID__"] = pickle.loads("""ccopy_reg | ||
_reconstructor | ||
p1 | ||
(cuuid | ||
UUID | ||
p2 | ||
c__builtin__ | ||
object | ||
p3 | ||
NtRp4 | ||
(dp5 | ||
S'int' | ||
p6 | ||
L6878234180695968092962607642541102622L | ||
sb.""") | ||
self.vs[3]["MT_subtypeMatching__"] = pickle.loads("""I00 | ||
.""") | ||
self.vs[3]["MT_label__"] = pickle.loads("""S'1' | ||
.""") | ||
self.vs[3]["MT_subtypes__"] = pickle.loads("""(lp1 | ||
.""") | ||
self.vs[3]["mm__"] = pickle.loads("""S'MT_pre__Process' | ||
p1 | ||
.""") | ||
self.vs[3]["MT_dirty__"] = pickle.loads("""I00 | ||
.""") | ||
self.vs[3]["MT_pre__name"] = pickle.loads("""S"@n#===============================================================================@n# This code is executed when evaluating if a node shall be matched by this rule.@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node 'n' by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression.@n#===============================================================================@n@nreturn True@n" | ||
p1 | ||
.""").replace("@n", "\n") | ||
self.vs[3]["GUID__"] = pickle.loads("""ccopy_reg | ||
_reconstructor | ||
p1 | ||
(cuuid | ||
UUID | ||
p2 | ||
c__builtin__ | ||
object | ||
p3 | ||
NtRp4 | ||
(dp5 | ||
S'int' | ||
p6 | ||
L181383295724235727119496965625160452114L | ||
sb.""") | ||
self.vs[4]["MT_subtypeMatching__"] = pickle.loads("""I00 | ||
.""") | ||
self.vs[4]["MT_label__"] = pickle.loads("""S'3' | ||
.""") | ||
self.vs[4]["MT_subtypes__"] = pickle.loads("""(lp1 | ||
.""") | ||
self.vs[4]["mm__"] = pickle.loads("""S'MT_pre__Process' | ||
p1 | ||
.""") | ||
self.vs[4]["MT_dirty__"] = pickle.loads("""I00 | ||
.""") | ||
self.vs[4]["MT_pre__name"] = pickle.loads("""S"@n#===============================================================================@n# This code is executed when evaluating if a node shall be matched by this rule.@n# You can access the value of the current node's attribute value by: attr_value.@n# You can access a matched node 'n' by: PreNode('n').@n# To access attribute x of node n, use: PreNode('n')['x'].@n# The given constraint must evaluate to a boolean expression.@n#===============================================================================@n@nreturn True@n" | ||
p1 | ||
.""").replace("@n", "\n") | ||
self.vs[4]["GUID__"] = pickle.loads("""ccopy_reg | ||
_reconstructor | ||
p1 | ||
(cuuid | ||
UUID | ||
p2 | ||
c__builtin__ | ||
object | ||
p3 | ||
NtRp4 | ||
(dp5 | ||
S'int' | ||
p6 | ||
L161807320235662615371860062293447749265L | ||
sb.""") | ||
def eval_name2(self, attr_value, PreNode, graph): | ||
|
||
#=============================================================================== | ||
# This code is executed when evaluating if a node shall be matched by this rule. | ||
# You can access the value of the current node's attribute value by: attr_value. | ||
# You can access a matched node 'n' by: PreNode('n'). | ||
# To access attribute x of node n, use: PreNode('n')['x']. | ||
# The given constraint must evaluate to a boolean expression. | ||
#=============================================================================== | ||
|
||
return True | ||
|
||
|
||
def eval_name1(self, attr_value, PreNode, graph): | ||
|
||
#=============================================================================== | ||
# This code is executed when evaluating if a node shall be matched by this rule. | ||
# You can access the value of the current node's attribute value by: attr_value. | ||
# You can access a matched node 'n' by: PreNode('n'). | ||
# To access attribute x of node n, use: PreNode('n')['x']. | ||
# The given constraint must evaluate to a boolean expression. | ||
#=============================================================================== | ||
|
||
return True | ||
|
||
|
||
def eval_name3(self, attr_value, PreNode, graph): | ||
|
||
#=============================================================================== | ||
# This code is executed when evaluating if a node shall be matched by this rule. | ||
# You can access the value of the current node's attribute value by: attr_value. | ||
# You can access a matched node 'n' by: PreNode('n'). | ||
# To access attribute x of node n, use: PreNode('n')['x']. | ||
# The given constraint must evaluate to a boolean expression. | ||
#=============================================================================== | ||
|
||
return True | ||
|
||
|
||
def constraint(self, PreNode, graph): | ||
""" | ||
Executable constraint code. | ||
@param PreNode: Function taking an integer as parameter | ||
and returns the node corresponding to that label. | ||
""" | ||
#=============================================================================== | ||
# This code is executed after the nodes in the LHS have been matched. | ||
# You can access a matched node labelled n by: PreNode('n'). | ||
# To access attribute x of node n, use: PreNode('n')['x']. | ||
# The given constraint must evaluate to a boolean expression: | ||
# returning True enables the rule to be applied, | ||
# returning False forbids the rule from being applied. | ||
#=============================================================================== | ||
|
||
return True | ||
|
||
|
Oops, something went wrong.