LotSizingDataModel.Solver 2.0.1
Solver-independent modeling, execution, monitoring and adapter infrastructure.
Loading...
Searching...
No Matches
TransportCostObjectiveTermBuilder.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/// Adds item-specific transport usage costs to the standard
15/// objective.
16/// </summary>
19{
20 /// <summary>
21 /// Gets the objective-term family identifier.
22 /// </summary>
23 public override string TermFamilyId =>
24 "transportCost";
25
26 /// <summary>
27 /// Determines whether transport costs are enabled.
28 /// </summary>
29 public override bool IsEnabled(
30 LotSizingInstance instance,
32 {
33 ArgumentNullException.ThrowIfNull(instance);
34 ArgumentNullException.ThrowIfNull(options);
35
36 return options.IncludeTransport;
37 }
38
39 /// <summary>
40 /// Builds transported-quantity cost terms.
41 /// </summary>
42 protected override ValueTask BuildTermsAsync(
43 LotSizingInstance instance,
45 LinearExpressionBuilder expressionBuilder,
47 CancellationToken cancellationToken)
48 {
49 foreach (
50 TransportCharacteristic characteristic
51 in instance.SupplyChain.TransportCharacteristics)
52 {
53 TransportResource resource =
54 instance.SupplyChain.TransportResources
55 .First(
56 candidate =>
57 candidate.Id ==
58 characteristic.TransportResourceId);
59
60 foreach (
61 AssignedTransportLane lane
62 in instance.SupplyChain.GetTransportLanes(resource.Id))
63 {
64 for (
65 int period = 1;
66 period <= instance.PlanningHorizon;
67 period++)
68 {
69 cancellationToken.ThrowIfCancellationRequested();
70
72 context,
73 expressionBuilder,
74 CreateKey(
76 characteristic.ItemId,
77 resource.Id,
78 lane)
79 .Add(
81 period)
82 .Build(),
83 characteristic.UnitUsageCost?[period] ??
84 0.0);
85 }
86 }
87 }
88
89 return ValueTask.CompletedTask;
90 }
91
92
93 private static MathematicalDomainKeyBuilder CreateKey(
94 string category,
95 int itemId,
96 int resourceId,
97 LotSizingDataModel.Core.PhysicalModel.AssignedTransportLane lane)
98 {
99 var keyBuilder =
101 category)
102 .Add(
104 itemId)
105 .Add(
107 resourceId);
108
110 keyBuilder,
111 lane.Origin);
112
114 keyBuilder,
115 lane.Destination);
116
117 return keyBuilder;
118 }
119
120}
Provides a fluent builder for linear expressions.
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 helper methods for one objective-term family of the standard lot-sizin...
static void AddCostTerm(MathematicalModelBuildContext context, LinearExpressionBuilder expressionBuilder, string domainKey, double coefficient)
Adds one variable cost term to the shared objective.
Adds item-specific transport usage costs to the standard objective.
override ValueTask BuildTermsAsync(LotSizingInstance instance, MathematicalModelBuildContext context, LinearExpressionBuilder expressionBuilder, StandardLotSizingFormulationOptions options, CancellationToken cancellationToken)
Builds transported-quantity cost terms.
override bool IsEnabled(LotSizingInstance instance, StandardLotSizingFormulationOptions options)
Determines whether transport costs are enabled.
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.