Exemple #1
0
 def AddProductionRule(self, edit=None):
     rule = dp.AddProductionRuleDialog(self, edit).result
     if rule:
         if edit:
             Rule.removeProd(edit[0])
         Rule.AddProduction(rule)
         self.RefreshLists()
Exemple #2
0
 def AddDrawingRule(self, edit=None):
     rule = dd.AddDrawingRuleDialog(self, edit).result
     if rule:
         if edit:
             Rule.removeDraw(edit[0])
         Rule.AddDrawing(rule)
         self.RefreshLists()
Exemple #3
0
 def parseSaveFile(self, s):
     Rule.wipe()
     settings = s.split('@')
     self.inp_seed.set(str(settings[1]))
     self.parseProdRules(settings[2])
     self.parseDrawRules(settings[3])
     self.RefreshLists()
Exemple #4
0
    def RefreshLists(self):
        self.list_prod.delete(0, END)
        self.list_draw.delete(0, END)

        l = self.formatRules(Rule.getProductions())
        for p in l:
            self.list_prod.insert(END, p)

        l = self.formatRules(Rule.getDrawings())
        for d in l:
            self.list_draw.insert(END, d)
Exemple #5
0
    def __formatTemplate(self):

        i = Position(0, 0)  # 扫描时行数
        eIndex = bIndex = -1  # 临时变量 记录rule在y坐标 起始位置和截止位置
        length = len(self.lines)  # 行数
        startPosition = endPosition = None  # 临时变量 记录rule起始位置和截止位置
        dpStartPos = dpEndPos = None  # 临时变量 记录rule对应模版截取的 起始位置和截止位置
        targetName = None  # 临时变量 记录rule的targetName
        dataString = None  # 临时变量 记录rule的dataString
        tmpIndex = None  # y坐标的临时变量
        lines = None  # 临时变量 记录复制的rule的lines(从dpStartPos和dpEndPos复制出来的内容)

        while i.row < length:

            bIndex = self.lines[i.row].find("[", i.column)
            if bIndex == -1:
                i.row += 1
                i.column = 0
                continue
            eIndex = self.lines[i.row].find("]", bIndex + 1)
            # 获得targetName
            targetName = self.lines[i.row][bIndex + 1 : eIndex]
            # 获得rule 起始位置
            startPosition = Position(i.row, bIndex)
            tmpIndex = self.lines[i.row].find("]", eIndex + 1)
            # 获得dataString
            dataString = self.lines[i.row][(eIndex + 1) : tmpIndex]
            # 截取内容的起始位置
            dpStartPos = Position(i.row, tmpIndex + 1)

            tmpIndex = self.lines[i.row].find(Rule.getRules()[targetName].endName, tmpIndex + 1)
            while tmpIndex == -1 and i.row < length:
                i.row += 1
                tmpIndex = self.lines[i.row].find(Rule.getRules()[targetName].endName)

            if tmpIndex == -1:
                raise Exception()

                # 获得rule截止位置
            endPosition = Position(i.row, tmpIndex + len(Rule.getRules()[targetName].endName) - 1)
            i.column = tmpIndex + 1
            # 截取内容的截止位置
            if tmpIndex:
                dpEndPos = Position(i.row, tmpIndex - 1)
            else:
                dpEndPos = Position(i.row - 1, len(self.lines[i.row - 1]))

                # 截取模版内容
            lines = self.__duplicatePart(dpStartPos, dpEndPos)
            # 创建rule
            self.rules.append(Rule.getRules()[targetName](startPosition, endPosition, dataString, lines))
def replace(s):
	prod = Rule.getProductions()
	idx = 0
	a = list(s)
	for c in a:
		for p in prod:
			if c == p[0]:
				a[idx] = p[1]
				break
		idx += 1
	return "".join(a)
Exemple #7
0
 def getDrawCount(self, s):
     draw_commands = []
     for r in Rule.getDrawings():
         if r[1].lower() == "draw":
             draw_commands.append(r[0])
     draw_count = 0;
     for c in s:
         for d in draw_commands:
             if c == d:
                 draw_count += 1
                 break
     return draw_count
Exemple #8
0
 def drawAll(self, newWindow= True):
     if self.generated == True:
         self.butt_print.config(state= 'disabled')
         self.timebuff = 0.0
         self.color = Color.white()
         self.thick = 2
         l = float(self.slid_linesize.get())
         a = float(self.slid_angle.get())
         Draw.init(self.startingPoint, l, a)
         if self.fullScreen.get() == 1:
             if newWindow:
                 self.curr_canvas = dc.BigCanvas(self).canvas
             self.canvas.delete("all")
         else:
             self.curr_canvas = self.canvas
         self.curr_canvas.delete("all")
         self.curr_canvas.config(bg= Color.getHexString(self.bgColor.get()))
         rainbow = self.rainbowCheck.get() == 1
         if rainbow or self.incThickYN:
             self.incStep = 1.0/float(self.getDrawCount(self.output))
             self.percent = 0.0
         for c in self.output:
             if c == '[':
                 Draw.push()
             elif c == ']':
                 Draw.pop()
             else:
                 for r in Rule.getDrawings():
                     if c == r[0]:
                         if len(r) > 2:
                             params = (r[1], r[2])
                         else:
                             params = (r[1],)
                         s = float(self.slid_timer.get())
                         self.do(params, s, rainbow)
                         break
         self.butt_print.config(state= 'normal')
Exemple #9
0
 def add_rule(self, cond, conc):
     self.rules.append(Rule(cond, conc))
