10
10
import java .time .ZonedDateTime ;
11
11
import java .util .*;
12
12
import javax .measure .quantity .Power ;
13
+ import org .slf4j .Logger ;
13
14
import tech .units .indriya .ComparableQuantity ;
14
15
15
16
/**
@@ -69,6 +70,19 @@ public ExtendedFlexOptionsResult(
69
70
this .disaggregated = disaggregated ;
70
71
}
71
72
73
+ /**
74
+ * Method for adding disaggregated flex option results to this object.
75
+ *
76
+ * <p>Note: This method does not check, if the disaggregated flex options match the total flex
77
+ * options. To do this, please use the method {@link #checkFlexOptions(Logger)}.
78
+ *
79
+ * @param uuid of the inferior model
80
+ * @param flexOptionsResult the flex options of the inferior model
81
+ */
82
+ public void addDisaggregated (UUID uuid , FlexOptionsResult flexOptionsResult ) {
83
+ this .disaggregated .put (uuid , flexOptionsResult );
84
+ }
85
+
72
86
/** Returns the uuid of the sender ({@link #getInputModel()}) of the results. */
73
87
public UUID getSender () {
74
88
return getInputModel ();
@@ -94,6 +108,69 @@ public Map<UUID, FlexOptionsResult> getDisaggregated() {
94
108
return Collections .unmodifiableMap (disaggregated );
95
109
}
96
110
111
+ /**
112
+ * Method for checking if the disaggregated flex options match the total flex options.
113
+ *
114
+ * @param log used for logging
115
+ * @return {@code true} if the flex options match, else {@code false}
116
+ */
117
+ public boolean checkFlexOptions (Logger log ) {
118
+ List <ComparableQuantity <Power >> refs = new ArrayList <>();
119
+ List <ComparableQuantity <Power >> mins = new ArrayList <>();
120
+ List <ComparableQuantity <Power >> maxs = new ArrayList <>();
121
+
122
+ disaggregated .forEach (
123
+ (uuid , flexOptionsResult ) -> {
124
+ refs .add (flexOptionsResult .getpRef ());
125
+ mins .add (flexOptionsResult .getpMin ());
126
+ maxs .add (flexOptionsResult .getpMax ());
127
+ });
128
+
129
+ ComparableQuantity <Power > ref = getpRef ();
130
+ ComparableQuantity <Power > min = getpMin ();
131
+ ComparableQuantity <Power > max = getpMax ();
132
+
133
+ Optional <ComparableQuantity <Power >> refSum = refs .stream ().reduce (ComparableQuantity ::add );
134
+ Optional <ComparableQuantity <Power >> minSum = mins .stream ().reduce (ComparableQuantity ::add );
135
+ Optional <ComparableQuantity <Power >> maxSum = maxs .stream ().reduce (ComparableQuantity ::add );
136
+
137
+ boolean isRefValid = false ;
138
+ boolean isMinValid = false ;
139
+ boolean isMaxValid = false ;
140
+
141
+ if (refSum .isPresent ()) {
142
+ isRefValid = refSum .get ().isEquivalentTo (ref );
143
+
144
+ if (!isRefValid ) {
145
+ log .warn ("Disaggregated reference power does not match total reference power." );
146
+ }
147
+ } else {
148
+ log .warn ("Cannot check disaggregated reference power." );
149
+ }
150
+
151
+ if (minSum .isPresent ()) {
152
+ isMinValid = minSum .get ().isEquivalentTo (min );
153
+
154
+ if (!isMinValid ) {
155
+ log .warn ("Disaggregated minimum power does not match total minimum power." );
156
+ }
157
+ } else {
158
+ log .warn ("Cannot check disaggregated minimum power." );
159
+ }
160
+
161
+ if (maxSum .isPresent ()) {
162
+ isMaxValid = maxSum .get ().isEquivalentTo (max );
163
+
164
+ if (!isMaxValid ) {
165
+ log .warn ("Disaggregated maximum power does not match total maximum power." );
166
+ }
167
+ } else {
168
+ log .warn ("Cannot check disaggregated maximum power." );
169
+ }
170
+
171
+ return isRefValid && isMinValid && isMaxValid ;
172
+ }
173
+
97
174
@ Override
98
175
public boolean equals (Object o ) {
99
176
if (this == o ) return true ;
0 commit comments