LotSizingDataModel.Core 2.0.1
Core domain model, shared abstractions and XML-serializable entities.
Loading...
Searching...
No Matches
OptimizationObjectivePolicy.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Xml.Serialization;
6
8
9/// <summary>
10/// Declares the business objective policy independently from any particular
11/// mathematical scalarization implementation.
12/// </summary>
13[Serializable]
14[XmlType(TypeName = "optimizationObjectivePolicy")]
15public sealed partial class OptimizationObjectivePolicy :
17{
18 private ObjectiveAggregationMode _aggregationMode =
20
21 [XmlAttribute("aggregationMode")]
23 {
24 get => _aggregationMode;
25 set => SetProperty(
26 ref _aggregationMode,
27 value);
28 }
29
30 [XmlArray("criteria")]
31 [XmlArrayItem("criterion")]
32 public List<OptimizationObjectiveCriterion> Criteria
33 {
34 get;
35 } = new();
36
37 [XmlIgnore]
39 Criteria.Count(
40 criterion =>
41 criterion is not null &&
42 criterion.IsEnabled);
43
44 [XmlIgnore]
47
48 [XmlIgnore]
50 {
51 get
52 {
55 .Where(
56 candidate =>
57 candidate is not null &&
58 candidate.IsEnabled)
59 .OrderBy(
60 candidate =>
61 candidate.Priority)
62 .ThenBy(
63 candidate =>
64 Criteria.IndexOf(candidate))
65 .FirstOrDefault();
66
67 return criterion?.Kind ??
69 }
70 }
71
72 public void EnsureValid()
73 {
76 .Where(
77 criterion =>
78 criterion is not null &&
79 criterion.IsEnabled)
80 .ToArray();
81
82 if (enabled.Length == 0)
83 {
84 throw new InvalidOperationException(
85 "An objective policy must contain at least one enabled " +
86 "criterion.");
87 }
88
89 if (
90 enabled.Any(
91 criterion =>
92 criterion.Kind ==
94 {
95 throw new InvalidOperationException(
96 "Enabled objective criteria require a known criterion kind.");
97 }
98
99 if (
100 enabled
101 .GroupBy(
102 criterion =>
103 criterion.Kind)
104 .Any(
105 group =>
106 group.Count() > 1))
107 {
108 throw new InvalidOperationException(
109 "Enabled objective criterion kinds must be unique.");
110 }
111
112 if (
115 enabled.Length != 1)
116 {
117 throw new InvalidOperationException(
118 "Single objective aggregation requires exactly one enabled " +
119 "criterion.");
120 }
121
122 if (
124 ObjectiveAggregationMode.WeightedSum &&
125 (
126 enabled.Length < 2 ||
127 enabled.All(
128 criterion =>
129 criterion.Weight == 0.0)
130 ))
131 {
132 throw new InvalidOperationException(
133 "Weighted-sum aggregation requires at least two enabled " +
134 "criteria and at least one positive weight.");
135 }
136
137 if (
139 ObjectiveAggregationMode.Lexicographic &&
140 (
141 enabled.Length < 2 ||
142 enabled
143 .GroupBy(
144 criterion =>
145 criterion.Priority)
146 .Any(
147 group =>
148 group.Count() > 1)
149 ))
150 {
151 throw new InvalidOperationException(
152 "Lexicographic aggregation requires at least two enabled " +
153 "criteria with distinct priorities.");
154 }
155 }
156}
Base class for model objects that notify listeners when one of their properties changes.
Declares one business optimization criterion in an objective policy.
Declares the business objective policy independently from any particular mathematical scalarization i...
OptimizationObjectiveKind
Business-level optimization criterion family.
ObjectiveAggregationMode
Policy used to combine several enabled optimization criteria.