Exemple #10
0
import Data, InitPeolple, DrawFirst, Rule, Income
import matplotlib.pyplot as plt
import matplotlib.animation
import numpy as np
import time

init = InitPeolple.InitPeople()
draw = DrawFirst.draw()
move = Rule.PeopleMove()
income = Income.outDirection()
# allPeople=init.creatPeople()
allPeople = init.creatAppointPeo()
allWall = init.creatWall()
allExit = init.creatExit()
# while Data.flag:

for p in allPeople:
    income.outDirection(p, allPeople)
    direction = max(p.allInComeBySort.items(), key=lambda x: x[1])[0]
    print('direction ==', direction)
# for p in allPeople:
#     defineDirection.countDefine(p)
#     isCrash.isNextNull(p, allPeople)
#     print(p.nextNull)
#     move.moveRight(p)
#     # if not p.type:
# plt.figure(figsize=(10,6))

# while Data.flag:
#     for p in allPeople:
#         defineDirection.countDefine(p)
Exemple #11
0
 def packProdRules(self):
     return self.packRules(Rule.getProductions())
Exemple #12
0
 def packDrawRules(self):
     return self.packRules(Rule.getDrawings())
Exemple #13
0
 def DeleteProductionRule(self):
     s = self.list_prod.curselection()
     if s:
         Rule.removeProd(s[0])
         self.RefreshLists()
Exemple #14
0
 def DeleteDrawingRule(self):
     s = self.list_draw.curselection()
     if s:
         Rule.removeDraw(s[0])
         self.RefreshLists()
Exemple #15
0
    def __init__(self, source=""):
        self.source = source

        self.rules = []
        self.rules += [Rule.Rule("#CRLF", "ENFORCED_CRLF")]
        self.rules += [Rule.Rule("#version", "VERSION_DIRECTIVE")]
        self.rules += [Rule.Rule("#define", "DEFINE_DIRECTIVE")]
        self.rules += [Rule.Rule("/\*(.|\n)*\*/", "MULTILINE_COMMENT")]
        self.rules += [Rule.Rule("//.*\n", "SINGLELINE_COMMENT")]
        self.rules += [Rule.Rule("\n", "CRLF")]
        self.rules += [Rule.Rule("\d+", "INTEGER_CONSTANT")]
        self.rules += [
            Rule.Rule("((-?\d+\.\d*)|(-?\d*\.\d+))([eE]([-\+]?)\d+)?",
                      "FLOAT_CONSTANT")
        ]
        self.rules += [Rule.Rule("\.([xyzw]+|[rgba]+)", "SWIZZLE")]
        self.rules += [Rule.Rule("if", "IF")]
        self.rules += [Rule.Rule("else", "ELSE")]
        self.rules += [Rule.Rule("for", "FOR")]
        self.rules += [Rule.Rule("uniform", "UNIFORM")]
        self.rules += [Rule.Rule("const", "CONST")]
        self.rules += [Rule.Rule("float", "FLOAT")]
        self.rules += [Rule.Rule("int", "INT")]
        self.rules += [Rule.Rule("vec2", "VEC2")]
        self.rules += [Rule.Rule("vec3", "VEC3")]
        self.rules += [Rule.Rule("vec4", "VEC4")]
        self.rules += [Rule.Rule("mat2", "MAT2")]
        self.rules += [Rule.Rule("mat3", "MAT3")]
        self.rules += [Rule.Rule("mat4", "MAT4")]
        self.rules += [Rule.Rule("break", "BREAK")]
        self.rules += [Rule.Rule("sampler2D", "SAMPLER2D")]
        self.rules += [Rule.Rule(";", "SEMICOLON")]
        self.rules += [Rule.Rule(":", "COLON")]
        self.rules += [Rule.Rule(",", "COMMA")]
        self.rules += [Rule.Rule("\?", "QUESTIONMARK")]
        self.rules += [Rule.Rule("\.", "DOT")]
        self.rules += [Rule.Rule("=", "EQUAL")]
        self.rules += [Rule.Rule("<=", "LESSEQUAL")]
        self.rules += [Rule.Rule(">=", "GREATEREQUAL")]
        self.rules += [Rule.Rule("==", "ISEQUAL")]
        self.rules += [Rule.Rule("!=", "NOTEQUAL")]
        self.rules += [Rule.Rule("<", "LESSTHAN")]
        self.rules += [Rule.Rule(">", "GREATERTHAN")]
        self.rules += [Rule.Rule("\+=", "PLUSEQUAL")]
        self.rules += [Rule.Rule("\*=", "TIMESEQUAL")]
        self.rules += [Rule.Rule("/=", "DIVEQUAL")]
        self.rules += [Rule.Rule("-=", "MINUSEQUAL")]
        self.rules += [Rule.Rule("\*", "TIMES")]
        self.rules += [Rule.Rule("/", "DIVBY")]
        self.rules += [Rule.Rule("\+", "PLUS")]
        self.rules += [Rule.Rule("-", "MINUS")]
        self.rules += [Rule.Rule("\(", "LPAREN")]
        self.rules += [Rule.Rule("\)", "RPAREN")]
        self.rules += [Rule.Rule("\[", "LBRACKET")]
        self.rules += [Rule.Rule("\]", "RBRACKET")]
        self.rules += [Rule.Rule("{", "LBRACE")]
        self.rules += [Rule.Rule("}", "RBRACE")]
        self.rules += [Rule.Rule("[|]{2}", "OR")]
        self.rules += [Rule.Rule("[&]{2}", "AND")]
        self.rules += [Rule.Rule("gl_FragColor", "GL_FRAGCOLOR")]
        self.rules += [Rule.Rule("gl_FragCoord", "GL_FRAGCOORD")]
        self.rules += [Rule.Rule("in", "IN_QUALIFIER")]
        self.rules += [Rule.Rule("out", "OUT_QUALIFIER")]
        self.rules += [Rule.Rule("inout", "INOUT_QUALIFIER")]
        self.rules += [Rule.Rule("void", "VOID")]
        self.rules += [Rule.Rule("texture", "TEXTURE")]
        self.rules += [Rule.Rule("main", "MAIN")]
        self.rules += [Rule.Rule("sin", "SIN")]
        self.rules += [Rule.Rule("cos", "COS")]
        self.rules += [Rule.Rule("tan", "TAN")]
        self.rules += [Rule.Rule("asin", "ASIN")]
        self.rules += [Rule.Rule("acos", "ACOS")]
        self.rules += [Rule.Rule("atan", "ATAN")]
        self.rules += [Rule.Rule("sinh", "SINH")]
        self.rules += [Rule.Rule("cosh", "COSH")]
        self.rules += [Rule.Rule("tanh", "TANH")]
        self.rules += [Rule.Rule("asinh", "ASINH")]
        self.rules += [Rule.Rule("acosh", "ACOSH")]
        self.rules += [Rule.Rule("atanh", "ATANH")]
        self.rules += [Rule.Rule("length", "LENGTH")]
        self.rules += [Rule.Rule("reflect", "REFLECT")]
        self.rules += [Rule.Rule("refract", "REFRACT")]
        self.rules += [Rule.Rule("step", "STEP")]
        self.rules += [Rule.Rule("smoothstep", "SMOOTHSTEP")]
        self.rules += [Rule.Rule("clamp", "CLAMP")]
        self.rules += [Rule.Rule("dot", "DOT")]
        self.rules += [Rule.Rule("abs", "ABS")]
        self.rules += [Rule.Rule("pow", "POW")]
        self.rules += [Rule.Rule("mix", "MIX")]
        self.rules += [Rule.Rule("floor", "FLOOR")]
        self.rules += [Rule.Rule("fract", "FRACT")]
        self.rules += [Rule.Rule("round", "ROUND")]
        self.rules += [Rule.Rule("ceil", "CEIL")]
        self.rules += [Rule.Rule("max", "MAX")]
        self.rules += [Rule.Rule("min", "MIN")]
        self.rules += [Rule.Rule("mod", "MOD")]
        self.rules += [Rule.Rule("sign", "SIGN")]
        self.rules += [Rule.Rule("exp", "EXP")]
        self.rules += [Rule.Rule("normalize", "NORMALIZE")]
        self.rules += [Rule.Rule("cross", "CROSS")]
        self.rules += [Rule.Rule("sqrt", "SQRT")]
        self.rules += [Rule.Rule("continue", "CONTINUE")]
        self.rules += [Rule.Rule("return", "RETURN")]
        self.rules += [Rule.Rule("smoothstep", "SMOOTHSTEP")]
        self.rules += [Rule.Rule("all", "ALL")]
        self.rules += [Rule.Rule("lessThan", "LESSTHAN")]

        self.rules += [Rule.Rule("[a-zA-Z_]+[a-zA-Z0-9_]*", "IDENTIFIER")]
        self.index = 0
        self.line = 0
        self.column = 0

        pass
