Пример #1
0
def test_generate_instance(instance_generator):
    """Use stateless instance generating function."""
    if isinstance(instance_generator, ecole.instance.FileGenerator):
        pytest.skip("No generate_instance for file loaders")
    InstanceGenerator = type(instance_generator)
    model = InstanceGenerator.generate_instance(
        random_engine=ecole.RandomEngine())
    assert isinstance(model, ecole.scip.Model)
Пример #2
0
def test_RandomEngine():
    """Test bindings of the RandomEngine."""
    assert ecole.RandomEngine.min_seed < ecole.RandomEngine.max_seed
    random_engine = ecole.RandomEngine(42)
    rand_val_1 = random_engine()
    assert isinstance(rand_val_1, int)

    random_engine.seed(42)
    rand_val_2 = random_engine()
    assert rand_val_1 == rand_val_2
Пример #3
0
def test_RandomEngine_copy():
    """Copy create a new RandomEngine with same state."""
    random_engine = ecole.RandomEngine(42)

    random_engine_copy = copy.copy(random_engine)
    assert random_engine_copy == random_engine
    assert random_engine_copy is not random_engine

    random_engine_deepcopy = copy.deepcopy(random_engine)
    assert random_engine_deepcopy == random_engine
    assert random_engine_deepcopy is not random_engine
Пример #4
0
def test_seed():
    """Random engine is consumed."""
    env = MockEnvironment()
    env.seed(33)
    assert env.random_engine == ecole.RandomEngine(33)
Пример #5
0
def test_generate_instance(instance_generator):
    """Use stateless instance generating function."""
    InstanceGenerator = type(instance_generator)
    model = InstanceGenerator.generate_instance(
        random_engine=ecole.RandomEngine())
    assert isinstance(model, ecole.scip.Model)
Пример #6
0
def test_random_engine_init(instance_generator):
    """Construct a random engine."""
    type(instance_generator)(random_engine=ecole.RandomEngine())
Пример #7
0
def test_RandomEngine_pickle():
    """Pickle preserve the state of the RandomEngine."""
    random_engine = ecole.RandomEngine(42)
    assert random_engine == pickle.loads(pickle.dumps(random_engine))
Пример #8
0
 def test_set_random_state(self, model):
     """Random engine is consumed."""
     random_engine = ecole.RandomEngine(33)
     self.dynamics.set_dynamics_random_state(model, random_engine)
     assert random_engine != ecole.RandomEngine(33)
Пример #9
0
def test_random_engine_init(instance_generator):
    """Construct a random engine."""
    if isinstance(instance_generator, ecole.instance.FileGenerator):
        pytest.skip("No dataset in default directory")
    type(instance_generator)(random_engine=ecole.RandomEngine())