Skip to content

Add constraints for optimization problems #484

@JingyuQian

Description

@JingyuQian

🚀 Feature

Don't know if this has been raised before or should be the purpose of this lib, but it would be nice to allow adding constraints for an optimization problem.

Motivation

Some optimization problems take on the form:

$$min\text{ } F(x,y,z),\text{ } s.t. \text{ }x\leq\alpha,...$$

while $F(x,y,z)$ is easy to implement as:

$$F(x,y,z)=\sum_i[w_ig_i(x,y,z)]^2$$

the constraints don't have an explicit way to implement. One alternative is to write it as a normal loss and give a relatively large $w_i$, but I found it in practice this doesn't work very well.

Pitch

Something like the following

objective = th.Objective()
# Add losses
objective.add_loss(loss_function)
...
# Add constraints
objective.add_constraint(constraint_function)

Additional context

The project casadi has something as

from casadi import Opti
optim = Opti()
optim.subject_to(optim.bounded(lower_bound, x, upper_bound))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions