LotSizingDataModel.Solver 2.0.1
Solver-independent modeling, execution, monitoring and adapter infrastructure.
Loading...
Searching...
No Matches
TransportVariableFamilyBuilder.cs
Go to the documentation of this file.
1using System;
2using System.Linq;
3using System.Threading;
4using System.Threading.Tasks;
5using LotSizingDataModel.Core.PhysicalModel;
6using LotSizingDataModel.Core.Relationships;
7using LotSizingDataModel.Instance;
10
12
13/// <summary>
14/// Builds item-specific transported-quantity variables on each
15/// lane of an allowed transport resource.
16/// </summary>
17public sealed class TransportVariableFamilyBuilder :
19{
20 /// <summary>
21 /// Gets the transport variable-family identifier.
22 /// </summary>
23 public override string FamilyId =>
25
26 /// <summary>
27 /// Determines whether transport variables are enabled.
28 /// </summary>
29 public override bool IsEnabled(
30 LotSizingInstance instance,
32 {
33 ArgumentNullException.ThrowIfNull(instance);
34 ArgumentNullException.ThrowIfNull(options);
35
36 return
37 options.IncludeTransport &&
38 instance.SupplyChain.TransportCharacteristics.Count > 0 &&
39 instance.SupplyChain.TransportResources.Count > 0;
40 }
41
42 /// <summary>
43 /// Builds transported-quantity variables.
44 /// </summary>
45 protected override ValueTask BuildFamilyAsync(
46 LotSizingInstance instance,
49 CancellationToken cancellationToken)
50 {
51 int planningHorizon =
52 instance.PlanningHorizon;
53
54 foreach (
55 TransportCharacteristic characteristic
56 in instance.SupplyChain.TransportCharacteristics)
57 {
58 cancellationToken.ThrowIfCancellationRequested();
59
60 TransportResource resource =
61 instance.SupplyChain.TransportResources
62 .FirstOrDefault(
63 candidate =>
64 candidate.Id ==
65 characteristic.TransportResourceId)
66 ?? throw new InvalidOperationException(
67 $"Transport resource " +
68 $"{characteristic.TransportResourceId} " +
69 "referenced by a transport characteristic " +
70 "does not exist.");
71
72 foreach (
73 AssignedTransportLane lane
74 in instance.SupplyChain.GetTransportLanes(resource.Id))
75 {
76 for (
77 int period = 1;
78 period <= planningHorizon;
79 period++)
80 {
81 cancellationToken.ThrowIfCancellationRequested();
82
83 string domainKey =
84 CreateTransportKey(
86 characteristic.ItemId,
87 resource,
88 lane)
89 .Add(
91 period)
92 .Build();
93
95 context,
96 $"T_i{characteristic.ItemId}_r{resource.Id}" +
97 $"_l{lane.Id}_t{period}",
98 domainKey,
99 double.PositiveInfinity,
100 $"Transported quantity of item " +
101 $"{characteristic.ItemId} using resource " +
102 $"{resource.Id} in period {period}.");
103 }
104 }
105 }
106
107 return ValueTask.CompletedTask;
108 }
109
110
111 private static MathematicalDomainKeyBuilder CreateTransportKey(
112 string category,
113 int itemId,
114 TransportResource resource,
115 AssignedTransportLane lane)
116 {
117 var keyBuilder =
119 category)
120 .Add(
122 itemId)
123 .Add(
125 resource.Id);
126
128 keyBuilder,
129 lane.Origin);
130
132 keyBuilder,
133 lane.Destination);
134
135 return keyBuilder;
136 }
137
138}
Builds stable business-domain keys for mathematical variables and constraints.
MathematicalDomainKeyBuilder Add(string name, string value)
Adds a text segment.
Provides the shared state required while constructing a solver-independent mathematical model.
Creates canonical domain-key fragments shared by standard formulation builders and provides warehouse...
static MathematicalDomainKeyBuilder AddDestinationWarehouse(MathematicalDomainKeyBuilder builder, WarehouseReference warehouse)
Adds a destination warehouse reference.
static MathematicalDomainKeyBuilder AddOriginWarehouse(MathematicalDomainKeyBuilder builder, WarehouseReference warehouse)
Adds an origin warehouse reference.
Configures the standard solver-independent mixed-integer lot-sizing formulation.
Provides common validation and variable-registration helpers for one variable family of the standard ...
static MathematicalVariable AddNonNegativeContinuousVariable(MathematicalModelBuildContext context, string name, string domainKey, double upperBound=double.PositiveInfinity, string description="")
Creates and registers one continuous non-negative variable.
Builds item-specific transported-quantity variables on each lane of an allowed transport resource.
override bool IsEnabled(LotSizingInstance instance, StandardLotSizingFormulationOptions options)
Determines whether transport variables are enabled.
override string FamilyId
Gets the transport variable-family identifier.
override ValueTask BuildFamilyAsync(LotSizingInstance instance, MathematicalModelBuildContext context, StandardLotSizingFormulationOptions options, CancellationToken cancellationToken)
Builds transported-quantity variables.
Provides the canonical mathematical domain-key categories used to identify lot-sizing decision famili...
const string Transport
Identifies transported-quantity decision variables.
Provides the canonical mathematical domain-key segment names used by lot-sizing variables and constra...
const string TransportResource
Transport-resource identifier segment.