# Código - Planejamento # Método de solução: Metodo Iterativo atraves de Programação Linear Inteira Mixta reset; option version; option show_stats 1; option log_file 'results_69_moderate_5.txt'; model plan_gd_ve.mod; data plan_gd_ve.dat; option presolve 0; option solver cplex; #Linearization #Ponto inicial de referencia printf "\nDeterminacacao do ponto de referencia inicial:\n"; option relax_integrality 1; objective CTD_0; let index:=1; for {t in T,d in D,h in H,(i,j) in L}{ let Vq_inc[t,d,h,j]:=1; let P_inc[t,d,h,i,j]:=0; let Q_inc[t,d,h,i,j]:=0; let Iq_inc[t,d,h,i,j]:=(P_inc[t,d,h,i,j]^2+Q_inc[t,d,h,i,j]^2)/Vq_inc[t,d,h,j]} let fact1[index]:=0; let fact2[index]:=0; let fact3[index]:=0; printf "\nTRANSITION %1d\n",index; solve; let time[index]:=_ampl_elapsed_time + _total_solve_elapsed_time; include plan_gd_ve.inc; let gap[index]:=0; let fo_b[index]:=sb*CTD_0; let es_pq[index]:= sum {t in T,d in D,h in H,(i,j) in L}(DPij[t,d,h,i,j]^2+DQij[t,d,h,i,j]^2); let es_vi[index]:= sum {t in T,d in D,h in H, (i,j) in L} abs((Vq[t,d,h,j]-Vq_inc[t,d,h,j])*Iq[t,d,h,i,j]); let es_e2[index]:= sum {t in T,d in D,h in H,(i,j) in L} e2[t,d,h,i,j]; let erro_max_psae[index]:= sb*max {t in T,d in D,h in H,i in No_SAE} abs(P_sae[t,d,h,i]+p_sae[t,d,h,i]-abs(p_sae[t,d,h,i]-P_sae[t,d,h,i])); let es_max[index]:=max(es_pq[index],es_vi[index],es_e2[index]); let erro_sup[index]:=sb*max{t in T,d in D,h in H,(i,j) in L} (sqrt(Vq[t,d,h,j]*Iq[t,d,h,i,j])-sqrt(Pij[t,d,h,i,j]^2+Qij[t,d,h,i,j]^2)); let erro_inf[index]:=sb*min{t in T,d in D,h in H,(i,j) in L} (sqrt(Vq[t,d,h,j]*Iq[t,d,h,i,j])-sqrt(Pij[t,d,h,i,j]^2+Qij[t,d,h,i,j]^2)); printf "\nSumatorio de erros e2 %5.5f",es_e2[index]; printf "\nSumatorio de erros pq %5.5f",es_pq[index]; printf "\nSumatorio de erros vi %5.5f",es_vi[index]; printf "\nMaximum Psae error %1.5f",erro_max_psae[index]; printf "\nMaximo erro superior %3.4f", erro_sup[index]; printf "\nMaximo erro inferior %3.4f", erro_inf[index]; printf "\n"; # Solucao do problema relaxado # Assignment of initial factors let index:=index+1; for {t in T,d in D,h in H,(i,j) in L}{ let Vq_inc[t,d,h,j]:=Vq[t,d,h,j]; let P_inc[t,d,h,i,j]:=round(Pij[t,d,h,i,j],4); let Q_inc[t,d,h,i,j]:=round(Qij[t,d,h,i,j],4); let Iq_inc[t,d,h,i,j]:=round((P_inc[t,d,h,i,j]^2+Q_inc[t,d,h,i,j]^2)/Vq_inc[t,d,h,j],8)} let exp1:=if es_e2[index-1]>0 then min(round(log10(0.1*CTD_0/es_e2[index-1])),0) else 0; let exp2:=min(round(log10(0.1*CTD_0/es_pq[index-1])),0); let exp3:=1; let fact1[index]:=10^exp1; let fact2[index]:=10^exp2; let fact3[index]:=10^exp3; objective CTD_1; printf "\nTRANSITION %1d\n",index; solve; let time[index]:=_ampl_elapsed_time + _total_solve_elapsed_time; let gap[index]:=0; include plan_gd_ve.inc; let fo_b[index]:=sb*CTD_0; let es_pq[index]:= sum {t in T,d in D,h in H,(i,j) in L}(DPij[t,d,h,i,j]^2+DQij[t,d,h,i,j]^2); let es_vi[index]:= sum {t in T,d in D,h in H, (i,j) in L} abs((Vq[t,d,h,j]-Vq_inc[t,d,h,j])*Iq[t,d,h,i,j]); let es_e2[index]:= sum {t in T,d in D,h in H,(i,j) in L} e2[t,d,h,i,j]; let erro_max_psae[index]:= sb*max {t in T,d in D,h in H,i in No_SAE} abs(P_sae[t,d,h,i]+p_sae[t,d,h,i]-abs(p_sae[t,d,h,i]-P_sae[t,d,h,i])); let es_max[index]:=sb*max(es_pq[index],es_vi[index],es_e2[index]); let erro_sup[index]:=sb*max{t in T,d in D,h in H,(i,j) in L} (sqrt(Vq[t,d,h,j]*Iq[t,d,h,i,j])-sqrt(Pij[t,d,h,i,j]^2+Qij[t,d,h,i,j]^2)); let erro_inf[index]:=sb*min{t in T,d in D,h in H,(i,j) in L} (sqrt(Vq[t,d,h,j]*Iq[t,d,h,i,j])-sqrt(Pij[t,d,h,i,j]^2+Qij[t,d,h,i,j]^2)); printf "\nSumatorio de erros e2 %5.5f",es_e2[index]; printf "\nSumatorio de erros pq %5.5f",es_pq[index]; printf "\nSumatorio de erros vi %5.5f",es_vi[index]; printf "\nFactor de erro e2 %10.4f",fact1[index]; printf "\nFactor de erro pq %10.4f",fact2[index]; printf "\nFactor de erro vi %10.4f",fact3[index]; printf "\nMaximum Psae error %10.4f",erro_max_psae[index]; printf "\nMaximo erro superior %3.4f", erro_sup[index]; printf "\nMaximo erro inferior %3.4f", erro_inf[index]; printf "\n"; #Solucao do problema relaxado #Improvement repeat { let index:=index+1; printf "\nTRANSITION %1d\n",index; for {t in T,d in D,h in H,(i,j) in L}{ let Vq_inc[t,d,h,j]:=Vq[t,d,h,j]; let P_inc[t,d,h,i,j]:=round(Pij[t,d,h,i,j],4); let Q_inc[t,d,h,i,j]:=round(Qij[t,d,h,i,j],4); let Iq_inc[t,d,h,i,j]:=round((P_inc[t,d,h,i,j]^2+Q_inc[t,d,h,i,j]^2)/Vq_inc[t,d,h,j],8)} let exp1:=if (es_e2[index-1]==es_max[index-1] and es_e2[index-1]>=0.8*es_max[index-2]) then exp1+1 else exp1; let exp2:=if (es_pq[index-1]==es_max[index-1] and es_pq[index-1]>=0.8*es_max[index-2]) then exp2+1 else exp2; let exp3:=if (es_vi[index-1]==es_max[index-1] and es_vi[index-1]>=0.8*es_max[index-2]) then exp3+1 else exp3; let fact1[index]:=10^exp1; let fact2[index]:=10^exp2; let fact3[index]:=10^exp3; solve; let time[index]:=_ampl_elapsed_time + _total_solve_elapsed_time; include plan_gd_ve.inc; let gap[index]:=0; let fo_b[index]:=sb*CTD_0; let es_pq[index]:= sum {t in T,d in D,h in H,(i,j) in L}(DPij[t,d,h,i,j]^2+DQij[t,d,h,i,j]^2); let es_vi[index]:= sum {t in T,d in D,h in H, (i,j) in L} abs((Vq[t,d,h,j]-Vq_inc[t,d,h,j])*Iq[t,d,h,i,j]); let es_e2[index]:= sum {t in T,d in D,h in H,(i,j) in L} e2[t,d,h,i,j]; let erro_max_psae[index]:= sb*max {t in T,d in D,h in H,i in No_SAE} abs(P_sae[t,d,h,i]+p_sae[t,d,h,i]-abs(p_sae[t,d,h,i]-P_sae[t,d,h,i])); let es_max[index]:=max(es_pq[index],es_vi[index],es_e2[index]); let erro_sup[index]:=sb*max{t in T,d in D,h in H,(i,j) in L} (sqrt(Vq[t,d,h,j]*Iq[t,d,h,i,j])-sqrt(Pij[t,d,h,i,j]^2+Qij[t,d,h,i,j]^2)); let erro_inf[index]:=sb*min{t in T,d in D,h in H,(i,j) in L} (sqrt(Vq[t,d,h,j]*Iq[t,d,h,i,j])-sqrt(Pij[t,d,h,i,j]^2+Qij[t,d,h,i,j]^2)); printf "\nSumatorio de erros e2 %5.5f",es_e2[index]; printf "\nSumatorio de erros pq %5.5f",es_pq[index]; printf "\nSumatorio de erros vi %5.5f",es_vi[index]; printf "\nFactor de erro e2 %10.4f",fact1[index]; printf "\nFactor de erro pq %10.4f",fact2[index]; printf "\nFactor de erro vi %10.4f",fact3[index]; printf "\nMaximum Psae error %10.4f",erro_max_psae[index]; printf "\nMaximo erro superior %3.4f", erro_sup[index]; printf "\nMaximo erro inferior %3.4f", erro_inf[index]; printf "\n"; let erro_max:=max(abs(erro_sup[index]),abs(erro_inf[index])); } until erro_max<1000 or index==iter_max; /* #Integer solution improvement #option cplex_options 'mipgap=5e-2 mipdisplay=4 bardisplay=1 display=2 rinsheur=10 mipcuts=2 solutiontype=2 nodes=1000'; suffix priority IN, integer,>=0,<=9999; suffix direction IN, integer,>=-1,<=1; let {n in No_WD} n_wd[n].direction:=-1; let {n in No_WD} n_wd[n].priority:=500; let {n in No_SAE} n_sae[n].direction:=-1; let {n in No_SAE} n_sae[n].priority:=1000; let {n in No_BC} n_bcs[n].direction:=-1; let {n in No_BC} n_bcs[n].priority:=200; let {n in No_BC} n_bcf[n].direction:=-1; let {n in No_BC} n_bcf[n].priority:=100; */ #Integer solution option relax_integrality 0; suffix relmipgap OUT; option cplex_options 'mipgap=2.5e-2 mipdisplay=2 nodes=1500 return_mipgap=7 mipstartalg=2'; repeat { let index:=index+1; printf "\nTRANSITION %1d\n",index; for {t in T,d in D,h in H,(i,j) in L}{ let Vq_inc[t,d,h,j]:=Vq[t,d,h,j]; let P_inc[t,d,h,i,j]:=round(Pij[t,d,h,i,j],4); let Q_inc[t,d,h,i,j]:=round(Qij[t,d,h,i,j],4); let Iq_inc[t,d,h,i,j]:=round((P_inc[t,d,h,i,j]^2+Q_inc[t,d,h,i,j]^2)/Vq_inc[t,d,h,j],8)} let exp1:=if (es_e2[index-1]==es_max[index-1] and es_e2[index-1]>=0.8*es_max[index-2]) then exp1+1 else exp1; let exp2:=if (es_pq[index-1]==es_max[index-1] and es_pq[index-1]>=0.8*es_max[index-2]) then exp2+1 else exp2; let exp3:=if (es_vi[index-1]==es_max[index-1] and es_vi[index-1]>=0.8*es_max[index-2]) then exp3+1 else exp3; let fact1[index]:=10^exp1; let fact2[index]:=10^exp2; let fact3[index]:=10^exp3; solve; let time[index]:=_ampl_elapsed_time + _total_solve_elapsed_time; include plan_gd_ve.inc; let gap[index]:=Current.relmipgap; let fo_b[index]:=sb*CTD_0; let es_pq[index]:= sum {t in T,d in D,h in H,(i,j) in L}(DPij[t,d,h,i,j]^2+DQij[t,d,h,i,j]^2); let es_vi[index]:= sum {t in T,d in D,h in H, (i,j) in L} abs((Vq[t,d,h,j]-Vq_inc[t,d,h,j])*(Iq[t,d,h,i,j]-Iq_inc[t,d,h,i,j])); let es_e2[index]:= sum {t in T,d in D,h in H,(i,j) in L} e2[t,d,h,i,j]; let erro_max_psae[index]:= sb*max {t in T,d in D,h in H,i in No_SAE} abs(P_sae[t,d,h,i]+p_sae[t,d,h,i]-abs(p_sae[t,d,h,i]-P_sae[t,d,h,i])); let es_max[index]:=max(es_pq[index],es_vi[index],es_e2[index]); let erro_sup[index]:=sb*max{t in T,d in D,h in H,(i,j) in L} (sqrt(abs(Vq[t,d,h,j]*Iq[t,d,h,i,j]))-sqrt(Pij[t,d,h,i,j]^2+Qij[t,d,h,i,j]^2)); let erro_inf[index]:=sb*min{t in T,d in D,h in H,(i,j) in L} (sqrt(abs(Vq[t,d,h,j]*Iq[t,d,h,i,j]))-sqrt(Pij[t,d,h,i,j]^2+Qij[t,d,h,i,j]^2)); printf "\nSumatorio de erros e2 %5.5f",es_e2[index]; printf "\nSumatorio de erros pq %5.5f",es_pq[index]; printf "\nSumatorio de erros vi %5.5f",es_vi[index]; printf "\nFactor de erro e2 %10.4f",fact1[index]; printf "\nFactor de erro pq %10.4f",fact2[index]; printf "\nFactor de erro vi %10.4f",fact3[index]; printf "\nMaximum Psae error %10.4f",erro_max_psae[index]; printf "\nMaximo erro superior %3.4f", erro_sup[index]; printf "\nMaximo erro inferior %3.4f", erro_inf[index]; printf "\nRelative GAP %3.4f", gap[index]; printf "\n"; let erro_max:=max(abs(erro_sup[index]),abs(erro_inf[index])); } until erro_max<10 or index==iter_max; if gap[index]>1e-3 or erro_max>1 then { option cplex_options 'mipgap=1e-3 mipdisplay=2 rinsheur=100 nodes=1500 return_mipgap=7 mipstartalg=2'; repeat { let index:=index+1; printf "\nTRANSITION %1d\n",index; for {t in T,d in D,h in H,(i,j) in L}{ let Vq_inc[t,d,h,j]:=Vq[t,d,h,j]; let P_inc[t,d,h,i,j]:=round(Pij[t,d,h,i,j],4); let Q_inc[t,d,h,i,j]:=round(Qij[t,d,h,i,j],4); let Iq_inc[t,d,h,i,j]:=round((P_inc[t,d,h,i,j]^2+Q_inc[t,d,h,i,j]^2)/Vq_inc[t,d,h,j],8)} let exp1:=if (es_e2[index-1]==es_max[index-1] and es_e2[index-1]>=0.8*es_max[index-2]) then exp1+1 else exp1; let exp2:=if (es_pq[index-1]==es_max[index-1] and es_pq[index-1]>=0.8*es_max[index-2]) then exp2+1 else exp2; let exp3:=if (es_vi[index-1]==es_max[index-1] and es_vi[index-1]>=0.8*es_max[index-2]) then exp3+1 else exp3; let fact1[index]:=10^exp1; let fact2[index]:=10^exp2; let fact3[index]:=10^exp3; solve; let time[index]:=_ampl_elapsed_time + _total_solve_elapsed_time; include plan_gd_ve.inc; let gap[index]:=Current.relmipgap; let fo_b[index]:=sb*CTD_0; let es_pq[index]:= sum {t in T,d in D,h in H,(i,j) in L}(DPij[t,d,h,i,j]^2+DQij[t,d,h,i,j]^2); let es_vi[index]:= sum {t in T,d in D,h in H, (i,j) in L} abs((Vq[t,d,h,j]-Vq_inc[t,d,h,j])*Iq[t,d,h,i,j]); let es_e2[index]:= sum {t in T,d in D,h in H,(i,j) in L} e2[t,d,h,i,j]; let erro_max_psae[index]:= sb*max {t in T,d in D,h in H,i in No_SAE} abs(P_sae[t,d,h,i]+p_sae[t,d,h,i]-abs(p_sae[t,d,h,i]-P_sae[t,d,h,i])); let es_max[index]:=max(es_pq[index],es_vi[index],es_e2[index]); let erro_sup[index]:=sb*max{t in T,d in D,h in H,(i,j) in L} (sqrt(abs(Vq[t,d,h,j]*Iq[t,d,h,i,j]))-sqrt(Pij[t,d,h,i,j]^2+Qij[t,d,h,i,j]^2)); let erro_inf[index]:=sb*min{t in T,d in D,h in H,(i,j) in L} (sqrt(abs(Vq[t,d,h,j]*Iq[t,d,h,i,j]))-sqrt(Pij[t,d,h,i,j]^2+Qij[t,d,h,i,j]^2)); printf "\nSumatorio de erros e2 %5.5f",es_e2[index]; printf "\nSumatorio de erros pq %5.5f",es_pq[index]; printf "\nSumatorio de erros vi %5.5f",es_vi[index]; printf "\nFactor de erro e2 %10.4f",fact1[index]; printf "\nFactor de erro pq %10.4f",fact2[index]; printf "\nFactor de erro vi %10.4f",fact3[index]; printf "\nMaximum Psae error %10.4f",erro_max_psae[index]; printf "\nMaximo erro superior %3.4f", erro_sup[index]; printf "\nMaximo erro inferior %3.4f", erro_inf[index]; printf "\nRelative GAP %3.4f", gap[index]; printf "\n"; let erro_max:=max(abs(erro_sup[index]),abs(erro_inf[index])); } until erro_max<1 or index==iter_max;} printf "\n %2s %10s %10s %10s %10s %10s %10s\n", "Trans", "OF", "fact1", "fact2", "fact3", "gap", "time"; for{i in 1..index}{ printf "\n %2s %10.2f %10.2f %10.2f %10.2f %10.3f %10.2f\n", i, fo_b[i], fact1[i], fact2[i], fact3[i], gap[i], time[i];}