Пример #1
0
 def agentsready(self, tx, intf, agentclass="FallAgent"):
     # Apply changes from waittime not dest
     agents = intf.getnodeagents(tx, self.name)
     clock = intf.gettime(tx)
     if clock in self.queue.keys() and agents:
         for ag in agents:
             if ag["id"] in self.queue[clock].keys() and self.queue[clock][
                     ag["id"]][1]:
                 self.mobchange = intf.getnodevalue(tx, self.name, "modm",
                                                    "Node", "name")
                 self.confchange = intf.getnodevalue(
                     tx, self.name, "modc", "Node", "name")
                 self.recoverrate = intf.getnodevalue(
                     tx, self.name, "energy", "Node", "name")
                 intf.updateagent(
                     tx, ag["id"], "mob",
                     normal(
                         (self.queue[clock][ag["id"]][1] * self.mobchange),
                         1, 1)[0])
                 intf.updateagent(
                     tx, ag["id"], "conf",
                     normal(
                         (self.queue[clock][ag["id"]][1] * self.confchange),
                         1, 1)[0])
                 intf.updateagent(
                     tx, ag["id"], "energy",
                     self.queue[clock][ag["id"]][1] * self.recoverrate)
                 intf.updateagent(tx, ag["id"], "referal", True)
                 agent = FallAgent(ag["id"])
                 agent.logging(tx, intf,
                               "Hos discharge, " + str(intf.gettime(tx)))
     super(HosNode, self).agentsready(tx, intf)
Пример #2
0
 def agentsready(self, tx, intf, agentclass):
     agents = intf.getnodeagents(tx, self.name, "name")
     clock = intf.gettime(tx)
     if self.queue or self.queue == {}:
         queueagents = [
             key for time in self.queue.keys()
             for key in self.queue[time].keys()
         ]
         newagents = [ag for ag in agents if ag["id"] not in queueagents]
         # run prediction on each unqueued agent
         for ag in newagents:
             self.agentprediction(tx, ag, intf)
     for ag in agents:
         if self.queue:
             if clock in self.queue.keys():
                 if ag["id"] in self.queue[clock].keys():
                     agper = self.agentperception(
                         tx, ag, intf, self.queue[clock][ag["id"]][0],
                         self.queue[clock][ag["id"]])
                     FallAgent(ag["id"]).move(tx, intf, agper)
         else:
             agper = self.agentperception(tx, ag, intf)
             FallAgent(ag["id"]).move(tx, intf, agper)
     if self.queue and clock in self.queue.keys():
         del self.queue[clock]
Пример #3
0
 def agentperception(self, tx, agent, intf, dest=None, waittime=None):
     view = super(InterventionNode,
                  self).agentperception(tx, agent, intf, dest, waittime)
     ag = FallAgent(agent["id"])
     ag.logging(tx, intf, self.name + ", " + str(intf.gettime(tx)))
     if agent["mob"] > 0.6:
         intf.updateagent(tx, agent["id"], "referal", "False", "name")
     return view
Пример #4
0
 def agentprediction(self, tx, agent, intf):
     view = super(HosNode, self).agentprediction(tx, agent, intf)[1:]
     clock = intf.gettime(tx)
     ag = FallAgent(agent["id"])
     ag.logging(tx, intf, "Hos admitted, " + str(clock))
     mean = min(
         -9 * min(agent["mob"], 1) + 14,
         -9 * (min(agent["conf_res"], 1) + min(agent["mob_res"], 1)) + 14)
     time = poisson(mean, 1)[0]
     if clock + time not in self.queue.keys():
         self.queue[clock + time] = {}
     dest = [edge for edge in view if edge.end_node["name"] == "Home"]
     self.queue[clock + time][agent["id"]] = (dest[0], time)
Пример #5
0
            "WHERE a.name='Home' AND b.name='InterventionOpen' "
            "CREATE (a)-[r:REACHES {effort:0.3, mobility:0.5, confidence:0.5, worth:2, allowed:'At risk, Healthy', ref:'False'}]->(b)")
    ses.run("MATCH (a), (b) "
            "WHERE a.name='InterventionOpen' AND b.name='Home' "
            "CREATE (a)-[r:REACHES {effort:0, mobility:1, confidence:1, worth:1}]->(b)")
    # Falls
    ses.run("MATCH (a), (b) "
            "WHERE a.name='Intervention' AND b.name='Hos' "
            "CREATE (a)-[r:REACHES {effort:0, mobility:1, confidence:1, energy: -0.8, modm:-0.25, modc:-0.35}]->(b)")
    ses.run("MATCH (a), (b) "
            "WHERE a.name='InterventionOpen' AND b.name='Hos' "
            "CREATE (a)-[r:REACHES {effort:0, mobility:1, confidence:1, energy: -0.8, modm:-0.25, modc:-0.35}]->(b)")
    ses.run("MATCH (a), (b) "
            "WHERE a.name='Social' AND b.name='Hos' "
            "CREATE (a)-[r:REACHES {effort:0, mobility:1, confidence:1, energy: -0.8, modm:-0.25, modc:-0.35}]->(b)")
    ses.run("MATCH (a), (b) "
            "WHERE a.name='Home' AND b.name='Hos' "
            "CREATE (a)-[r:REACHES {effort:0, mobility:1, confidence:1, energy: -0.8, modm:-0.25, modc:-0.5}]->(b)")
    ses.run("MATCH (a), (b) "
            "WHERE a.name='Home' AND b.name='Care' "
            "CREATE (a)-[r:REACHES {effort:0, worth:-1, mobility:1, confidence:1}]->(b)")
    ses.run("MATCH (a), (b) "
            "WHERE a.name='Hos' AND b.name='Care' "
            "CREATE (a)-[r:REACHES {effort:0, worth:-100, mobility:1, confidence:1}]->(b)")
    # Declare a fall agent with a None id and use it to generate a set of agents into the system
    fa = FallAgent(None)
    intf = Interface()
    for i in range(750):
        ses.write_transaction(fa.generator, intf, [0.8, 0.9, 1])
