2using System.Collections.Generic;
22 private readonly Dictionary<string, MathematicalVariable>
23 _variablesByDomainKey =
25 StringComparer.Ordinal);
31 _variablesByDomainKey.Count;
50 ArgumentNullException.ThrowIfNull(
59 if (!_variablesByDomainKey.TryAdd(
63 throw new InvalidOperationException(
64 $
"The mathematical variable domain key " +
65 $
"'{domainKey}' is already registered.");
91 ArgumentNullException.ThrowIfNull(
96 string normalizedDomainKey =
100 if (!
string.IsNullOrWhiteSpace(
105 StringComparison.Ordinal))
107 throw new InvalidOperationException(
108 "The supplied domain key does not match the " +
109 "mathematical variable domain key.");
133 string normalizedDomainKey =
137 return _variablesByDomainKey.ContainsKey(
138 normalizedDomainKey);
157 string normalizedDomainKey =
161 if (_variablesByDomainKey.TryGetValue(
168 throw new KeyNotFoundException(
169 $
"No mathematical variable is registered for domain " +
170 $
"key '{normalizedDomainKey}'.");
190 string normalizedDomainKey =
194 return _variablesByDomainKey.TryGetValue(
212 string normalizedDomainKey =
216 return _variablesByDomainKey.Remove(
217 normalizedDomainKey);
225 _variablesByDomainKey.Clear();
234 public IReadOnlyDictionary<string, MathematicalVariable>
237 return new Dictionary<string, MathematicalVariable>(
238 _variablesByDomainKey,
239 StringComparer.Ordinal);
242 private static string NormalizeDomainKey(
245 if (
string.IsNullOrWhiteSpace(
248 throw new InvalidOperationException(
249 "A mathematical variable domain key is required.");
252 return domainKey.Trim();
Maintains the correspondence between business-domain keys and mathematical variables during model con...
bool Contains(string domainKey)
Determines whether a variable is registered for a domain key.
int Count
Gets the number of registered variables.
bool TryGet(string domainKey, out MathematicalVariable? variable)
Attempts to get the variable registered for a domain key.
void Register(MathematicalVariable variable)
Registers a mathematical variable using its domain key.
MathematicalVariable GetRequired(string domainKey)
Gets the variable registered for a domain key.
void Clear()
Removes all registered variables.
IReadOnlyDictionary< string, MathematicalVariable > GetSnapshot()
Returns a snapshot of all registered variables.
bool Remove(string domainKey)
Removes the variable registered for a domain key.
void Register(string domainKey, MathematicalVariable variable)
Registers a mathematical variable with an explicit domain key.
Represents one decision variable in a mathematical optimization model.
string DomainKey
Gets or sets an optional domain key used to map the mathematical variable back to a lot-sizing decisi...
void EnsureValid()
Validates the mathematical variable.