Exemple #16
0
    def __init__(self, source=""):
        self.source = source

        self.rules = []
        self.rules += [Rule.Rule("#version", "VERSION_DIRECTIVE")]
        self.rules += [Rule.Rule("#define", "DEFINE_DIRECTIVE")]
        self.rules += [Rule.Rule("/\*(.|\n)*\*/", "MULTILINE_COMMENT")]
        self.rules += [Rule.Rule("//.*\n", "SINGLELINE_COMMENT")]
        self.rules += [Rule.Rule("\n", "CRLF")]
        self.rules += [Rule.Rule("\d+", "INTEGER_CONSTANT")]
        self.rules += [
            Rule.Rule("((-?\d+\.\d*)|(-?\d*\.\d+))([eE]([-\+]?)\d+)?",
                      "FLOAT_CONSTANT")
        ]
        self.rules += [Rule.Rule("if", "IF")]
        self.rules += [Rule.Rule("else", "ELSE")]
        self.rules += [Rule.Rule("uniform", "UNIFORM")]
        self.rules += [Rule.Rule("const", "CONST")]
        self.rules += [Rule.Rule("float", "FLOAT")]
        self.rules += [Rule.Rule("int", "INT")]
        self.rules += [Rule.Rule("vec2", "VEC2")]
        self.rules += [Rule.Rule("vec3", "VEC3")]
        self.rules += [Rule.Rule("vec4", "VEC4")]
        self.rules += [Rule.Rule("mat2", "MAT2")]
        self.rules += [Rule.Rule("mat3", "MAT3")]
        self.rules += [Rule.Rule("mat4", "MAT4")]
        self.rules += [Rule.Rule("sampler2D", "SAMPLER2D")]
        self.rules += [Rule.Rule(";", "SEMICOLON")]
        self.rules += [Rule.Rule(",", "COLON")]
        self.rules += [Rule.Rule("\.", "DOT")]
        self.rules += [Rule.Rule("=", "EQUAL")]
        self.rules += [Rule.Rule("<=", "LESSEQUAL")]
        self.rules += [Rule.Rule(">=", "GREATEREQUAL")]
        self.rules += [Rule.Rule("==", "ISEQUAL")]
        self.rules += [Rule.Rule("!=", "NOTEQUAL")]
        self.rules += [Rule.Rule("<", "LESSTHAN")]
        self.rules += [Rule.Rule(">", "GREATERTHAN")]
        self.rules += [Rule.Rule("\+=", "PLUSEQUAL")]
        self.rules += [Rule.Rule("\*=", "TIMESEQUAL")]
        self.rules += [Rule.Rule("/=", "DIVEQUAL")]
        self.rules += [Rule.Rule("-=", "MINUSEQUAL")]
        self.rules += [Rule.Rule("\*", "TIMES")]
        self.rules += [Rule.Rule("/", "DIVBY")]
        self.rules += [Rule.Rule("\+", "PLUS")]
        self.rules += [Rule.Rule("-", "MINUS")]
        self.rules += [Rule.Rule("\(", "LPAREN")]
        self.rules += [Rule.Rule("\)", "RPAREN")]
        self.rules += [Rule.Rule("\[", "LBRACKET")]
        self.rules += [Rule.Rule("\]", "RBRACKET")]
        self.rules += [Rule.Rule("{", "LBRACE")]
        self.rules += [Rule.Rule("}", "RBRACE")]
        self.rules += [Rule.Rule("[|]{2}", "OR")]
        self.rules += [Rule.Rule("[&]{2}", "AND")]
        self.rules += [Rule.Rule("gl_FragColor", "GL_FRAGCOLOR")]
        self.rules += [Rule.Rule("gl_FragCoord", "GL_FRAGCOORD")]
        self.rules += [Rule.Rule("in", "IN_QUALIFIER")]
        self.rules += [Rule.Rule("out", "OUT_QUALIFIER")]
        self.rules += [Rule.Rule("inout", "INOUT_QUALIFIER")]
        self.rules += [Rule.Rule("void", "VOID")]
        self.rules += [Rule.Rule("texture", "TEXTURE")]
        self.rules += [Rule.Rule("main", "MAIN")]
        self.rules += [Rule.Rule("sin", "SIN")]
        self.rules += [Rule.Rule("cos", "COS")]
        self.rules += [Rule.Rule("tan", "TAN")]
        self.rules += [Rule.Rule("asin", "ASIN")]
        self.rules += [Rule.Rule("acos", "ACOS")]
        self.rules += [Rule.Rule("atan", "ATAN")]
        self.rules += [Rule.Rule("sinh", "SINH")]
        self.rules += [Rule.Rule("cosh", "COSH")]
        self.rules += [Rule.Rule("tanh", "TANH")]
        self.rules += [Rule.Rule("asinh", "ASINH")]
        self.rules += [Rule.Rule("acosh", "ACOSH")]
        self.rules += [Rule.Rule("atanh", "ATANH")]
        self.rules += [Rule.Rule("length", "LENGTH")]
        self.rules += [Rule.Rule("return", "RETURN")]
        self.rules += [Rule.Rule("smoothstep", "SMOOTHSTEP")]
        self.rules += [Rule.Rule("step", "STEP")]
        self.rules += [Rule.Rule("[a-zA-Z_]+[a-zA-Z0-9_]*", "IDENTIFIER")]
        self.index = 0
        self.line = 0
        self.column = 0

        pass
Exemple #17
0
def run_insert_old(case_s, P, R, steps):
    resultData = []  #返回总列表
    if case_s == 0:  #危险源位置设置
        Data.FX_N = 19
    elif case_s == 1:
        Data.FX_N = 15
    elif case_s == 2:
        Data.FX_N = 10
    elif case_s == 3:
        Data.FX_N = 5
    elif case_s == 4:
        Data.FX_N = 2
    Data.PEOPLE_DENSYTY = P  #行人密度
    Data.PEOPLE_NUMBER = int(Data.ROOM_N * Data.ROOM_M *
                             Data.PEOPLE_DENSYTY)  #行人数量
    Data.FX_SIGMA_2 = R  #危险源大小
    Data.FX_R = 2 * np.sqrt(Data.FX_SIGMA_2)  # 影响范围半径
    Data.FX_P = 2 * Data.FX_SIGMA_2  # 系数 p越大 高斯函数的圆形越大

    # init = InitPeolple.InitPeople()#实例化 产生行人类
    # draw = DrawFirst.draw()#实例化 画图类
    # income = Income.outDirection()
    allPeople = InitPeolple.creatPeople()  #产生随机行人
    # allPeople=init.creatAppointPeo()#产生指定行人
    allWall = InitPeolple.creatWall()  #创建墙壁
    allExit = InitPeolple.creatExit()  #创建出口

    T = []  #疏散时间
    S = []  #剩余行人
    V = []  #行人速度
    Q = []  #出口流量
    Q.append(0)  #将出口流量[0]设为0 Q列表少一个数

    evac_time = 0  #疏散时间

    while Data.flag:  #循环开始
        move_on_num = 0  #本次时间步移动的行人
        move_off_num = 0  #本次时间步静止的行人
        vector = 0  #本次时间步行人速度
        for p in allPeople:  #遍历行人
            Income.outDirection(p, allPeople)  #计算收益
            direction = max(p.allInComeBySort.items(),
                            key=lambda x: x[1])[0]  #获取方向
            if direction == 5:  #如果行人静止
                move_off_num = move_off_num + 1  #计数器+1
            else:
                move_on_num = move_on_num + 1  #计数器+1
            Rule.chickOverAround(p, allPeople)  #检测是否到达出口
            Rule.PeopleMove(p, direction)  #行人移动

        # draw.drawPeople(allPeople)#绘制行人
        # print(evac_time,"---",len(allPeople),"---",move_on_num/len(allPeople))

        if len(allPeople) == 0:  #如果行人全部疏散完毕
            vector = 1  #速度设为1
            Data.flag = False  #循环标志--停止
        else:
            vector = move_on_num / len(allPeople)  #行人速度=移动的行人/总行人
        if vector > 1:  #如果行人速度>1
            vector = 1.0  #设置为1

        T.append(evac_time)  #将疏散时间添加到T
        S.append(len(allPeople))  #将剩余行人添加到S
        V.append(vector)  #将行人速度添加到V

        evac_time = evac_time + 1  #疏散时间+1

    for i in range(len(S) - 1):  #遍历行人
        quar = S[i] - S[i + 1]  #出口流量=上一步的行人总数-下一步的行人总数
        Q.append(quar)  #将出口流量添加到Q
    '''将各种参数添加到返回列表'''
    resultData.append(case_s)
    resultData.append(P)
    resultData.append(R)
    resultData.append(steps)
    resultData.append(T)
    resultData.append(S)
    resultData.append(V)
    resultData.append(Q)

    return resultData
