Beispiel #1
0
    def rand_one_to_one_algorithm(grid):
        """Algoritme die 'random' de huizen één op één aan een batterij aansluit"""

        houses = grid.get_houses()
        batteries = grid.get_batteries()
        randomize_objects(houses, batteries)

        for house in houses:
            battery = choice(batteries)
            battery.lay_cable_to_house(house)
Beispiel #2
0
    def dist_cap_algorithm(grid):
        """
            Algoritme die 'random' de huizen aan de zo dichtbijzijnste batterij aansluit,
            waarbij de output in de capaciteit past
        """

        houses = grid.get_houses()
        batteries = grid.get_batteries()
        randomize_objects(houses, batteries)

        for house in houses:
            battery = find_battery(batteries, house)
            battery.lay_cable_to_house(house)
Beispiel #3
0
    def rand_cable_dist_cap(grid):
        """
            Algoritme die ook naar bestaande gelegde kabels kijkt,
            en de de kabel/batterij kiest met minste afstand
        """

        # Verkrijg huizen en batterijen en schud ze
        houses = grid.get_houses()
        batteries = grid.get_batteries()
        randomize_objects(houses, batteries)

        for house in houses:

            # Zoek dichtsbijzijndste batterij, bepaal afstand, en houd bij met afstand kabel
            battery = find_battery(batteries, house)
            distance_battery = house.distance(battery)
            best_distance_cable = 1000000
            best_cable = tuple

            for b in batteries:

                # Pak resterende capaciteit batterij
                remaining = b.get_remaining()

                # Condities op kabels en output, prune als niet voldoet
                if not b.is_empty():
                    if remaining >= house.get_output():
                        cables = b.get_unique_cables()

                        for c in cables:
                            distance_cable = house.distance(c)

                            # Is er een kabel dichterbijer, sla dit op en onthoud gegevens
                            if distance_cable < best_distance_cable:
                                best_distance_cable = distance_cable
                                best_cable = c
                                battery_cable = b

            # Conditie: controleer afstand batterij en kabel, en selecteert minste afstand
            if best_distance_cable < distance_battery:
                battery_cable.set_house(house)
                house.lay_cable_to_cable(best_cable, battery_cable)

            else:
                battery.lay_cable_to_house(house)
Beispiel #4
0
    def worst_dist_no_cap_shared_cable(grid):
        """
            Algoritme die ook naar bestaande gelegde kabels kijkt,
            en de de kabel/batterij kiest met minste afstand
        """

        # Verkrijg batterijen en huizen en schud ze
        houses = grid.get_houses()
        batteries = grid.get_batteries()
        randomize_objects(houses, batteries)

        for house in houses:

            # Zoek de slechtste batterij, bereken afstand met huis en houd gegevens bij
            battery = find_worst_battery(batteries, house)
            distance_battery = house.distance(battery)
            worst_distance_cable = 0
            worst_cable = tuple

            for b in batteries:
                cables = b.get_unique_cables()

                for c in cables:
                    distance_cable = house.distance(c)

                    # Als het kan, wijzig slechtste kabel en afstand en onthoud gegevens
                    if distance_cable > worst_distance_cable:
                        worst_distance_cable = distance_cable
                        worst_cable = c
                        battery_cable = b

            # Conditie: controleer afstand batterij en kabel, en selecteert minste afstand
            if worst_distance_cable > distance_battery:
                battery_cable.set_house(house)
                house.lay_cable_to_cable(worst_cable, battery_cable)

            else:
                battery.lay_cable_to_house(house)
Beispiel #5
0
    def best_dist_no_cap_shared_cable(grid):
        """
            Algoritme die ook naar bestaande gelegde kabels kijkt,
            en de de kabel/batterij kiest met minste afstand
        """

        houses = grid.get_houses()
        batteries = grid.get_batteries()
        randomize_objects(houses, batteries)

        for house in houses:

            # Initialiseer variabelen voor bepaling batterij gegevens
            battery = find_best_battery(batteries, house)
            distance_battery = house.distance(battery)
            best_distance_cable = 1000000
            best_cable = tuple

            for b in batteries:
                cables = b.get_unique_cables()

                for c in cables:
                    distance_cable = house.distance(c)

                    # Als de afstand van de kabel beter is dan de beste afstand die geconstateerd is
                    if distance_cable < best_distance_cable:
                        best_distance_cable = distance_cable
                        best_cable = c
                        battery_cable = b

            # Controleer afstand kabel met dichtsbijzijnste batterij, beter: sluit aan
            if best_distance_cable < distance_battery:
                battery_cable.set_house(house)
                house.lay_cable_to_cable(best_cable, battery_cable)

            # Anders: sluit aan dichtsbijzijnste batterij
            else:
                battery.lay_cable_to_house(house)
Beispiel #6
0
    def switch_up(grid):
        """
            Algoritme die 'random' de batterijen aan de zo dichtbijzijnste huizen aansluit,
            waarbij de output in de capaciteit past
        """

        # Verkrijg huizen en batterijen, schud ze, en pak kopie van huizen
        houses = grid.get_houses()
        batteries = grid.get_batteries()
        randomize_objects(houses, batteries)
        houses_copy = deepcopy(houses)

        for battery in batteries:

            # Batterij blijft huizen toevoegen tot find_house niks returned, oftewel batterij vol
            while True:
                house = find_house(battery, houses_copy)

                if house:
                    battery.lay_cable_to_house(house)

                else:
                    break