コード例 #1
0
    def set_random_loads(max_for_each_route):
        scheme_len = len(SystemBuilder.scheme.node)
        for route in SystemBuilder.routes:
            for k in range(int(random() * max_for_each_route)):

                dispatch_st_num = route.route_list[int(random() * route.length())]

                destination_is_founded = False
                counter = 0
                while not destination_is_founded:
                    counter += 1
                    assert counter < 999
                    destination_st_num = int(random() * scheme_len) + 1
                    try:
                        way_length, way_list = nx.bidirectional_dijkstra(
                            SystemBuilder.routes_scheme, dispatch_st_num, destination_st_num)
                        new_growth_coeff = GrowthCoeff(RandomFunctions.growth_coef_func(), way_list)
                        destination_is_founded = True
                        SystemBuilder.growth_coeffs.append(new_growth_coeff)
                        attr_name = SystemBuilder.ATTRIBUTE_GROWTH_LIST
                        SystemBuilder.scheme.node[dispatch_st_num][attr_name].append(new_growth_coeff)
                    except nx.exception.NetworkXError:
                        pass
                    except nx.exception.NetworkXNoPath:
                        pass
コード例 #2
0
    def build_random_routes(attempts_num, min_len):
        scheme_len = len(SystemBuilder.scheme.node)
        k = 0
        while k < attempts_num:
            first_station_number = int(random() * scheme_len) + 1
            second_station_number = int(random() * scheme_len) + 1
            way_len, way_list = \
                nx.bidirectional_dijkstra(SystemBuilder.scheme, first_station_number, second_station_number)
            if way_len >= min_len:
                way_list = way_list + way_list[::-1][1:]
                new_route = Route(way_list, RandomFunctions.launch_cost_func(way_list))
                SystemBuilder.routes.append(new_route)
            k += 1

        SystemBuilder._create_routes_scheme()
コード例 #3
0
    def build_random_brunches(len, first_number=1, second_number=2):
        drop_len_func = lambda len: int(len/4)
        brunch_prob = 0.5
        brunch_list = list()

        for k in range(len-1):
            SystemBuilder.scheme.add_edge(first_number, second_number, weight=1)
            SystemBuilder.scheme[first_number][second_number][SystemBuilder.ATTRIBUTE_TIME_IN_WAY] = RandomFunctions.time_distance_func()
            if random() < brunch_prob:
                brunch_list.append(first_number)
            first_number = second_number
            second_number += 1

        try:
            if SystemBuilder.build_random_brunches.max < second_number:
                SystemBuilder.build_random_brunches.max = second_number
        except AttributeError:
            SystemBuilder.build_random_brunches.max = second_number

        for number in brunch_list:
            SystemBuilder.build_random_brunches(
                drop_len_func(len), first_number=number, second_number=SystemBuilder.build_random_brunches.max)

        attr_name = SystemBuilder.ATTRIBUTE_GROWTH_LIST
        nx.set_node_attributes(SystemBuilder.scheme, attr_name, None)
        for num in SystemBuilder.scheme.nodes():
            SystemBuilder.scheme.node[num][attr_name] = list()
コード例 #4
0
 def set_random_launch_periods():
     for route in SystemBuilder.routes:
         route.period = RandomFunctions.period_func()
コード例 #5
0
 def set_random_storage_costs():
     attr_name = SystemBuilder.ATTRIBUTE_STORAGE_PRICE
     nx.set_node_attributes(SystemBuilder.scheme, attr_name, None)
     for num in SystemBuilder.scheme.nodes():
         SystemBuilder.scheme.node[num][attr_name] = RandomFunctions.storage_cost_func()
コード例 #6
0
 def set_random_launch_costs():
     for route in SystemBuilder.routes:
         route.cost_of_launch = RandomFunctions.launch_cost_func(route.route_list)