-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.jl
105 lines (79 loc) · 3.67 KB
/
main.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
ROOT = pwd()
include(joinpath(ROOT, "src_SOShierarchy", "SOShierarchy.jl"))
function main()
problem = buildPOP_WB2(v2max=1.022, setnetworkphase=false)
relax_ctx = set_relaxation(problem; hierarchykind=:Real,
# symmetries=[PhaseInvariance],
d = 1)
problem = buildPOP_WB2(v2max=1.022, setnetworkphase=true)
relax_ctx = set_relaxation(problem; hierarchykind=:Real,
# symmetries=[PhaseInvariance],
d = 1)
println("\n--------------------------------------------------------")
println("problem = \n$problem")
println("\n--------------------------------------------------------")
println("relax_ctx = \n$relax_ctx")
########################################
# Construction du sparsity pattern, extension chordale, cliques maximales.
max_cliques = get_maxcliques(relax_ctx, problem)
println("\n--------------------------------------------------------")
println("max cliques =")
println(max_cliques)
########################################
# Compute moment and localizing matrices parameters: order et variables
momentmat_param, localizingmat_param = build_sparsity(relax_ctx, problem, max_cliques)
println("\n--------------------------------------------------------")
println("moment params =")
for (cliquename, dcl) in momentmat_param
println("Moment matrix, $cliquename \t -> dcl = $dcl")
end
for (key, (val1, val2)) in localizingmat_param
@printf("%15s \t -> di-ki = %i, \tcliques = ", key, val2)
for clique in val1 print("$clique, ") end
@printf("\b\b \n")
end
########################################
# Build the moment relaxation problem
mmtrel_pb = MomentRelaxation{Float64}(relax_ctx, problem, momentmat_param, localizingmat_param, max_cliques)
println("\n--------------------------------------------------------")
println("mmtrel_pb = $mmtrel_pb")
########################################
# Convert to a primal SDP problem
sdpinstance = build_SDPInstance(relax_ctx, mmtrel_pb)
# println("\n--------------------------------------------------------")
# println("sdpinstance = \n$sdpinstance")
path = joinpath(pwd(), "Mosek_runs", "worksdp")
mkpath(path)
export_SDP(sdpinstance, path)
sdp_instance = read_SDPInstance(path)
println("VAR_TYPES size: $(size(sdp_instance.VAR_TYPES))")
println("BLOCKS size: $(size(sdp_instance.BLOCKS))")
println("LINEAR size: $(size(sdp_instance.LINEAR))")
println("CONST size: $(size(sdp_instance.CONST))")
sdp = SDP_Problem()
set_constraints!(sdp, sdp_instance)
set_vartypes!(sdp, sdp_instance)
set_blocks!(sdp, sdp_instance)
set_linvars!(sdp, sdp_instance)
set_matrices!(sdp, sdp_instance)
set_linear!(sdp, sdp_instance)
set_const!(sdp, sdp_instance)
# println(sdp)
primal = SortedDict{Tuple{String,String,String}, Float64}()
dual = SortedDict{Tuple{String, String, String}, Float64}()
primobj, dualobj = solve_mosek(sdp::SDP_Problem, primal, dual)
# # println("Primal solution")
# # for ((blockname, var1, var2), val) in primal
# # @printf("%15s %5s %5s %f\n", blockname, var1, var2, val)
# # end
# # println("\nDual solution NEGATED")
# # for var in problem.variables
# # ctrname = get_momentcstrname()
# # var1 = var[1]
# # var2 = "1"
# # val = dual[(ctrname, var1, var2)]
# # println("($(ctrname), $(var1), $(var2)) = $(-val)")
# # end
# println("Objectives : $primobj, $dualobj")
end
main()