1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.hipparchus.optim.nonlinear.vector.constrained;
18
19 import org.hipparchus.linear.RealMatrix;
20 import org.hipparchus.linear.RealVector;
21 import org.hipparchus.optim.ConvergenceChecker;
22 import org.hipparchus.optim.OptimizationData;
23 import org.hipparchus.util.FastMath;
24
25
26
27
28 public class ADMMQPConvergenceChecker implements ConvergenceChecker<LagrangeSolution>, OptimizationData {
29
30
31 private final RealMatrix h;
32
33
34 private final RealMatrix a;
35
36
37 private final RealVector q;
38
39
40 private final double epsAbs;
41
42
43 private final double epsRel;
44
45
46 private boolean converged;
47
48
49
50
51
52
53
54
55 ADMMQPConvergenceChecker(final RealMatrix h, final RealMatrix a, final RealVector q,
56 final double epsAbs, final double epsRel) {
57 this.h = h;
58 this.a = a;
59 this.q = q;
60 this.epsAbs = epsAbs;
61 this.epsRel = epsRel;
62 this.converged = false;
63 }
64
65
66 @Override
67 public boolean converged(final int i, final LagrangeSolution previous, final LagrangeSolution current) {
68 return converged;
69 }
70
71
72
73
74
75
76
77
78 public boolean converged(final double rp, final double rd, final double maxPrimal, final double maxDual) {
79 boolean result = false;
80
81 if (rp <= epsPrimalDual(maxPrimal) && rd <= epsPrimalDual(maxDual)) {
82 result = true;
83 converged = true;
84 }
85 return result;
86 }
87
88
89
90
91
92
93 public double residualPrime(final RealVector x, final RealVector z) {
94 return a.operate(x).subtract(z).getLInfNorm();
95 }
96
97
98
99
100
101
102 public double residualDual(final RealVector x, final RealVector y) {
103 return q.add(a.transpose().operate(y)).add(h.operate(x)).getLInfNorm();
104 }
105
106
107
108
109
110
111 public double maxPrimal(final RealVector x, final RealVector z) {
112 return FastMath.max(a.operate(x).getLInfNorm(), z.getLInfNorm());
113 }
114
115
116
117
118
119
120 public double maxDual(final RealVector x, final RealVector y) {
121 return FastMath.max(FastMath.max(h.operate(x).getLInfNorm(),
122 a.transpose().operate(y).getLInfNorm()),
123 q.getLInfNorm());
124 }
125
126
127
128
129
130
131 private double epsPrimalDual(final double maxPrimalDual) {
132 return epsAbs + epsRel * maxPrimalDual;
133 }
134
135 }