ULSAlgorithms 1.1.0-g3e5595996d
High-performance exact and heuristic algorithms for uncapacitated lot sizing
Loading...
Searching...
No Matches
UlsSolverFactory.cs
Go to the documentation of this file.
2
4
5/// <summary>
6/// Creates public ULS strategies from stable catalog identifiers.
7/// </summary>
8public static class UlsSolverFactory
9{
10 /// <summary>
11 /// Creates a new solver using its stable catalog identifier and default
12 /// constructor policy.
13 /// </summary>
14 /// <param name="id">Stable lower-kebab-case strategy identifier.</param>
15 /// <returns>A fresh solver instance.</returns>
16 public static IUlsSolver Create(string id) =>
18
19 /// <summary>
20 /// Creates a new solver using its stable catalog identifier and explicit
21 /// constructor-level configuration.
22 /// </summary>
23 /// <param name="id">Stable strategy identifier.</param>
24 /// <param name="options">Composed factory options.</param>
25 /// <returns>A fresh configured solver instance.</returns>
26 public static IUlsSolver Create(
27 string id,
29 {
30 ArgumentNullException.ThrowIfNull(options);
31
32 return UlsSolverCatalog
33 .Get(id)
34 .Create(options);
35 }
36
37 /// <summary>
38 /// Creates a new solver from a versioned serializable configuration.
39 /// </summary>
40 /// <param name="configuration">
41 /// Stable solver identifier plus constructor-level options.
42 /// </param>
43 /// <returns>A fresh configured solver instance.</returns>
44 public static IUlsSolver Create(
45 UlsSolverConfiguration configuration)
46 {
47 ArgumentNullException.ThrowIfNull(configuration);
48
49 configuration.Validate();
50
51 return Create(
52 configuration.SolverId,
53 configuration.Options);
54 }
55
56 /// <summary>
57 /// Attempts to create a solver using its stable catalog identifier.
58 /// </summary>
59 /// <param name="id">Stable identifier.</param>
60 /// <param name="solver">Created solver, or null when the identifier is unknown.</param>
61 /// <returns>True when a solver was created.</returns>
62 public static bool TryCreate(
63 string? id,
64 out IUlsSolver? solver)
65 {
66 if (!UlsSolverCatalog.TryGet(id, out var descriptor))
67 {
68 solver = null;
69 return false;
70 }
71
72 solver = descriptor.Create();
73 return true;
74 }
75
76 /// <summary>
77 /// Attempts to create a configured solver using its stable catalog
78 /// identifier.
79 /// </summary>
80 /// <param name="id">Stable identifier.</param>
81 /// <param name="options">Composed factory options.</param>
82 /// <param name="solver">Created solver, or null when the identifier is unknown.</param>
83 /// <returns>True when a solver was created.</returns>
84 /// <remarks>
85 /// Unknown identifiers return false. Invalid or unsupported options for a
86 /// known identifier are programming/configuration errors and therefore
87 /// still throw.
88 /// </remarks>
89 public static bool TryCreate(
90 string? id,
92 out IUlsSolver? solver)
93 {
94 ArgumentNullException.ThrowIfNull(options);
95
96 if (!UlsSolverCatalog.TryGet(id, out var descriptor))
97 {
98 solver = null;
99 return false;
100 }
101
102 solver = descriptor.Create(options);
103 return true;
104 }
105}
Canonical runtime inventory of every public IUlsSolver strategy.
static bool TryGet(string? id, [NotNullWhen(true)] out UlsSolverDescriptor? descriptor)
Attempts to resolve one descriptor by stable identifier.
static UlsSolverDescriptor Get(string id)
Gets one descriptor by stable identifier.
Versioned, serializable definition of one ULS strategy and its constructor-level options.
string SolverId
Gets or sets the stable solver identifier.
void Validate()
Validates the schema, stable solver ID and all strategy-specific options without constructing or solv...
UlsSolverCreationOptions Options
Gets or sets the constructor-level strategy options.
Composes the existing strategy-specific constructor options used by UlsSolverFactory.
IUlsSolver Create()
Creates a new solver instance using the strategy's default constructor policy.
Creates public ULS strategies from stable catalog identifiers.
static bool TryCreate(string? id, out IUlsSolver? solver)
Attempts to create a solver using its stable catalog identifier.
static IUlsSolver Create(string id, UlsSolverCreationOptions options)
Creates a new solver using its stable catalog identifier and explicit constructor-level configuration...
static bool TryCreate(string? id, UlsSolverCreationOptions options, out IUlsSolver? solver)
Attempts to create a configured solver using its stable catalog identifier.
static IUlsSolver Create(string id)
Creates a new solver using its stable catalog identifier and default constructor policy.
static IUlsSolver Create(UlsSolverConfiguration configuration)
Creates a new solver from a versioned serializable configuration.
Defines the common strategy contract implemented by every ULS solver.
Definition IUlsSolver.cs:14