Exemplo n.º 1
0
def timeIterationStepManyToOne49():
    random.seed("random")
    for i in range(200000):
        agentid = focal_agent_sim.select_focal_agent(network, "random", agents)
        neighborsid = neighbor_selector_sim.select_neighbors(
            network, "random", agentid, "many-to-one")
        influence_sim.spread_influence(network, "axelrod",
                                       agentid, neighborsid,
                                       list(all_attributes), "many-to-one")
Exemplo n.º 2
0
def timeIterationStepOneToMany49():
    random.seed("random")
    for i in range(200000):
        agentid = focal_agent_sim.select_focal_agent(network, "random", agents)
        neighborsid = neighbor_selector_sim.select_neighbors(
            network, "random", agentid, "one-to-many")
        influence_sim.spread_influence(network, "axelrod",
                                       agentid, neighborsid,
                                       list(all_attributes), "one-to-many",
                                       HammingDistance())
Exemplo n.º 3
0
def timeIterationStepOneToMany5000Overlap():
    all_attributes = network.nodes[1].keys()
    random.seed("random")
    for i in range(20000):
        agentid = focal_agent_sim.select_focal_agent(network, "random")
        neighborsid = neighbor_selector_sim.select_neighbors(
            network, "random", agentid, "one-to-many")
        influence_sim.spread_influence(network, "stochasticOverlap",
                                       agentid, neighborsid,
                                       list(all_attributes), "one-to-many")
Exemplo n.º 4
0
def timeIterationStepOneToOne5000():
    all_attributes = network.node[1].keys()
    random.seed("random")
    for i in range(2000000):
        agentid = focal_agent_sim.select_focal_agent(network, "random",
                                                     agents5000)
        neighborsid = neighbor_selector_sim.select_neighbors(
            network, "random", agentid, "one-to-one")
        influence_sim.spread_influence(network, "axelrod",
                                       [agentid], neighborsid,
                                       list(all_attributes), "one-to-one")
Exemplo n.º 5
0
def timeIterationStepOneToOne9():
    network = network_init.generate_network("grid", **{"num_agents": 9})
    agents_init.initialize_attributes(network, "random")
    all_attributes = network.nodes[1].keys()
    random.seed("random")
    for i in range(2000000):
        agentid = focal_agent_sim.select_focal_agent(network, "random")
        neighborsid = neighbor_selector_sim.select_neighbors(
            network, "random", agentid, "one-to-one")
        influence_sim.spread_influence(network, "axelrod",
                                       [agentid], neighborsid,
                                       list(all_attributes), "one-to-one")
Exemplo n.º 6
0
def timeIterationStepOneToOne49Overlap():
    network = network_init.generate_network("grid")
    agents_init.initialize_attributes(network, "random")
    all_attributes = network.node[1].keys()
    random.seed("random")
    for i in range(2000000):
        agentid = focal_agent_sim.select_focal_agent(network, "random")
        neighborsid = neighbor_selector_sim.select_neighbors(
            network, "random", agentid, "one-to-one")
        influence_sim.spread_influence(network, "stochasticOverlap",
                                       agentid, neighborsid,
                                       list(all_attributes), "one-to-one")
Exemplo n.º 7
0
    def run_step(self):
        """
        Executes one iteration of the simulation step which includes the selection of a focal agent, the selection
        of the neighbors and the influence step.
        If the user passed their own implementations of those components, they will be called to execute these steps,
        otherwise the respective factory functions will be called.
        """

        selected_agent = focal_agent_sim.select_focal_agent(self.network, self.focal_agent_selector,
                                                            self.agentIDs, **self.parameter_dict)

        neighbors = neighbor_selector_sim.select_neighbors(self.network, self.neighbor_selector,
                                                           selected_agent,
                                                           self.communication_regime, **self.parameter_dict)

        success = influence_sim.spread_influence(self.network,
                                                 self.influence_function,
                                                 selected_agent,
                                                 neighbors,
                                                 self.communication_regime,
                                                 self.dissimilarity_calculator,
                                                 self.influenceable_attributes,
                                                 **self.parameter_dict)

        if self.tickwise and self.time_steps % self.tickwise_output_step_size == 0:  # list is not empty
            defaults_selected = [i for i in self.tickwise if i in CreateOutputTable._implemented_output_realizations]
            if len(defaults_selected) > 0:
                self.tickwise_output['defaults'].append(
                    CreateOutputTable.create_output_table(network=self.network, realizations=defaults_selected))
            for i in self.tickwise:
                if not i in defaults_selected:
                    if isinstance(i, CreateOutputTable.OutputTableCreator):
                        self.tickwise_output[i.label].append(i.create_output(network=self.network))
                    else:
                        self.tickwise_output[i].append(
                            OutputMeasures.AttributeReporter(feature=i).create_output(self.network))

        self.time_steps += 1
        if success:
            self.influence_steps += 1