dri.close()
Пример #6
0
    def agentperception(self, tx, agent, intf, dest=None, waittime=None):
        view = super(FallNode, self).agentperception(tx, agent, intf, dest,
                                                     waittime)
        if type(view) == list:
            for edge in view:
                if "allowed" in edge.keys():
                    if not agent["referal"] and edge["ref"]:
                        view.remove(edge)
                    else:
                        allowed = edge["allowed"].split(',')
                        if not agent["wellbeing"] in allowed:
                            view.remove(edge)
            destinations = [edge.end_node["name"] for edge in view]
        else:
            destinations = [view.end_node["name"]]
            if "allowed" in view.keys():
                if not agent["referal"]:
                    view = []
                else:
                    allowed = view["allowed"].split(',')
                    if not agent["wellbeing"] in allowed:
                        view = []

        # If Care in options check for zero mobility
        if "Care" in destinations and agent["mob"] <= 0:
            view = [edge for edge in view if edge.end_node["name"] == "Care"]
        # If Hos and GP in options check for fall and return hos or GP,
        #  no prediction just straight check based on  mobility
        elif "Hos" in destinations and "GP" in destinations:
            if (r := random()) < exp(-3 * agent["mob"]):
                view = [
                    edge for edge in view if edge.end_node["name"] == "Hos"
                ]
                # Mark a severe fall has happened in agent log
                ag = FallAgent(agent["id"])
                ag.logging(tx, intf, "Severe Fall, " + str(intf.gettime(tx)))
                intf.updateagent(tx, agent["id"], "wellbeing", "Fallen")
            elif r < exp(-3 * (agent["mob"] - 0.1 * agent["mob"])):
                view = [edge for edge in view if edge.end_node["name"] == "GP"]
                # Mark a moderate fall has happened in agent log
                ag = FallAgent(agent["id"])
                ag.logging(tx, intf, "Moderate Fall, " + str(intf.gettime(tx)))
                intf.updateagent(tx, agent["id"], "wellbeing", "Fallen")
            elif r < exp(-3 * (agent["mob"] - 0.3 * agent["mob"])):
                # Mark a mild fall has happened in agent log
                ag = FallAgent(agent["id"])
                ag.logging(tx, intf, "Mild Fall, " + str(intf.gettime(tx)))
                intf.updateagent(tx, agent["id"], "wellbeing", "Fallen")
Пример #7
0
 def agentprediction(self, tx, agent, intf):
     view = intf.perception(tx, agent["id"])[1:]
     minenergy = min([edge["energy"] for edge in view if edge["energy"]] + [
         edge.end_node["energy"] for edge in view if edge.end_node["energy"]
     ])
     recoverytime = (minenergy - agent["energy"]) / self.recoverrate
     if agent["energy"] < minenergy:
         (falltime, falltype) = self.predictfall(agent["mob"])
         t = 1
         mob = agent["mob"]
         while t < falltime:
             mob = mob + self.mobchange
             (nfalltime, nfalltype) = self.predictfall(mob)
             if nfalltime + t < falltime:
                 (falltime, falltype) = (nfalltime + t, nfalltype)
             t = t + 1
         if falltime < recoverytime and not falltype == "Mild":
             # Add agent to queue with fall
             queuetime = falltime + intf.gettime(tx)
             intf.updateagent(tx, agent["id"], "wellbeing", "Fallen")
             if queuetime not in self.queue.keys():
                 self.queue[queuetime] = {}
             if falltype == "Severe":
                 dest = [
                     edge for edge in view if edge.end_node["name"] == "Hos"
                 ]
                 self.queue[queuetime][agent["id"]] = (dest[0], falltime)
                 ag = FallAgent(agent["id"])
                 ag.logging(tx, intf, "Severe Fall, " + str(queuetime))
             elif falltype == "Moderate":
                 dest = [
                     edge for edge in view if edge.end_node["name"] == "GP"
                 ]
                 self.queue[queuetime][agent["id"]] = (dest[0], falltime)
                 ag = FallAgent(agent["id"])
                 ag.logging(tx, intf, "Moderate Fall, " + str(queuetime))
         else:
             # Add agent to queue with recovery
             if falltype == "Mild":
                 queuetime = falltime + intf.gettime(tx)
                 ag = FallAgent(agent["id"])
                 ag.logging(tx, intf, "Mild Fall, " + str(queuetime))
                 intf.updateagent(tx, agent["id"], "wellbeing", "Fallen")
             if recoverytime + intf.gettime(tx) not in self.queue.keys():
                 self.queue[recoverytime + intf.gettime(tx)] = {}
             self.queue[recoverytime +
                        intf.gettime(tx)][agent["id"]] = (None,
                                                          recoverytime)
     else:
         # Add agent to next time step - no waittime or dest
         if intf.gettime(tx) + 1 not in self.queue.keys():
             self.queue[intf.gettime(tx) + 1] = {}
         self.queue[intf.gettime(tx) + 1][agent["id"]] = (None, None)