def test_posAS2posTS(self): axes = (Axis("theta", -6.0, 0.0, 1.), Axis("theta_dot", -5.0, 0.0, 1.), Axis("x", -4.0, 0.0, 1.)) self.topologicalSpace = TopologicalSpace(*axes) pos_TS = [1, 3, 2] pos_AS = self.topologicalSpace.pos_TS2pos_AS(pos_TS) pos_TS_ans = tuple([np.array([val]) for val in pos_TS]) self.assertEqual(pos_TS_ans, self.topologicalSpace.pos_AS2pos_TS(pos_AS))
def test_get_boundary_condition(self): axes = (Axis("theta", -2.0, 2.0, 0.1), Axis("theta_dot", -1.0, 1.0, 0.1)) self.topologicalSpace = TopologicalSpace(*axes) self.model = SinglePendulum(0, 0, mass=0.6, length=2, drag=0.1) graph_center = ["theta", "theta_dot", [0, 0]] self.fuildSimulator = FuildSimulator(self.topologicalSpace, [0, 0], graph_center, [-1, 0, 1], 0, self.model, 0.001) self.fuildSimulator.get_boundary_condition()
def test_save_velcity_space(self): print("test_save_velcity_space") axes = (Axis("theta", -7.0, 7.0, 0.1), Axis("theta_dot", -7.0, 7.0, 0.1)) self.topologicalSpace = TopologicalSpace(*axes) self.model = SinglePendulum(0, 0, mass=0.6, length=2, drag=0.1) graph_center = ["theta", "theta_dot", [0, 0]] self.fuildSimulator = FuildSimulator(self.topologicalSpace, [1, 1], graph_center, [-1, 0, 1], 0, self.model, 0.00001) self.fuildSimulator.init_velocity_space(True)
def test_init_stochastic_matrix(self): axes = (Axis("theta", -7.0, 7.0, 0.1), Axis("theta_dot", -7.0, 7.0, 0.1)) self.topologicalSpace = TopologicalSpace(*axes) self.model = SinglePendulum(0, 0, mass=0.6, length=2, drag=0.1) graph_center = ["theta", "theta_dot", [0, 0]] self.fuildSimulator = FuildSimulator(self.topologicalSpace, [1, 1], graph_center, [-1, 0, 1], 0, self.model, 0.00001) self.fuildSimulator.init_velocity_space(False) self.fuildSimulator.init_stochastic_matrix(True) self.fuildSimulator.add_obstacle([-4., -2.], [-3., -1.5]) self.fuildSimulator.method1_5(100000, True)
from src.submodule.PhysicsSimulator.SinglePendulum.SinglePendulum import SinglePendulum import os import json init_dir = os.getcwd() num = 3 path = "./stochastic_matrix/SinglePendulum/stochastic_matrix" + str(num) os.chdir(path) with open('param.json', 'r') as json_file: json_data = json.load(json_file) os.chdir("../../../") axes_param_list = [ list(param_dict.values()) for param_dict in json_data["axes"] ] print(axes_param_list) axes = [Axis(*param) for param in axes_param_list] print(axes) t_s = TopologicalSpace(*axes) model = SinglePendulum(0, 0, **json_data["model_param"]) graph_center = ["theta", "theta_dot", [0, 0]] u_set = json_data["u_set"] moderate_u = json_data["moderate_u"] inputCalculator = FuildSimulator(t_s, [0, 0], graph_center, [-1, 0, 1], 0, model, json_data["delta_t"]) inputCalculator.load_stochastic_matrix(num) # inputCalculator.init_eye() # inputCalculator.method1() inputCalculator.method2(0.0024, 10000, True)
def test_init(self): axes = (Axis("theta", -1.0, 0.0, 1.), Axis("theta_dot", -1.0, 0.0, 1.), Axis("x", -2.0, 0.0, 1.)) self.topologicalSpace = TopologicalSpace(*axes) print(len(self.topologicalSpace.astablishment_space)) print(self.topologicalSpace.astablishment_space)
from unittest import TestCase from src.TimeToPosition import TimeToPosition from src.TopologicalSpace import TopologicalSpace from src.Axis import Axis import numpy as np axes = (Axis("theta", -10.0, 10.0, 0.01), Axis("theta_dot", -10.0, 10.0, 0.01)) t_s = TopologicalSpace(*axes) graph_center = ["theta", "theta_dot", [0, 0]] d = 1. u_set = np.arange(-2., 2. + d, d).tolist() moderate_u = 0 inputCalculator = TimeToPosition(t_s, (0, 0), graph_center, u_set, moderate_u) inputCalculator.method3()
from unittest import TestCase from src.TopologicalSpace import TopologicalSpace from src.Axis import Axis import numpy as np axes = (Axis("theta", -1.0, 7.0, 0.1), Axis("theta_dot", -7.0, 7.0, 0.1)) topologicalSpace = TopologicalSpace(*axes) print(topologicalSpace.astablishment_space) stochastic_matrix = topologicalSpace.stochastic_matrix(0) # for lists in stochastic_matrix: # print(lists) print("stochastic_matrix_5") stochastic_matrix_5 = np.linalg.matrix_power(stochastic_matrix, 5) for lists in stochastic_matrix_5: print(lists) coodinate = [1, 3] topologicalSpace.write_val(coodinate, 1.2) print(topologicalSpace.get_val(coodinate))
from unittest import TestCase from src.InputCalculator import InputCalculator from src.TopologicalSpace import TopologicalSpace from src.Axis import Axis import numpy as np axes = (Axis("theta", -1.0, 7.0, 0.1), Axis("theta_dot", -10.0, 10.0, 0.05)) t_s = TopologicalSpace(*axes) graph_center = ["theta", "theta_dot", [0, 0]] d = 1. u_set = np.arange(-2., 2. + d, d).tolist() moderate_u = 0 inputCalculator = InputCalculator(t_s, (0, 0), graph_center, u_set, moderate_u) inputCalculator.init_stochastic_matrix(True) inputCalculator.init_eye() inputCalculator.method1() # inputCalculator.method2(0.024, 100) # inputCalculator.update_astablishment_space() # inputCalculator.t_s.show_plot("theta", "theta_dot", [0, 0]) # while(True): # for i in range(1000): # inputCalculator.simulate() # inputCalculator.update_astablishment_space() # inputCalculator.t_s.show_plot("theta", "theta_dot", [0, 0]) # print(inputCalculator._simulate_time)
from unittest import TestCase from src.Axis import Axis axis = Axis("test", 0.0, 10.2, 0.3) print(axis.name) print(axis.elements) print(axis.num2val(3)) print(axis.val2num(0.5)) axis.check_num_range(len(axis.elements))