Пример #1
0
def build_tiny_block_with_objects():
    """Build an empty block."""
    b = tiny_block()
    b.x = build_variable()
    b.c = constraint()
    b.o = objective()
    return b
Пример #2
0
def _get_tiny_block():
    b = tiny_block()
    b.x1 = variable(domain_type=None, lb=None, ub=None)
    b.x2 = variable(domain_type=None, lb=None, ub=None)
    b.x3 = variable(domain_type=None, lb=None, ub=None)
    b.x4 = variable(domain_type=None, lb=None, ub=None)
    b.x5 = variable(domain_type=None, lb=None, ub=None)
    b.x6 = variable(domain_type=None, lb=None, ub=None)
    b.x7 = variable(domain_type=None, lb=None, ub=None)
    b.x8 = variable(domain_type=None, lb=None, ub=None)
    return b
Пример #3
0
def _get_tiny_block_wstaticvars():
    myvar = _staticvariable
    b = tiny_block()
    b.x1 = myvar()
    b.x2 = myvar()
    b.x3 = myvar()
    b.x4 = myvar()
    b.x5 = myvar()
    b.x6 = myvar()
    b.x7 = myvar()
    b.x8 = myvar()
    return b
Пример #4
0
    def _generate_model(self):
        self.model = pmo.block()
        model = self.model
        model._name = self.description

        model.s = [1,2]

        model.x_unused = pmo.variable(domain=pmo.Integers)
        model.x_unused.stale = False

        model.x_unused_initialy_stale = pmo.variable(domain=pmo.Integers)
        model.x_unused_initialy_stale.stale = True

        model.X_unused = pmo.create_variable_dict(keys=model.s,
                                                  domain=pmo.Integers)
        model.X_unused_initialy_stale = \
            pmo.create_variable_dict(keys=model.s,
                                     domain=pmo.Integers)
        for i in model.s:
            model.X_unused[i].stale = False
            model.X_unused_initialy_stale[i].stale = True

        model.x = pmo.variable(domain=pmo.IntegerInterval(bounds=(None,None)))
        model.x.stale = False

        model.x_initialy_stale = pmo.variable(domain=pmo.Integers)
        model.x_initialy_stale.stale = True

        model.X = pmo.create_variable_dict(keys=model.s,
                                           domain=pmo.Integers)
        model.X_initialy_stale = pmo.create_variable_dict(keys=model.s,
                                                          domain=pmo.Integers)
        for i in model.s:
            model.X[i].stale = False
            model.X_initialy_stale[i].stale = True

        model.obj = pmo.objective(model.x + \
                                  model.x_initialy_stale + \
                                  sum(model.X.values()) + \
                                  sum(model.X_initialy_stale.values()))

        model.c = pmo.constraint_dict()
        model.c[1] = pmo.constraint(model.x          >= 1)
        model.c[2] = pmo.constraint(model.x_initialy_stale    >= 1)
        model.c[3] = pmo.constraint(model.X[1]       >= 0)
        model.c[4] = pmo.constraint(model.X[2]       >= 1)
        model.c[5] = pmo.constraint(model.X_initialy_stale[1] >= 0)
        model.c[6] = pmo.constraint(model.X_initialy_stale[2] >= 1)

        # Test that stale flags do not get updated
        # on inactive blocks (where "inactive blocks" mean blocks
        # that do NOT follow a path of all active parent blocks
        # up to the top-level model)
        flat_model = model.clone()
        model.b = pmo.block()
        model.B = pmo.block_dict()
        model.b.b = flat_model.clone()
        model.B[1] = pmo.tiny_block()
        model.B[1].b = flat_model.clone()
        model.B[2] = pmo.tiny_block()
        model.B[2].b = flat_model.clone()

        model.b.deactivate()
        model.B.deactivate()
        model.b.b.activate()
        model.B[1].b.activate()
        model.B[2].b.deactivate()
        assert model.b.active is False
        assert model.B[1].active is False
        assert model.B[1].active is False
        assert model.b.b.active is True
        assert model.B[1].b.active is True
        assert model.B[2].b.active is False