diff --git a/code/core/modules/network/achieve.py b/code/core/modules/network/achieve.py new file mode 100644 index 0000000..0654881 --- /dev/null +++ b/code/core/modules/network/achieve.py @@ -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" + + + + + + + + + + \ No newline at end of file diff --git a/code/core/modules/network/actionnode.py b/code/core/modules/network/actionnode.py new file mode 100644 index 0000000..141fa71 --- /dev/null +++ b/code/core/modules/network/actionnode.py @@ -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 + + + \ No newline at end of file diff --git a/code/core/modules/network/agenda.py b/code/core/modules/network/agenda.py new file mode 100644 index 0000000..87c6b14 --- /dev/null +++ b/code/core/modules/network/agenda.py @@ -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 \ No newline at end of file diff --git a/code/core/modules/network/believe.py b/code/core/modules/network/believe.py new file mode 100644 index 0000000..961e7b9 --- /dev/null +++ b/code/core/modules/network/believe.py @@ -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) + + + + + + + \ No newline at end of file diff --git a/code/core/modules/network/controlaction.py b/code/core/modules/network/controlaction.py new file mode 100644 index 0000000..c31ffd6 --- /dev/null +++ b/code/core/modules/network/controlaction.py @@ -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) + \ No newline at end of file diff --git a/code/core/modules/network/disbelieve.py b/code/core/modules/network/disbelieve.py new file mode 100644 index 0000000..180e365 --- /dev/null +++ b/code/core/modules/network/disbelieve.py @@ -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) + \ No newline at end of file diff --git a/code/core/modules/network/do_all.py b/code/core/modules/network/do_all.py new file mode 100644 index 0000000..ccb05f3 --- /dev/null +++ b/code/core/modules/network/do_all.py @@ -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) + + + + + + + + + + + + \ No newline at end of file diff --git a/code/core/modules/network/do_one.py b/code/core/modules/network/do_one.py new file mode 100644 index 0000000..9161654 --- /dev/null +++ b/code/core/modules/network/do_one.py @@ -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) + + + + + + + + + + + \ No newline at end of file diff --git a/code/core/modules/network/snif.py b/code/core/modules/network/snif.py new file mode 100644 index 0000000..d40f177 --- /dev/null +++ b/code/core/modules/network/snif.py @@ -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 + + + + + + + \ No newline at end of file diff --git a/code/core/modules/network/sniterate.py b/code/core/modules/network/sniterate.py new file mode 100644 index 0000000..6c7e3e6 --- /dev/null +++ b/code/core/modules/network/sniterate.py @@ -0,0 +1,74 @@ + +from act import act +from agenda import agenda +from controlaction import controlAction + + + +class SNIterate (controlAction): + def __init__(self) -> None: + super().__init__() + + def __init__(self, identity): + super().__init__(identity) + + + def perform(self,act): + if act.stage is agenda.start: + self.start() + elif act.stage is agenda.test_precondition: + self.test() + + else: + return + + + def start(act): + + guards = [] + act.stage = agenda.test_precondition + actStack.push(act) + for n in act.getDownCableSet().getDownCable("obj").getNodeSet(): + guards.append(n.getDownCableSet().getDownCable("guard").getNodeSet()) + + for guard in guards: + + acttopropchannel = #currentcontext with requester "ACT" and reporter (guard) + #and this instance guard recieve request from this acttoprop channnel + guard.recieverequest(acttopropchannel) + + # asserting proconditions with this new channel + + + + + + + def test(act): + possible_acts = [] + all_guard_act = [] + satisfied_guard = [] + satisfied_guard.append(act.process_reports()) + act.stage = agenda.done + all_guard_act = act.getDownCableSet().getDownCable("obj").getNodeSet() + + for guard_act in all_guard_act: + contain_all = True + for n in guard_act.getDownCableSet().getDownCable("guard").getNodeSet(): + if (not satisfied_guard.__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 + for i in len(possible_acts): + wire.append(add_new_wire(r1,possible_acts[i])) + + wire.append(add_new_wire(r2,"#new node called action node")) + #then build new moleculer node (will not cooded yet) + #restart the agenda of this mo;eculer node (act node) + #added to the act stack + \ No newline at end of file diff --git a/code/core/modules/network/snsequence.py b/code/core/modules/network/snsequence.py new file mode 100644 index 0000000..dff11ea --- /dev/null +++ b/code/core/modules/network/snsequence.py @@ -0,0 +1,32 @@ + + + +#from act import act +#from agenda import agenda +#from controlaction import controlAction + + +from controlaction import controlaction + + +class SNSequence (controlaction):#take a control action + def __init__(self) -> None: + super().__init__() + + def __init__(self, identity): + super().__init__(identity) + + + + + def perform (act): #as Node set class in not finished we us lists but hashtags will work if we have node set class + acts=[] + acts.append(act.cable.getDownCableSet().getDownCable("obj").getNodeSet()) + while not len(acts) is 0: + #next_act = acts.getNode(acts.size()-1) + next_act = acts[len(acts)-1] + act.stage = agenda.start + Runner.addtoActQ(next_act) + #acts.remove_node(next_act) + + acts.remove(next_act) \ No newline at end of file diff --git a/code/core/modules/network/withall.py b/code/core/modules/network/withall.py new file mode 100644 index 0000000..f3fba82 --- /dev/null +++ b/code/core/modules/network/withall.py @@ -0,0 +1,73 @@ +from act import act +from actionnode import actionnode +from agenda import agenda +from controlaction import controlaction + + +class withall(controlaction): + def __init__(self) -> None: + super().__init__() + + def __init__(self, identity): + super().__init__(identity) + + + + def perform (act): + if act.stage == agenda.start: + act.start + elif act.stage == agenda.identify_objects: + act.itentifyObjects + else: + return + + + + def start(act): + act.stage = agenda.identify_objects + Runner.addtoactQ (act) + node = act.cable.getDownCableSet().getDownCable("like as").getNodeSet().getNode(0) + acttopropchannel = acttopropchannel.addchannel(Controller().getcurrentconttext,act,node,True) + node.recieverequest(acttopropchannel) + act.addChannel(acttopropchannel) + + + def itentifyObjects (act): + constants = act.controller.processReports() + act.stage= agenda.done + wire = [] + r1 = relaton.action + r2 = relation.doo + doNode = act.cable.getDowncableset().getDownCable("do").getNodeSet().getNode(0) + actionNode=doNode.cable.getDowncableset().getDownCable("action").getNodeSet().getNode(0) + possible_acts = [] + wireaction = [] + wireaction.append({r2,actionNode}) + i =0 + while i < len(constants): + wireslist = [] + wireslist.append({r1,constants.get(i)}) + wireslist.append(wireaction) + #build new moleculer act node from wire List + possible_acts.append("this new moleculer node") + i = i+1 + + + arrayDoAll = [] + y=0 + while y < len(possible_acts): + arrayDoAll.append({r2,possible_acts.pop}) + y=y+1 + + #build an action node + #add to arrayDoOne this new action node with relation r1 + #build new moleculer node + #restart agenda for this new moleculer node the add it to act stack + + + + + + + + \ No newline at end of file diff --git a/code/core/modules/network/withsome.py b/code/core/modules/network/withsome.py new file mode 100644 index 0000000..fc77724 --- /dev/null +++ b/code/core/modules/network/withsome.py @@ -0,0 +1,47 @@ + +from act import act +from agenda import agenda +from controlaction import controlaction + + +class withsome(controlaction): + def __init__(self) -> None: + super().__init__() + + def __init__(self, identity): + super().__init__(identity) + + + + def perform (act): + if act.stage == agenda.start: + act.start + elif act.stage == agenda.identify_objects: + act.itentifyObjects + else: + return + + + + def start(act): + act.stage = agenda.identify_objects + Runner.addtoactQ (act) + node = act.cable.getDownCableSet().getDownCable("like as").getNodeSet().getNode(0) + acttopropchannel = acttopropchannel.addchannel(Controller().getcurrentconttext,act,node,True) + node.recieverequest(acttopropchannel) + act.addChannel(acttopropchannel) + + + def itentifyObjects (act): + constants = act.controller.processReports() + act.stage= agenda.done + wire = [] + r1 = relaton.action + r2 = relation.doo + + + + + + + \ No newline at end of file