def compute_simulations_mt(milp_ce, z3_ce): vs = 20 step = 0.000001 closed1_a_matrix = np.array([[0, -21052.6316, 0, 0], [42105.2632, -40100.2506, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]], dtype=float) closed1_c_vector = np.array([21052.6316 * vs, 0 * vs, 1, 1], dtype=float) open1_a_matrix = np.array([[0, -21052.6316, 0, 0], [42105.2632, -40100.2506, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]], dtype=float) open1_c_vector = np.array([0 * vs, 0 * vs, 1, 1], dtype=float) milp_simulation_1 = compute_simulation(milp_ce, closed1_a_matrix, closed1_c_vector, step, 0.000022 / step) init_state_in_open1 = milp_simulation_1[len(milp_simulation_1) - 1] milp_simulation_2 = compute_simulation(init_state_in_open1, open1_a_matrix, open1_c_vector, step, 0.000029 / step) z3_simulation_1 = compute_simulation(z3_ce, closed1_a_matrix, closed1_c_vector, step, 0.000022 / step) init_state_in_open1 = z3_simulation_1[len(z3_simulation_1) - 1] z3_simulation_2 = compute_simulation(init_state_in_open1, open1_a_matrix, open1_c_vector, step, 0.000029 / step) with open("simulation", 'w') as f: f.write('milp_simulation = [') for point in milp_simulation_1: f.write('{},{};\n'.format(str(point[0]), str(point[1]))) for point in milp_simulation_2: f.write('{},{};\n'.format(str(point[0]), str(point[1]))) f.write('];\n') f.write('z3_simulation = [') for point in z3_simulation_1: f.write('{},{};\n'.format(str(point[0]), str(point[1]))) for point in z3_simulation_2: f.write('{},{};\n'.format(str(point[0]), str(point[1]))) f.write('];\n')
def compute_simulation_mt(longest_ce, deepest_ce): a_matrix = np.array([[0, -1, 1, 0, 0], [0, -0.02, 0, 1, 0], [0, 0, 0, 0, 0], [0, -2, 2, -2, 0], [0, 0, 0, 0, 0]]) c_vector = np.array([0, 0, 0, 0, 1], dtype=float) longest_ce_simulation = compute_simulation(longest_ce, a_matrix, c_vector, 0.2, 100) deepest_ce_simulation = compute_simulation(deepest_ce, a_matrix, c_vector, 0.2, 100) with open("simulation", 'w') as f: f.write('longest_simulation = [') t = 0.0 for point in longest_ce_simulation: f.write('{},{};\n'.format(str(point[0]), str(point[1]))) t = t + 0.2 f.write(']') f.write('\n**************************************\n') f.write('deepest_simulation = [') t = 0.0 for point in deepest_ce_simulation: f.write('{},{};\n'.format(point[0], str(point[1]))) t = t + 0.2 f.write(']')
def compute_simulation_py(longest_ce, deepest_ce): step = 0.08 max_time = 4.0 loc3_a_matrix = np.array( [[-2, 0, 0, 0, 0, 0], [0, -1, 0, 0, 0, 0], [5, 0, -5, 0, 0, 0], [0, 0, 5, -5, 0, 0], [0, 0, 0, 5, -5, 0], [0, 0, 0, 0, 5, -5]], dtype=float) loc3_c_vector = np.array([1.4, -0.7, 0, 0, 0, 0], dtype=float) deepest_simulation = compute_simulation(deepest_ce, loc3_a_matrix, loc3_c_vector, step, step * 16 / step) longest_simulation = compute_simulation(longest_ce, loc3_a_matrix, loc3_c_vector, step, step * 16 / step) sim_t = np.array(deepest_simulation).T plt.plot(sim_t[1], sim_t[5], 'g-') sim_t = np.array(longest_simulation).T plt.plot(sim_t[1], sim_t[5], 'r-') init_state_in_loc4 = deepest_simulation[len(deepest_simulation) - 1] loc4_a_matrix = np.array( [[-2, 0, 0, 0, 0, 0], [0, -1, 0, 0, 0, 0], [5, 0, -5, 0, 0, 0], [0, 0, 5, -5, 0, 0], [0, 0, 0, 5, -5, 0], [0, 0, 0, 0, 5, -5]], dtype=float) loc4_c_vector = np.array([-1.4, 0.7, 0, 0, 0, 0], dtype=float) deepest_simulation = compute_simulation(init_state_in_loc4, loc4_a_matrix, loc4_c_vector, step, step * 5 / step) sim_t = np.array(deepest_simulation).T plt.plot(sim_t[1], sim_t[5], 'g-') init_state_in_loc4 = longest_simulation[len(longest_simulation) - 1] longest_simulation = compute_simulation(init_state_in_loc4, loc4_a_matrix, loc4_c_vector, step, step * 5 / step) sim_t = np.array(longest_simulation).T plt.plot(sim_t[1], sim_t[5], 'r-') loc2_a_matrix = np.array( [[-2, 0, 0, 0, 0, 0], [0, -1, 0, 0, 0, 0], [5, 0, -5, 0, 0, 0], [0, 0, 5, -5, 0, 0], [0, 0, 0, 5, -5, 0], [0, 0, 0, 0, 5, -5]], dtype=float) loc2_c_vector = np.array([-1.4, 0.7, 0, 0, 0, 0], dtype=float) init_state_in_loc2 = deepest_simulation[len(deepest_simulation) - 1] deepest_simulation = compute_simulation(init_state_in_loc2, loc2_a_matrix, loc2_c_vector, step, step * 16 / step) sim_t = np.array(deepest_simulation).T plt.plot(sim_t[1], sim_t[5], 'g-') plt.show()
def compute_simulation_mt(milp_ce, z3_ce): a_matrix = np.array([[-0.1, 1], [-1, -0.1]]) c_vector = np.array([0, 0], dtype=float) milp_ce_simulation = compute_simulation(milp_ce, a_matrix, c_vector, 0.2, 100) z3_ce_simulation = compute_simulation(z3_ce, a_matrix, c_vector, 0.2, 100) with open("simulation", 'w') as f: f.write('milp_simulation = [') for point in milp_ce_simulation: f.write('{},{};\n'.format(str(point[0]), str(point[1]))) f.write(']') f.write('\n**************************************\n') f.write('z3_simulation = [') for point in z3_ce_simulation: f.write('{},{};\n'.format(point[0], str(point[1]))) f.write(']')
def compute_simulation_py(longest_ce, deepest_ce, robust_ce): vs = 20 step = 0.000001 closed1_a_matrix = np.array([[0, -21052.6316, 0, 0], [42105.2632, -40100.2506, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]], dtype=float) closed1_c_vector = np.array([21052.6316 * vs, 0 * vs, 1, 1], dtype=float) open1_a_matrix = np.array([[0, -21052.6316, 0, 0], [42105.2632, -40100.2506, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]], dtype=float) open1_c_vector = np.array([0 * vs, 0 * vs, 1, 1], dtype=float) simulation = compute_simulation(longest_ce, closed1_a_matrix, closed1_c_vector, step, 0.000022 / step) sim_t = np.array(simulation).T plt.plot(sim_t[1], sim_t[0], 'r-') init_state_in_open1 = simulation[len(simulation) - 1] simulation = compute_simulation(init_state_in_open1, open1_a_matrix, open1_c_vector, step, 0.000029 / step) sim_t = np.array(simulation).T plt.plot(sim_t[1], sim_t[0], 'r-') simulation = compute_simulation(deepest_ce, closed1_a_matrix, closed1_c_vector, step, 0.000022 / step) sim_t = np.array(simulation).T plt.plot(sim_t[1], sim_t[0], 'g-') init_state_in_open1 = simulation[len(simulation) - 1] simulation = compute_simulation(init_state_in_open1, open1_a_matrix, open1_c_vector, step, 0.000029 / step) sim_t = np.array(simulation).T plt.plot(sim_t[1], sim_t[0], 'g-') simulation = compute_simulation(robust_ce, closed1_a_matrix, closed1_c_vector, step, 0.000022 / step) sim_t = np.array(simulation).T plt.plot(sim_t[1], sim_t[0], 'b-') init_state_in_open1 = simulation[len(simulation) - 1] simulation = compute_simulation(init_state_in_open1, open1_a_matrix, open1_c_vector, step, 0.000029 / step) sim_t = np.array(simulation).T plt.plot(sim_t[1], sim_t[0], 'b-')
def compute_simulation_mt(longest_ce, deepest_ce = None): a_matrix = np.array([[0, -1, 1, 0, 0], [0, 0, 0, 1, 0], [0, 0, 0, 0, 0], [1, -4, 3, -1.2, 0], [0, 0, 0, 0, 0]]) c_vector = np.array([0, 0, 0, -10, 1], dtype=float) longest_ce_simulation = compute_simulation(longest_ce, a_matrix, c_vector, 0.1, 200) deepest_ce_simulation = compute_simulation(deepest_ce, a_matrix, c_vector, 0.1, 200) with open("simulation", 'w') as f: f.write(' Unsafe longest_simulation = [') t = 0.0 for point in longest_ce_simulation: f.write('{},{};\n'.format(str(point[4]), str(point[1]))) t = t + 0.1 f.write('];') f.write('\n**************************************\n') f.write('deepest_simulation = [') t = 0.0 for point in deepest_ce_simulation: f.write('{},{};\n'.format(point[4], str(point[1]))) t = t + 0.1 f.write('];')
def compute_simulation_mt(smt_ce, milp_ce=None): a_matrix = np.array([[-0.1, -1, 0], [1, -0.1, 0], [0, 0, -0.15]]) c_vector = np.array([0, 0, 0], dtype=float) smt_ce_simulation = compute_simulation(smt_ce, a_matrix, c_vector, 0.1, 200) milp_ce_simulation = compute_simulation(milp_ce, a_matrix, c_vector, 0.1, 200) with open("simulation", 'w') as f: f.write(' SMT_simulation = [') t = 0.0 for point in smt_ce_simulation: f.write('{},{};\n'.format(str(point[0]), str(point[2]))) t = t + 0.1 f.write('];') f.write('\n**************************************\n') f.write('MILP_simulation = [') t = 0.0 for point in milp_ce_simulation: f.write('{},{};\n'.format(str(point[0]), str(point[2]))) t = t + 0.1 f.write('];')
def compute_simulation_mt(counter_exs): a_matrix = np.array([[-0.1, 1], [-1, -0.1]]) c_vector = np.array([1, 0], dtype=float) with open("simulation", 'w') as f: for idx in range(len(counter_exs)): counter_ex = counter_exs[idx] # each counter_ex can have different ce's for different paths ce = np.array(counter_ex[0]) # Take the one for the first path print(ce) ce_simulation = compute_simulation(ce, [a_matrix], [c_vector], [15], 0.2) ce_name = 'simulation' + str(idx) + "[" f.write(ce_name) for point in ce_simulation: f.write('{},{};\n'.format(str(point[0]), str(point[1]))) f.write(']') f.write('\n**************************************\n')
b_matrices = [] c_vectors = [] max_steps = [] step_inputs = [] for idx in range(n_locations): step_input = ast.literal_eval(lines[l_idx]) step_inputs.append(step_input) l_idx += 1 a_matrices.append(a_matrix) b_matrices.append(b_matrix) c_vector = np.matmul(b_matrix, step_input) c_vector[dim - 1] = step_size # print(c_vector) c_vectors.append(c_vector) max_steps.append(1) init_rect = ast.literal_eval(lines[l_idx]) last_pair = (0.0, 0.0) init_rect.append(last_pair) print(init_rect) l_idx += 1 ref_simulation = np.array(compute_simulation(ref_state, a_matrices, c_vectors, max_steps, 1, disc_dyn=True)) print(ref_simulation) # sim_t = np.array(ref_simulation).T # plt.plot(sim_t[0], sim_t[1], 'b', linestyle='--') # plt.show() init_r = HyperRectangle(init_rect) pv_object = run_hylaa(settings, init_r, None, ref_simulation, step_inputs, k_matrix, a_matrices, b_matrices)
def compute_simulation_py(robust_ce, longest_ce): cap_d = 0.4 cap_t = 0.000025 L = 0.00008 # L = 80*10e-6 one_by_L = 12500 one_by_L_by_3 = 4166.67 R = 30 one_by_C = 1000000 # C = 1e-6 one_by_RC = 33333.33 v_in = 100 # u step = 0.000001 loc1_a_matrix = np.array( [[0, 0, 0, 0, 0], [0, 0, -one_by_L, 0, 0], [0, one_by_C, -one_by_RC, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]], dtype=float) loc1_c_vector = np.array([one_by_L * v_in, L * v_in, 0, 0, 1], dtype=float) robust_simulation = compute_simulation(robust_ce, loc1_a_matrix, loc1_c_vector, step, step * 11 / step) sim_t = np.array(robust_simulation).T plt.plot(sim_t[1], sim_t[2], 'r--', linewidth='2') init_state_in_loc2 = robust_simulation[len(robust_simulation) - 1] loc2_a_matrix = np.array( [[0, 0, 0, 0, 0], [0, 0, -one_by_L, 0, 0], [0, one_by_C, -one_by_RC, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]], dtype=float) loc2_c_vector = np.array([-one_by_L_by_3, 0, 0, 0, 1], dtype=float) robust_simulation = compute_simulation(init_state_in_loc2, loc2_a_matrix, loc2_c_vector, step, step * 5 / step) sim_t = np.array(robust_simulation).T plt.plot(sim_t[1], sim_t[2], 'r--', linewidth='2') init_state_in_loc5 = robust_simulation[len(robust_simulation) - 1] loc5_a_matrix = np.array( [[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, -one_by_RC, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]], dtype=float) loc5_c_vector = np.array([-one_by_L_by_3, 0, 0, 0, 1], dtype=float) robust_simulation = compute_simulation(init_state_in_loc5, loc5_a_matrix, loc5_c_vector, step, step * 2 / step) sim_t = np.array(robust_simulation).T plt.plot(sim_t[1], sim_t[2], 'r--', linewidth='2') longest_simulation = compute_simulation(longest_ce, loc1_a_matrix, loc1_c_vector, step, step * 11 / step) sim_t = np.array(longest_simulation).T plt.plot(sim_t[1], sim_t[2], 'b--', linewidth='2') init_state_in_loc2 = longest_simulation[len(longest_simulation) - 1] longest_simulation = compute_simulation(init_state_in_loc2, loc2_a_matrix, loc2_c_vector, step, step * 5 / step) sim_t = np.array(longest_simulation).T plt.plot(sim_t[1], sim_t[2], 'b--', linewidth='2') init_state_in_loc5 = longest_simulation[len(longest_simulation) - 1] longest_simulation = compute_simulation(init_state_in_loc5, loc5_a_matrix, loc5_c_vector, step, step * 2 / step) sim_t = np.array(longest_simulation).T plt.plot(sim_t[1], sim_t[2], 'b--', linewidth='2') plt.show()
def compute_simulation_py(longest_ce, deepest_ce, robust_ce): step = 0.02 a_matrix = np.array([[0.0, 1.0], [-100.0, -4.0]], dtype=float) c_vector = np.array([0.0, -9.81], dtype=float) deepest_simulation = compute_simulation(deepest_ce, a_matrix, c_vector, step, 0.2 / step) longest_simulation = compute_simulation(longest_ce, a_matrix, c_vector, step, 0.2 / step) robust_simulation = compute_simulation(robust_ce, a_matrix, c_vector, step, 0.2 / step) sim_t = np.array(deepest_simulation).T deepest_ce_handle = plt.plot(sim_t[0], sim_t[1], 'g', label='Deepest Counterexample=[-0.99, 0.15]', linestyle='--', linewidth='2') sim_t = np.array(longest_simulation).T longest_ce_handle = plt.plot(sim_t[0], sim_t[1], 'r', label='Longest Counterexample=[-1.05, -0.15]', linestyle='-.', linewidth='2') sim_t = np.array(robust_simulation).T robust_ce_handle = plt.plot(sim_t[0], sim_t[1], 'b', label='Robust Counterexample=[-1.026, 0.0]', linestyle='--', linewidth='2') init_state_in_freefall = deepest_simulation[len(deepest_simulation) - 1] a_matrix = np.array([[0.0, 1.0], [0.0, 0.0]], dtype=float) c_vector = np.array([0.0, -9.81], dtype=float) deepest_simulation = compute_simulation(init_state_in_freefall, a_matrix, c_vector, step, 0.2 / step) sim_t = np.array(deepest_simulation).T plt.plot(sim_t[0], sim_t[1], 'g', linestyle='--') init_state_in_freefall = longest_simulation[len(longest_simulation) - 1] a_matrix = np.array([[0.0, 1.0], [0.0, 0.0]], dtype=float) c_vector = np.array([0.0, -9.81], dtype=float) longest_simulation = compute_simulation(init_state_in_freefall, a_matrix, c_vector, step, 0.2 / step) sim_t = np.array(longest_simulation).T plt.plot(sim_t[0], sim_t[1], 'r', linestyle='-.') init_state_in_freefall = robust_simulation[len(robust_simulation) - 1] a_matrix = np.array([[0.0, 1.0], [0.0, 0.0]], dtype=float) c_vector = np.array([0.0, -9.81], dtype=float) robust_simulation = compute_simulation(init_state_in_freefall, a_matrix, c_vector, step, 0.2 / step) sim_t = np.array(robust_simulation).T plt.plot(sim_t[0], sim_t[1], 'b', linestyle='--') usafe_vertices = np.array([[-0.5, 5], [0.5, 5], [0.5, 6.2], [-0.5, 6.2], [-0.5, 5]]) usafe_region_handle = plt.plot( usafe_vertices.T[0], usafe_vertices.T[1], label='Unsafe Region=([-0.5,0.5],[5.0,6.2])', linestyle='--', linewidth='3', color='crimson') plt.legend(handles=[ longest_ce_handle[0], deepest_ce_handle[0], robust_ce_handle[0], usafe_region_handle[0] ]) plt.show()