示例#1
0
    def test_example_1(self, dispatch):
        import simulai

        # Step 0 - Definition of model frame

        frame = "Modelo"

        # Step 1- Definition of input variables

        espera = simulai.DiscreteVariable("Espera", 60, 300, 10,
                                          "Models." + frame + ".espera")
        stock = simulai.DiscreteVariable("Stock", 10, 50, 10,
                                         "Models." + frame + ".stock")
        numviajes = simulai.DiscreteVariable("Numero de viajes", 1, 5, 1,
                                             "Models." + frame + ".numviajes")

        var_input = [espera, stock, numviajes]

        # Step 2- Definition of output variables

        transportes = simulai.OutcomeVariable(
            "Distancia Transportes", "Models." + frame + ".transportes", 2, 9)
        buffers = simulai.OutcomeVariable("Llenado buffers",
                                          "Models." + frame + ".buffers", 3,
                                          20)
        salidas = simulai.OutcomeVariable("Espera en las Salidas",
                                          "Models." + frame + ".salidas", 2,
                                          20)

        var_output = [transportes, buffers, salidas]

        # Step 3- Choice of method, plant and simulation file.
        # Enter input variables and output variables.

        my_method = simulai.Qlearning(v_i=var_input,
                                      episodes_max=5,
                                      steps_max=10)
        my_plant = simulai.BasePlant(
            method=my_method,
            v_i=var_input,
            v_o=var_output,
            filename="MaterialHandling.spp",
            modelname=frame,
        )

        # Step 4- Run the simulation

        my_plant.process_simulation()
        print(my_method.r_episode)

        assert isinstance(my_method.r_episode, np.ndarray)
        assert my_method.r_episode.all() == 0
示例#2
0
    def test_ini_saq1(self, dispatch, com, espera, stock, numviajes):
        import simulai

        basem = simulai.Qlearning(v_i=[espera], episodes_max=1, steps_max=10)
        basem.ini_saq()

        assert isinstance(basem.Q, np.ndarray)
        assert isinstance(basem.S, np.ndarray)
        assert isinstance(basem.actions, np.ndarray)
        assert basem.Q.shape == (25, 3)
        assert basem.S.shape == (25,)
        assert basem.actions.shape == (3,)
        assert (basem.Q == 0).all()
        assert bool((basem.S == 0).all()) is False
        assert bool((basem.actions == 0).all()) is False

        with pytest.raises(Exception):
            basen = simulai.Qlearning(
                v_i=[espera, stock, numviajes, espera, stock],
                episodes_max=1,
                steps_max=10,
            )
            basen.ini_saq()
        with pytest.raises(Exception):
            basel = simulai.Qlearning(
                v_i=[
                    simulai.DiscreteVariable(
                        "Espera", 10, 10000, 1, "Models.Modelo.espera"
                    )
                ],
                episodes_max=1,
                steps_max=10,
            )
            basel.ini_saq()
示例#3
0
    def test_process_sarsa(
        self,
        dispatch,
        com,
        espera,
        stock,
        numviajes,
        transportes,
        buffers,
        salidas,
    ):
        import simulai

        pcss = simulai.Sarsa(
            v_i=[
                simulai.DiscreteVariable(
                    "Espera", 60, 300, 10, "Models.Modelo.espera"
                ),
                simulai.DiscreteVariable(
                    "Stock", 10, 50, 10, "Models.Modelo.stock"
                ),
                simulai.DiscreteVariable(
                    "Numero de viajes", 1, 5, 1, "Models.Modelo.numviajes"
                ),
            ],
            episodes_max=1,
            steps_max=10,
            seed=24,
        )
        b = simulai.BasePlant(
            method=pcss,
            v_i=[espera, stock, numviajes],
            v_o=[transportes, buffers, salidas],
            filename="MaterialHandling.spp",
            modelname="Model",
        )

        b.connection()

        r_episodes, s0, a0 = pcss.process()

        assert isinstance(r_episodes, np.ndarray), "Should be an array"
        assert isinstance(s0, np.ndarray), "Should be an array"
        assert a0 == 0
示例#4
0
    def test_discretevariable(self, dispatch, com, espera):
        import simulai

        parm = espera
        assert isinstance(parm.name, str), "Should be a string"
        assert isinstance(parm.lower_limit, int), "Should be an integer"
        assert isinstance(parm.upper_limit, int), "Should be an integer"
        assert isinstance(parm.step, int), "Should be an integer"
        assert isinstance(parm.path, str), "Should be a string"

        with pytest.raises(TypeError):
            simulai.DiscreteVariable(
                {"e": "Espera"}, 60, 300, 10, "Models.Modelo.espera"
            )
        with pytest.raises(TypeError):
            simulai.DiscreteVariable(
                "Espera", 60.0, 300, 10, "Models.Modelo.espera"
            )
        with pytest.raises(TypeError):
            simulai.DiscreteVariable(
                "Espera", 60, 300.0, 10, "Models.Modelo.espera"
            )
        with pytest.raises(TypeError):
            simulai.DiscreteVariable(
                "Espera", 60, 300, 10.0, "Models.Modelo.espera"
            )
        with pytest.raises(TypeError):
            simulai.DiscreteVariable("Espera", 60, 300, 10, False)

        with pytest.raises(ValueError):
            simulai.DiscreteVariable(
                "Espera", -60, 300, 10, "Models.Modelo.espera"
            )
        with pytest.raises(ValueError):
            simulai.DiscreteVariable(
                "Espera", 60, -300, 10, "Models.Modelo.espera"
            )
        with pytest.raises(ValueError):
            simulai.DiscreteVariable(
                "Espera", 60, 300, -10, "Models.Modelo.espera"
            )
示例#5
0
    def numviajes(self):
        import simulai

        return simulai.DiscreteVariable(
            "Numero de viajes", 1, 5, 1, "Models.Modelo.numviajes"
        )
示例#6
0
    def stock(self):
        import simulai

        return simulai.DiscreteVariable(
            "Stock", 10, 50, 10, "Models.Modelo.stock"
        )
示例#7
0
    def espera_stp60(self):
        import simulai

        return simulai.DiscreteVariable(
            "Espera", 60, 300, 60, "Models.Modelo.espera"
        )
示例#8
0
import simulai

# Step 0 - Definition of model frame

frame = "Modelo"

# Step 1- Definition of input variables

espera = simulai.DiscreteVariable("Espera", 60, 300, 10,
                                  "Models." + frame + ".espera")
stock = simulai.DiscreteVariable("Stock", 10, 50, 10,
                                 "Models." + frame + ".stock")
numviajes = simulai.DiscreteVariable("Numero de viajes", 1, 5, 1,
                                     "Models." + frame + ".numviajes")

var_input = [espera, stock, numviajes]

# Step 2- Definition of output variables

transportes = simulai.OutcomeVariable("Distancia Transportes",
                                      "Models." + frame + ".transportes", 2, 9)
buffers = simulai.OutcomeVariable("Llenado buffers",
                                  "Models." + frame + ".buffers", 3, 20)
salidas = simulai.OutcomeVariable("Espera en las Salidas",
                                  "Models." + frame + ".salidas", 2, 20)

var_output = [transportes, buffers, salidas]

# Step 3- Choice of method, plant and simulation file.
# Enter input variables and output variables.