LotSizingDataModel.Solver 2.0.1
Solver-independent modeling, execution, monitoring and adapter infrastructure.
Loading...
Searching...
No Matches
SolverRuntimeBuildResult.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.Linq;
5
7
8/// <summary>
9/// Represents the result of building the solver runtime from
10/// discovery information and dynamically loaded adapter
11/// plugins.
12/// </summary>
13public sealed class SolverRuntimeBuildResult
14{
15 private readonly List<SolverAdapterLoadResult>
16 _adapterLoadResults =
17 new();
18
19 private readonly List<string>
20 _diagnostics =
21 new();
22
23 /// <summary>
24 /// Initializes an empty solver-runtime build result.
25 /// </summary>
27 {
28 }
29
30 /// <summary>
31 /// Gets or sets the discovery result used to build the
32 /// runtime.
33 /// </summary>
35 {
36 get;
37 set;
38 }
39
40 /// <summary>
41 /// Gets or sets the runtime context created from the
42 /// discovered and loaded solver infrastructure.
43 /// </summary>
45 {
46 get;
47 set;
48 }
49
50 /// <summary>
51 /// Gets all adapter-loading attempts performed while
52 /// building the runtime.
53 /// </summary>
54 public List<SolverAdapterLoadResult>
56 _adapterLoadResults;
57
58 /// <summary>
59 /// Gets diagnostic messages produced while building the
60 /// runtime.
61 /// </summary>
62 public List<string> Diagnostics =>
63 _diagnostics;
64
65 /// <summary>
66 /// Gets a value indicating whether a runtime context was
67 /// created successfully.
68 /// </summary>
69 public bool IsSuccessful =>
70 RuntimeContext is not null;
71
72 /// <summary>
73 /// Gets a value indicating whether at least one adapter was
74 /// loaded successfully.
75 /// </summary>
76 public bool HasLoadedAdapter =>
77 _adapterLoadResults.Any(
78 result =>
79 result.IsLoaded);
80
81 /// <summary>
82 /// Gets the number of successfully loaded adapters.
83 /// </summary>
84 public int LoadedAdapterCount =>
85 _adapterLoadResults.Count(
86 result =>
87 result.IsLoaded);
88
89 /// <summary>
90 /// Gets a value indicating whether the resulting runtime
91 /// can currently execute at least one solver.
92 /// </summary>
93 public bool CanSolve =>
94 RuntimeContext?.CanSolve ==
95 true;
96
97 /// <summary>
98 /// Adds an adapter-loading result.
99 /// </summary>
100 /// <param name="loadResult">
101 /// Adapter-loading result to retain.
102 /// </param>
103 /// <exception cref="ArgumentNullException">
104 /// Thrown when <paramref name="loadResult"/> is
105 /// <see langword="null"/>.
106 /// </exception>
108 SolverAdapterLoadResult loadResult)
109 {
110 ArgumentNullException.ThrowIfNull(
111 loadResult);
112
113 _adapterLoadResults.Add(
114 loadResult);
115 }
116
117 /// <summary>
118 /// Adds a diagnostic message.
119 /// </summary>
120 /// <param name="message">
121 /// Diagnostic message.
122 /// </param>
123 /// <exception cref="ArgumentException">
124 /// Thrown when <paramref name="message"/> is empty.
125 /// </exception>
126 public void AddDiagnostic(
127 string message)
128 {
129 if (string.IsNullOrWhiteSpace(
130 message))
131 {
132 throw new ArgumentException(
133 "A solver-runtime diagnostic cannot be empty.",
134 nameof(message));
135 }
136
137 _diagnostics.Add(
138 message.Trim());
139 }
140
141 /// <summary>
142 /// Adds a collection of diagnostic messages.
143 /// </summary>
144 /// <param name="diagnostics">
145 /// Diagnostic messages to append.
146 /// </param>
147 /// <exception cref="ArgumentNullException">
148 /// Thrown when <paramref name="diagnostics"/> is
149 /// <see langword="null"/>.
150 /// </exception>
151 public void AddDiagnostics(
152 IEnumerable<string> diagnostics)
153 {
154 ArgumentNullException.ThrowIfNull(
155 diagnostics);
156
157 foreach (
158 string diagnostic
159 in diagnostics)
160 {
161 if (!string.IsNullOrWhiteSpace(
162 diagnostic))
163 {
164 _diagnostics.Add(
165 diagnostic.Trim());
166 }
167 }
168 }
169}
Represents the result of attempting to load a solver adapter plugin.
Represents the complete result of solver and adapter discovery on the current computer.
int LoadedAdapterCount
Gets the number of successfully loaded adapters.
SolverRuntimeContext? RuntimeContext
Gets or sets the runtime context created from the discovered and loaded solver infrastructure.
SolverDiscoveryResult? DiscoveryResult
Gets or sets the discovery result used to build the runtime.
void AddDiagnostic(string message)
Adds a diagnostic message.
bool CanSolve
Gets a value indicating whether the resulting runtime can currently execute at least one solver.
bool HasLoadedAdapter
Gets a value indicating whether at least one adapter was loaded successfully.
bool IsSuccessful
Gets a value indicating whether a runtime context was created successfully.
void AddDiagnostics(IEnumerable< string > diagnostics)
Adds a collection of diagnostic messages.
List< string > Diagnostics
Gets diagnostic messages produced while building the runtime.
void AddAdapterLoadResult(SolverAdapterLoadResult loadResult)
Adds an adapter-loading result.
SolverRuntimeBuildResult()
Initializes an empty solver-runtime build result.
List< SolverAdapterLoadResult > AdapterLoadResults
Gets all adapter-loading attempts performed while building the runtime.
Represents the solver runtime infrastructure available to the application after adapter discovery and...