コード例 #1
0
 def test_init(self):
     bench = SigmoidBenchmark()
     bench.set_action_values((3, ))
     env = bench.get_environment()
     wrapped = PolicyProgressWrapper(env, compute_optimal_sigmoid)
     self.assertTrue(len(wrapped.policy_progress) == 0)
     self.assertTrue(len(wrapped.episode) == 0)
     self.assertFalse(wrapped.compute_optimal is None)
コード例 #2
0
def make_sigmoid(config):
    bench = SigmoidBenchmark()
    for k in config.keys():
        if k == "action_values":
            bench.set_action_values(config[k])
        else:
            bench.config[k] = config[k]
    return bench.get_environment()
コード例 #3
0
    def test_read_instances(self):
        bench = SigmoidBenchmark()
        bench.read_instance_set()
        self.assertTrue(len(bench.config.instance_set.keys()) == 300)
        self.assertTrue(len(bench.config.instance_set[0]) == 4)
        first_inst = bench.config.instance_set[0]

        bench2 = SigmoidBenchmark()
        env = bench2.get_environment()
        self.assertTrue(len(env.instance_set[0]) == 4)
        self.assertTrue(env.instance_set[0] == first_inst)
        self.assertTrue(len(env.instance_set.keys()) == 300)
コード例 #4
0
 def test_render(self, mock_plt):
     bench = SigmoidBenchmark()
     bench.set_action_values((3, ))
     env = bench.get_environment()
     env = PolicyProgressWrapper(env, compute_optimal_sigmoid)
     for _ in range(2):
         done = False
         env.reset()
         while not done:
             _, _, done, _ = env.step(1)
     env.render_policy_progress()
     self.assertTrue(mock_plt.show.called)
コード例 #5
0
 def test_read_instances(self):
     bench = SigmoidBenchmark()
     bench.read_instance_set()
     self.assertTrue(len(bench.config.instance_set) == 100)
     self.assertTrue(len(bench.config.instance_set[0]) == 2)
     self.assertTrue(bench.config.instance_set[0] ==
                     [2.0004403531465558, 7.903476325943215])
     bench2 = SigmoidBenchmark()
     env = bench2.get_environment()
     self.assertTrue(len(env.instance_set[0]) == 2)
     self.assertTrue(
         env.instance_set[0] == [2.0004403531465558, 7.903476325943215])
     self.assertTrue(len(env.instance_set) == 100)
コード例 #6
0
    def test_step(self):
        bench = SigmoidBenchmark()
        bench.set_action_values((3, ))
        bench.config.instance_set = [[0, 0], [1, 1], [3, 4], [5, 6]]
        env = bench.get_environment()
        wrapped = PolicyProgressWrapper(env, compute_optimal_sigmoid)

        wrapped.reset()
        _, _, done, _ = wrapped.step(1)
        self.assertTrue(len(wrapped.episode) == 1)
        while not done:
            _, _, done, _ = wrapped.step(1)
        self.assertTrue(len(wrapped.episode) == 0)
        self.assertTrue(len(wrapped.policy_progress) == 1)
コード例 #7
0
 def test_scenarios(self):
     scenarios = [
         "sigmoid_1D3M.json",
         "sigmoid_2D3M.json",
         "sigmoid_3D3M.json",
         "sigmoid_5D3M.json",
     ]
     for s in scenarios:
         path = os.path.join("dacbench/additional_configs/sigmoid", s)
         bench = SigmoidBenchmark(path)
         self.assertTrue(bench.config is not None)
         env = bench.get_environment()
         state = env.reset()
         self.assertTrue(state is not None)
         state, _, _, _ = env.step(0)
         self.assertTrue(state is not None)
コード例 #8
0
# Helper method to print current set


def print_instance_set(instance_set):
    c = 1
    for i in instance_set:
        print(f"Instance {c}: {i[0]}, {i[1]}")
        c += 1


# Make Sigmoid benchmark
bench = SigmoidBenchmark()
bench.set_action_values([3])

# First example: read instances from default instance set path
instances_from_file = bench.get_environment()
print("Instance set read from file")
print_instance_set(instances_from_file.instance_set)
print("\n")

# Second example: Sample instance set before training
instance_set = sample_instance(20)
bench.config.instance_set = instance_set
instances_sampled_beforehand = bench.get_environment()
print("Instance set sampled before env creation")
print_instance_set(instances_sampled_beforehand.instance_set)
print("\n")

# Third example: Sample instances during training using the InstanceSamplingWrapper
print("Instance sampled each reset")
instances_on_the_fly = InstanceSamplingWrapper(
コード例 #9
0
 def test_get_env(self):
     bench = SigmoidBenchmark()
     env = bench.get_environment()
     self.assertTrue(issubclass(type(env), SigmoidEnv))