예제 #1
0
    def altruism(self, altruisticProbability, selfishProbability, altruismCost,
                 altruismBenefit, disease, harshness, numTicks):
        """
        Runs an experiment of the Biology/Evolution/Altruism model.

        :returns: The table output of the experiment.
        """
        job = uuid4()
        exp_path = '/tmp/%s/experiment.xml' % job
        out_path = '/tmp/%s/out.csv' % job

        params = {
            'altruistic-probability': altruisticProbability,
            'selfish-probability': selfishProbability,
            'cost-of-altruism': altruismCost,
            'benefit-from-altruism': altruismBenefit,
            'disease': disease,
            'harshness': harshness,
        }

        exp = Experiment(steps=numTicks, params=params)
        exp.add_metric(color='pink').add_metric(color='green')
        exp.write_xml(exp_path)

        model = '%s/models/Sample Models/Biology/Evolution/Altruism.nlogo' % NETLOGO_HOME
        self.call_experiment(model, exp_path, exp.name, out_path)

        with open(out_path, 'r') as out_file:
            return out_file.read()