LotSizingDataModel.Core 2.1.0
Core domain model, shared abstractions and XML-serializable entities.
Loading...
Searching...
No Matches
ResourceLoadAnalyzer.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.Linq;
8
10
11/// <summary>
12/// Aggregates the capacity loads generated by several items
13/// using the same resource during one planning period.
14///
15/// The analyzer supports:
16/// - production work centers;
17/// - warehouses;
18/// - transport resources.
19///
20/// It does not modify the supply-chain model.
21/// </summary>
22public sealed class ResourceLoadAnalyzer
23{
24 /// <summary>
25 /// Initializes a resource-load analyzer and creates
26 /// a new supply-chain index.
27 /// </summary>
29 : this(
31 supplyChain ??
32 throw new ArgumentNullException(
33 nameof(supplyChain))))
34 {
35 }
36
37 /// <summary>
38 /// Initializes a resource-load analyzer using
39 /// an existing supply-chain index.
40 /// </summary>
42 {
43 Index = index ??
44 throw new ArgumentNullException(nameof(index));
45
47 Queries = new SupplyChainQueries(index);
48 }
49
50 /// <summary>
51 /// Gets the analyzed supply chain.
52 /// </summary>
53 public SupplyChain SupplyChain { get; }
54
55 /// <summary>
56 /// Gets the entity index used by the analyzer.
57 /// </summary>
58 public SupplyChainIndex Index { get; }
59
60 /// <summary>
61 /// Gets the query service used to resolve relationships.
62 /// </summary>
64
65 /// <summary>
66 /// Rebuilds the underlying entity index.
67 ///
68 /// Call this method after directly changing entity
69 /// collections in the supply chain.
70 /// </summary>
71 public void RebuildIndex()
72 {
73 Index.Rebuild();
74 }
75
76 #region Production load
77
78 /// <summary>
79 /// Aggregates the production loads generated by several
80 /// items on the same work center during one period.
81 ///
82 /// Several entries referring to the same item are combined.
83 /// Their quantities are summed and setup is counted once
84 /// when at least one entry activates it.
85 /// </summary>
87 WorkCenterReference workCenterReference,
88 int period,
89 IEnumerable<ItemResourceActivity> activities)
90 {
91 ArgumentNullException.ThrowIfNull(
92 workCenterReference);
93
94 ValidatePeriod(period);
95
96 WorkCenter workCenter =
97 Index.GetRequiredWorkCenter(
98 workCenterReference);
99
100 IReadOnlyList<NormalizedActivity>
101 normalizedActivities =
102 NormalizeActivities(activities);
103
104 var itemLoads =
105 new List<ItemLoadResult>(
106 normalizedActivities.Count);
107
108 foreach (NormalizedActivity activity
109 in normalizedActivities)
110 {
111 ProductionCharacteristic characteristic =
112 Queries.GetRequiredProductionCharacteristic(
113 activity.ItemId,
114 workCenterReference);
115
116 double unitCapacity =
117 characteristic.UnitCapacityConsumption
118 ?.GetConsumption(period) ??
119 0.0;
120
121 double setupCapacity =
122 activity.SetupActivated
123 ? characteristic.SetupTime
124 ?.GetSetupTime(period) ??
125 0.0
126 : 0.0;
127
128 itemLoads.Add(
129 CreateItemLoad(
130 activity,
131 unitCapacity,
132 setupCapacity,
133 itemSpecificRegularCapacity: null,
134 itemSpecificAdditionalCapacity: null));
135 }
136
137 double? productionCapacity = workCenter.GetProductionCapacity(period);
138
139 return CreateReport(
140 ResourceLoadKind.Production,
141 resourceKey:
142 $"{workCenterReference.PlantId}:" +
143 $"{workCenterReference.WorkCenterId}",
144 resourceName: workCenter.Name,
145 period,
146 itemLoads,
147 globalRegularCapacity: productionCapacity,
148 globalAdditionalCapacity: productionCapacity > 0
149 ? workCenter.AdditionalCapacity?.GetMaximumAdditionalCapacity(period) : null);
150 }
151
152 #endregion
153
154 #region Warehouse load
155
156 /// <summary>
157 /// Aggregates the storage loads generated by several items
158 /// in the same warehouse during one period.
159 ///
160 /// The quantity of an activity represents the inventory
161 /// level of the corresponding item during the period.
162 /// </summary>
164 WarehouseReference warehouseReference,
165 int period,
166 IEnumerable<ItemResourceActivity> activities)
167 {
168 ArgumentNullException.ThrowIfNull(
169 warehouseReference);
170
171 ValidatePeriod(period);
172
173 Warehouse warehouse =
174 Index.GetRequiredWarehouse(
175 warehouseReference);
176
177 IReadOnlyList<NormalizedActivity>
178 normalizedActivities =
179 NormalizeActivities(activities);
180
181 var itemLoads =
182 new List<ItemLoadResult>(
183 normalizedActivities.Count);
184
185 foreach (NormalizedActivity activity
186 in normalizedActivities)
187 {
188 Inventory inventory =
189 Queries.GetRequiredInventory(
190 activity.ItemId,
191 warehouseReference);
192
193 double unitCapacity =
194 inventory.UnitCapacityConsumption
195 ?.GetConsumption(period) ??
196 0.0;
197
198 double setupCapacity =
199 activity.SetupActivated
200 ? inventory.SetupTime
201 ?.GetSetupTime(period) ??
202 0.0
203 : 0.0;
204
205 itemLoads.Add(
206 CreateItemLoad(
207 activity,
208 unitCapacity,
209 setupCapacity,
210 itemSpecificRegularCapacity:
211 inventory.CapacityConstraint
212 ?.GetMaximumCapacity(period),
213 itemSpecificAdditionalCapacity:
214 inventory.AdditionalCapacity
215 ?.GetMaximumAdditionalCapacity(
216 period)));
217 }
218
219 double? storageCapacity = warehouse.GetStorageCapacity(period);
220
221 return CreateReport(
222 ResourceLoadKind.Storage,
223 resourceKey:
224 $"{warehouseReference.Kind}:" +
225 $"{warehouseReference.ReferenceId}",
226 resourceName: warehouse.Name,
227 period,
228 itemLoads,
229 globalRegularCapacity:
230 storageCapacity,
231 globalAdditionalCapacity: storageCapacity.HasValue
232 ? warehouse.AdditionalCapacity?.GetMaximumAdditionalCapacity(period) : null);
233 }
234
235 #endregion
236
237 #region Transport load
238
239 /// <summary>
240 /// Aggregates the transport loads generated by several items
241 /// using the same transport resource during one period.
242 ///
243 /// The quantity of an activity must represent the total
244 /// quantity transported by the resource for the item during
245 /// the period, over all its transport lanes.
246 /// </summary>
248 int transportResourceId,
249 int period,
250 IEnumerable<ItemResourceActivity> activities)
251 {
252 ValidatePeriod(period);
253
254 TransportResource resource =
255 Index.GetRequiredTransportResource(
256 transportResourceId);
257
258 IReadOnlyList<NormalizedActivity>
259 normalizedActivities =
260 NormalizeActivities(activities);
261
262 var itemLoads =
263 new List<ItemLoadResult>(
264 normalizedActivities.Count);
265
266 foreach (NormalizedActivity activity
267 in normalizedActivities)
268 {
269 TransportCharacteristic characteristic =
270 Queries.GetRequiredTransportCharacteristic(
271 activity.ItemId,
272 transportResourceId);
273
274 double unitCapacity =
275 characteristic.UnitCapacityConsumption
276 ?.GetConsumption(period) ??
277 0.0;
278
279 double setupCapacity =
280 activity.SetupActivated
281 ? characteristic.SetupTime
282 ?.GetSetupTime(period) ??
283 0.0
284 : 0.0;
285
286 itemLoads.Add(
287 CreateItemLoad(
288 activity,
289 unitCapacity,
290 setupCapacity,
291 itemSpecificRegularCapacity:
292 characteristic.CapacityConstraint
293 ?.GetMaximumCapacity(period),
294 itemSpecificAdditionalCapacity:
295 characteristic.AdditionalCapacity
296 ?.GetMaximumAdditionalCapacity(
297 period)));
298 }
299
300 return CreateReport(
301 ResourceLoadKind.Transport,
302 resourceKey: transportResourceId.ToString(),
303 resourceName: resource.Name,
304 period,
305 itemLoads,
306 globalRegularCapacity:
307 resource.CapacityConstraint
308 ?.GetMaximumCapacity(period),
309 globalAdditionalCapacity:
310 resource.AdditionalCapacity
311 ?.GetMaximumAdditionalCapacity(period));
312 }
313
314 #endregion
315
316 #region Private calculations
317
318 private ResourceLoadReport CreateReport(
319 ResourceLoadKind resourceKind,
320 string resourceKey,
321 string resourceName,
322 int period,
323 IEnumerable<ItemLoadResult> itemLoads,
324 double? globalRegularCapacity,
325 double? globalAdditionalCapacity)
326 {
327 ValidateOptionalCapacityConfiguration(
328 globalRegularCapacity,
329 globalAdditionalCapacity,
330 "global resource capacity");
331
332 return new ResourceLoadReport(
333 resourceKind,
334 resourceKey,
335 resourceName,
336 period,
337 itemLoads,
338 globalRegularCapacity,
339 globalAdditionalCapacity);
340 }
341
342 private static ItemLoadResult CreateItemLoad(
343 NormalizedActivity activity,
344 double unitCapacity,
345 double setupCapacity,
346 double? itemSpecificRegularCapacity,
347 double? itemSpecificAdditionalCapacity)
348 {
349 ValidateNonNegativeFiniteValue(
350 unitCapacity,
351 nameof(unitCapacity));
352
353 ValidateNonNegativeFiniteValue(
354 setupCapacity,
355 nameof(setupCapacity));
356
357 ValidateOptionalCapacityConfiguration(
358 itemSpecificRegularCapacity,
359 itemSpecificAdditionalCapacity,
360 "item-specific capacity");
361
362 double quantityCapacity =
363 activity.Quantity * unitCapacity;
364
365 if (!double.IsFinite(quantityCapacity))
366 {
367 throw new InvalidOperationException(
368 "The calculated unit-capacity requirement " +
369 "exceeds the supported numerical range.");
370 }
371
372 double requiredCapacity =
373 quantityCapacity + setupCapacity;
374
375 if (!double.IsFinite(requiredCapacity))
376 {
377 throw new InvalidOperationException(
378 "The calculated resource load exceeds the " +
379 "supported numerical range.");
380 }
381
382 return new ItemLoadResult(
383 activity.ItemId,
384 activity.Quantity,
385 activity.SetupActivated,
386 unitCapacity,
387 setupCapacity,
388 requiredCapacity,
389 itemSpecificRegularCapacity,
390 itemSpecificAdditionalCapacity);
391 }
392
393 private IReadOnlyList<NormalizedActivity>
394 NormalizeActivities(
395 IEnumerable<ItemResourceActivity> activities)
396 {
397 ArgumentNullException.ThrowIfNull(activities);
398
399 var normalized =
400 new Dictionary<int, NormalizedActivity>();
401
402 foreach (ItemResourceActivity activity
403 in activities)
404 {
405 if (activity is null)
406 {
407 throw new ArgumentException(
408 "The activity collection cannot contain null.",
409 nameof(activities));
410 }
411
412 Index.GetRequiredItem(activity.ItemId);
413
414 ValidateNonNegativeFiniteValue(
415 activity.Quantity,
416 nameof(activity.Quantity));
417
418 if (!normalized.TryGetValue(
419 activity.ItemId,
420 out NormalizedActivity? existing))
421 {
422 normalized.Add(
423 activity.ItemId,
424 new NormalizedActivity(
425 activity.ItemId,
426 activity.Quantity,
427 activity.SetupActivated));
428
429 continue;
430 }
431
432 double totalQuantity =
433 existing.Quantity +
434 activity.Quantity;
435
436 if (!double.IsFinite(totalQuantity))
437 {
438 throw new InvalidOperationException(
439 $"The aggregated quantity for item " +
440 $"{activity.ItemId} exceeds the supported " +
441 "numerical range.");
442 }
443
444 normalized[activity.ItemId] =
445 new NormalizedActivity(
446 activity.ItemId,
447 totalQuantity,
448 existing.SetupActivated ||
449 activity.SetupActivated);
450 }
451
452 return normalized.Values
453 .OrderBy(activity => activity.ItemId)
454 .ToArray();
455 }
456
457 private void ValidatePeriod(int period)
458 {
459 if (period < 1 ||
460 period > SupplyChain.PlanningHorizon)
461 {
462 throw new ArgumentOutOfRangeException(
463 nameof(period),
464 period,
465 $"The period must be between 1 and " +
466 $"{SupplyChain.PlanningHorizon}.");
467 }
468 }
469
470 private static void
471 ValidateOptionalCapacityConfiguration(
472 double? regularCapacity,
473 double? additionalCapacity,
474 string capacityName)
475 {
476 if (regularCapacity.HasValue)
477 {
478 ValidateNonNegativeFiniteValue(
479 regularCapacity.Value,
480 nameof(regularCapacity));
481 }
482
483 if (additionalCapacity.HasValue)
484 {
485 ValidateNonNegativeFiniteValue(
486 additionalCapacity.Value,
487 nameof(additionalCapacity));
488
489 if (!regularCapacity.HasValue)
490 {
491 throw new InvalidOperationException(
492 $"The {capacityName} defines additional " +
493 "capacity without regular capacity.");
494 }
495 }
496 }
497
498 private static void ValidateNonNegativeFiniteValue(
499 double value,
500 string parameterName)
501 {
502 if (!double.IsFinite(value) ||
503 value < 0.0)
504 {
505 throw new ArgumentOutOfRangeException(
506 parameterName,
507 value,
508 "The value must be finite and non-negative.");
509 }
510 }
511
512 #endregion
513
514 /// <summary>
515 /// Identifies the type of resource represented
516 /// by a load report.
517 /// </summary>
519 {
520 /// <summary>
521 /// Production resource such as a work center.
522 /// </summary>
524
525 /// <summary>
526 /// Storage resource such as a warehouse.
527 /// </summary>
529
530 /// <summary>
531 /// Transport resource.
532 /// </summary>
534 }
535
536 /// <summary>
537 /// Represents the activity of one item on a resource
538 /// during one planning period.
539 /// </summary>
540 public sealed class ItemResourceActivity
541 {
542 /// <summary>
543 /// Initializes an item-resource activity.
544 /// </summary>
545 /// <param name="itemId">
546 /// Identifier of the processed item.
547 /// </param>
548 /// <param name="quantity">
549 /// Non-negative finite quantity processed, stored
550 /// or transported during the period.
551 /// </param>
552 /// <param name="setupActivated">
553 /// Indicates whether the setup capacity must be included.
554 /// </param>
556 int itemId,
557 double quantity,
558 bool setupActivated)
559 {
560 if (itemId <= 0)
561 {
562 throw new ArgumentOutOfRangeException(
563 nameof(itemId),
564 itemId,
565 "The item identifier must be strictly positive.");
566 }
567
568 ValidateNonNegativeFiniteValue(
569 quantity,
570 nameof(quantity));
571
572 ItemId = itemId;
573 Quantity = quantity;
574 SetupActivated = setupActivated;
575 }
576
577 /// <summary>
578 /// Gets the item identifier.
579 /// </summary>
580 public int ItemId { get; }
581
582 /// <summary>
583 /// Gets the processed, stored or transported quantity.
584 /// </summary>
585 public double Quantity { get; }
586
587 /// <summary>
588 /// Gets a value indicating whether setup is activated.
589 /// </summary>
590 public bool SetupActivated { get; }
591 }
592
593 /// <summary>
594 /// Internal activity obtained after grouping all entries
595 /// referring to the same item.
596 /// </summary>
597 private sealed class NormalizedActivity
598 {
599 public NormalizedActivity(
600 int itemId,
601 double quantity,
602 bool setupActivated)
603 {
604 ItemId = itemId;
605 Quantity = quantity;
606 SetupActivated = setupActivated;
607 }
608
609 public int ItemId { get; }
610
611 public double Quantity { get; }
612
613 public bool SetupActivated { get; }
614 }
615
616 /// <summary>
617 /// Represents the load generated by one item on a resource.
618 /// </summary>
619 public sealed class ItemLoadResult
620 {
621 /// <summary>
622 /// Initializes the capacity-load result of one item
623 /// on a resource during one planning period.
624 /// </summary>
625 /// <param name="itemId">
626 /// Identifier of the item.
627 /// </param>
628 /// <param name="quantity">
629 /// Quantity processed, stored or transported.
630 /// </param>
631 /// <param name="setupActivated">
632 /// Indicates whether setup is activated.
633 /// </param>
634 /// <param name="unitCapacity">
635 /// Capacity consumed per quantity unit.
636 /// </param>
637 /// <param name="setupCapacity">
638 /// Setup capacity included in the load.
639 /// </param>
640 /// <param name="requiredCapacity">
641 /// Total capacity required by the item.
642 /// </param>
643 /// <param name="maximumRegularCapacity">
644 /// Item-specific regular-capacity limit,
645 /// or null when no such limit exists.
646 /// </param>
647 /// <param name="maximumAdditionalCapacity">
648 /// Item-specific additional-capacity limit,
649 /// or null when no such limit exists.
650 /// </param>
652 int itemId,
653 double quantity,
654 bool setupActivated,
655 double unitCapacity,
656 double setupCapacity,
657 double requiredCapacity,
658 double? maximumRegularCapacity,
659 double? maximumAdditionalCapacity)
660 {
661 ValidateNonNegativeFiniteValue(
662 quantity,
663 nameof(quantity));
664
665 ValidateNonNegativeFiniteValue(
666 unitCapacity,
667 nameof(unitCapacity));
668
669 ValidateNonNegativeFiniteValue(
670 setupCapacity,
671 nameof(setupCapacity));
672
673 ValidateNonNegativeFiniteValue(
674 requiredCapacity,
675 nameof(requiredCapacity));
676
677 ValidateOptionalCapacityConfiguration(
678 maximumRegularCapacity,
679 maximumAdditionalCapacity,
680 "item-specific capacity");
681
682 ItemId = itemId;
683 Quantity = quantity;
684 SetupActivated = setupActivated;
685 UnitCapacity = unitCapacity;
686 SetupCapacity = setupCapacity;
687 RequiredCapacity = requiredCapacity;
688
690 maximumRegularCapacity;
691
693 maximumAdditionalCapacity;
694 }
695
696 /// <summary>
697 /// Gets the item identifier.
698 /// </summary>
699 public int ItemId { get; }
700
701 /// <summary>
702 /// Gets the item quantity.
703 /// </summary>
704 public double Quantity { get; }
705
706 /// <summary>
707 /// Gets a value indicating whether setup is activated.
708 /// </summary>
709 public bool SetupActivated { get; }
710
711 /// <summary>
712 /// Gets the capacity consumed per item unit.
713 /// </summary>
714 public double UnitCapacity { get; }
715
716 /// <summary>
717 /// Gets the setup capacity included in the load.
718 /// </summary>
719 public double SetupCapacity { get; }
720
721 /// <summary>
722 /// Gets the total capacity required by the item.
723 /// </summary>
724 public double RequiredCapacity { get; }
725
726 /// <summary>
727 /// Gets the item-specific regular-capacity limit.
728 ///
729 /// Null means that no item-specific limit exists.
730 /// </summary>
731 public double? MaximumRegularCapacity { get; }
732
733 /// <summary>
734 /// Gets the item-specific additional-capacity limit.
735 /// </summary>
736 public double? MaximumAdditionalCapacity { get; }
737
738 /// <summary>
739 /// Gets a value indicating whether an item-specific
740 /// capacity constraint exists.
741 /// </summary>
743 MaximumRegularCapacity.HasValue;
744
745 /// <summary>
746 /// Gets the item-specific total maximum capacity.
747 /// </summary>
748 public double? MaximumTotalCapacity =>
749 MaximumRegularCapacity.HasValue
750 ? MaximumRegularCapacity.Value +
752 : null;
753
754 /// <summary>
755 /// Gets the additional capacity required beyond
756 /// the regular item-specific capacity.
757 /// </summary>
759 MaximumRegularCapacity.HasValue
760 ? Math.Max(
761 0.0,
764 : 0.0;
765
766 /// <summary>
767 /// Gets a value indicating whether the item load fits
768 /// its regular item-specific capacity.
769 /// </summary>
770 public bool FitsRegularCapacity =>
771 !MaximumRegularCapacity.HasValue ||
774
775 /// <summary>
776 /// Gets a value indicating whether the item load fits
777 /// its regular plus additional item-specific capacity.
778 /// </summary>
779 public bool FitsTotalCapacity =>
780 !MaximumTotalCapacity.HasValue ||
783
784 /// <summary>
785 /// Gets the amount exceeding the item-specific
786 /// maximum capacity.
787 /// </summary>
788 public double CapacityExcess =>
789 MaximumTotalCapacity.HasValue
790 ? Math.Max(
791 0.0,
794 : 0.0;
795
796 /// <inheritdoc/>
797 public override string ToString()
798 {
800 {
801 return
802 $"Item {ItemId}: required " +
803 $"{RequiredCapacity}; no item-specific limit";
804 }
805
806 return
807 $"Item {ItemId}: required {RequiredCapacity}; " +
808 $"maximum {MaximumTotalCapacity}; " +
809 $"feasible {FitsTotalCapacity}";
810 }
811 }
812
813 /// <summary>
814 /// Represents the aggregated load of one resource
815 /// during one planning period.
816 /// </summary>
817 public sealed class ResourceLoadReport
818 {
819 private readonly ItemLoadResult[] _itemLoads;
820 /// <summary>
821 /// Initializes a report describing the aggregated load
822 /// of a resource during one planning period.
823 /// </summary>
824 /// <param name="resourceKind">
825 /// Type of resource being analyzed: production, storage
826 /// or transport.
827 /// </param>
828 /// <param name="resourceKey">
829 /// Technical key uniquely identifying the resource.
830 /// </param>
831 /// <param name="resourceName">
832 /// Human-readable name of the resource.
833 /// </param>
834 /// <param name="period">
835 /// One-based planning period analyzed by the report.
836 /// </param>
837 /// <param name="itemLoads">
838 /// Individual item loads aggregated on the resource.
839 /// </param>
840 /// <param name="maximumRegularCapacity">
841 /// Maximum regular capacity available during the period,
842 /// or null when no global regular-capacity constraint exists.
843 /// </param>
844 /// <param name="maximumAdditionalCapacity">
845 /// Maximum additional capacity available during the period,
846 /// or null when no global additional capacity is defined.
847 /// </param>
848 /// <exception cref="ArgumentException">
849 /// Thrown when the resource key is empty or invalid.
850 /// </exception>
851 /// <exception cref="ArgumentNullException">
852 /// Thrown when the item-load collection is null.
853 /// </exception>
854 /// <exception cref="ArgumentOutOfRangeException">
855 /// Thrown when the planning period is not strictly positive.
856 /// </exception>
858 ResourceLoadKind resourceKind,
859 string resourceKey,
860 string resourceName,
861 int period,
862 IEnumerable<ItemLoadResult> itemLoads,
863 double? maximumRegularCapacity,
864 double? maximumAdditionalCapacity)
865 {
866 ArgumentException.ThrowIfNullOrWhiteSpace(
867 resourceKey);
868
869 ArgumentNullException.ThrowIfNull(itemLoads);
870
871 if (period <= 0)
872 {
873 throw new ArgumentOutOfRangeException(
874 nameof(period),
875 period,
876 "The period must be strictly positive.");
877 }
878
879 ValidateOptionalCapacityConfiguration(
880 maximumRegularCapacity,
881 maximumAdditionalCapacity,
882 "global resource capacity");
883
884 ResourceKind = resourceKind;
885 ResourceKey = resourceKey;
886 ResourceName = resourceName ?? string.Empty;
887 Period = period;
888
889 _itemLoads = itemLoads
890 .OrderBy(load => load.ItemId)
891 .ToArray();
892
894 maximumRegularCapacity;
895
897 maximumAdditionalCapacity;
898
900 CalculateTotalRequiredCapacity(
901 _itemLoads);
902 }
903
904 /// <summary>
905 /// Gets the resource type.
906 /// </summary>
908
909 /// <summary>
910 /// Gets the technical resource key.
911 /// </summary>
912 public string ResourceKey { get; }
913
914 /// <summary>
915 /// Gets the resource name.
916 /// </summary>
917 public string ResourceName { get; }
918
919 /// <summary>
920 /// Gets the analyzed planning period.
921 /// </summary>
922 public int Period { get; }
923
924 /// <summary>
925 /// Gets the individual item loads.
926 /// </summary>
927 public IReadOnlyList<ItemLoadResult> ItemLoads =>
928 Array.AsReadOnly(_itemLoads);
929
930 /// <summary>
931 /// Gets the number of loaded item types.
932 /// </summary>
933 public int ItemCount => _itemLoads.Length;
934
935 /// <summary>
936 /// Gets the aggregated required capacity.
937 /// </summary>
938 public double TotalRequiredCapacity { get; }
939
940 /// <summary>
941 /// Gets the global regular-capacity limit.
942 /// </summary>
943 public double? MaximumRegularCapacity { get; }
944
945 /// <summary>
946 /// Gets the global additional-capacity limit.
947 /// </summary>
948 public double? MaximumAdditionalCapacity { get; }
949
950 /// <summary>
951 /// Gets a value indicating whether the resource
952 /// has a global capacity constraint.
953 /// </summary>
955 MaximumRegularCapacity.HasValue;
956
957 /// <summary>
958 /// Gets the global total maximum capacity.
959 /// </summary>
960 public double? MaximumTotalCapacity =>
961 MaximumRegularCapacity.HasValue
962 ? MaximumRegularCapacity.Value +
964 : null;
965
966 /// <summary>
967 /// Gets the additional capacity required beyond
968 /// the global regular capacity.
969 /// </summary>
971 MaximumRegularCapacity.HasValue
972 ? Math.Max(
973 0.0,
976 : 0.0;
977
978 /// <summary>
979 /// Gets a value indicating whether the aggregated load
980 /// fits the regular global capacity.
981 /// </summary>
982 public bool FitsRegularCapacity =>
983 !MaximumRegularCapacity.HasValue ||
986
987 /// <summary>
988 /// Gets a value indicating whether the aggregated load
989 /// fits the regular plus additional global capacity.
990 /// </summary>
991 public bool FitsTotalCapacity =>
992 !MaximumTotalCapacity.HasValue ||
995
996 /// <summary>
997 /// Gets the amount exceeding the global maximum capacity.
998 /// </summary>
999 public double CapacityExcess =>
1000 MaximumTotalCapacity.HasValue
1001 ? Math.Max(
1002 0.0,
1005 : 0.0;
1006
1007 /// <summary>
1008 /// Gets a value indicating whether all item-specific
1009 /// capacity constraints are respected.
1010 /// </summary>
1012 _itemLoads.All(
1013 load => load.FitsTotalCapacity);
1014
1015 /// <summary>
1016 /// Gets the item loads exceeding an item-specific
1017 /// capacity limit.
1018 /// </summary>
1019 public IReadOnlyList<ItemLoadResult>
1021 _itemLoads
1022 .Where(
1023 load =>
1024 !load.FitsTotalCapacity)
1025 .ToArray();
1026
1027 /// <summary>
1028 /// Gets a value indicating whether both the global
1029 /// capacity and all item-specific capacities are respected.
1030 /// </summary>
1031 public bool IsFeasible =>
1034
1035 /// <summary>
1036 /// Returns a textual summary of the resource load,
1037 /// its available capacity and its feasibility.
1038 /// </summary>
1039 /// <returns>
1040 /// A human-readable description of the resource-load report.
1041 /// </returns>
1042 public override string ToString()
1043 {
1044 string capacityDescription =
1046 ? $"maximum {MaximumTotalCapacity}"
1047 : "no global capacity limit";
1048
1049 return
1050 $"{ResourceKind} resource {ResourceKey}, " +
1051 $"period {Period}: required " +
1052 $"{TotalRequiredCapacity}, " +
1053 $"{capacityDescription}, " +
1054 $"feasible {IsFeasible}";
1055 }
1056
1057 private static double
1058 CalculateTotalRequiredCapacity(
1059 IEnumerable<ItemLoadResult> loads)
1060 {
1061 double total = 0.0;
1062
1063 foreach (ItemLoadResult load in loads)
1064 {
1065 total += load.RequiredCapacity;
1066
1067 if (!double.IsFinite(total))
1068 {
1069 throw new InvalidOperationException(
1070 "The aggregated resource load exceeds " +
1071 "the supported numerical range.");
1072 }
1073 }
1074
1075 return total;
1076 }
1077 }
1078}
Represents the load generated by one item on a resource.
double? MaximumRegularCapacity
Gets the item-specific regular-capacity limit.
ItemLoadResult(int itemId, double quantity, bool setupActivated, double unitCapacity, double setupCapacity, double requiredCapacity, double? maximumRegularCapacity, double? maximumAdditionalCapacity)
Initializes the capacity-load result of one item on a resource during one planning period.
bool FitsTotalCapacity
Gets a value indicating whether the item load fits its regular plus additional item-specific capacity...
double? MaximumTotalCapacity
Gets the item-specific total maximum capacity.
double RequiredCapacity
Gets the total capacity required by the item.
bool SetupActivated
Gets a value indicating whether setup is activated.
bool FitsRegularCapacity
Gets a value indicating whether the item load fits its regular item-specific capacity.
bool HasItemSpecificCapacity
Gets a value indicating whether an item-specific capacity constraint exists.
double SetupCapacity
Gets the setup capacity included in the load.
double RequiredAdditionalCapacity
Gets the additional capacity required beyond the regular item-specific capacity.
double? MaximumAdditionalCapacity
Gets the item-specific additional-capacity limit.
double CapacityExcess
Gets the amount exceeding the item-specific maximum capacity.
Represents the activity of one item on a resource during one planning period.
double Quantity
Gets the processed, stored or transported quantity.
ItemResourceActivity(int itemId, double quantity, bool setupActivated)
Initializes an item-resource activity.
bool SetupActivated
Gets a value indicating whether setup is activated.
Represents the aggregated load of one resource during one planning period.
override string ToString()
Returns a textual summary of the resource load, its available capacity and its feasibility.
bool HasGlobalCapacityConstraint
Gets a value indicating whether the resource has a global capacity constraint.
ResourceLoadReport(ResourceLoadKind resourceKind, string resourceKey, string resourceName, int period, IEnumerable< ItemLoadResult > itemLoads, double? maximumRegularCapacity, double? maximumAdditionalCapacity)
Initializes a report describing the aggregated load of a resource during one planning period.
double RequiredAdditionalCapacity
Gets the additional capacity required beyond the global regular capacity.
double CapacityExcess
Gets the amount exceeding the global maximum capacity.
bool AllItemSpecificCapacitiesSatisfied
Gets a value indicating whether all item-specific capacity constraints are respected.
IReadOnlyList< ItemLoadResult > ItemLoads
Gets the individual item loads.
bool FitsTotalCapacity
Gets a value indicating whether the aggregated load fits the regular plus additional global capacity.
bool IsFeasible
Gets a value indicating whether both the global capacity and all item-specific capacities are respect...
IReadOnlyList< ItemLoadResult > ItemSpecificCapacityViolations
Gets the item loads exceeding an item-specific capacity limit.
bool FitsRegularCapacity
Gets a value indicating whether the aggregated load fits the regular global capacity.
double? MaximumAdditionalCapacity
Gets the global additional-capacity limit.
ResourceLoadReport AnalyzeWorkCenterLoad(WorkCenterReference workCenterReference, int period, IEnumerable< ItemResourceActivity > activities)
Aggregates the production loads generated by several items on the same work center during one period.
SupplyChainQueries Queries
Gets the query service used to resolve relationships.
SupplyChainIndex Index
Gets the entity index used by the analyzer.
void RebuildIndex()
Rebuilds the underlying entity index.
ResourceLoadAnalyzer(SupplyChain supplyChain)
Initializes a resource-load analyzer and creates a new supply-chain index.
ResourceLoadAnalyzer(SupplyChainIndex index)
Initializes a resource-load analyzer using an existing supply-chain index.
SupplyChain SupplyChain
Gets the analyzed supply chain.
ResourceLoadReport AnalyzeTransportResourceLoad(int transportResourceId, int period, IEnumerable< ItemResourceActivity > activities)
Aggregates the transport loads generated by several items using the same transport resource during on...
ResourceLoadReport AnalyzeWarehouseLoad(WarehouseReference warehouseReference, int period, IEnumerable< ItemResourceActivity > activities)
Aggregates the storage loads generated by several items in the same warehouse during one period.
ResourceLoadKind
Identifies the type of resource represented by a load report.
Provides fast access to the entities contained in a supply chain.
SupplyChain SupplyChain
Gets the indexed supply chain.
A transport resource with its own shared capacities and costs.
Represents a warehouse in the supply chain.
Definition Warehouse.cs:19
Represents a serializable reference to a warehouse.
Represents a production work center belonging to a plant.
Definition WorkCenter.cs:15
Represents a serializable reference to a work center.
Provides high-level read-only queries over a supply-chain model.
Represents the inventory of an item in a warehouse.
Definition Inventory.cs:20
AdditionalCapacity? AdditionalCapacity
Gets or sets the maximum additional storage capacity available specifically for this item.
CapacityConstraint? CapacityConstraint
Gets or sets the maximum storage capacity reserved for this item during each planning period.
Represents the production characteristics of an item on a specific work center.
Represents the transport characteristics of an item for a specific transport resource.
AdditionalCapacity? AdditionalCapacity
Gets or sets the maximum additional transport capacity available specifically for this item.
CapacityConstraint? CapacityConstraint
Gets or sets the maximum transport capacity available specifically for this item during each planning...