2011-12-28 7 views
0

2.0との配列の比較は、最近、私はこの質問をしました。複数の場所からの発送が可能で、基本的には効率的な発送をしたいので、購入したすべての商品を1か所から発送することができれば、グループ化して発送しますが、そうでない場合はできるだけグループ化して残りを発送します最も高い在庫レベルが利用可能であればどこからでも。インテリジェント.NET VB

休暇中にもう少し考えてみたら、私はそういうアプローチにはならないと思います。

つの理由

  1. 場所の数が可変であることを持っているので、このシステムは、スケーラブルです。
  2. アイテムの数もそう

スケーラブルなので、代わりに、適切な在庫場所をリストの、私は今、それぞれの項目について、それぞれの場所で利用可能在庫の数量を一覧表示しています。

Items  Locations 
_________|__1___|___2__|__3__| - this is location IDs 
Item 1 | 3 , 4 , 1 - this is the qty of stock available 
Item 2 | 2 , 4 , 0  
Item 3 | 1 , 3 , 1  
Item 4 | 6 , 1 , 3  

私はここ

stockDetails = "3,4,1|2,4,0|1,3,1|6,1,3" 

すなわちアレイ

を分割して作成するために使用されるかもしれない文字列にこれを変えることができ、カンマ区切り値は、各在庫場所で利用可能な在庫の量でありますパイプは個々の項目を分けるので、上記の表は上の文字列に変換されます。

私は多次元配列に熱心ではなく、ストックポジションの数がわからなくてもどのように作成するのか分かりません。

私たちは、安全在庫数量が入荷位置IDへ相関させる正しい順序であることを

  1. をとることができます。
  2. コンマで区切られた各パイプの一連の値は、コンマで区切られた同じ数の値を持ちます。

ピックの場所を特定する方法はありません。

上記の例では、実際には4つの品目すべてを在庫場所1から選択することができ、各品目の1つだけを購入することができます。顧客がアイテム3のうち2つを購入したとします。その場合、ピックはロケーション2からのものでなければなりません。購入したアイテムの数、購入したアイテムの数、から選ぶことです。

私は、入手可能な在庫が最も高い場所からピッキングすることから始めましたが、不要な複数の発送場所で終わったため、在庫が複数の場所から選択できるときは意味がありませんでした。

これらの可変長文字列/配列を分析して、ディスパッチする最もインテリジェントな方法を判断するにはどうすればよいですか。

私は人間の頭脳を使って株価表からうまく動くことができますが、VB.NETをプログラミングする方法はわかりません!

VBの例を参考にしてください。また、私のオリジナルの質問についての助けに感謝しますが、私は指定しませんでしたが、Linqを.NET 2.0フレームワークとして使用することはできません。

+0

あなたはジェネリックコレクションを使用することができます、またはあなたが何らかの理由でアレイを使用して立ち往生している:更新

ここではCalculateInventory方法の.NET 2.0バージョンですか? –

+0

いいえ、立ち往生していない、ちょうどinexpereinced。私はGoogleの一般的なコレクションを使用します...助けてくれるものへの適切なリンクがある場合は、教えてください! :-) –

+0

http://msdn.microsoft.com/en-us/library/system.collections.generic.aspx –

答えて

2

これが私のアプリケーションだった場合、それぞれの場所で、要求された製品ごとに利用可能な数量のリストを保持する小さなクラスを作成します。

データを取得すると、少なくとも1つの製品の在庫がある場所ごとに、これらのロケーションクラスのコレクションを作成します。

私は、その場所から達成できる製品のパーセンテージを示す重みを提供する方法を持っています。私は、もし知られていれば、場所から配送場所までの距離を示す方法もあるでしょう。

ロケーションクラスは、アイテムの割合と距離を比較メトリックとして使用してIComparableを実装し、アイテムをコレクション内で並べ替えることができます。オーダーから満たされることになる場所を決定するために

、私は次の操作を行います:

1)場所のリストをソートし、リストの最初のものを選択します。場所が分かっている場合は、これも配達先に最も近い場所になります。

2)手順1で選択した場所が注文の100%を満たしていない場合は、場所の一覧を繰り返して、選択した場所で満足していた製品を削除します。指定された場所が0%の場合は、場所のコレクションからその場所を削除します。

3)すべての製品は選ばれていないと場所がリストに残っている場合は、ステップ1

からの再起動がうまくいけば、これはあなたが正しい軌道に乗ることができます。ここで

更新

はあなたが始めるために何かです。

この

は仕事最後に

