Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Constraints and Penalties at the same time. #7

Open
dvnoble opened this issue Jan 23, 2024 · 1 comment
Open

Adding Constraints and Penalties at the same time. #7

dvnoble opened this issue Jan 23, 2024 · 1 comment
Labels
documentation Improvements or additions to documentation help wanted Extra attention is needed

Comments

@dvnoble
Copy link

dvnoble commented Jan 23, 2024

Hello!

I'd like to know how can I add a constraint and set its penalty at the same time. Which is the best way of doing that? Can I do it in batches (adding many constraints and their respective penalties in a single command)?

I haven't found an answer in the documentation, sorry if I missed something.

Thanks

@pedromxavier pedromxavier added documentation Improvements or additions to documentation help wanted Extra attention is needed labels Sep 11, 2024
@pedromxavier
Copy link
Member

The way to define the penalty factor for a constraint is through the ToQUBO.Attributes.ConstraintEncodingPenaltyHint() atttribute, as in

julia> using JuMP, QUBO

julia> model = Model(ToQUBO.Optimizer)
A JuMP Model
├ solver: Virtual QUBO Model
├ objective_sense: FEASIBILITY_SENSE
├ num_variables: 0
├ num_constraints: 0
└ Names registered in the model: none

julia> @variable(model, 0 <= x[1:3] <= 10)
3-element Vector{VariableRef}:
 x[1]
 x[2]
 x[3]

julia> @constraint(model, c, x[1] + x[2] + x[3] <= 10)
c : x[1] + x[2] + x[3]  10

julia> set_attribute(c, ToQUBO.Attributes.ConstraintEncodingPenaltyHint(), 20.0)

julia> optimize!(model)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants