Esempio n. 1
0
def printCLIPS():
    print(chr(27) + "[2J")
    print('PASO {}'.format(PASO))
    print('Instancias')
    print(getInstanceString())
    print('Facts')
    clips.PrintFacts()
    print('\nAgenda')
    # clips.RefreshAgenda()
    clips.PrintAgenda()
    print()
Esempio n. 2
0
def user_status_checking():
    dealers = Messagebox.objects.filter(fromaddr=eng_var[4], topic="Request for Service", ack=1, nack=0)
    a = clips.Fact(eng_var[3])
    print (clips.PrintFacts())
    for dealer in dealers:
        try:
            a.Slots['username'] = dealer.toaddr
            a.Slots['foraid'] = dealer.message
            a.Slots['action'] = "Allocate"
            a.Slots['quantity'] = dealer.parameter
            a.Assert()
            dealer.nack = 1
            dealer.save()
        except clips.ClipsError:
            print ("Already Asserted Fact")
Esempio n. 3
0
def message_dealer(usernm, lat3, long3, obj):
    dealers = Messagebox.objects.filter(toaddr=usernm,
                                        topic="Request",
                                        ack=1,
                                        nack=0)
    e = clips.Fact(obj)
    print(clips.PrintFacts())
    for dealer in dealers:
        try:
            e.Slots['aid'] = dealer.message
            e.Slots['latitude'] = lat3
            e.Slots['longitude'] = long3
            e.Slots['quantity'] = dealer.parameter
            e.Assert()
            dealer.nack = 1
            dealer.save()
        except clips.ClipsError:
            print("Already Asserted Fact")
Esempio n. 4
0
import pandas as pd

facts = pd.read_csv("facts.csv",
                    sep=";",
                    encoding='cp1252',
                    squeeze=True,
                    lineterminator="\n")
defrules = pd.read_csv("defrules.csv",
                       sep=";",
                       encoding='cp1252',
                       squeeze=True,
                       lineterminator="\n")

print(facts.shape)

print(defrules.shape)

clips.Reset()

for x in facts[1:10]:
    print(x)
    clips.Assert(x)

for x in defrules[1:5]:
    s = str(x)
    print(s)
    clips.Build(s)

clips.PrintFacts()
clips.PrintRules()
Esempio n. 5
0
def PrintFacts():
    _clipsLock.acquire()
    clips.PrintFacts()
    _clipsLock.release()
Esempio n. 6
0
def system_run(input_ set):
    if 'hazard' in input_set:
        clips.Clear()
        clips.Reset()

        eng_var[:]=[]

        eng_var.append(input_set['lat'])

        eng_var.append(input_set['long'])

        eng_var.append(clips.BuildTemplate("entity", """
        (slot aid (type STRING))
        (slot latitude (type NUMBER))
        (slot longitude (type NUMBER))
        (slot quantity (type NUMBER))
        """, "template for a entity"))

        eng_var.append(clips.BuildTemplate("allies", """
        (slot username (type STRING))
        (slot foraid (type STRING))
        (slot action (type STRING))
        (slot quantity (type NUMBER))
        """, "template for a allies"))

        eng_var.append(input_set['control'])

        eng_var.append(clips.BuildTemplate("disaster", """
        (slot hazard (type STRING))
        (slot latitude (type NUMBER))
        (slot longitude (type NUMBER))
        (slot span (type NUMBER))
        """, "template for a disaster"))

        d=clips.Fact(eng_var[5])
        d.Slots['hazard'] = input_set['hazard']
        d.Slots['latitude'] = input_set['lat']
        d.Slots['longitude'] = input_set['long']
        d.Slots['span'] = input_set['span']
        d.Assert()

        facts[:] = []
        fields[:] = []
        list_map[:] = []

        clips.RegisterPythonFunction(invoke_pronearea)
        clips.RegisterPythonFunction(display_disaster)
        clips.RegisterPythonFunction(invoke_entity)
        clips.RegisterPythonFunction(invoke_useralert)
        clips.RegisterPythonFunction(invoke_user_allocate )
        clips.RegisterPythonFunction(invoke_user_deallocate)
        clips.RegisterPythonFunction(invoke_message)
        clips.RegisterPythonFunction(invoke_alert_area)

        clips.BatchStar("/home/jishnu/PycharmProjects/dmis/controlunit/expertsystem/inference.clp")
        clips.Run()

    if 'refresh' in input_set:
        if len(eng_var)==0:
            return {'fact': facts, 'field': fields,'map_data':list_map}
        message_dealer(input_set['control'],eng_var[0],eng_var[1],eng_var[2])
        user_status_checking()
        clips.Run()

    if 'send' in input_set:
        if len(eng_var)==0:
            return {'fact': facts, 'field': fields,'map_data':list_map}
        message_handler(input_set['control'],input_set['selectaid'],input_set['parameter'])

    if 'deallocate' in input_set:
        try:
            clips.Assert("(DeallocateAll)")
        except clips.ClipsError:
            print("Error in Deallocation")
        clips.Run()
        facts[:] = []
        fields[:] = []
        list_map[:] = []

    clips.SendCommand("run")
    print (clips.PrintFacts())
    list_temp=list(facts)
    list_temp.reverse()
    return {'fact':list_temp,'field':list(set(fields)),'map_data':list_map}