''' <summary> 
''' This collection contains a list if LocationQuantities keyed by LocationId 
''' </summary> 
''' <remarks></remarks> 
Public Class LocationQuantitiesCollection 
    Inherits Generic.List(Of LocationQuantities) 

    ' A local dictionary used for indexing 
    Private m_cDictionaries As Generic.Dictionary(Of Integer, LocationQuantities) 

    Public Sub New() 
     m_cDictionaries = New Generic.Dictionary(Of Integer, LocationQuantities) 
    End Sub 

    ''' <summary> 
    ''' This method adds the product and quantity to the specified location 
    ''' </summary> 
    ''' <param name="wLocationId"></param> 
    ''' <param name="wProductId"></param> 
    ''' <param name="dQuantity"></param> 
    ''' <remarks></remarks> 
    Public Sub AddLocationAndQuantityForProduct(wLocationId As Integer, wProductId As Integer, dQuantity As Decimal) 

     Dim oLocationQuantities As LocationQuantities 

     ' First, see if the location id exists in this collection 
     If m_cDictionaries.ContainsKey(wLocationId) Then 
      ' It does exist, so get a local reference 
      oLocationQuantities = m_cDictionaries(wLocationId) 
     Else 
      ' It does not exist, so add a new entry 

      oLocationQuantities = New LocationQuantities 
      oLocationQuantities.LocationId = wLocationId 

      ' The product id does not exist, so add a new entry 
      m_cDictionaries.Add(wLocationId, oLocationQuantities) 

      ' Finally, add it to the underlying list 
      Me.Add(oLocationQuantities) 
     End If 

     ' Finally, add the product and quantity to the location quantity 
     oLocationQuantities.AddQuantityForProductId(wProductId, dQuantity) 
    End Sub 

    ''' <summary> 
    ''' This method calculates the inventory for the specified products and returns a dictionary keyed by productid 
    ''' whose value is the locationid for the product 
    ''' </summary> 
    ''' <param name="cProductIds"></param> 
    ''' <returns></returns> 
    ''' <remarks></remarks> 
    Public Function CalculateInventory(cProductIds As List(Of Integer)) As Generic.Dictionary(Of Integer, Integer) 

     ' This dictionary is keyed by productid and the value is the location id that the product will be delivered from 
     Dim cProductLocations As New Generic.Dictionary(Of Integer, Integer) 
     ' The list of productids left to find 
     Dim cProductsToFind As New Generic.Dictionary(Of Integer, Integer) 

     ' Copy all requested product ids to the list of product ids to find 
     For Each wProductId As Integer In cProductIds 
      cProductsToFind.Add(wProductId, wProductId) 
     Next 

     If Me.Count <> 0 Then 
      Do While cProductsToFind.Count <> 0 
       Dim oLocation As LocationQuantities 

       ' Calculate the weight for each of the locations 
       For Each oLocation In Me 
        oLocation.CalculateWeight(cProductIds) 
       Next 

       ' Sort the list of locations. 
       Me.Sort() 

       ' Get the first location in the list, update the product locations, then remove the products from each of the locations. 
       oLocation = Me.Item(0) 

       ' If there are no available products, bail out of the loop 
       If oLocation.Weight = 0 Then 
        Exit Do 
       End If 

       ' For each of the products to be found (cycle backwards because we may be removing items from the list) 
       For nI As Integer = cProductsToFind.Count - 1 To 0 Step -1 
        Dim wProductId As Integer 

        ' Get the productid 
        wProductId = cProductsToFind.Keys(nI) 

        ' If this location has a quantity, record this location as the location for the product and remove the product from the list 
        ' of products to find. 
        If oLocation.ProductQuantities.ContainsKey(wProductId) AndAlso oLocation.ProductQuantities(wProductId) <> 0 Then 
         ' This code assumes that found products have been removed 
         cProductLocations.Add(wProductId, oLocation.LocationId) 
         ' Remove the product to find from the list of products to find 
         cProductsToFind.Remove(wProductId) 
        End If 
       Next 

       If cProductsToFind.Count <> 0 Then 
        ' If there are more products to find, remove the found products from each of the locations and process again. 
        For Each oLocation In Me 
         ' Work backwards through the list of keys since we may be removing items 
         For nI As Integer = oLocation.ProductQuantities.Keys.Count - 1 To 0 Step -1 
          Dim wProductId As Integer 

          ' Get the product id 
          wProductId = oLocation.ProductQuantities.Keys(nI) 

          ' If we no longer need to find this product id, remove it from the list of product quantities at this location 
          If Not cProductsToFind.ContainsKey(wProductId) Then 
           cProductsToFind.Remove(wProductId) 
          End If 
         Next 
        Next 
       End If 
      Loop 
     End If 

     Return cProductLocations 
    End Function 
End Class 

の多くを行い、上記項目のコレクションクラスの場所のクラスここで

