|
| 1 | +import numpy as np |
| 2 | + |
| 3 | +from gcaa.core.utility import MinimumCostAlongLoitering |
| 4 | + |
| 5 | + |
| 6 | +def test_minimum_cost_along_loitering_basic(): |
| 7 | + agent_pos = np.array([0.0, 0.0]) |
| 8 | + agent_va = np.array([0.0, 0.0]) |
| 9 | + |
| 10 | + task_pos = np.array([ |
| 11 | + [1.0, 1.0], |
| 12 | + [2.0, -1.0] |
| 13 | + ]) |
| 14 | + |
| 15 | + task_radius = np.array([0.5, 1.0]) |
| 16 | + task_tloiter = np.array([1.0, 2.0]) |
| 17 | + task_tf = np.array([5.0, 10.0]) |
| 18 | + kdrag = 0.1 |
| 19 | + j = 0 |
| 20 | + |
| 21 | + rin, vt, rho = MinimumCostAlongLoitering( |
| 22 | + agent_pos, |
| 23 | + agent_va, |
| 24 | + task_pos, |
| 25 | + task_radius, |
| 26 | + task_tloiter, |
| 27 | + task_tf, |
| 28 | + j, |
| 29 | + kdrag |
| 30 | + ) |
| 31 | + |
| 32 | + assert rin.shape == (2,) |
| 33 | + assert vt.shape == (2,) |
| 34 | + assert np.isfinite(rho) |
| 35 | + assert rho > 0 |
| 36 | + |
| 37 | + |
| 38 | +def test_minimum_cost_monotonic_radius(): |
| 39 | + agent_pos = np.array([0.0, 0.0]) |
| 40 | + agent_va = np.array([0.0, 0.0]) |
| 41 | + task_pos = np.array([[1.0, 0.0]]) |
| 42 | + task_tloiter = np.array([1.0]) |
| 43 | + task_tf = np.array([5.0]) |
| 44 | + kdrag = 0.1 |
| 45 | + j = 0 |
| 46 | + |
| 47 | + r_small = np.array([0.2]) |
| 48 | + r_large = np.array([2.0]) |
| 49 | + |
| 50 | + _, _, rho_small = MinimumCostAlongLoitering( |
| 51 | + agent_pos, agent_va, task_pos, |
| 52 | + r_small, task_tloiter, task_tf, j, kdrag |
| 53 | + ) |
| 54 | + _, _, rho_large = MinimumCostAlongLoitering( |
| 55 | + agent_pos, agent_va, task_pos, |
| 56 | + r_large, task_tloiter, task_tf, j, kdrag |
| 57 | + ) |
| 58 | + |
| 59 | + # Larger radius → longer loiter → higher cost |
| 60 | + assert rho_large > rho_small |
| 61 | + |
| 62 | + |
| 63 | +def test_minimum_cost_repeatability(): |
| 64 | + # Ensure deterministic behavior (no randomness) |
| 65 | + agent_pos = np.array([0.0, 0.0]) |
| 66 | + agent_va = np.array([0.0, 0.0]) |
| 67 | + task_pos = np.array([[0.5, 0.8]]) |
| 68 | + radius = np.array([1.0]) |
| 69 | + tloiter = np.array([1.2]) |
| 70 | + tf = np.array([4.0]) |
| 71 | + j = 0 |
| 72 | + kdrag = 0.2 |
| 73 | + |
| 74 | + r1 = MinimumCostAlongLoitering(agent_pos, agent_va, task_pos, |
| 75 | + radius, tloiter, tf, j, kdrag) |
| 76 | + r2 = MinimumCostAlongLoitering(agent_pos, agent_va, task_pos, |
| 77 | + radius, tloiter, tf, j, kdrag) |
| 78 | + |
| 79 | + assert np.allclose(r1[0], r2[0]) |
| 80 | + assert np.allclose(r1[1], r2[1]) |
| 81 | + assert np.isclose(r1[2], r2[2]) |
0 commit comments