Ejemplo n.º 1
0
def buiten_naar_binnen():
    cable_list = []
    cl = []
    connected = 0

    batteries = helpers.readtxt("tools/wijk1_batterijen.txt")
    houses = helpers.readcsv("tools/wijk1_huizen.csv")

    distance = helpers.distance_sort(batteries, houses)
    sorted_houses = helpers.sort_houses(houses)

    for house in sorted_houses:
        for key in distance[house[0]]:
            if helpers.match_with_house(
                    houses[house[0]],
                    batteries[key[0]]) and houses[house[0]].output > 0:
                cable = helpers.Cable(houses[house[0]].pos_x,
                                      houses[house[0]].pos_y, key[0])
                cable_list.append(cable)
                cl = helpers.connect_to_battery(house[0], key[0], cable_list,
                                                batteries, houses)
                connected += 1
                break

    return len(cl), houses, batteries, cl
Ejemplo n.º 2
0
def cable_list():
    connected = 0
    cable_list = []
    cl = []
    batteries = helpers.readtxt("tools/wijk1_batterijen.txt")
    houses = helpers.readcsv("tools/wijk1_huizen.csv")

    for i in range(len(houses)):
        for j in range(len(batteries)):
            if helpers.match_with_house(houses[i],
                                        batteries[j]) and houses[i].output > 0:
                cable = helpers.Cable(houses[i].pos_x, houses[i].pos_y, i)
                cable_list.append(cable)
                cl = helpers.connect_to_battery(i, j, cable_list, batteries,
                                                houses)
                connected += 1
                break

    return len(cl), houses, batteries, cl
Ejemplo n.º 3
0
def cable_list_sneller():
    cable_list = []
    cl = []
    connected = 0

    batteries = helpers.readtxt("tools/wijk1_batterijen.txt")
    houses = helpers.readcsv("tools/wijk1_huizen.csv")

    distance = helpers.distance_sort(batteries, houses)

    for i in range(len(houses)):
        for key in distance[i]:
            if helpers.match_with_house(houses[i], batteries[key[0]]) and houses[i].output > 0:
                cable = helpers.Cable(houses[i].pos_x, houses[i].pos_y, i)
                cable_list.append(cable)
                cl = helpers.connect_to_battery(i, key[0], cable_list, batteries, houses)
                connected += 1
                break

    return len(cl), houses, batteries, cl
Ejemplo n.º 4
0
def verre_huizen_eerst():
    cable_list = []
    cl = []
    connected = 0

    batteries = helpers.readtxt("tools/wijk1_batterijen.txt")
    houses = helpers.readcsv("tools/wijk1_huizen.csv")

    distance = helpers.sort_on_battery_distance(batteries, houses)

    for house in distance:
        for batt in house:
            if helpers.match_with_house(
                    houses[batt[2]],
                    batteries[batt[1]]) and houses[batt[2]].output > 0:
                cable = helpers.Cable(houses[batt[2]].pos_x,
                                      houses[batt[2]].pos_y, batt[1])
                cable_list.append(cable)
                cl = helpers.connect_to_battery(batt[2], batt[1], cable_list,
                                                batteries, houses)
                connected += 1
                break

    return len(cl), houses, batteries, cl
Ejemplo n.º 5
0
def random_and_hillclimber_batteries():
    print("amount of random restarts?")
    random_restarts = input()

    battery_locations = []
    winner = []

    batteries = helpers.readtxt("tools/wijk1_batterijen.txt")
    houses = helpers.readcsv("tools/wijk1_huizen.csv")

    previous = 20000

    for a in range(int(random_restarts)):
        helpers.reset_batteries(batteries)
        for bat in batteries:
            bat.pos_x = randint(0, 50)
            bat.pos_y = randint(0, 50)

        distance = helpers.distance_sort(batteries, houses)
        sorted_houses = helpers.sort_houses(houses)
        score, connected = helpers.connection_score(sorted_houses, distance,
                                                    batteries, houses)

        if score < previous:
            helpers.reset_batteries(batteries)
            cl = helpers.connection(sorted_houses, distance, batteries, houses)
            previous = score
            battery_locations = []
            for bat in batteries:
                battery = helpers.Battery(bat.pos_x, bat.pos_y, bat.capacity)
                battery_locations.append(battery)
            winner = cl

    final_batteries = battery_locations
    print("amount of hillclimber moves?")
    moves = input()

    for b in range(int(moves)):
        for i in range(len(battery_locations)):
            battery_locations[i].pos_x = final_batteries[i].pos_x
            battery_locations[i].pos_y = final_batteries[i].pos_y
        helpers.reset_batteries(battery_locations)
        helpers.swap(battery_locations[randint(0, 4)], battery_locations)

        distance = helpers.distance_sort(battery_locations, houses)
        sorted_houses = helpers.sort_houses(houses)
        score, connected = helpers.connection_score(sorted_houses, distance,
                                                    battery_locations, houses)

        if score < previous:
            previous = score
            helpers.reset_batteries(battery_locations)
            hill = helpers.connection(sorted_houses, distance,
                                      battery_locations, houses)
            final_batteries = []
            for bat in battery_locations:
                battery = helpers.Battery(bat.pos_x, bat.pos_y, bat.capacity)
                final_batteries.append(battery)
            winner = hill

    return len(winner), houses, final_batteries, winner