Exemple #18
0
else:
    # Load Things

    Env3i.tr = Thing.ThingRegistryClass(Env3i)
    conf = read_c.read_things_conf(Env3i.conf_root)
    Env3i.tr.load_things(conf)

    # Load Rule Subscriptions of Things
    for th in Env3i.tr.Things.keys():
        tid = Env3i.tr.Things[th].get_tid()
        top = Env3i.tr.Things[th].get_topics()
        logging.info(f'Loaded device {tid}, needs {top}')
        if top is None:
            pass
        else:
            r = RuleClass.Rule(name=tid+":"+top, topic=top, rule_action=Env3i.tr.Things[th])
            Env3i.rr.add_rule(r)

logging.info(f'{str(len(Env3i.rr.rules))} topic rules added.')

# Env3i.se = ShadowEngine.ShadowEngineClass(Env3i)

Env3i.mqtt = MQTTHandlerClass.MQTTHandlerClass(Env3i)
Env3i.mqtt.setRuleList(Env3i.rr.rules)
Env3i.mqtt.connect_to_server(m_conf)

i = 0

while True:
    Env3i.mqtt.client.loop()
    time.sleep(0.25)
Exemple #19
0
class TestRule(unittest.TestCase):
    def setUp(self):
        self.Aagent1 = Atomic_Agent('S', ['u'], 'cyt')
        self.Aagent12 = Atomic_Agent('S', ['p'], 'cyt')
        self.Aagent13 = Atomic_Agent('S', ['u', 'p'], 'cyt')
        self.Aagent2 = Atomic_Agent('T', ['u'], 'cyt')
        self.Aagent22 = Atomic_Agent('T', ['p'], 'cyt')
        self.Aagent23 = Atomic_Agent('T', ['u', 'p'], 'cyt')
        self.Aagent3 = Atomic_Agent('N', ['u'], 'cyt')
        self.Aagent32 = Atomic_Agent('N', ['p'], 'cyt')
        self.Aagent33 = Atomic_Agent('N', ['u', 'p'], 'cyt')
        self.Aagent4 = Atomic_Agent('N', ['u', 'p'], 'liq')

        self.Sagent1 = Structure_Agent('KaiC', [self.Aagent1, self.Aagent2], 'cyt')
        self.Sagent2 = Structure_Agent('KaiC', [self.Aagent2, self.Aagent1], 'cyt')
        self.Sagent3 = Structure_Agent('KaiC', [self.Aagent2, self.Aagent3], 'cyt')
        self.Sagent4 = Structure_Agent('KaiC', [self.Aagent13, self.Aagent23], 'cyt')
        self.Sagent5 = Structure_Agent('KaiC', [self.Aagent12, self.Aagent22, self.Aagent32], 'cyt')
        self.Sagent6 = Structure_Agent('KaiC', [self.Aagent22, self.Aagent12], 'cyt')
        self.Sagent7 = Structure_Agent('KaiC', [self.Aagent13, self.Aagent2], 'cyt')
        self.Sagent8 = Structure_Agent('KaiC', [self.Aagent1, self.Aagent23], 'cyt')
        self.Sagent9 = Structure_Agent('KaiC', [self.Aagent1, self.Aagent22], 'cyt')
        self.Sagent10 = Structure_Agent('KaiC', [], 'cyt')
        self.Sagent11 = Structure_Agent('KaiC', [self.Aagent1], 'cyt')
        self.Sagent12 = Structure_Agent('KaiC', [self.Aagent12], 'cyt')
        self.Sagent13 = Structure_Agent('KaiC', [self.Aagent23, self.Aagent33], 'cyt')
        self.Sagent14 = Structure_Agent('KaiC', [self.Aagent12, self.Aagent23, self.Aagent33], 'cyt')

        self.Xagent1 = Complex_Agent([self.Sagent1, self.Sagent2], 'cyt')
        self.Xagent2 = Complex_Agent([self.Sagent2, self.Sagent1], 'cyt')
        self.Xagent3 = Complex_Agent([self.Sagent1, self.Sagent3], 'cyt')
        self.Xagent4 = Complex_Agent([self.Sagent3, self.Sagent1], 'cyt')
        self.Xagent5 = Complex_Agent([self.Sagent4, self.Sagent1], 'cyt')
        self.Xagent6 = Complex_Agent([self.Sagent1, self.Sagent1], 'cyt')
        self.Xagent7 = Complex_Agent([self.Sagent11, self.Sagent10, self.Sagent10], 'cyt')
        self.Xagent8 = Complex_Agent([self.Sagent1, self.Sagent4, self.Sagent9], 'cyt')
        self.Xagent9 = Complex_Agent([self.Sagent5, self.Sagent4, self.Sagent9], 'cyt')
        self.Xagent10 = Complex_Agent([self.Aagent1, self.Aagent1], 'cyt')
        self.Xagent11 = Complex_Agent([self.Sagent12, self.Sagent10, self.Sagent10], 'cyt')
        self.Xagent12 = Complex_Agent([self.Sagent11, self.Sagent4, self.Sagent5], 'cyt')
        self.Xagent13 = Complex_Agent([self.Sagent12, self.Sagent4, self.Sagent5], 'cyt')
        self.Xagent14 = Complex_Agent([self.Sagent1, self.Sagent3, self.Sagent5], 'cyt')
        self.Xagent15 = Complex_Agent([self.Sagent4, self.Sagent13], 'cyt')
        self.Xagent16 = Complex_Agent([self.Sagent4, self.Sagent13, self.Sagent14], 'cyt')
        self.Xagent17 = Complex_Agent([self.Sagent10, self.Sagent10], 'cyt')
        self.Xagent18 = Complex_Agent([self.Sagent6, self.Sagent1], 'cyt')
        self.Xagent19 = Complex_Agent([self.Sagent1, self.Sagent6], 'cyt')
        self.Xagent20 = Complex_Agent([self.Sagent4, self.Sagent4], 'cyt')
        self.Xagent21 = Complex_Agent([self.Sagent4, self.Sagent4, self.Sagent4, self.Sagent4], 'cyt')
        self.Xagent22 = Complex_Agent([self.Sagent6, self.Sagent1, self.Sagent6, self.Sagent1], 'cyt')
        self.Xagent23 = Complex_Agent([self.Sagent6, self.Sagent1, self.Sagent1, self.Sagent6], 'cyt')
        self.Xagent24 = Complex_Agent([self.Sagent1, self.Sagent6, self.Sagent6, self.Sagent1], 'cyt')
        self.Xagent25 = Complex_Agent([self.Sagent1, self.Sagent6, self.Sagent1, self.Sagent6], 'cyt')
        self.Xagent26 = Complex_Agent([self.Sagent6, self.Sagent6], 'cyt')


        self.Rule1 = Rule([self.Aagent1], [self.Aagent12])
        self.Rule2 = Rule([self.Sagent1], [self.Sagent9])
        self.Rule3 = Rule([self.Aagent32], [])
        self.Rule4 = Rule([self.Aagent1, self.Aagent1], [self.Xagent10])
        self.Rule5 = Rule([], [self.Aagent32])
        self.Rule6 = Rule([self.Xagent7], [self.Xagent11])
        self.Rule7 = Rule([self.Xagent15, self.Sagent14], [self.Xagent16])
        self.Rule8 = Rule([self.Sagent10, self.Sagent10], [self.Xagent17])
        self.Rule9 = Rule([self.Xagent20, self.Xagent20], [self.Xagent21])
        self.Rule10 = Rule([self.Xagent10], [self.Aagent1, self.Aagent1])
        self.Rule11 = Rule([self.Xagent16], [self.Xagent15, self.Sagent14])
        self.Rule12 = Rule([self.Xagent21], [self.Xagent20, self.Xagent20])
        self.Rule13 = Rule([self.Aagent33], [self.Aagent4])
        self.Rule14 = Rule([], [])
        self.Rule15 = Rule([], [])
        self.Rule16 = Rule([], [])
        self.Rule17 = Rule([], [])
        self.Rule18 = Rule([], [])
        self.Rule19 = Rule([], [])
        self.Rule20 = Rule([], [])

    def test_equal(self):
        self.assertTrue(self.Rule1.__eq__(self.Rule1))
        self.assertTrue(self.Rule2.__eq__(self.Rule2))
        self.assertFalse(self.Rule1.__eq__(self.Rule2))

    def test_print(self):
        self.assertEqual(self.Rule1.__str__(), self.Rule1.__str__())
        self.assertEqual(self.Rule1.__str__(), "S{u}::cyt => S{p}::cyt")

    def test_hash(self):
        self.assertNotEqual(hash(self.Rule1), hash(self.Rule2))
        self.assertEqual(hash(self.Rule2), hash(self.Rule2))

    def test_checkcandidateAndLhs(self):
        self.assertTrue(self.Rule7.checkcandidateAndLhs([self.Xagent3, self.Sagent5]))
        self.assertFalse(self.Rule7.checkcandidateAndLhs([self.Xagent4, self.Sagent5]))

    def test_match(self):
        candidate1 = [self.Xagent3, self.Sagent5]
        self.assertEqual(self.Rule7.match(candidate1), [tuple(candidate1)])

    def test_formComplex(self):
        candidate_old = [self.Aagent1, self.Aagent1]
        candidate_new = [self.Xagent10]
        self.assertEqual(self.Rule4.formComplex(candidate_old), candidate_new)
        candidate_old = [self.Xagent3, self.Sagent5]
        candidate_new = [self.Xagent14]
        self.assertEqual(self.Rule7.formComplex(candidate_old), candidate_new)

    def test_dissociateComplex(self):
        candidate_old = [self.Xagent10]
        candidate_new = [self.Aagent1, self.Aagent1]
        self.assertEqual(self.Rule10.dissociateComplex(candidate_old), candidate_new)
        candidate_old = [self.Xagent14]
        candidate_new = [self.Xagent3, self.Sagent5]
        self.assertEqual(self.Rule11.dissociateComplex(candidate_old), candidate_new)

    def test_translate(self):
        candidate_old = []
        candidate_new = [self.Aagent32 ]
        self.assertEqual(self.Rule5.translate(), candidate_new)

    def test_degrade(self):
        candidate_old = [self.Aagent32]
        candidate_new = []
        self.assertEqual(self.Rule3.degrade(candidate_old), candidate_new)

    def test_changeAtomicStates(self):
        self.assertEqual(changeAtomicStates(self.Aagent12, self.Aagent1), self.Aagent12)

    def test_changeStructureStates(self):
        self.assertEqual(changeStructureStates(self.Sagent9, self.Sagent1), self.Sagent9)

    def test_changeComplexStates(self):
        self.assertEqual(changeComplexStates(self.Xagent11, self.Xagent12), self.Xagent13)

    def test_replace(self):
        candidate_old = [self.Aagent1, self.Aagent1]
        candidate_new = [self.Xagent10]
        self.assertEqual(self.Rule4.replace(candidate_old), candidate_new)
        candidate_old = []
        candidate_new = [self.Aagent32]
        self.assertEqual(self.Rule5.replace(candidate_old), candidate_new)
        candidate_old = [self.Aagent32]
        candidate_new = []
        self.assertEqual(self.Rule3.replace(candidate_old), candidate_new)
        candidate_old = [self.Aagent1]
        candidate_new = [self.Aagent12]
        self.assertEqual(self.Rule1.replace(candidate_old), candidate_new)
        candidate_old = [self.Sagent1]
        candidate_new = [self.Sagent9]
        self.assertEqual(self.Rule2.replace(candidate_old), candidate_new)
        candidate_old = [self.Xagent12]
        candidate_new = [self.Xagent13]
        self.assertEqual(self.Rule6.replace(candidate_old), candidate_new)
        candidate_old = [self.Xagent10]
        candidate_new = [self.Aagent1, self.Aagent1]
        self.assertEqual(self.Rule10.replace(candidate_old), candidate_new)

    def test_replacement(self):
        candidate_old = [self.Xagent3, self.Sagent5]
        candidate_new = [[self.Xagent14]]
        self.assertEqual(sorted(self.Rule7.replacement(candidate_old)), sorted(candidate_new))
        candidate_old = [self.Sagent1, self.Sagent3]
        candidate_new = [[self.Xagent3]]
        self.assertEqual(sorted(self.Rule8.replacement(candidate_old)), sorted(candidate_new))
        candidate_old = [self.Xagent18, self.Xagent19]
        candidate_new = [[self.Xagent22]]
        self.assertEqual(sorted(self.Rule9.replacement(candidate_old)), sorted(candidate_new))
        candidate_old = [self.Xagent22]
        candidate_new = [[self.Xagent19, self.Xagent19], [self.Xagent6, self.Xagent26]]
        self.assertEqual(sorted(self.Rule12.replacement(candidate_old)), sorted(candidate_new))
        candidate_old = [self.Aagent33]
        candidate_new = [[self.Aagent4]]
        self.assertEqual(sorted(self.Rule13.replacement(candidate_old)), sorted(candidate_new))
