DCOPF, 0 <= P2total <= 80); @variable(DCOPF, -50 <= F13 <= 50); @variable(DCOPF, -50 <= F12 <= 50); @variable(DCOPF, -50 <= F23 <= 50); @variable(DCOPF, Pmin[i] <= P1[i= 1:2] <= Pseg1[i]); @variable(DCOPF, Pmin[i] <= P2[i= 1:2] <= Pseg2[i]); @variable(DCOPF, Pmin[i] <= P3[i= 1:2] <= Pseg3[i]); @variable(DCOPF, Pmin[i] <= P4[i= 1:2] <= Pseg4[i]); @variable(DCOPF, -1 <= theta1 <= 1); @variable(DCOPF, -1 <= theta2 <= 1); @variable(DCOPF, -1 <= theta3 <= 1); @objective(DCOPF, Min, 400 + Cost[1,1]P1[1] + Cost[1,2]P2[1] + Cost[1,3]P3[1] + Cost[1,4]P4[1] + 500 + Cost[2,1]P1[2] + Cost[2,2]P2[2] + Cost[2,3]P3[2] + Cost[2,4]P4[2]); @constraint(DCOPF, P1total == P1[1] + P2[1] + P3[1] + P4[1]); @constraint(DCOPF, P2total == P1[2] + P2[2] + P3[2] + P4[2]); @constraint(DCOPF, PowerB1, P1total - F13 - F12 == 0); @constraint(DCOPF, PowerB2, P2total - F23 - F12 == 0); @constraint(DCOPF, PowerBalance, F13 == 10100(theta1-theta3)); @constraint(DCOPF, PowerBalance1, F12 == 10100(theta1-theta2)); @constraint(DCOPF, PowerBalance2, F23 == 10*100(theta2-theta3)); @constraint(DCOPF, PowerBalance3, P1total - F13 - F12 == 0); @constraint(DCOPF, PowerBalance4, P2total + F12 - F23 == 0); @constraint(DCOPF, PowerBalance5, F13+F23 == 100); @constraint(DCOPF, PowerBalance6, theta1 == 0); optimize!(DCOPF); println("Objective Value: ", objective_value(DCOPF)); println("P1 = ", value(P1total)); println("P2 = ", value(P2total)); println("F13 = ", value(F13)); println("F12 = ", value(F12)); println("F23 = ", value(F23)); println("theta1 = ", value(theta1)); println("theta2 = ", value(theta2)); println("theta3 = ", value(theta3)); I keep getting this error: ERROR: Result index of attribute MathOptInterface.ObjectiveValue(1) out of bounds. There are currently 0 solution(s) in the model. Stacktrace: [1] check_result_index_bounds @ C:\Users\ncpat\.julia\packages\MathOptInterface\3JqTJ\src\attributes.jl:207 [inlined] [2] get(model::Gurobi.Optimizer, attr::MathOptInterface.ObjectiveValue) @ Gurobi C:\Users\ncpat\.julia\packages\Gurobi\yvF0V\src\MOI_wrapper\MOI_wrapper.jl:3133 [3] get(b::MathOptInterface.Bridges.LazyBridgeOptimizer{Gurobi.Optimizer}, attr::MathOptInterface.ObjectiveValue) @ MathOptInterface.Bridges C:\Users\ncpat\.julia\packages\MathOptInterface\3JqTJ\src\Bridges\bridge_optimizer.jl:1111 [4] _get_model_attribute(model::MathOptInterface.Utilities.CachingOptimizer{…}, attr::MathOptInterface.ObjectiveValue) @ MathOptInterface.Utilities C:\Users\ncpat\.julia\packages\MathOptInterface\3JqTJ\src\Utilities\cachingoptimizer.jl:828 [5] get @ MathOptInterface.Utilities C:\Users\ncpat\.julia\packages\MathOptInterface\3JqTJ\src\Utilities\cachingoptimizer.jl:895 [inlined] [6] _moi_get_result(model::MathOptInterface.Utilities.CachingOptimizer{…}, args::MathOptInterface.ObjectiveValue) @ JuMP C:\Users\ncpat\.julia\packages\JuMP\027Gt\src\optimizer_interface.jl:663 [7] get(model::Model, attr::MathOptInterface.ObjectiveValue) @ JuMP C:\Users\ncpat\.julia\packages\JuMP\027Gt\src\optimizer_interface.jl:683 [9] objective_value(model::Model) @ JuMP C:\Users\ncpat\.julia\packages\JuMP\027Gt\src\objective.jl:50 [10] top-level scope @ REPL[154]:1 Some type information was truncated. Use `show(err)` to see complete types. The point of this code is to implement the DCOPF problem with piece-wise linear cost functions for the 3-bus system
can you fix my code:
using JuMP, Gurobi DCOPF = Model(Gurobi.Optimizer);
NoLoadCost = [400 500];
Cost = [26 29 33 37;44 52 60 68];
Pseg1 = [10 20];
Pseg2 = [20 20];
Pseg3 = [20 20];
Pseg4 = [20 20];
Pmin = [0 0];
@variable(DCOPF, 0 <= P1total <= 70);
@variable(DCOPF, 0 <= P2total <= 80);
@variable(DCOPF, -50 <= F13 <= 50);
@variable(DCOPF, -50 <= F12 <= 50);
@variable(DCOPF, -50 <= F23 <= 50);
@variable(DCOPF, Pmin[i] <= P1[i= 1:2] <= Pseg1[i]);
@variable(DCOPF, Pmin[i] <= P2[i= 1:2] <= Pseg2[i]);
@variable(DCOPF, Pmin[i] <= P3[i= 1:2] <= Pseg3[i]);
@variable(DCOPF, Pmin[i] <= P4[i= 1:2] <= Pseg4[i]);
@variable(DCOPF, -1 <= theta1 <= 1);
@variable(DCOPF, -1 <= theta2 <= 1);
@variable(DCOPF, -1 <= theta3 <= 1);
@objective(DCOPF, Min, 400 + Cost[1,1]P1[1] + Cost[1,2]P2[1] + Cost[1,3]P3[1] + Cost[1,4]P4[1] + 500 + Cost[2,1]P1[2] + Cost[2,2]P2[2] + Cost[2,3]P3[2] + Cost[2,4]P4[2]); @constraint(DCOPF, P1total == P1[1] + P2[1] + P3[1] + P4[1]);
@constraint(DCOPF, P2total == P1[2] + P2[2] + P3[2] + P4[2]);
@constraint(DCOPF, PowerB1, P1total - F13 - F12 == 0);
@constraint(DCOPF, PowerB2, P2total - F23 - F12 == 0);
@constraint(DCOPF, PowerBalance, F13 == 10100(theta1-theta3));
@constraint(DCOPF, PowerBalance1, F12 == 10100(theta1-theta2));
@constraint(DCOPF, PowerBalance2, F23 == 10*100(theta2-theta3));
@constraint(DCOPF, PowerBalance3, P1total - F13 - F12 == 0);
@constraint(DCOPF, PowerBalance4, P2total + F12 - F23 == 0);
@constraint(DCOPF, PowerBalance5, F13+F23 == 100); @constraint(DCOPF, PowerBalance6, theta1 == 0);
optimize!(DCOPF);
println("Objective Value: ", objective_value(DCOPF));
println("P1 = ", value(P1total));
println("P2 = ", value(P2total));
println("F13 = ", value(F13));
println("F12 = ", value(F12));
println("F23 = ", value(F23));
println("theta1 = ", value(theta1));
println("theta2 = ", value(theta2));
println("theta3 = ", value(theta3));
I keep getting this error:
ERROR: Result index of attribute MathOptInterface.ObjectiveValue(1) out of bounds. There are currently 0 solution(s) in the model.
Stacktrace:
[1] check_result_index_bounds
@ C:\Users\ncpat\.julia\packages\MathOptInterface\3JqTJ\src\attributes.jl:207 [inlined]
[2] get(model::Gurobi.Optimizer, attr::MathOptInterface.ObjectiveValue)
@ Gurobi C:\Users\ncpat\.julia\packages\Gurobi\yvF0V\src\MOI_wrapper\MOI_wrapper.jl:3133
[3] get(b::MathOptInterface.Bridges.LazyBridgeOptimizer{Gurobi.Optimizer}, attr::MathOptInterface.ObjectiveValue)
@ MathOptInterface.Bridges C:\Users\ncpat\.julia\packages\MathOptInterface\3JqTJ\src\Bridges\bridge_optimizer.jl:1111
[4] _get_model_attribute(model::MathOptInterface.Utilities.CachingOptimizer{…}, attr::MathOptInterface.ObjectiveValue)
@ MathOptInterface.Utilities C:\Users\ncpat\.julia\packages\MathOptInterface\3JqTJ\src\Utilities\cachingoptimizer.jl:828
[5] get
@ MathOptInterface.Utilities C:\Users\ncpat\.julia\packages\MathOptInterface\3JqTJ\src\Utilities\cachingoptimizer.jl:895 [inlined]
[6] _moi_get_result(model::MathOptInterface.Utilities.CachingOptimizer{…}, args::MathOptInterface.ObjectiveValue)
@ JuMP C:\Users\ncpat\.julia\packages\JuMP\027Gt\src\optimizer_interface.jl:663
[7] get(model::Model, attr::MathOptInterface.ObjectiveValue)
@ JuMP C:\Users\ncpat\.julia\packages\JuMP\027Gt\src\optimizer_interface.jl:683
[9] objective_value(model::Model)
@ JuMP C:\Users\ncpat\.julia\packages\JuMP\027Gt\src\objective.jl:50
[10] top-level scope
@ REPL[154]:1
Some type information was truncated. Use `show(err)` to see complete types.
The point of this code is to implement the DCOPF problem with piece-wise linear cost functions for the 3-bus system
image attached
Step by step
Solved in 3 steps