Ejemplo n.º 6
0
def brute_force_batterijen():
    batteries = helpers.readtxt("tools/wijk1_batterijen.txt")
    houses = helpers.readcsv("tools/wijk1_huizen.csv")
    winner = []
    previous = 10000

    for i0 in range(50):
        for j0 in range(50):
            helpers.reset_batteries(batteries)
            batteries[0].pos_x = i0
            batteries[0].pos_y = j0

            distance = helpers.distance_sort(batteries, houses)
            sorted_houses = helpers.sort_houses(houses)
            score, connected = helpers.connection_score(
                sorted_houses, distance, batteries, houses)

            if score < previous:
                previous = score
                helpers.reset_batteries(batteries)
                cl = helpers.connection(sorted_houses, distance, batteries,
                                        houses)
                battery_locations = []
                for baty in batteries:
                    battery = helpers.Battery(baty.pos_x, baty.pos_y,
                                              baty.capacity)
                    battery_locations.append(battery)
                winner = cl

            for i1 in range(50):
                for j1 in range(50):
                    helpers.reset_batteries(batteries)
                    batteries[1].pos_x = i1
                    batteries[1].pos_y = j1

                    distance = helpers.distance_sort(batteries, houses)
                    sorted_houses = helpers.sort_houses(houses)
                    score, connected = helpers.connection_score(
                        sorted_houses, distance, batteries, houses)

                    if score < previous:
                        previous = score
                        helpers.reset_batteries(batteries)
                        cl = helpers.connection(sorted_houses, distance,
                                                batteries, houses)
                        battery_locations = []
                        for baty in batteries:
                            battery = helpers.Battery(baty.pos_x, baty.pos_y,
                                                      baty.capacity)
                            battery_locations.append(battery)
                        winner = cl

                for i2 in range(50):
                    for j2 in range(50):
                        helpers.reset_batteries(batteries)
                        batteries[2].pos_x = i2
                        batteries[2].pos_y = j2

                        distance = helpers.distance_sort(batteries, houses)
                        sorted_houses = helpers.sort_houses(houses)
                        score, connected = helpers.connection_score(
                            sorted_houses, distance, batteries, houses)

                        if score < previous:
                            previous = score
                            helpers.reset_batteries(batteries)
                            cl = helpers.connection(sorted_houses, distance,
                                                    batteries, houses)
                            battery_locations = []
                            for baty in batteries:
                                battery = helpers.Battery(
                                    baty.pos_x, baty.pos_y, baty.capacity)
                                battery_locations.append(battery)
                            winner = cl

                    for i3 in range(50):
                        for j3 in range(50):
                            helpers.reset_batteries(batteries)
                            batteries[3].pos_x = i3
                            batteries[3].pos_y = j3

                            distance = helpers.distance_sort(batteries, houses)
                            sorted_houses = helpers.sort_houses(houses)
                            score, connected = helpers.connection_score(
                                sorted_houses, distance, batteries, houses)

                            if score < previous:
                                previous = score
                                helpers.reset_batteries(batteries)
                                cl = helpers.connection(
                                    sorted_houses, distance, batteries, houses)
                                battery_locations = []
                                for baty in batteries:
                                    battery = helpers.Battery(
                                        baty.pos_x, baty.pos_y, baty.capacity)
                                    battery_locations.append(battery)
                                winner = cl

                        for i4 in range(50):
                            for j4 in range(50):
                                helpers.reset_batteries(batteries)
                                batteries[4].pos_x = i4
                                batteries[4].pos_y = j4

                                distance = helpers.distance_sort(
                                    batteries, houses)
                                sorted_houses = helpers.sort_houses(houses)
                                score, connected = helpers.connection_score(
                                    sorted_houses, distance, batteries, houses)

                                if score < previous:
                                    previous = score
                                    helpers.reset_batteries(batteries)
                                    cl = helpers.connection(
                                        sorted_houses, distance, batteries,
                                        houses)
                                    battery_locations = []
                                    for baty in batteries:
                                        battery = helpers.Battery(
                                            baty.pos_x, baty.pos_y,
                                            baty.capacity)
                                        battery_locations.append(battery)
                                    winner = cl

    return len(winner), houses, battery_locations, winner