Exemple #20
0
def dataMine():
	rules = Rulesets(frequentItemSets())
	Rule.remove_all()
	for rule in rules:
		Rule.add_rule(rule[0],rule[1],rule[2])
Exemple #21
0
    def setUp(self):
        self.Aagent1 = Atomic_Agent('S', ['u'], 'cyt')
        self.Aagent12 = Atomic_Agent('S', ['p'], 'cyt')
        self.Aagent13 = Atomic_Agent('S', ['u', 'p'], 'cyt')
        self.Aagent2 = Atomic_Agent('T', ['u'], 'cyt')
        self.Aagent22 = Atomic_Agent('T', ['p'], 'cyt')
        self.Aagent23 = Atomic_Agent('T', ['u', 'p'], 'cyt')
        self.Aagent3 = Atomic_Agent('N', ['u'], 'cyt')
        self.Aagent32 = Atomic_Agent('N', ['p'], 'cyt')
        self.Aagent33 = Atomic_Agent('N', ['u', 'p'], 'cyt')
        self.Aagent4 = Atomic_Agent('N', ['u', 'p'], 'liq')

        self.Sagent1 = Structure_Agent('KaiC', [self.Aagent1, self.Aagent2], 'cyt')
        self.Sagent2 = Structure_Agent('KaiC', [self.Aagent2, self.Aagent1], 'cyt')
        self.Sagent3 = Structure_Agent('KaiC', [self.Aagent2, self.Aagent3], 'cyt')
        self.Sagent4 = Structure_Agent('KaiC', [self.Aagent13, self.Aagent23], 'cyt')
        self.Sagent5 = Structure_Agent('KaiC', [self.Aagent12, self.Aagent22, self.Aagent32], 'cyt')
        self.Sagent6 = Structure_Agent('KaiC', [self.Aagent22, self.Aagent12], 'cyt')
        self.Sagent7 = Structure_Agent('KaiC', [self.Aagent13, self.Aagent2], 'cyt')
        self.Sagent8 = Structure_Agent('KaiC', [self.Aagent1, self.Aagent23], 'cyt')
        self.Sagent9 = Structure_Agent('KaiC', [self.Aagent1, self.Aagent22], 'cyt')
        self.Sagent10 = Structure_Agent('KaiC', [], 'cyt')
        self.Sagent11 = Structure_Agent('KaiC', [self.Aagent1], 'cyt')
        self.Sagent12 = Structure_Agent('KaiC', [self.Aagent12], 'cyt')
        self.Sagent13 = Structure_Agent('KaiC', [self.Aagent23, self.Aagent33], 'cyt')
        self.Sagent14 = Structure_Agent('KaiC', [self.Aagent12, self.Aagent23, self.Aagent33], 'cyt')

        self.Xagent1 = Complex_Agent([self.Sagent1, self.Sagent2], 'cyt')
        self.Xagent2 = Complex_Agent([self.Sagent2, self.Sagent1], 'cyt')
        self.Xagent3 = Complex_Agent([self.Sagent1, self.Sagent3], 'cyt')
        self.Xagent4 = Complex_Agent([self.Sagent3, self.Sagent1], 'cyt')
        self.Xagent5 = Complex_Agent([self.Sagent4, self.Sagent1], 'cyt')
        self.Xagent6 = Complex_Agent([self.Sagent1, self.Sagent1], 'cyt')
        self.Xagent7 = Complex_Agent([self.Sagent11, self.Sagent10, self.Sagent10], 'cyt')
        self.Xagent8 = Complex_Agent([self.Sagent1, self.Sagent4, self.Sagent9], 'cyt')
        self.Xagent9 = Complex_Agent([self.Sagent5, self.Sagent4, self.Sagent9], 'cyt')
        self.Xagent10 = Complex_Agent([self.Aagent1, self.Aagent1], 'cyt')
        self.Xagent11 = Complex_Agent([self.Sagent12, self.Sagent10, self.Sagent10], 'cyt')
        self.Xagent12 = Complex_Agent([self.Sagent11, self.Sagent4, self.Sagent5], 'cyt')
        self.Xagent13 = Complex_Agent([self.Sagent12, self.Sagent4, self.Sagent5], 'cyt')
        self.Xagent14 = Complex_Agent([self.Sagent1, self.Sagent3, self.Sagent5], 'cyt')
        self.Xagent15 = Complex_Agent([self.Sagent4, self.Sagent13], 'cyt')
        self.Xagent16 = Complex_Agent([self.Sagent4, self.Sagent13, self.Sagent14], 'cyt')
        self.Xagent17 = Complex_Agent([self.Sagent10, self.Sagent10], 'cyt')
        self.Xagent18 = Complex_Agent([self.Sagent6, self.Sagent1], 'cyt')
        self.Xagent19 = Complex_Agent([self.Sagent1, self.Sagent6], 'cyt')
        self.Xagent20 = Complex_Agent([self.Sagent4, self.Sagent4], 'cyt')
        self.Xagent21 = Complex_Agent([self.Sagent4, self.Sagent4, self.Sagent4, self.Sagent4], 'cyt')
        self.Xagent22 = Complex_Agent([self.Sagent6, self.Sagent1, self.Sagent6, self.Sagent1], 'cyt')
        self.Xagent23 = Complex_Agent([self.Sagent6, self.Sagent1, self.Sagent1, self.Sagent6], 'cyt')
        self.Xagent24 = Complex_Agent([self.Sagent1, self.Sagent6, self.Sagent6, self.Sagent1], 'cyt')
        self.Xagent25 = Complex_Agent([self.Sagent1, self.Sagent6, self.Sagent1, self.Sagent6], 'cyt')
        self.Xagent26 = Complex_Agent([self.Sagent6, self.Sagent6], 'cyt')


        self.Rule1 = Rule([self.Aagent1], [self.Aagent12])
        self.Rule2 = Rule([self.Sagent1], [self.Sagent9])
        self.Rule3 = Rule([self.Aagent32], [])
        self.Rule4 = Rule([self.Aagent1, self.Aagent1], [self.Xagent10])
        self.Rule5 = Rule([], [self.Aagent32])
        self.Rule6 = Rule([self.Xagent7], [self.Xagent11])
        self.Rule7 = Rule([self.Xagent15, self.Sagent14], [self.Xagent16])
        self.Rule8 = Rule([self.Sagent10, self.Sagent10], [self.Xagent17])
        self.Rule9 = Rule([self.Xagent20, self.Xagent20], [self.Xagent21])
        self.Rule10 = Rule([self.Xagent10], [self.Aagent1, self.Aagent1])
        self.Rule11 = Rule([self.Xagent16], [self.Xagent15, self.Sagent14])
        self.Rule12 = Rule([self.Xagent21], [self.Xagent20, self.Xagent20])
        self.Rule13 = Rule([self.Aagent33], [self.Aagent4])
        self.Rule14 = Rule([], [])
        self.Rule15 = Rule([], [])
        self.Rule16 = Rule([], [])
        self.Rule17 = Rule([], [])
        self.Rule18 = Rule([], [])
        self.Rule19 = Rule([], [])
        self.Rule20 = Rule([], [])