Public Class LocationQuantities 
    Implements IComparable 

    Public Sub New() 
     m_cProductQuantities = New Generic.Dictionary(Of Integer, Decimal) 
    End Sub 

    Private m_wLocationId As Integer 

    Public Property LocationId As Integer 
     Get 
      Return m_wLocationId 
     End Get 
     Set(value As Integer) 
      m_wLocationId = value 
     End Set 
    End Property 

    Private m_cProductQuantities As Generic.Dictionary(Of Integer, Decimal) 
    ''' <summary> 
    ''' A collection of quantities for each product. The key to the collection is the product id 
    ''' </summary> 
    ''' <value></value> 
    ''' <returns></returns> 
    ''' <remarks></remarks> 
    Public ReadOnly Property ProductQuantities As Generic.Dictionary(Of Integer, Decimal) 
     Get 
      Return m_cProductQuantities 
     End Get 
    End Property 

    Private m_dWeight As Double 
    ''' <summary> 
    ''' This contains the weight of products for this location as set in CalculateWeight 
    ''' </summary> 
    ''' <value></value> 
    ''' <returns></returns> 
    ''' <remarks></remarks> 
    Public ReadOnly Property Weight As Double 
     Get 
      Return m_dWeight 
     End Get 
    End Property 

    ''' <summary> 
    ''' This method sets the weight for the specified list of product ids 
    ''' </summary> 
    ''' <param name="cProductIds"></param> 
    ''' <remarks></remarks> 
    Public Sub CalculateWeight(cProductIds As Generic.List(Of Integer)) 

     Dim wAvailableProducts As Integer 

     ' Cycle through the list of available products 
     For Each wProductId As Integer In cProductIds 
      ' If our list of products contains the specified product and the product quantity is not 0 
      If Me.ProductQuantities.ContainsKey(wProductId) AndAlso Me.ProductQuantities(wProductId) <> 0 Then 
       ' Increase the count 
       wAvailableProducts += 1 
      End If 
     Next 

     ' Finally calculate the weight as the percentage of available products 
     If cProductIds.Count <> 0 Then 
      m_dWeight = wAvailableProducts/cProductIds.Count 
     Else 
      m_dWeight = 0 
     End If 
    End Sub 

    ''' <summary> 
    ''' This method is used to compare one location to the next 
    ''' </summary> 
    ''' <param name="obj"></param> 
    ''' <returns></returns> 
    ''' <remarks></remarks> 
    Public Function CompareTo(obj As Object) As Integer Implements System.IComparable.CompareTo 

     With DirectCast(obj, LocationQuantities) 
      Return .Weight.CompareTo(Me.Weight) 
     End With 
    End Function 

    ''' <summary> 
    ''' This method is used to add a quantity for the specified productid 
    ''' </summary> 
    ''' <param name="wProductId"></param> 
    ''' <param name="dQuantity"></param> 
    ''' <remarks></remarks> 
    Public Sub AddQuantityForProductId(wProductId As Integer, dQuantity As Decimal) 

     ' First, see if the product id exists in the list of our product quantities 
     If Me.ProductQuantities.ContainsKey(wProductId) Then 
      ' It does exist, so add the new quantity to the existing value 
      Me.ProductQuantities(wProductId) += dQuantity 
     Else 
      ' The product id does not exist, so add a new entry 
      Me.ProductQuantities.Add(wProductId, dQuantity) 
     End If 
    End Sub 
End Class 

に開始されている、ここからの抽出物であります在庫をロードし、所与のアイテムの出所を計算するために使用できるフォーム。

Public Class Form1 

    Dim m_cLocationsAndQuantities As LocationQuantitiesCollection 

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click 
     Call LoadLocationsAndQuantities() 
     Call DoInventoryCalculation() 
    End Sub 

    ''' <summary> 
    ''' Load the locations and quantities 
    ''' </summary> 
    ''' <remarks></remarks> 
    Public Sub LoadLocationsAndQuantities() 

     m_cLocationsAndQuantities = New LocationQuantitiesCollection 

     Dim wLocationId As Integer 
     Dim wProductId As Integer 
     Dim dQuantity As Decimal 

     wLocationId = 1 
     wProductId = 1 
     dQuantity = 120 

     m_cLocationsAndQuantities.AddLocationAndQuantityForProduct(wLocationId, wProductId, dQuantity) 

     wProductId = 2 
     dQuantity = 10 

     m_cLocationsAndQuantities.AddLocationAndQuantityForProduct(wLocationId, wProductId, dQuantity) 

     wLocationId = 2 
     wProductId = 1 
     dQuantity = 4 

     m_cLocationsAndQuantities.AddLocationAndQuantityForProduct(wLocationId, wProductId, dQuantity) 

    End Sub 

    ''' <summary> 
    ''' Perform the inventory calculations 
    ''' </summary> 
    ''' <remarks></remarks> 
    Public Sub DoInventoryCalculation() 

     ' The list of productids to calculate inventory for 
     Dim cProductIds As New List(Of Integer) 
     ' The list of locations where each product will be obtained. The key is the productid and the value is the locationid 
     Dim cLocationsAndProducts As Generic.Dictionary(Of Integer, Integer) 

     Dim wProductId As Integer 

     ' Calculate the inventory for productid 1 
     wProductId = 1 

     cProductIds.Add(wProductId) 

     ' Finally, calculate the inventory 
     cLocationsAndProducts = m_cLocationsAndQuantities.CalculateInventory(cProductIds) 

     If cLocationsAndProducts Is Nothing OrElse cLocationsAndProducts.Count = 0 Then 
      Console.WriteLine("None of the requested products could be found at any location") 
     Else 
      For Each wProductId In cLocationsAndProducts.Keys 
       Console.WriteLine("Product ID " & wProductId & " will be delivered from Location ID " & cLocationsAndProducts(wProductId)) 
      Next 
     End If 
    End Sub 

End Class 
''' <summary> 
''' This method calculates the inventory for the specified products and returns a dictionary keyed by productid 
''' whose value is the locationid for the product 
''' </summary> 
''' <param name="cProductIds"></param> 
''' <returns></returns> 
''' <remarks></remarks> 
Public Function CalculateInventory(cProductIds As List(Of Integer)) As Generic.Dictionary(Of Integer, Integer) 

    ' This dictionary is keyed by productid and the value is the location id that the product will be delivered from 
    Dim cProductLocations As New Generic.Dictionary(Of Integer, Integer) 
    ' The list of productids left to find 
    Dim cProductsToFind As New Generic.Dictionary(Of Integer, Integer) 

    ' Copy all requested product ids to the list of product ids to find 
    For Each wProductId As Integer In cProductIds 
     cProductsToFind.Add(wProductId, wProductId) 
    Next 

    If Me.Count <> 0 Then 
     Do While cProductsToFind.Count <> 0 
      Dim oLocation As LocationQuantities 

      ' Calculate the weight for each of the locations 
      For Each oLocation In Me 
       oLocation.CalculateWeight(cProductIds) 
      Next 

      ' Sort the list of locations. 
      Me.Sort() 

      ' Get the first location in the list, update the product locations, then remove the products from each of the locations. 
      oLocation = Me.Item(0) 

      ' If there are no available products, bail out of the loop 
      If oLocation.Weight = 0 Then 
       Exit Do 
      End If 

      Dim cKeysToRemove As New List(Of Integer) 

      ' For each of the products to be found 
      For Each wProductId As Integer In cProductsToFind.Keys 
       ' If this location has a quantity, record this location as the location for the product and remove the product from the list 
       ' of products to find. 
       If oLocation.ProductQuantities.ContainsKey(wProductId) AndAlso oLocation.ProductQuantities(wProductId) <> 0 Then 
        ' This code assumes that found products have been removed 
        cProductLocations.Add(wProductId, oLocation.LocationId) 
        ' Add the productid to the list of items to be removed 
        cKeysToRemove.Add(wProductId) 
       End If 
      Next 

      ' Now remove the productids 
      For Each wProductId As Integer In cKeysToRemove 
       cProductsToFind.Remove(wProductId) 
      Next 

      If cProductsToFind.Count <> 0 Then 
       ' If there are more products to find, remove the found products from each of the locations and process again. 
       For Each oLocation In Me 
        For Each wProductId As Integer In oLocation.ProductQuantities.Keys 
         ' If we no longer need to find this product id, remove it from the list of product quantities at this location 
         If Not cProductsToFind.ContainsKey(wProductId) Then 
          cProductsToFind.Remove(wProductId) 
         End If 
        Next 
       Next 
      End If 
     Loop 
    End If 

    Return cProductLocations 
End Function 
+0

それはまさに私がやりたいことです...刺激的に、私はプログラミングの専門知識を超えているかもしれないと思います!うーん... ...ありがとう、私は正しい方向に私を指して、私は推測する、私はグーグルを続けるよ! –

+0

@JamieHartnoll:距離の部分を除いて、あなたが取り組まなければならない主な概念を実装するいくつかのスターターコードで答えを更新しました。 –

+0

それは素晴らしいです!ありがとう、義務の呼び出しを超えて行って、ありがとう!私は距離の面を心配していないので、それはクールです。私は今月曜日まで適切にこれに到達することができませんが、返信されます! Jamie –

関連する問題