Exemplo n.º 1
0
def tigrePomcpBenchmark():
    print(
        "Has seleccionado ejecución benchmark con POMCP para el Problema del Tigre"
    )
    pasos = 0
    recompensa = 0
    listaPasos = []
    listaRecompensas = []
    for i in range(30):
        params = RunnerParams("tiger.POMDP", None, "pomcp", float('inf'), 30,
                              False, False)

        with open(params.algo_config) as algo_config:
            algo_params = json.load(algo_config)
            runner = PomdpRunnerBenchmark(params)
            a = runner.run(**algo_params)

        pasos += a[0]
        recompensa += a[1]
        print('Resuelto en {} pasos'.format(a[0]))
        print('Recompensa: {}'.format(a[1]))
        listaPasos.append(a[0])
        listaRecompensas.append(a[1])

    mediaPasos = pasos / 30
    mediaRecompensa = recompensa / 30
    desviaciones = calculaDesviacionTipica(listaPasos, listaRecompensas,
                                           mediaPasos, mediaRecompensa)
    print(
        '========================================================================='
    )
    print('Media de pasos: {}'.format(mediaPasos))
    print('Recompensa media: {}'.format(mediaRecompensa))
    print('Desviación típica pasos: {}'.format(desviaciones[0]))
    print('Desviación típica recompensas: {}'.format(desviaciones[1]))
Exemplo n.º 2
0
    def run(self):
        problema = self.controller.shared_data["problema"]
        algoritmo = self.controller.shared_data["algoritmo"]
        budget = self.controller.shared_data["presupuesto"].get()
        max_play = self.controller.shared_data["intentos"].get()
        modo = self.controller.shared_data["modoEjecucion"]

        if (problema == "Tigre" or problema == "Recipientes"):
            try:
                budget = float(budget)
                try:
                    max_play = int(max_play)
                except ValueError:
                    max_play = 100
            except ValueError:
                budget = float('inf')
                try:
                    max_play = int(max_play)
                except ValueError:
                    max_play = 100
        elif (problema == "LaserTag" or problema == "Rocksample"):
            try:
                max_play = int(max_play)
                try:
                    budget = float(budget)
                except ValueError:
                    budget = float('inf')
            except ValueError:
                max_play = 100
                try:
                    budget = float(budget)
                except ValueError:
                    budget = float('inf')

        parser = argparse.ArgumentParser()

        parser.add_argument('--config', type=str, default=algoritmo)
        parser.add_argument('--env', type=str, default=problema + ".POMDP")
        parser.add_argument('--budget', type=float, default=budget)
        parser.add_argument('--snapshot', type=bool, default=False)
        parser.add_argument('--logfile', type=str, default=None)
        parser.add_argument('--random_prior', type=bool, default=False)
        parser.add_argument('--max_play', type=int, default=max_play)

        args = vars(parser.parse_args())
        params = RunnerParams(**args)

        with open(params.algo_config) as algo_config:
            algo_params = json.load(algo_config)
            runner = PomdpRunner(params)

            runner.run(modo, problema, **algo_params)

        self.controller.show_frame("PageThree")
Exemplo n.º 3
0
def tigrePomcpSilenciosa():
    print(
        "Has seleccionado ejecución silenciosa con POMCP para el Problema del Tigre"
    )

    params = RunnerParams("tiger.POMDP", None, "pomcp", float('inf'), 30,
                          False, False)

    with open(params.algo_config) as algo_config:
        algo_params = json.load(algo_config)
        runner = PomdpRunnerSilenciosa(params)
        runner.run(**algo_params)
Exemplo n.º 4
0
def puentePbviSilenciosa():
    print(
        "Has seleccionado ejecución silenciosa con PBVI para el Problema del Puente"
    )

    params = RunnerParams("puente.POMDP", None, "pbvi", float('inf'), 100,
                          False, False)

    with open(params.algo_config) as algo_config:
        algo_params = json.load(algo_config)
        runner = PomdpRunnerSilenciosa(params)
        runner.run(**algo_params)
Exemplo n.º 5
0
def puentePomcpInteractiva():
    print(
        "Has seleccionado ejecución interactiva con POMCP para el Problema del Puente"
    )

    params = RunnerParams("puente.POMDP", None, "pomcp", float('inf'), 10,
                          False, False)

    with open(params.algo_config) as algo_config:
        algo_params = json.load(algo_config)
        runner = PomdpRunnerInteractive(params)
        runner.run(**algo_params)
