Skip to content
75 changes: 75 additions & 0 deletions code/core/modules/network/achieve.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
from array import array

from agenda import agenda
from controlaction import controlAction



class Achieve (controlAction):
def __init__(self) -> None:
super().__init__()

def perform(act):
if act.stage is agenda.start:
act.start(act)
elif act.stage is agenda.find_plan:
act.find_plan(act)
else:
return


def start(act):
prop_node = act.Cable().getdownCableset.getdowncable("obj").getnodeset.getNode(0)
context =act.get_context()
plans_goal=[]
asserted = context.isSupported(prop_node)
if(asserted):
return
else:
act.stage = agenda.find_plan
Runner.addToActQ(act)
r1 = relation.plan
r2 = relation.goal
wire = []
wire.append(add_wire(r1,x))
wire.append(add_wire(r2,x))
plan_goal =node().add_moleculer_node(wire,act)
plans_goal.append(plan_goal)
#acttopropchannel = channel().addChannel(act,plan_goal,True)
#plan_goal.Node().receive_request(acttopropchannel)
#act.getplansChannel().addChannel(acttoprop)




def find_plan(act):
plans = []
plans.append(ReasonController.BackwardChain(act,Controller().getCurrentContext(),"ACT"))
if plans:
act.stage = agenda.done
wire = []
r1 = relation.do
r2 = relation.action
for i in len(plans):
wire.append(new_wire(r1,plan[i]))


action_node = Node().add_new_node("oneplan","do one")
wire.append(new_wire(r2,action_node))
node().add_moleculer_node(wire,action_node)

new_actnode= agenda.start
Runner.addToActQ(new_actnode)

else:
return "plans are in planning algorithm"










21 changes: 21 additions & 0 deletions code/core/modules/network/actionnode.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

from node import node,abstractmethod
class actionnode(node):
def __init__(self,primitve):
self._primitive = primitve


def __init__(self,identity):
super().__init__(identity)

@abstractmethod
def perform (act):
pass

def get_primitive(self):
return self._primitive
def set_primitive(self,x):
self._primitive=x



12 changes: 12 additions & 0 deletions code/core/modules/network/agenda.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import enum


class agenda(enum.Enum):
start = 1
find_plan = 2
find_preconditions = 3
test_precondition = 4
find_effects = 5
execute = 6
done = 7
identify_objects = 8
29 changes: 29 additions & 0 deletions code/core/modules/network/believe.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from act import act
from actionnode import actionnode


class believe (actionnode):
def __init__(self) -> None:
super().__init__()
actionnode.set_primitive(True)

def __init__(self,identity) -> None:
super().__init__(identity)
actionnode.set_primitive(True)

def perform(act):
prop_node =Cable(act).getDowncableset().getDownCable('obj').getnodeset().getnode(0)
Context().addToContext(prop_node,"")

support = []
support.append(prop_node.get_basic_support())
new_report = []
new_report.append("new report of this support and get current context name ")
prop_node.sent(new_report)







14 changes: 14 additions & 0 deletions code/core/modules/network/controlaction.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from act import act
from actionnode import actionnode , abstractmethod


class controlaction (actionnode):
def __init__(self) -> None:
super().__init__()
actionnode.set_primitive(True)


def __init__(self,identity):
super().__init__(identity)
actionnode.set_primitive(True)

19 changes: 19 additions & 0 deletions code/core/modules/network/disbelieve.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from Reportset import ReportSet
from act import act
from Reportset import ReportSet
from actionnode import actionnode

class disbelieve(actionnode):
def __init__(self) -> None:
super().__init__()

def __init__(self,identity):
super().__init__(identity)
actionnode.set_primitive(True)



def perform(act):
p = act.cable.getDownCableSet().getDownCable("obj").getNodeSet().getNode(0)
ContextController.removepropfromcontext(p)

39 changes: 39 additions & 0 deletions code/core/modules/network/do_all.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from pickle import FALSE, TRUE
from pydoc import resolve
from random import Random, randint
import random

from agenda import agenda
from controlaction import controlaction


class do_all (controlaction):
def __init__(self) -> None:
super().__init__()
def __init__(self, identity):
super().__init__(identity)



def perform (act): #this should take an act
#acts should be a node set but NodeSet class is not finished so i can not use it
acts = []
acts.append(act.Cable.getDownCableset().getDowncable("do").getNodeSet())
while not len(acts) is 0:

next_act = random.choice(acts)
act.stage = agenda.start
Runner.addToActQ(next_act)
acts.remove(next_act)












33 changes: 33 additions & 0 deletions code/core/modules/network/do_one.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import random

from act import act
from agenda import agenda
from controlaction import controlaction

#to run this class we will remove anything comes from outside to make sure the function works
class DoOne (controlaction): #subclass of control action
def __init__(self) -> None:
super().__init__()

def __init__(self, identity):
super().__init__(identity)


def perform (act): # take an act

acts = []
acts.append(act.cable.getDownCableSet().getDownCable("do").getNodeSet())
next_act = random.choice(acts)
act.stage = agenda.start
Runner.addtoActQ(next_act)











87 changes: 87 additions & 0 deletions code/core/modules/network/snif.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@

import array
from tracemalloc import stop
from agenda import agenda

from controlaction import controlaction


class snif(controlaction):# controlAction,act


def __init__(self) -> None:
super().__init__()


def __init__(self, identity):
super().__init__(identity)

def perform(act):
guards =[]
if act.stage == agenda.start:
act.start()
elif act.stage == agenda.test_precondition:
act.test()
else:
return

def start(act):
guards = []
act.stage = agenda.test_precondition
Runner.addtoActQ(act)

for n in act.Cable().getDownCableSet().getDownCable("obj").getNodeSet():
guards.append(n.Cable().getDowncableset().getdowncable("guard").getNOdeset())
break

for guard in guards:
#acttopropchannel = Channel().add_new_channel(Controller().getcurrentcontext(),act,guard,True)
#guard.Node().recieverequest(acttopropchannel)
#act.Channel().getassertingpreconditionChannel().addChannel(acttopropChannel)
break

def test(act):
possible_acts = []
satisfied_guards = []
satisfied_guards.append(Controller().backword_chaining(act))
act.stage = agenda.done
all_guard_acts = Cable(act).getDownCableSet().getDownCable("obj").getNodeSet()
for guard_act in all_guard_acts:
contain_all = True
for n in guard_act.getDownCableSet().getDownCable("guard").getNodeSet():
if (not satisfied_guards.__contains__(n)):
contain_all = False

if contain_all:
possible_acts.append(guard_act.getDownCableSet().getDownCable("act").getNodeSet().getNOde(0))




wire =[]

r1 = relation.do
r2 = relation.action
i=0

while (i < len(possible_acts)):
wire.append({r1,possible_acts[i]})
i=i+1

doaction = node().build_new_node("doone","doone")

wire.append({r2,doaction}) #add a new node called action node
doOne = Node().add_new_moleculer_node(wire,act)
doOne.stage = agenda.start
Runner.addtoActQ(doOne)



#these comments should change to code lines when their implementation is complete







Loading