예제 #1
0
def scheme1():
    stations = {Station("1"),
                Station("2"),
                Station("3"),
                Station("4"),
                Station("5"),
                }

    scheme = Scheme(stations)
    scheme.add_way(10, "1", "3")
    scheme.add_way(10, "2", "3")
    scheme.add_way(10, "4", "3")
    scheme.add_way(10, "5", "3")

    # scheme.add_train_by_route_names("pobeda", ["1", "3", "5"])
    # scheme.add_train_by_route_names("lenin", ["2", "3", "4"])

    # st1 = scheme.find_station_by_name("1")
    # st2 = scheme.find_station_by_name("2")
    # st3 = scheme.find_station_by_name("3")
    # st4 = scheme.find_station_by_name("4")
    # st5 = scheme.find_station_by_name("5")
    #
    # w13 = scheme.find_way_by_end_names("1", "3")
    # w23 = scheme.find_way_by_end_names("5", "3")
    # w43 = scheme.find_way_by_end_names("4", "3")
    # w53 = scheme.find_way_by_end_names("5", "3")

    # t1 = scheme.find_train_by_name("pobeda")
    # t2 = scheme.find_train_by_name("lenin")

    return scheme
    def create_scheme88(number_of_trains, number_of_one_direct_ways):
        scheme = Scheme()

        SimpleConfigurationGenerator.add_brunch(scheme, "a", 22)
        SimpleConfigurationGenerator.add_brunch(scheme, "b", 16, "a5")
        SimpleConfigurationGenerator.add_brunch(scheme, "c", 11, "a10")
        SimpleConfigurationGenerator.add_brunch(scheme, "d", 18, "a15")
        SimpleConfigurationGenerator.add_brunch(scheme, "e", 21, "a20")

        a1 = SimpleConfigurationGenerator.create_route_by_names_in_branch("a", 0, 10)
        a2 = SimpleConfigurationGenerator.create_route_by_names_in_branch("a", 10, 20)
        a3 = SimpleConfigurationGenerator.create_route_by_names_in_branch("a", 7, 13)


        b1 = SimpleConfigurationGenerator.create_route_by_names_in_branch("b", 0, 7)
        b2 = SimpleConfigurationGenerator.create_route_by_names_in_branch("b", 0, 9)
        b3 = SimpleConfigurationGenerator.create_route_by_names_in_branch("b", 2, 8)

        c1 = SimpleConfigurationGenerator.create_route_by_names_in_branch("c", 2, 10)
        c2 = SimpleConfigurationGenerator.create_route_by_names_in_branch("c", 1, 5)
        c3 = SimpleConfigurationGenerator.create_route_by_names_in_branch("c", 8, 2)

        d1 = SimpleConfigurationGenerator.create_route_by_names_in_branch("d", 6, 13)
        d2 = SimpleConfigurationGenerator.create_route_by_names_in_branch("d", 17, 5)
        d3 = SimpleConfigurationGenerator.create_route_by_names_in_branch("d", 8, 0)

        ab = SimpleConfigurationGenerator.create_route_by_names_in_branch("a", 0, 5) + \
              SimpleConfigurationGenerator.create_route_by_names_in_branch("b", 0, 2)
        ac = SimpleConfigurationGenerator.create_route_by_names_in_branch("a", 0, 10) + \
              SimpleConfigurationGenerator.create_route_by_names_in_branch("c", 0, 7)
        ad = SimpleConfigurationGenerator.create_route_by_names_in_branch("a", 0, 15) + \
              SimpleConfigurationGenerator.create_route_by_names_in_branch("d", 0, 5)
        ae = SimpleConfigurationGenerator.create_route_by_names_in_branch("a", 0, 20) + \
              SimpleConfigurationGenerator.create_route_by_names_in_branch("e", 0, 10)
        bad = SimpleConfigurationGenerator.create_route_by_names_in_branch("b", 3, 0) + \
              SimpleConfigurationGenerator.create_route_by_names_in_branch("a", 5, 15) + \
              SimpleConfigurationGenerator.create_route_by_names_in_branch("d", 0, 2)


        route_list = [a1, a2, a3, b1, b2, b3, c1, c2, c3, d1, d2, d3, ab, ac, ad, ae, bad]

        for i in range(number_of_trains):
            tr_name = "tr" + str(i)
            route = route_list[(i % len(route_list))]
            scheme.add_train(tr_name, route)

        for i in range(number_of_one_direct_ways):
            rand_index = randint(0, len(scheme.ways))
            k = 0
            for way in scheme.ways:
                if k == rand_index:
                    way.direct_property = Way.PROPERTY_ONE_DIRECT
                k += 1

        return scheme
    def load_configuration(name):

        path = ConfigurationParser.PATH + name

        scheme = Scheme()
        conf_file = open(path, "r")
        conf_file.readline()
        stations_line = conf_file.readline().rstrip()
        names, times_sets = ConfigurationParser.parse_stations_string(stations_line)
        for name, time_set in zip(names, times_sets):
            scheme.add_station(name, time_set)

        conf_file.readline()
        ways_line = conf_file.readline().rstrip()
        times_to_pass, st1_names, st2_names, direct_properties = ConfigurationParser.parse_ways_string(ways_line)
        for time, st1, st2, property in zip(times_to_pass, st1_names, st2_names, direct_properties):
            scheme.add_way(time, st1, st2, property)

        conf_file.readline()
        trains_line = conf_file.readline().rstrip()
        names, routes = ConfigurationParser.parse_trains_string(trains_line)
        for name, route in zip(names, routes):
            scheme.add_train(name, route)

        return scheme