Thank you for your replies and help.
The code looks like as I put below. I have anather section for all the data, I used for the simulation. This is just where I have problem and need help. But in the way you told me could not generate what I want. If it had worked, the result for Q must be 12*20
where12 (size of the vector) times 20 (number of scenarios). However the code gives me 20*10000 or 0*20
. That means the loop takes the first or the last element from the vector and considers it as the row or columon of Q. which was not the intention. That was my problem priorly and came here to seek help. Hope you got me right.
Q_mean_vec=[0 3000 3500 4000 4500 5000 5500 6000 6500 7000 7500 10000]
delta_i=comp *ones(I);
delta_j=comp* ones(J);
varphi_i=comp *ones(I);
varphi_j=comp* ones(J);
chi_i=0 *ones(I);
chi_j=0* ones(J);
mm=size(Q_mean_vec,2)
obj_gen=zeros(mm);cvar_i_gen=zeros(mm,I);cvar_j_gen=zeros(mm,J);Pi_i_gen=zeros(mm,I,W);Pi_j_gen=zeros(mm,J,W);EPi_i_gen=zeros(mm,I);EPi_j_gen=zeros(mm,J);qF_i_gen=zeros(mm,I);qF_j_gen=zeros(mm,J);qS_i_gen=zeros(mm,I,W);qS_j_gen=zeros(mm,J,W);PF_gen=zeros(mm);PS_gen=zeros(mm,W)
obj_CFD =zeros(mm);cvar_i_CFD =zeros(mm,I);cvar_j_CFD =zeros(mm,J);Pi_i_CFD =zeros(mm,I,W);Pi_j_CFD =zeros(mm,J,W);EPi_i_CFD =zeros(mm,I);EPi_j_CFD =zeros(mm,J);qF_i_CFD =zeros(mm,I);qF_j_CFD =zeros(mm,J);qS_i_CFD =zeros(mm,I,W);qS_j_CFD =zeros(mm,J,W);PF_CFD =zeros(mm);PS_CFD =zeros(mm,W)
obj_two=zeros(mm);cvar_i_two=zeros(mm,I);cvar_j_two=zeros(mm,J);Pi_i_two=zeros(mm,I,W);Pi_j_two=zeros(mm,J,W);EPi_i_two=zeros(mm,I);EPi_j_two=zeros(mm,J);qF_i_two=zeros(mm,I);qF_j_two=zeros(mm,J);qS_i_two=zeros(mm,I,W);qS_j_two=zeros(mm,J,W);PS_two=zeros(mm,W)
Pi_i_only=zeros(mm,I,W);Pi_j_only=zeros(mm,J,W);EPi_i_only=zeros(mm,I);EPi_j_only=zeros(mm,J);qS_i_only=zeros(mm,I,W);qS_j_only=zeros(mm,J,W);PS_only=zeros(mm,W) qmean = 0 for Q_v in Q_mean_vec global qmean qmean = qmean + 1 Q_mean = Q_v Q_std = 0.2 Q_sigma = Q_std .* Q_v dQ = MvNormal(Q_v, Q_sigma) Q = rand(dQ,W)
qmean = 0
for Q_v in Q_mean_vec
global qmean
qmean = qmean + 1
Q_mean = Q_v
Q_std = 0.2
Q_sigma = Q_std .* Q_v
dQ = MvNormal(Q_v, Q_sigma)
Q = rand(dQ,W)
(obj_gen[qmean],cvar_i_gen[qmean,:],cvar_j_gen[qmean,:],Pi_i_gen[qmean,:,:],Pi_j_gen[qmean,:,:],EPi_i_gen[qmean,:],EPi_j_gen[qmean,:],qF_i_gen[qmean,:],qF_j_gen[qmean,:],qS_i_gen[qmean,:,:],qS_j_gen[qmean,:,:],PF_gen[qmean],PS_gen[qmean,:],status)=general_equi_NLP(I,J,W,a,b,c,Q,gamma_S,gamma_F,beta_S,beta_F,qmax_F_i,qmin_F_i,qmax_F_j,qmin_F_j,phi,M,M_dual,alpha,sigma_i,sigma_j,delta_i,varphi_i,varphi_j,chi_i,chi_j)
println(qmean,"->",status," OF -> ",obj_gen[qmean])
(obj_CFD[qmean],cvar_i_CFD[qmean,:],cvar_j_CFD[qmean,:],Pi_i_CFD[qmean,:,:],Pi_j_CFD[qmean,:,:],EPi_i_CFD[qmean,:],EPi_j_CFD[qmean,:],qF_i_CFD[qmean,:],qF_j_CFD[qmean,:],qS_i_CFD[qmean,:,:],qS_j_CFD[qmean,:,:],PF_CFD[qmean],PS_CFD[qmean,:],status)=CFD_equi_NLP(I,J,W,a,b,c,Q,gamma_S,gamma_F,beta_S,beta_F,qmax_F_i,qmin_F_i,qmax_F_j,qmin_F_j,phi,M,M_dual,alpha,sigma_i,sigma_j,delta_i,varphi_i,varphi_j,chi_i,chi_j)
println(status," OF -> ",obj_CFD[qmean])
(obj_two[qmean],cvar_i_two[qmean,:],cvar_j_two[qmean,:],Pi_i_two[qmean,:,:],Pi_j_two[qmean,:,:],EPi_i_two[qmean,:],EPi_j_two[qmean,:],qF_i_two[qmean,:],qF_j_two[qmean,:],qS_i_two[qmean,:,:],qS_j_two[qmean,:,:],PS_two[qmean,:],status)=Two_part_equi_NLP(I,J,W,a,b,c,Q,gamma_S,gamma_F,beta_S,beta_F,qmax_F_i,qmin_F_i,qmax_F_j,qmin_F_j,phi,M,M_dual,alpha,sigma_i,sigma_j,delta_i,varphi_i,varphi_j,chi_i,chi_j)
println(status," OF -> ",obj_two[qmean])
(PS_only[qmean,:], qS_i_only[qmean,:,:],qS_j_only[qmean,:,:], Pi_i_only[qmean,:,:],Pi_j_only[qmean,:,:], EPi_i_only[qmean,:],EPi_j_only[qmean,:])=Only_spot(I,J,W,a,b,c,Q,gamma_S,beta_S,delta_i)
end
if comp==0 name_comp = string(“Cournot_results_RES.jld”) else name_comp = string(“Competitive_results_RES.jld”) end @save name_comp obj_two cvar_i_two cvar_j_two Pi_i_two Pi_j_two EPi_i_two EPi_j_two qF_i_two qF_j_two qS_i_two qS_j_two obj_CFD cvar_i_CFD cvar_j_CFD Pi_i_CFD Pi_j_CFD EPi_i_CFD EPi_j_CFD qF_i_CFD qF_j_CFD qS_i_CFD qS_j_CFD PF_CFD PS_CFD obj_gen cvar_i_gen cvar_j_gen Pi_i_gen Pi_j_gen EPi_i_gen EPi_j_gen qF_i_gen qF_j_gen qS_i_gen qS_j_gen PF_gen PS_gen PS_only qS_i_only qS_j_only Pi_i_only Pi_j_only EPi_i_only EPi_j_only
#=As it could be seen from above, qmean is the first element in the vector and it supposed automated when it is qmean=qmean+1=#
#=Just try the code below and you will see if it genarates what it has to generate. It doesnt give sense what it gives Q is not
10000Ă—20 Array{Float64,2}:
1519.28 2985.87 476.075 … 2715.85 4134.3 -908.621
1371.42 1237.13 2605.16 952.586 2282.29 1354.05
-3531.76 1627.48 -54.9649 -2912.9 -1878.2 -2421.25
302.855 -3741.64 -83.5187 -789.506 206.86 -861.804
475.353 -2665.26 -1811.17 -389.738 2239.35 42.435
964.401 -1328.83 -697.692 … -220.086 -865.61 587.97
-1136.12 -1045.77 -3353.4 1617.66 -357.055 984.174
-1248.5 2433.42 2209.21 -1573.54 660.237 83.8777
1847.68 -1186.83 -1134.5 -2994.51 -1236.82 2070.42
839.699 -1225.06 -2685.57 -2629.12 -430.576 -3.99456
-513.981 1998.83 1987.8 … 885.013 885.386 183.42
-2261.29 893.061 3334.27 -3.60624 1603.16 -2551.26
3378.73 1438.13 -3998.07 194.097 -297.471 2009.85
⋮ ⋱
4044.37 3291.43 -3031.23 -6046.27 -2567.44 -2112.24
600.755 -851.435 -1562.54 -2525.1 -1603.94 2008.06
-1765.07 -700.273 3132.21 … -911.996 206.341 -2068.15
-4254.92 1426.3 702.223 896.844 -1956.92 -1968.51
-343.506 1288.68 -1973.32 3135.77 -1183.38 -4035.13
-523.642 -997.373 2418.8 -2207.67 -2146.25 -364.775
-453.447 1372.88 2182.59 2392.01 -1552.5 114.411
1824.95 -348.986 344.384 … 1328.87 -793.081 2134.66
-1483.69 -408.258 870.426 -2124.35 -2255.04 -1059.69
-2014.03 -606.51 -896.236 -478.832 -939.712 107.686
3412.07 1322.66 -1491.08 302.769 227.449 3991.34
-2477.5 -576.577 -118.4 -462.442 -632.303 -4565.68 =#
Q_mean_vec=[0 3000 3500 4000 4500 5000 5500 6000 6500 7000 7500 10000]
qmean = 0
for Q_v in Q_mean_vec
qmean = 0
global qmean
qmean = qmean + 1
Q_mean = Q_v
Q_std = 0.2
Q_sigma = Q_std .* Q_v
dQ = MvNormal(Q_v, Q_sigma)
Q = rand(dQ,W)
end
Q
#Therefore, the error message in the main code is as follows
BoundsError: attempt to access 0Ă—20 Array{Float64,2} at index [1, 1]
Stacktrace:
[1] macro expansion at C:\Users\Utente\.julia\v0.6\JuMP\src\parsenlp.jl:249 [inlined]
[2] macro expansion at C:\Users\Utente\.julia\v0.6\JuMP\src\macros.jl:1352 [inlined]
[3] general_equi_NLP(::Int64, ::Int64, ::Int64, ::Array{Float64,2}, ::Array{Float64,2}, ::Array{Float64,2}, ::Array{Float64,2}, ::Array{Float64,1}, ::Int64, ::Array{Float64,1}, ::Float64, ::Array{Float64,1}, ::Array{Float64,1}, ::Array{Float64,1}, ::Array{Float64,1}, ::Float64, ::Int64, ::Int64, ::Float64, ::Array{Float64,2}, ::Array{Float64,2}, ::Array{Float64,1}, ::Array{Float64,1}, ::Array{Float64,1}, ::Array{Float64,1}, ::Array{Float64,1}) at .\In[169]:70
[4] macro expansion at .\In[348]:32 [inlined]
[5] anonymous at .\<missing>:?
[6] include_string(::String, ::String) at .\loading.jl:522