Skip to content

Create functionality to approximate NLP functions present in a optimization model. #13

Description

@andrewrosemberg

Create functionality to approximate NLP functions present in a optimization model by ML proxies (e.g. Neural Network).

For example, if we have an optimization problem dependent on non-linear (NL) expressions:

function build_test_nlp_model()
    model = Model()

    @variable(model, x[i = 1:2]);

    @variable(model, y[i = 1:2] >= 0.0);

    ex1 = sin(x[1])
    ex2 = cos(x[2])

    cons = @NLconstraint(model, ex1 == ex2)

    @objective(model, Min, sum(x) + sum(y))

    return model, cons
end

We might be able to extract and evaluate NLP expressions:

function constraints_nlp_evaluator(model, x)
    d = NLPEvaluator(model)
    MOI.initialize(d, [:ExprGraph])

    f = zeros(length(model.nlp_model.constraints))

    MOI.eval_constraint(d, f, x)

    return f
end

model, cons = build_test_nlp_model()
input = [[i] for i in rand(1000)]
output = constraints_nlp_evaluator.(model, input)

After fitting a proxy to these expressions/functions, we can add them back to the optimization problem:

flux_model = Chain(Dense(3, 3, relu), Dense(3, 1))

ex = flux_model(x)[1]

cons = @constraint(model, ex == 1)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions