Please I need help to get this code running. I am using mosek to solve this optimization problem but I keep getting errors. I tried correcting it severally but I keep getting the error " no method matching ^ ". I will be grateful if anyone can help me get this code to work. Thank you. The code is below

using JuMP
using Mosek
using MosekTools
model= Model(Mosek.Optimizer)
# Let parameter
m=15 # num customers
NumVar=5 # num hospitals
###Declare the variables###
@variable(model, x[i=1:NumVar], Bin)
@variable(model, R>=0)
@variable(model, X>=0)
@variable(model, y>=0)
###Define your constraints###
for i in 1:NumVar
@constraint(model, x[i]>=1)
@constraint(model, ( sqrt((x[i]^x -X)^2 + (x[i]^y -y)^2 ) + r[i] )x[i] <= R )
end
###Define the objective function###
@objective(model, Min, R)
##Showing and solving the model##
@show model
print(model)
optimize!(model)
@show termination_status(model)
@show primal_status(model)
@show dual_status(model)
@show objective_value(model)
for i in 1:NumVar
println("x[$i] = ", value(x[i]))
println("r[$i] = ", value(r[i]))
end
@show value(y)

The problem is this constraint. The error is saying you canâ€™t write x[i]^x, because the power is a vector, not a number. Did you mean X instead?

You also have r[i], but that isnâ€™t defined, and Iâ€™m not sure why you have the constraint x[i] >= 1 if x[I] is binary, because that just forces x[i] to be 1.

However, even if you fix all that, you still canâ€™t write this constraint and pass it to Mosek because it is nonlinear.

Youâ€™ll need to write it as a nonlinear constraint using @NLconstraint, and pass it to a MINLP solver like Juniper.jl. But youâ€™ll likely still run into some issues because you allow x[i]^0 and a sqrt(0) terms.

Is this the full problem youâ€™re trying to solve? What is the real formulation?

You need to take another look at the subscripts in your math formulation. You have r_i in the big constraint, as well as i in I and i in J_i.

You should also think a lot more about your formulation.

What does it mean for (x_j)^x if x_j is either 0 or 1? The power has no effect, so you can just remove it.

Is r_i really a variable or is it data? Canâ€™t r_i just take arbitrarily negative values to reduce R? Is r_i >= 0?

Does it make sense for x and y to have upper bounds of 1? I donâ€™t think theyâ€™d ever be something outside those values if the left-hand side of their inner square terms are 0 or 1`?

Why do you even need for all j in J? Thereâ€™s no data, so every constraint is identical.

Ignoring the formulation issues, hereâ€™s how you could write it in JuMP, but note that you likely wonâ€™t get the answer youâ€™re expecting because the formulation doesnâ€™t make sense: