You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import MathOptInterface
const MOI = MathOptInterface
const MOIU = MOI.Utilities
#= 1 Pure Annealer - working=#
model = MOI.instantiate(ToQUBO.QuantumAnnealer.Optimizer, with_bridge_type = Float64)
x = MOI.add_variables(model, 2);
for xᵢ in x
MOI.add_constraint(model, xᵢ, MOI.ZeroOne())
end# alternatively#=x, c = MOI.add_constrained_variables(model, fill(MOI.ZeroOne(), 2))=#
MOI.set(model, MOI.ObjectiveSense(), MOI.MAX_SENSE)
MOI.set(
model,
MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}}(),
MOI.ScalarAffineFunction(MOI.ScalarAffineTerm.([1.0, 1.2], x), 0.0),
);
optimize!(model)
#= 2 Pure Annealer - faile=#
model = MOI.instantiate(ToQUBO.QuantumAnnealer.Optimizer, with_bridge_type = Float64)
x = MOI.add_variables(model, 2);
# will fail in `optimize!` because there is no auto conversion from Int to Binfor xᵢ in x
MOI.add_constraint(model, xᵢ, MOI.Integer())
end# alternatively#=x, c = MOI.add_constrained_variables(model, fill(MOI.Integer(), 2))=#
MOI.set(model, MOI.ObjectiveSense(), MOI.MAX_SENSE)
MOI.set(
model,
MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}}(),
MOI.ScalarAffineFunction(MOI.ScalarAffineTerm.([1.0, 1.2], x), 0.0),
);
optimize!(model)
#= 3 QUBO converter=#
model = MOI.instantiate(
()->ToQUBO.Optimizer(annealer = ToQUBO.QuantumAnnealer.Optimizer),
with_bridge_type = Float64)
x = MOI.add_variables(model, 2);
# will work because ToQUBO.Optimizer will know how to expand an integer variables# into binariesfor xᵢ in x
MOI.add_constraint(model, xᵢ, MOI.Integer())
end
MOI.set(model, MOI.ObjectiveSense(), MOI.MAX_SENSE)
MOI.set(
model,
MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}}(),
MOI.ScalarAffineFunction(MOI.ScalarAffineTerm.([1.0, 1.2], x), 0.0),
);
optimize!(model)
The text was updated successfully, but these errors were encountered:
PS: Last example will fail since the variables xᵢ are unbounded. Do you think there is anything we could do about it, appart from yelling at the user about it? I got very interested on the InfiniteOpt.jl package due to quadratures and other stuff I just had in mind before.
I'd be interested in being part of this conversation. You might not know, but the InfintOpt package developer is doing a postdoc at the department I'm currently at (and we're friends). The package is cool too!
The text was updated successfully, but these errors were encountered: