File size: 1,861 Bytes
43c68a3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# UnitCommitment.jl: Optimization Package for Security-Constrained Unit Commitment
# Copyright (C) 2020, UChicago Argonne, LLC. All rights reserved.
# Released under the modified BSD license. See COPYING.md for more details.

using JuMP, MPI, TimerOutputs

Base.@kwdef mutable struct PHTermination
    max_iterations::Int = 1000
    max_time::Float64 = 14400.0
    min_feasibility::Float64 = 1e-3
    min_improvement::Float64 = 1e-3
    min_iterations::Int = 2
end

Base.@kwdef mutable struct PHIterationInfo
    global_infeas::Float64
    global_obj::Float64
    global_residual::Float64
    iteration_number::Int
    iteration_time::Float64
    sp_vals::Array{Float64,1}
    sp_obj::Float64
    target::Array{Float64,1}
    total_elapsed_time::Float64
end

Base.@kwdef mutable struct ProgressiveHedging <: SolutionMethod
    initial_weights::Union{Vector{Float64},Nothing} = nothing
    initial_target::Union{Vector{Float64},Nothing} = nothing
    ρ::Float64 = 1.0
    λ::Float64 = 0.0
    print_interval::Int = 1
    termination::PHTermination = PHTermination()
    inner_method::SolutionMethod = XavQiuWanThi2019.Method()
end

struct SpResult
    obj::Float64
    vals::Array{Float64,1}
end

Base.@kwdef mutable struct PHSubProblem
    mip::JuMP.Model
    obj::AffExpr
    consensus_vars::Array{VariableRef,1}
    weights::Array{Float64,1}
end

Base.@kwdef struct PhSubProblemSolution
    obj::Float64
    vals::Array{Float64,1}
    residuals::Array{Float64,1}
end

Base.@kwdef mutable struct PHSubProblemParams
    ρ::Float64
    λ::Array{Float64,1}
    target::Array{Float64,1}
end

struct MpiInfo
    comm::Any
    rank::Int
    root::Bool
    nprocs::Int

    function MpiInfo(comm)
        rank = MPI.Comm_rank(comm) + 1
        is_root = (rank == 1)
        nprocs = MPI.Comm_size(comm)
        return new(comm, rank, is_root, nprocs)
    end
end