Пример #1
0
    def test_peaked_utility_cutoff(self):
        test_data = [
            (0.00, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]),
            (0.10, [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0]),
            (0.20, [0, 0.5, 1, 0, 0, 0, 0, 0, 0, 0, 0]),
            (0.30, [0, 0.333333333, 0.666666667, 1, 0, 0, 0, 0, 0, 0, 0]),
            (0.40, [0, 0.25, 0.5, 0.75, 1, 0, 0, 0, 0, 0, 0]),
            (0.50, [0, 0.2, 0.4, 0.6, 0.8, 1, 0, 0, 0, 0, 0]),
            (0.60, [
                0, 0.166666667, 0.333333333, 0.5, 0.666666667, 0.833333333, 1,
                0, 0, 0, 0
            ]),
            (0.70, [
                0, 0.142857143, 0.285714286, 0.428571429, 0.571428571,
                0.714285714, 0.857142857, 1, 0, 0, 0
            ]),
            (0.80, [0, 0.125, 0.25, 0.375, 0.5, 0.625, 0.75, 0.875, 1, 0, 0]),
            (0.90, [
                0, 0.111111111, 0.222222222, 0.333333333, 0.444444444,
                0.555555556, 0.666666667, 0.777777778, 0.888888889, 1, 0
            ]),
            (1.00, [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1]),
        ]

        for peak, exepcted_output_list in test_data:
            peaked_utility = create_peaked_utility(peak, True)
            self.check_expected_output_for_range_0_1(
                'peaked_cutoff_' + str(peak), peaked_utility,
                exepcted_output_list)
Пример #2
0
    def test_value_error_outside_0_1(self):
        functions = {
            'flat': create_flat_utility(0.5),
            'peaked': create_peaked_utility(0.5),
            'peaked_cutoff': create_peaked_utility(0.5, True),
            'spiked': create_spiked_utility(0.5),
            'create_flat': create_flat_utility,
            'create_peaked': create_peaked_utility,
            'create_spiked': create_spiked_utility,
        }

        error_inputs = [-10, -1, -0.1, -0.00001, 1.00001, 1.1, 2, 10]

        for name, function in functions.items():
            for error_input in error_inputs:
                with self.subTest(name=name, input=error_input):
                    with self.assertRaises(ValueError):
                        function(error_input)
    def test_get_unsatisfied_agent_indices_satisficers(self):

        parameters = [
            (ut.create_flat_utility(0.5), [0, 1, 2, 3, 4, 5, 6, 7, 8]),
            (ut.create_peaked_utility(0.5), [0, 1, 2, 3, 4, 5, 6, 7, 8]),
            (ut.create_spiked_utility(0.5), [0, 1, 2, 3, 4, 5, 6, 7, 8]),
        ]

        self.check_get_unsatisfied_agent_indices_expected_output(
            parameters, True)
Пример #4
0
from schelling.simulation import run_simulation, get_save_state_callback
from schelling.simulation_settings import SimulationSettings
import schelling.utility_functions as ut

import click
import os
import sys

_utility_function_creators = {
    'flat': ut.create_flat_utility,
    'peaked': ut.create_peaked_utility,
    'peaked_cutoff': lambda peak: ut.create_peaked_utility(peak, cutoff=True),
    'spiked': ut.create_spiked_utility,
}


@click.command()
@click.option(
    '--grid-size',
    '-s',
    default=30,
    help='Simulation grid size (grid is square with specified side). '
    'Default = 30.')
@click.option('--vacancy-proportion',
              '-v',
              default=0.2,
              help='Proportion of vacant spots in grid. Default = 0.2')
@click.option(
    '--agent-proportion',
    '-a',
    multiple=True,