1616from __future__ import annotations
1717
1818import numpy as np
19- from absl .testing import absltest
19+ from absl .testing import absltest , parameterized
2020
2121import envpool .jumanji .registration # noqa: F401
2222from envpool .registration import make_gymnasium
2323
2424
25- class JumanjiCVRPTest (absltest .TestCase ):
25+ class JumanjiCVRPTest (parameterized .TestCase ):
2626 """Checks native CVRP transitions."""
2727
28- def test_visit_customer_and_return_to_depot (self ) -> None :
28+ @parameterized .parameters (3 , 20 , 30 )
29+ def test_visit_customer_and_return_to_depot (self , capacity : int ) -> None :
2930 """Checks visiting a customer then returning to depot."""
3031 env = make_gymnasium (
31- "CVRP-v1" , num_envs = 1 , seed = 0 , render_mode = "rgb_array"
32+ "CVRP-v1" ,
33+ num_envs = 1 ,
34+ seed = 0 ,
35+ cvrp_max_capacity = capacity ,
36+ render_mode = "rgb_array" ,
3237 )
3338 try :
3439 obs , _ = env .reset ()
@@ -37,6 +42,7 @@ def test_visit_customer_and_return_to_depot(self) -> None:
3742 self .assertTrue (bool (obs ["action_mask" ][0 , 1 ]))
3843 self .assertAlmostEqual (float (obs ["coordinates" ][0 , 1 , 0 ]), 0.05 )
3944 self .assertAlmostEqual (float (obs ["capacity" ][0 ]), 1.0 )
45+ self .assertAlmostEqual (float (obs ["demands" ][0 , 1 ]), 1 / capacity )
4046
4147 obs , reward , terminated , truncated , _ = env .step (
4248 np .asarray ([1 ], dtype = np .int32 )
@@ -48,7 +54,9 @@ def test_visit_customer_and_return_to_depot(self) -> None:
4854 self .assertFalse (bool (obs ["unvisited_nodes" ][0 , 1 ]))
4955 self .assertFalse (bool (obs ["action_mask" ][0 , 1 ]))
5056 self .assertTrue (bool (obs ["action_mask" ][0 , 0 ]))
51- self .assertAlmostEqual (float (obs ["capacity" ][0 ]), 0.95 , places = 6 )
57+ self .assertAlmostEqual (
58+ float (obs ["capacity" ][0 ]), (capacity - 1 ) / capacity , places = 6
59+ )
5260 self .assertEqual (int (obs ["trajectory" ][0 , 0 ]), 0 )
5361 self .assertEqual (int (obs ["trajectory" ][0 , 1 ]), 1 )
5462
0 commit comments