Esempio n. 1
0
def test_fluent_zero_not_equal_to_e1():
    param = TestParam("test", 3, 1)
    param.resample()

    zero = AffExpr(constant=np.array([[0], [0], [0]], dtype=np.float))

    lhs = AffExpr({param: 1})

    fluent = LinEqFluent('test_eq', 0, lhs, zero)
    assert not fluent.satisfied()
Esempio n. 2
0
def test_fluent_equal_after_opt():
    # model = grb.Model()
    # obj = grb.QuadExpr()

    param = TestParam("test", 3, 1)
    param.resample()

    zero = AffExpr(constant=np.array([[0], [0], [0]], dtype=np.float))

    # var = Variable(model, param)
    lhs = AffExpr({param: 1})

    fluent = LinEqFluent('test_eq', 0, lhs, zero)
    assert not fluent.satisfied()
Esempio n. 3
0
def test_fluent_equals():
    # model = grb.Model()
    # obj = grb.QuadExpr()

    param = TestParam("test", 3, 1)
    param.resample()

    three = AffExpr(constant=np.array([[3], [0], [-2]], dtype=np.float))

    # var = Variable(model, param)
    lhs = AffExpr({param: 2}, constant=np.array([[1], [0], [-2]]))

    fluent = LinEqFluent('test_eq', 0, lhs, three)
    assert fluent.satisfied()
Esempio n. 4
0
def test_eq_cnt_with_gurobi():
    model = grb.Model()
    obj = grb.QuadExpr()

    param = TestParam("test", 3, 1)
    param.resample()
    var = Variable(model, param)

    zero = AffExpr(constant=np.array([[0], [0], [0]], dtype=np.float))

    # var = Variable(model, param)
    lhs = AffExpr({param: 1})
    fluent = LinEqFluent('test_eq', 0, lhs, zero)

    variables = [Variable(model, param)]
    param_to_var = {param: variables[0]}

    constraints = Constraints(model)
    if isinstance(fluent, LinEqFluent):
        lhs = to_gurobi_expr(fluent.lhs, param_to_var)
        rhs = to_gurobi_expr(fluent.rhs, param_to_var)
        model.update()
        constraints.add_eq_cntr(lhs, rhs)
    assert not fluent.satisfied()

    for var in variables:
        for i in range(var.rows):
            for j in range(var.cols):
                v = var.grb_vars[i, j]
                obj += v*v - 2*v + 1

    model.setObjective(obj)
    model.update()
    model.optimize()

    var.update()
    var.update_hl_param()
    assert fluent.satisfied()