botellas.py

PHOTO EMBED

Mon May 22 2023 17:33:23 GMT+0000 (Coordinated Universal Time)

Saved by @javanegas #python

class Robot:
    def place_bottle(self, station) → None:
        ...
        pass

    def remove_bottle(self, station) → None:
        ...
        pass


class Station:
    def start_filling(self, station) → None:
        ...

    def time_to_fill(self, station) → int:
        ...

    def has_bottle(self, station) -> bool:
        ...

    def is_filling(self, station) -> bool:
        ...



def first_flow(stations, robot):
    for station in stations:
        if not station.has_bottle() and not station.is_filling():
            robot.place_bottle(station) # blocks for 1 second
            station.start_filling()
        elif station.has_bottle() and station.is_filling() and station.time_to_fill() == 0:
            station.stop_filling()
            robot.remove_bottle(station) # blocks for 2 seconds

def second_flow(stations, robot):
    # Objetivo no derramar
    ready_to_fill = []
    ready_to_remove = []
    while len(ready_to_fill) == len(stations):
        for station in stations:
            if not station.has_bottle():
                robot.place_bottle(station) # blocks for 1 second
                ready_to_fill.append(station)

    for station in ready_to_fill:
        station.start_filling()

    while len(ready_to_remove) == len(stations):
        for station in stations:
            if station.has_bottle() and station.is_filling() and station.time_to_fill() == 0:
                station.stop_filling()
                ready_to_remove.append(station)

    for station in ready_to_fill:
        station.remove_bottle()

   
# Estado global del proceso
# Staciones llenado botellas -> que necesito apagar -> prioridad
# Staciones vacias -> Que necesitan botellas para llenar -> si me alcanza el tiempo
# Staciones apagadas con botellas -> que necesitan ser sacadas -> solo si me alcanza el tiempo y no staciones vacias


def third_flow(stations, robot):
    # Tiempo variado de estaciones 
    # quiero retirar las botellas que ya esten listas si es que no tengo que detener otras botellas.
    filling_bottles_stations = []
    empty_stations = []
    turned_off_stations = []

    updated_filling_bottles = []
    for station in filling_bottles_stations:
        if station.time_to_fill() == 0:
            station.stop_filling()
            turned_off_stations.append(station)
        else:
            updated_filling_bottles.append(station)
    filling_bottles_stations = updated_filling_bottles





if __name__ == "__main__":
    stations = [Station() for _ in range(8)]
    robot = Robot()
    while True:
        basic_flow(stations, robot)



content_copyCOPY