Exemplo n.º 6
0
def anuncioPbviInteractiva():
    print(
        "Has seleccionado ejecución interactiva con PBVI para el Problema de los anuncios"
    )

    params = RunnerParams("anuncios.POMDP", None, "pbvi", float('inf'), 10,
                          False, False)

    with open(params.algo_config) as algo_config:
        algo_params = json.load(algo_config)
        runner = PomdpRunnerInteractive(params)
        runner.run(**algo_params)
Exemplo n.º 7
0
def ejecuta():
    if __name__ == '__main__':
        fin = False
        while not fin:
            print("Seleccione un problema:")
            print("[1] - Tigre")
            print("[2] - LaserTag")
            print("[3] - Recipientes")
            print("[4] - Rocksample")
            opciones_problema = [1, 2, 3, 4]

            numero_correcto = False
            problema = ""
            while problema == "":
                num_problema = int(input())
                if num_problema in opciones_problema:
                    if num_problema == 1:
                        problema = "Tigre"
                        print("Problema seleccionado:", problema)
                    elif num_problema == 2:
                        problema = "LaserTag"
                        budget = float('inf')
                        print("Problema seleccionado:", problema)
                        num_intentos = float('inf')
                    elif num_problema == 3:
                        problema = "Recipientes"
                        print("Problema seleccionado:", problema)
                    else:
                        problema = "Rocksample"
                        budget = float('inf')
                        print("Problema seleccionado:", problema)

                    print("Maximo numero de intentos: ", end="")
                    max_play = input()
                    if max_play == "":
                        max_play = float('inf')
                    if problema == "Tigre" or problema == "Recipientes":
                        print("Maximo presupuesto: ", end="")
                        budget = input()
                        if budget == "":
                            budget = float('inf')
                else:
                    print(
                        "El número seleccionado no corresponde a ningún problema."
                    )

            opciones_algoritmo = ["pomcp", "pbvi"]
            algoritmo = ""
            while algoritmo == "":
                print("Seleccione un algoritmo resolvedor:")
                print("[1] - POMCP")
                print("[2] - PBVI")
                num_algoritmo = int(input())
                if num_algoritmo == 1:
                    algoritmo = "pomcp"
                    print("Algoritmo seleccionado:", algoritmo)
                elif num_algoritmo == 2:
                    algoritmo = "pbvi"
                    print("Algoritmo seleccionado:", algoritmo)
                else:
                    print(
                        "El número introducido no corresponde a ningún algoritmo."
                    )

            opciones_modo = [1, 2, 3]
            modo = ""
            while modo == "":
                print("Seleccione un modo de ejecución:")
                print("[1] - Interactivo")
                print("[2] - Silencioso")
                print("[3] - Benchmark")
                numModo = int(input())
                if numModo == 1:
                    modo = "Interactivo"
                    print("Modo de ejecución seleccionado:", modo)
                elif numModo == 2:
                    modo = "Silencioso"
                    print("Modo de ejecución seleccionado:", modo)
                elif numModo == 3:
                    modo = "Benchmark"
                    print("Modo de ejecución seleccionado:", modo)
                else:
                    print(
                        "El número introducido no corresponde a ningún modo de ejecución."
                    )
            fin = True

        parser = argparse.ArgumentParser()
        parser.add_argument('--config', type=str, default=algoritmo)
        parser.add_argument('--env', type=str, default=problema + ".POMDP")
        parser.add_argument('--budget', type=float, default=budget)
        parser.add_argument('--snapshot', type=bool, default=False)
        parser.add_argument('--logfile', type=str, default=None)
        parser.add_argument('--random_prior', type=bool, default=False)
        parser.add_argument('--max_play', type=int, default=max_play)

        args = vars(parser.parse_args())
        params = RunnerParams(**args)

        with open(params.algo_config) as algo_config:
            algo_params = json.load(algo_config)
            runner = PomdpRunner(params)

            runner.run(modo, problema, **algo_params)
Exemplo n.º 8
0
    )
    parser.add_argument('--max_play',
                        type=int,
                        default=1000,
                        help='Maximum number of play steps')
    #New argument
    parser.add_argument(
        '--benchmark',
        type=int,
        default=0,
        help=
        'Sets the simulation to benchmark type, if present, must be followed of either "1" or "True"'
    )

    args = vars(parser.parse_args())
    params = RunnerParams(**args)

    with open(params.algo_config) as algo_config:
        algo_params = json.load(algo_config)
        runner = PomdpRunner(params)
        #If interactive simulation is selected, the system will simulate only 1 simulation
        if params.benchmark == 0:
            runner.run(**algo_params)
        else:
            # If benchmark simulation is selected, the system will simulate provided simulations
            for i in range(params.benchmark):
                runner.runBench(**algo_params)

            #Showing final results
            log.info('\n'.join([
                '+' * 20, 'Results after ending {} simulations:'.format(