2using System.Collections.Generic;
28 throw new ArgumentNullException(nameof(supplyChain))))
38 throw new ArgumentNullException(nameof(index));
64 #region Inventory queries
75 ArgumentNullException.ThrowIfNull(warehouse);
79 inventory.ItemId == itemId &&
95 ArgumentNullException.ThrowIfNull(warehouse);
98 throw new KeyNotFoundException(
99 $
"No inventory exists for item {itemId} and " +
100 $
"warehouse {FormatWarehouse(warehouse)}.");
109 Index.GetRequiredItem(itemId);
112 .Where(inventory => inventory.ItemId == itemId)
122 ArgumentNullException.ThrowIfNull(warehouse);
124 Index.GetRequiredWarehouse(warehouse);
144 Index.GetRequiredItem(inventory.ItemId))
150 #region Production-routing queries
158 return SupplyChain.ProductionRoutings.FirstOrDefault(
159 routing => routing.Id == routingId);
169 throw new KeyNotFoundException(
170 $
"Production routing {routingId} does not exist.");
176 public IReadOnlyList<ProductionRouting>
179 Index.GetRequiredItem(itemId);
182 .Where(routing => routing.ItemId == itemId)
189 public IReadOnlyList<ProductionRouting>
192 Index.GetRequiredPlant(plantId);
195 .Where(routing => routing.PlantId == plantId)
202 public IReadOnlyList<ProductionRouting>
207 Index.GetRequiredItem(itemId);
208 Index.GetRequiredPlant(plantId);
213 routing.ItemId == itemId &&
214 routing.PlantId == plantId)
220 #region Production-characteristic queries
231 ArgumentNullException.ThrowIfNull(workCenter);
236 characteristic.ItemId == itemId &&
238 characteristic.WorkCenter,
251 ArgumentNullException.ThrowIfNull(workCenter);
256 throw new KeyNotFoundException(
257 $
"No production characteristic exists for " +
258 $
"item {itemId} and work center " +
259 $
"{FormatWorkCenter(workCenter)}.");
265 public IReadOnlyList<ProductionCharacteristic>
268 Index.GetRequiredItem(itemId);
273 characteristic.ItemId == itemId)
280 public IReadOnlyList<ProductionCharacteristic>
284 ArgumentNullException.ThrowIfNull(workCenter);
286 Index.GetRequiredWorkCenter(workCenter);
292 characteristic.WorkCenter,
307 Index.GetRequiredItem(
308 characteristic.ItemId))
314 #region Demand queries
322 int distributionCenterId)
326 demand.ItemId == itemId &&
327 demand.DistributionCenterId ==
328 distributionCenterId);
337 int distributionCenterId)
341 distributionCenterId) ??
342 throw new KeyNotFoundException(
343 $
"No demand exists for item {itemId} and " +
344 $
"distribution center {distributionCenterId}.");
353 Index.GetRequiredItem(itemId);
356 .Where(demand => demand.ItemId == itemId)
363 public IReadOnlyList<Demand>
365 int distributionCenterId)
367 Index.GetRequiredDistributionCenter(
368 distributionCenterId);
373 demand.DistributionCenterId ==
374 distributionCenterId)
383 int distributionCenterId,
386 ValidatePeriod(period);
390 distributionCenterId)
396 #region Distribution-center sourcing queries
402 public IReadOnlyList<DistributionCenterSourcing>
404 int distributionCenterId,
407 Index.GetRequiredDistributionCenter(
408 distributionCenterId);
410 Index.GetRequiredItem(itemId);
415 sourcing.DistributionCenterId ==
416 distributionCenterId &&
417 sourcing.ItemId == itemId)
424 public IReadOnlyList<DistributionCenterSourcing>
428 ArgumentNullException.ThrowIfNull(warehouse);
430 Index.GetRequiredWarehouse(warehouse);
445 public IReadOnlyList<Warehouse>
447 int distributionCenterId,
451 distributionCenterId,
455 Index.GetRequiredWarehouse(
462 #region Supplier-delivery queries
467 public IReadOnlyList<SupplierDelivery>
470 Index.GetRequiredSupplier(supplierId);
475 delivery.SupplierId == supplierId)
482 public IReadOnlyList<SupplierDelivery>
485 Index.GetRequiredItem(itemId);
488 .Where(delivery => delivery.ItemId == itemId)
496 public IReadOnlyList<SupplierDelivery>
500 ArgumentNullException.ThrowIfNull(warehouse);
502 Index.GetRequiredWarehouse(warehouse);
517 public IReadOnlyList<Supplier>
527 delivery.ItemId == itemId &&
533 Index.GetRequiredSupplier(
534 delivery.SupplierId))
540 #region Transport-characteristic queries
549 int transportResourceId)
554 characteristic.ItemId == itemId &&
555 characteristic.TransportResourceId ==
556 transportResourceId);
566 int transportResourceId)
570 transportResourceId) ??
571 throw new KeyNotFoundException(
572 $
"No transport characteristic exists for " +
573 $
"item {itemId} and transport resource " +
574 $
"{transportResourceId}.");
580 public IReadOnlyList<TransportCharacteristic>
583 Index.GetRequiredItem(itemId);
588 characteristic.ItemId == itemId)
595 public IReadOnlyList<Item>
597 int transportResourceId)
599 Index.GetRequiredTransportResource(
600 transportResourceId);
605 characteristic.TransportResourceId ==
609 Index.GetRequiredItem(
610 characteristic.ItemId))
616 #region Transport-lane queries
621 public IReadOnlyList<DirectTransportOption>
625 ArgumentNullException.ThrowIfNull(origin);
627 Index.GetRequiredWarehouse(origin);
629 return EnumerateTransportOptions()
641 public IReadOnlyList<DirectTransportOption>
645 ArgumentNullException.ThrowIfNull(destination);
647 Index.GetRequiredWarehouse(destination);
649 return EnumerateTransportOptions()
653 option.Lane.Destination,
661 public IReadOnlyList<DirectTransportOption>
666 ArgumentNullException.ThrowIfNull(origin);
667 ArgumentNullException.ThrowIfNull(destination);
669 Index.GetRequiredWarehouse(origin);
670 Index.GetRequiredWarehouse(destination);
672 return EnumerateTransportOptions()
679 option.Lane.Destination,
692 ArgumentNullException.ThrowIfNull(origin);
693 ArgumentNullException.ThrowIfNull(destination);
697 destination).Count > 0;
704 public IReadOnlyList<DirectTransportOption>
710 Index.GetRequiredItem(itemId);
713 HashSet<int> compatibleResourceIds =
717 characteristic.ItemId == itemId)
720 characteristic.TransportResourceId)
728 compatibleResourceIds.Contains(
729 option.TransportResource.Id))
733 private IEnumerable<DirectTransportOption>
734 EnumerateTransportOptions()
741 yield
return new DirectTransportOption(
750 #region Capacity queries
760 ArgumentNullException.ThrowIfNull(workCenter);
761 ValidatePeriod(period);
764 Index.GetRequiredWorkCenter(workCenter);
766 return CreateCapacitySnapshot(
770 isItemSpecific:
false);
781 ArgumentNullException.ThrowIfNull(warehouse);
782 ValidatePeriod(period);
785 Index.GetRequiredWarehouse(warehouse);
787 return CreateCapacitySnapshot(
791 isItemSpecific:
false);
805 ArgumentNullException.ThrowIfNull(warehouse);
806 ValidatePeriod(period);
816 return CreateCapacitySnapshot(
820 isItemSpecific:
true);
833 int transportResourceId,
836 ValidatePeriod(period);
839 Index.GetRequiredTransportResource(
840 transportResourceId);
842 return CreateCapacitySnapshot(
846 isItemSpecific:
false);
858 int transportResourceId,
861 ValidatePeriod(period);
866 transportResourceId);
871 return CreateCapacitySnapshot(
875 isItemSpecific:
true);
883 private static CapacitySnapshot CreateCapacitySnapshot(
889 double? maximumRegularCapacity =
892 double? maximumAdditionalCapacity =
896 return new CapacitySnapshot(
897 maximumRegularCapacity,
898 maximumAdditionalCapacity,
906 private void ValidatePeriod(
int period)
911 throw new ArgumentOutOfRangeException(
914 $
"The period must be between 1 and " +
915 $
"{SupplyChain.PlanningHorizon}.");
919 private static bool SameWarehouse(
924 if (first is
null || second is
null)
926 return first is
null && second is
null;
929 return first.Kind == second.Kind &&
933 private static bool SameWorkCenter(
934 WorkCenterReference? first,
935 WorkCenterReference? second)
938 if (first is
null || second is
null)
940 return first is
null && second is
null;
943 return first.PlantId == second.PlantId &&
947 private static string FormatWarehouse(
948 WarehouseReference reference)
950 return $
"{reference.Kind}:{reference.ReferenceId}";
953 private static string FormatWorkCenter(
954 WorkCenterReference reference)
957 $
"{reference.PlantId}:{reference.WorkCenterId}";
983 throw new ArgumentNullException(
984 nameof(transportResource));
987 throw new ArgumentNullException(nameof(lane));
1009 $
"{TransportResource.Name}: " +
1010 $
"{FormatWarehouse(Lane.Origin)} -> " +
1011 $
"{FormatWarehouse(Lane.Destination)} " +
1012 $
"({LeadTime} period(s))";
1039 double? maximumRegularCapacity,
1040 double? maximumAdditionalCapacity,
1041 bool isItemSpecific)
1044 maximumRegularCapacity;
1047 maximumAdditionalCapacity;
1092 MaximumRegularCapacity.HasValue
1093 ? MaximumRegularCapacity.Value +
1102 return "No capacity constraint";
1106 $
"Regular: {MaximumRegularCapacity.Value}; " +
1108 $
"{MaximumAdditionalCapacity ?? 0.0}; " +
1109 $
"Total: {TotalMaximumCapacity}";
int Id
Gets or sets the numerical identifier of the entity.
Represents the maximum additional capacity that may be used during each planning period.
double GetMaximumAdditionalCapacity(int period)
Gets the maximum additional capacity available during a planning period.
Represents a maximum-capacity constraint defined for each planning period.
double GetMaximumCapacity(int period)
Gets the maximum capacity available during a planning period.
Provides fast access to the entities contained in a supply chain.
SupplyChain SupplyChain
Gets the indexed supply chain.
A runtime join of the central lane and assignment; stores no copied business data.
A transport resource with its own shared capacities and costs.
AdditionalCapacity? AdditionalCapacity
Gets or sets the maximum additional capacity that may be allocated to the transport resource during e...
CapacityConstraint? CapacityConstraint
Gets or sets the maximum regular capacity available for the transport resource during each planning p...
Represents a warehouse in the supply chain.
AdditionalCapacity? AdditionalCapacity
Gets or sets the maximum additional storage capacity that may be allocated to the warehouse.
CapacityConstraint? CapacityConstraint
Gets or sets the maximum global storage capacity of the warehouse during each planning period.
Represents a serializable reference to a warehouse.
int ReferenceId
Gets or sets the referenced identifier.
Represents a production work center belonging to a plant.
CapacityConstraint? CapacityConstraint
Gets or sets the maximum regular capacity available during each planning period.
AdditionalCapacity? AdditionalCapacity
Gets or sets the maximum additional capacity that may be allocated during each planning period.
Represents a serializable reference to a work center.
int WorkCenterId
Gets or sets the identifier of the referenced work center.
Represents the maximum regular and additional capacity available during one planning period.
double? MaximumRegularCapacity
Gets the regular-capacity limit.
override string ToString()
bool HasRegularCapacity
Gets a value indicating whether a regular-capacity constraint is active.
bool IsItemSpecific
Gets a value indicating whether the capacity is defined specifically for an item-resource relationshi...
double? TotalMaximumCapacity
Gets the total maximum capacity.
CapacitySnapshot(double? maximumRegularCapacity, double? maximumAdditionalCapacity, bool isItemSpecific)
Initializes a capacity snapshot for one resource and one planning period.
double? MaximumAdditionalCapacity
Gets the additional-capacity limit.
bool HasAdditionalCapacity
Gets a value indicating whether additional capacity is available.
override string ToString()
DirectTransportOption(TransportResource transportResource, AssignedTransportLane lane)
Initializes a direct transport option associating a transport resource with one of its lanes.
AssignedTransportLane Lane
Gets the origin, destination and lead time.
int LeadTime
Gets the direct-transport lead time.
TransportResource TransportResource
Gets the transport resource performing the movement.
IReadOnlyList< Supplier > GetSuppliersForInventory(int itemId, WarehouseReference warehouse)
Gets all suppliers able to deliver an item to a warehouse.
IReadOnlyList< SupplierDelivery > GetDeliveriesFromSupplier(int supplierId)
Gets all delivery possibilities offered by a supplier.
IReadOnlyList< Inventory > GetInventoriesForItem(int itemId)
Gets all inventories defined for an item.
Inventory GetRequiredInventory(int itemId, WarehouseReference warehouse)
Gets the inventory associated with an item and a warehouse.
IReadOnlyList< TransportCharacteristic > GetTransportCharacteristicsForItem(int itemId)
Gets all transport characteristics available for an item.
ProductionCharacteristic? FindProductionCharacteristic(int itemId, WorkCenterReference workCenter)
Finds the production characteristic associated with an item and a work center.
ProductionCharacteristic GetRequiredProductionCharacteristic(int itemId, WorkCenterReference workCenter)
Gets the production characteristic associated with an item and a work center.
IReadOnlyList< Demand > GetDemandsForItem(int itemId)
Gets all demands for an item.
SupplyChainQueries(SupplyChain supplyChain)
Initializes query services for a supply chain and creates a new entity index.
TransportCharacteristic? FindTransportCharacteristic(int itemId, int transportResourceId)
Finds the transport characteristic associated with an item and a transport resource.
IReadOnlyList< DirectTransportOption > GetDirectTransportOptionsForItem(int itemId, WarehouseReference origin, WarehouseReference destination)
Gets the direct transport options that can carry a specified item.
IReadOnlyList< ProductionRouting > GetProductionRoutingsForItem(int itemId)
Gets all production routings available for an item.
TransportCharacteristic GetRequiredTransportCharacteristic(int itemId, int transportResourceId)
Gets the transport characteristic associated with an item and a transport resource.
IReadOnlyList< Item > GetItemsProducedByWorkCenter(WorkCenterReference workCenter)
Gets all items that may be produced on a work center.
Demand? FindDemand(int itemId, int distributionCenterId)
Finds the demand associated with an item and a distribution center.
SupplyChainQueries(SupplyChainIndex index)
Initializes query services using an existing index.
void RebuildIndex()
Rebuilds the underlying entity index.
IReadOnlyList< ProductionCharacteristic > GetProductionCharacteristicsForWorkCenter(WorkCenterReference workCenter)
Gets all production characteristics using a work center.
ProductionRouting GetRequiredProductionRouting(int routingId)
Gets a production routing by its identifier.
SupplyChainIndex Index
Gets the entity index used to resolve references.
IReadOnlyList< DistributionCenterSourcing > GetSourcingsFromWarehouse(WarehouseReference warehouse)
Gets all sourcing relationships using a warehouse.
IReadOnlyList< SupplierDelivery > GetDeliveriesForItem(int itemId)
Gets all supplier deliveries available for an item.
CapacitySnapshot GetTransportResourceCapacity(int transportResourceId, int period)
Gets the global capacity of a transport resource during a planning period.
IReadOnlyList< ProductionCharacteristic > GetProductionCharacteristicsForItem(int itemId)
Gets all production characteristics defined for an item.
IReadOnlyList< SupplierDelivery > GetDeliveriesToWarehouse(WarehouseReference warehouse)
Gets all supplier deliveries whose destination is the specified warehouse.
CapacitySnapshot GetWorkCenterCapacity(WorkCenterReference workCenter, int period)
Gets the capacity available on a work center during a planning period.
IReadOnlyList< Demand > GetDemandsForDistributionCenter(int distributionCenterId)
Gets all demands expressed by a distribution center.
Inventory? FindInventory(int itemId, WarehouseReference warehouse)
Finds the inventory associated with an item and a warehouse.
IReadOnlyList< Item > GetItemsStoredInWarehouse(WarehouseReference warehouse)
Gets the items that can be stored in a warehouse.
IReadOnlyList< Warehouse > GetSupplyingWarehouses(int distributionCenterId, int itemId)
Gets the warehouses that can supply an item to a distribution center.
IReadOnlyList< DistributionCenterSourcing > GetSourcingOptions(int distributionCenterId, int itemId)
Gets all warehouse sourcing options available for an item and a distribution center.
CapacitySnapshot GetInventoryCapacity(int itemId, WarehouseReference warehouse, int period)
Gets the capacity applicable to a specific inventory.
IReadOnlyList< DirectTransportOption > GetIncomingTransportOptions(WarehouseReference destination)
Gets all direct transport options arriving at a warehouse.
IReadOnlyList< DirectTransportOption > GetOutgoingTransportOptions(WarehouseReference origin)
Gets all direct transport options leaving a warehouse.
CapacitySnapshot GetWarehouseCapacity(WarehouseReference warehouse, int period)
Gets the global capacity of a warehouse during a planning period.
Demand GetRequiredDemand(int itemId, int distributionCenterId)
Gets the demand associated with an item and a distribution center.
IReadOnlyList< ProductionRouting > GetProductionRoutingsForPlant(int plantId)
Gets all production routings belonging to a plant.
CapacitySnapshot GetTransportCapacity(int itemId, int transportResourceId, int period)
Gets the capacity applicable to an item transported by a transport resource.
ProductionRouting? FindProductionRouting(int routingId)
Finds a production routing by its identifier.
IReadOnlyList< DirectTransportOption > GetDirectTransportOptions(WarehouseReference origin, WarehouseReference destination)
Gets all direct transport options between two warehouses.
SupplyChain SupplyChain
Gets the queried supply chain.
IReadOnlyList< Item > GetItemsTransportedByResource(int transportResourceId)
Gets all items compatible with a transport resource.
IReadOnlyList< Inventory > GetInventoriesForWarehouse(WarehouseReference warehouse)
Gets all inventories defined in a warehouse.
IReadOnlyList< ProductionRouting > GetProductionRoutings(int itemId, int plantId)
Gets all production routings for an item in a plant.
bool HasDirectTransportConnection(WarehouseReference origin, WarehouseReference destination)
Determines whether at least one direct transport option exists between two warehouses.
double GetDemandQuantity(int itemId, int distributionCenterId, int period)
Gets the demand quantity for a specific period.
Represents the demand for an item issued by a distribution center.
double GetQuantity(int period)
Gets the demand quantity for a planning period.
Represents the inventory of an item in a warehouse.
AdditionalCapacity? AdditionalCapacity
Gets or sets the maximum additional storage capacity available specifically for this item.
CapacityConstraint? CapacityConstraint
Gets or sets the maximum storage capacity reserved for this item during each planning period.
Represents the production characteristics of an item on a specific work center.
Represents a production routing used to manufacture an item in a plant through one or more work cente...
Represents the transport characteristics of an item for a specific transport resource.
AdditionalCapacity? AdditionalCapacity
Gets or sets the maximum additional transport capacity available specifically for this item.
CapacityConstraint? CapacityConstraint
Gets or sets the maximum transport capacity available specifically for this item during each planning...
Represents the complete supply-chain data model.
List< Inventory > Inventories
Gets the item-warehouse inventories.
List< TransportResource > TransportResources
Gets the transport resources in the supply chain.
List< SupplierDelivery > SupplierDeliveries
Gets the supplier delivery possibilities.
List< DistributionCenterSourcing > DistributionCenterSourcings
Gets the warehouse sourcing options available to distribution centers.
IEnumerable< AssignedTransportLane > GetTransportLanes(int resourceId)
List< ProductionCharacteristic > ProductionCharacteristics
Gets the item-work-center production characteristics.
int PlanningHorizon
Gets or sets the number of periods in the global planning horizon.
List< TransportCharacteristic > TransportCharacteristics
Gets the item-transport-resource characteristics.
List< ProductionRouting > ProductionRoutings
Gets the production routings.
List< Demand > Demands
Gets the demands expressed by distribution centers.