JuMP variable definition

jump

#1

how i can defined different bounds or fixed values to elements of a vector variable?


#2

For example:

l = [0,1,2]
u = [1,2,3]
@variable(m, l[i] <= x[i=1:3] <= u[i])

#3

thanks for your answer,but, in this case Julia warning!@variable(PF, P[i=1:nGen; bus[:,2][i] == 2] == gen[:,2][i]/baseMVA)
@variable(PF, P[i=1:nBus; bus[:,2][i] == 1] == -bus[:,3][i]/baseMVA)
JuMP has been eliminated predefined variable values.


#4

You’ll need to provide more information (minimal stand-alone code example, full output, expected behavior).


#6

You put code in triple backticks (`) to make it easier to follow (or use Ctrl+Shift+C, or the preformatted text button at the top).


#7
using JuMP
PF = Model()
#system MVA 
basebaseMVA = 100;
# bus data
# bus_i type Pd Qd Gs Bs area Vm Va baseKV zone Vmax Vmin
bus = [
1 3 0 0 0 0 1 1 0 345 1 1.1 0.9
2 2 0 0 0 0 1 1 0 345 1 1.1 0.9
3 2 0 0 0 0 1 1 0 345 1 1.1 0.9
4 1 0 0 0 0 1 1 0 345 1 1.1 0.9
5 1 90 30 0 0 1 1 0 345 1 1.1 0.9
6 1 0 0 0 0 1 1 0 345 1 1.1 0.9
7 1 100 35 0 0 1 1 0 345 1 1.1 0.9
8 1 0 0 0 0 1 1 0 345 1 1.1 0.9
9 1 125 50 0 0 1 1 0 345 1 1.1 0.9];
# generator data
# bus Pg Qg Qmax Qmin Vg mBase status Pmax Pmin Pc1 Pc2 Qc1min Qc1max Qc2min Qc2max ramp_agc ramp_10 ramp_30 ramp_q apf
gen = [
1 0 0 300 -300 1 100 1 250 10 0 0 0 0 0 0 0 0 0 0 0
2 163 0 300 -300 1 100 1 300 10 0 0 0 0 0 0 0 0 0 0 0
3 85 0 300 -300 1 100 1 270 10 0 0 0 0 0 0 0 0 0 0 0;];
# branch data# fbus tbus r x b rateA rateB rateC ratio angle status angmin angmax
branch = [
1 4 0 0.0576 0 250 250 250 0 0 1 -360 360
4 5 0.017 0.092 0.158 250 250 250 0 0 1 -360 360
5 6 0.039 0.17 0.358 150 150 150 0 0 1 -360 360
3 6 0 0.0586 0 300 300 300 0 0 1 -360 360
6 7 0.0119 0.1008 0.209 150 150 150 0 0 1 -360 360
7 8 0.0085 0.072 0.149 250 250 250 0 0 1 -360 360
8 2 0 0.0625 0 250 250 250 0 0 1 -360 360
8 9 0.032 0.161 0.306 250 250 250 0 0 1 -360 360
9 4 0.01 0.085 0.176 250 250 250 0 0 1 -360 360];
nBus=size(bus,1); # Number of Busses
nGen=size(gen,1); # Number of Generators
@variables PF begin 
V[i=1:nBus], (lowerbound = bus[:,13][i], start = bus[:,8][i], upperbound = bus[:,12][i]) 
δ[i=1:nBus], (lowerbound = -pi, start = bus[:,9][i], upperbound = pi) 
P[i=1:nBus] 
Q[i=1:nBus]
end
@variable(PF, V[i=1:nBus;bus[:,2][i] == 3] == gen[:,6][i])
@variable(PF, δ[i=1:nBus;bus[:,2][i] == 3] == 0)
@variable(PF, gen[:,10][i]/baseMVA <= P[i=1:nBus;bus[:,2][i] == 3] <= gen[:,9][i]/baseMVA)
@variable(PF, gen[:,5][i]/baseMVA <= Q[i=1:nBus;bus[:,2][i] == 3] <= gen[:,4][i]/baseMVA)
@variable(PF, V[i=1:nBus;bus[:,2][i] == 2] == gen[:,6][i])
@variable(PF, P[i=1:nBus;bus[:,2][i] == 2] == gen[:,2][i]/baseMVA)
@variable(PF, gen[:,5][i]/baseMVA <= Q[i=1:nBus;bus[:,2][i] == 2] <= gen[:,4[i]/baseMVA)
@variable(PF, P[i=1:nBus;bus[:,2][i] == 1] == -bus[:,3][i]/baseMVA)
@variable(PF, Q[i=1:nBus;bus[:,2][i] == 1] == -bus[:,4][i]/baseMVA)
@variable(PF, bus[:,13][i] <= V[i=1:nBus;bus[:,2][i] == 1] <= bus[:,12][i])

NOTE: edited for formatting by @StefanKarpinski


#9

For the last 10 lines, you should use @constraint instead of @variable


#10

I did this, but the solution was infeasible.


#11

This is surprising. Could you give the code that gave you the infeasible solution ?


#12

If you primary interest is to solve AC Power Flows you might want to have a look at PowerModels.jl as an example.


Problem in Power Flow using Julia
#13

thanks for your response, but i wanted to solve own AC power flow to continue that to reach the solution of the “State Estimation” problem


#14

A post was merged into an existing topic: Problem in Power Flow using Julia


#15

I am not an expert in power flow optimization but we solved a power flow problem using Convex.jl here. It would be interesting to know if Convex.jl can be used to satisfy your needs?
We also support optimization with complex variables and coefficients.


#16

Just to clarify this point. The referenced Convex.jl model solves the SDP relaxation of the AC Power Flow equations. In some cases the SDP model can find a globally optimal solution to the AC model, but this is not guaranteed. Also the scalability of SDP solvers is a significant challenge for power system applications.