-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyJulia1.jl
155 lines (148 loc) · 5.54 KB
/
MyJulia1.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
include(joinpath(pwd(),"src_PowSysMod", "PowSysMod_body.jl"))
# push!(LOAD_PATH, "D:\\repo\\GOC_Gimaju\\src_PowSysMod")
# using PowSysMod, JuMP, KNITRO
function MyJulia1(rawFile, genFile, contFile)
println(rawFile, genFile, contFile)
folder_path, scenario = splitdir(splitdir(rawFile)[1])
folder = splitdir(folder_path)[2]
#
# rGOC = "/state/partition1/data/141982//Phase_0_IEEE14_1Scenario/scenario_1/powersystem.raw"
# gGOC = "/state/partition1/data/141982//Phase_0_IEEE14_1Scenario/scenario_1/generator.csv"
# cGOC = "/state/partition1/data/141982//Phase_0_IEEE14_1Scenario/scenario_1/contingency.csv"
#
f = open(joinpath("solutions",folder, scenario,"solution1.txt"),"r")
lines1 = readlines(f)
close(f)
s1 = open("solution1.txt","w")
for line in lines1
write(s1, line,"\n")
end
close(s1)
f = open(joinpath("solutions",folder, scenario,"solution2.txt"),"r")
lines2 = readlines(f)
close(f)
s2 = open("solution2.txt","w")
for line in lines2
write(s2, line, "\n")
end
close(s2)
# folder_path, scenario = splitdir(splitdir(rawFile)[1])
# folder = splitdir(folder_path)[2]
# outpath = joinpath("JuMP_runs","$(folder)_$(scenario)")
# ##read and load files
# OPFpbs = load_OPFproblems(rawFile, genFile, contFile)
# introduce_Sgenvariables!(OPFpbs)
# ## Building optimization problem
# pb_global = build_globalpb!(OPFpbs)
#
# ## convert into real problem
# pb_global_real = pb_cplx2real(pb_global)
#
# ##convert to JuMP model
# ##phase 1 : continuous relaxation
# println("
# ##############################################\n
# Phase 1 : resolution of continuous relaxation\n
# ##############################################")
#
# mysolver = KnitroSolver(KTR_PARAM_OUTLEV=3,
# KTR_PARAM_MAXIT=600,
# KTR_PARAM_SCALE=0,
# KTR_PARAM_FEASTOL=1.0,
# KTR_PARAM_OPTTOL=1.0,
# KTR_PARAM_FEASTOLABS=1.001e-6,
# KTR_PARAM_OPTTOLABS=1e-3,
# KTR_PARAM_BAR_INITPT=2,
# KTR_PARAM_PRESOLVE=0,
# KTR_PARAM_HONORBNDS=0,
# KTR_PARAM_MIP_INTVAR_STRATEGY=1)
# tic()
# my_timer = @elapsed m, variables_jump, ctr_jump, ctr_exp = get_JuMP_cartesian_model(pb_global_real, mysolver)
# @printf("%-35s%10.6f s\n", "get_JuMP_cartesian_model", my_timer)
# toc()
# #resolution
# solve(m)
#
# minslack = +Inf
# ctr_minslack = ""
# for (ctrname, (exp,lb,ub)) in ctr_exp
# body_value = getvalue(exp)
# slack = min(body_value-lb, ub-body_value)
# if slack <= minslack
# minslack = slack
# ctr_minslack = ctrname
# end
# end
# println("min slack for constraints in problem JuMP Phase 1 : ($minslack,$ctr_minslack)")
#
# ##phase 2 : resolution with complementary constraints + initial point = solution continuous relaxation
# println("
# ##############################################################################################\n
# Phase 2 : resolution with complementary constraints from the solution of continuous relaxation\n
# ##############################################################################################")
#
# mysolver2 = KnitroSolver(KTR_PARAM_OUTLEV=3,
# KTR_PARAM_MAXIT=600,
# KTR_PARAM_SCALE=0,
# KTR_PARAM_FEASTOL=1.0,
# KTR_PARAM_OPTTOL=1.0,
# KTR_PARAM_FEASTOLABS=1.001e-6,
# KTR_PARAM_OPTTOLABS=1e-3,
# KTR_PARAM_BAR_INITPT=2,
# KTR_PARAM_PRESOLVE=0,
# KTR_PARAM_HONORBNDS=0,
# KTR_PARAM_MIP_INTVAR_STRATEGY=2)
#
#
# setsolver(m, mysolver2)
# # tic()
# # my_timer = @elapsed m2, variables_jump2 = get_JuMP_cartesian_model(pb_global_real, mysolver)
# # @printf("%-35s%10.6f s\n", "get_JuMP_cartesian_model", my_timer)
# # f = open(joinpath(outpath,"JuMP_solution_phase1.csv"),"w")
# # write(f, "Varname ; Value\n")
# # for (varname, varjump) in variables_jump
# # write(f, "$varname; $(getvalue(varjump))\n")
# # setvalue(variables_jump[varname], getvalue(varjump))
# # end
# # close(f)
# # toc()
# #resolution
# solve(m)
#
# ##get values
# println("Objective value : ", getobjectivevalue(m),"\n")
#
# # println("----Solution csv writing")
# # f = open(joinpath(outpath,"JuMP_solution.csv"),"w")
# # write(f, "Varname ; Value\n")
# # for (varname, var) in variables_jump
# # value = getvalue(var)
# # write(f, "$varname; $value\n")
# # end
# # close(f)
#
# minslack = +Inf
# ctr_minslack = ""
# # f = open(joinpath(outpath,"KnitroJuMP_constraints_eval.csv"),"w")
# # write(f, "Ctrname ; Value ; LB ; UB\n")
# for (ctrname, (exp,lb,ub)) in ctr_exp
# body_value = getvalue(exp)
# slack = min(body_value-lb, ub-body_value)
# if slack <= minslack
# minslack = slack
# ctr_minslack = ctrname
# end
# # write(f, "$ctrname; $body_value ; $lb ; $ub ; $slack\n")
# end
# # close(f)
# # println("----End solution csv writing\n")
# println("min slack for constraints in problem JuMP Phase 2 : ($minslack,$ctr_minslack)")
#
# ##create solution1.txt and solution2.txt
# println("--Solution txt writing")
# write_solutions(OPFpbs, variables_jump, pwd())
# # write_solutions(OPFpbs, variables_jump, outpath)
# println("--End solution txt writing\n")
#
# return pb_global_real
end