Click here to Skip to main content
15,891,951 members
Home / Discussions / Algorithms
   

Algorithms

 
AnswerRe: Data Structures and Algorithm Pin
Richard Deeming26-Aug-16 5:41
mveRichard Deeming26-Aug-16 5:41 
AnswerRe: Data Structures and Algorithm Pin
Beginner Luck30-Aug-16 17:56
professionalBeginner Luck30-Aug-16 17:56 
QuestionHow to do Ray and Triangle-Edge Intersect/Picking? Pin
Farhad Reza7-Aug-16 3:45
Farhad Reza7-Aug-16 3:45 
AnswerRe: How to do Ray and Triangle-Edge Intersect/Picking? Pin
Kenneth Haugland10-Aug-16 5:55
mvaKenneth Haugland10-Aug-16 5:55 
AnswerRe: How to do Ray and Triangle-Edge Intersect/Picking? Pin
patbob18-Aug-16 11:57
patbob18-Aug-16 11:57 
GeneralRe: How to do Ray and Triangle-Edge Intersect/Picking? Pin
Farhad Reza18-Aug-16 23:38
Farhad Reza18-Aug-16 23:38 
GeneralRe: How to do Ray and Triangle-Edge Intersect/Picking? Pin
patbob19-Aug-16 5:50
patbob19-Aug-16 5:50 
QuestionPackage Calculations for Shipping, do you see room for improvement Pin
jkirkerx4-Aug-16 9:26
professionaljkirkerx4-Aug-16 9:26 
I'm in the process of writing my 4th generation package calculator. Over the years, UPS and FedEx require that you enter package dimensions and weight to get a quote.

Before I was able to create a clump, which I call a unit of mass, based off the cart database which contains each products dimensions, then cube that clump into a cube shape. But times have changed.

My 3rd generation package calculator was a complete failure overall, in which I tried using SQL Linq to calculate from the database

So here is my 4th generation attempt.

I get all the items from the database, and throw the items into 1 of 4 categories - List(Of

These will always be separate packages
Isolated Items - Case Quantities, you just slap a label on them and ship
Long Items, like sticks, long levels over 6ft

These can be combined into a single package, if under the max parameters
Thin Items like pancakes, AAA batteries less than 1/2" height
Common Items - you can throw them in a box, slap a label and ship

Then I wrote 4 functions that calculate the length, width, height, dimensional weight, gravity weight.

Within each function, a loop runs.
Each function is slightly different, ...
1. lines up the items by length, then loops down the lengths going wider, then taller
2. stacks them up like a tower, largest on the bottom
3. Isolate - its just a package, get the length, width, height, weight and go
4. Common - I'm in doubt on this one, needs improvement

If the limit is reached, the Create_Package fires and makes a Package.

So now I have these packages, and run Package_Combine, in which I see if I can throw a THIN package into the common box, to reduce the number of packages, because each package has a base cost of $7.00, and shoppers freak out.

The packages are a class of package_types, that are sent off to UPS or Fedex for a Quote, in which those programs I wrote loop and submit each package as a single shipment.

My code is too large to post. So I will post a snippet of 2 functions to start with.

So my question is, do you think I'm on the right track. Does a better more efficient way pop into your head. Did I make it way too complicated?
Think I get can further refine the 4 functions into 1 function by using more Linq?

I have to get this right this time, I'm tired of being poor and need to raise my income. I don't have the funds to just pay someone to write this, and how would I validate that person before hire.
Oh and I expect to hear crickets on this post, sit here forever with no reply.

Here are some known values
Private Const MAX_DIMENSIONAL_LENGTH As Decimal = 108.0
Private Const MAX_DIMENSIONAL_WEIGHT As Decimal = 165.0
Private Const MAX_GRAVITY_WEIGHT As Decimal = 150.0
Private Const MAX_TYPICAL_BOXLENGTH As Decimal = 37.0
Private Const MIN_TYPICAL_LONG_ITEM As Decimal = 72.0
Common Items - I'm in doubt about this one.
VB.NET
Private Shared Function Package_C1( _
  ByVal pItems As List(Of model_rateItems), 
  ByRef packages() As package_type) As Integer

    Dim pValue As Integer = 0
    Dim pdx As Integer = 0
    Dim item As New model_rateItems()

    Dim gWeight As Decimal = 0
    Dim dWeight As Decimal = 0
    Dim dPackage As Decimal = 0
    Dim oFlag As Boolean = True

    For Each p As model_rateItems In pItems _
       .OrderByDescending(Function(m) m.Length) _
       .OrderByDescending(Function(m) m.Width) _
       .OrderByDescending(Function(m) m.Height)

        pdx += 1

        If (p.Qty = 1) Then

            gWeight += p.Weight
            item.Cost += p.Cost
            item.Price += p.Price
            item.Weight += p.Weight
            item.Description = If(item.Description Is String.Empty, p.Description, item.Description & ", " & p.Description)
            item.Hazmat = If(p.Hazmat = True, True, item.Hazmat)
            item.DryIce = If(p.DryIce = True, True, item.DryIce)
            item.Origin = If(item.Origin Is String.Empty, p.Origin, item.Origin)

            item.Length = If(p.Length > item.Length, p.Length, item.Length)
            item.Width = If(p.Width > item.Width, p.Width, item.Width)
            item.Height = If(item.Height = 0, p.Height, (item.Height + p.Height))

            dWeight = Calc_DWeight(item)
            If (dWeight > MAX_DIMENSIONAL_WEIGHT Or item.Weight > MAX_GRAVITY_WEIGHT) Then
                pValue += Package_Create("COMMON", dWeight, item, packages)
            End If

        Else

            item.Cost += p.Cost * p.Qty
            item.Price += p.Price * p.Qty
            item.Weight += p.Weight * p.Qty
            item.Description = If(item.Description Is String.Empty, p.Description, item.Description & ", " & p.Description)
            item.Hazmat = If(p.Hazmat = True, True, item.Hazmat)
            item.DryIce = If(p.DryIce = True, True, item.DryIce)
            item.Origin = If(item.Origin Is String.Empty, p.Origin, item.Origin)

            item.Length = If(p.Length > item.Length, p.Length, item.Length)
            item.Width = If(p.Width > item.Width, p.Width, item.Width)
            item.Height = If(item.Height = 0, p.Height, (item.Height + (p.Height * p.Qty)))

            dWeight = Calc_DWeight(item)
            If (dWeight > MAX_DIMENSIONAL_WEIGHT Or item.Weight > MAX_GRAVITY_WEIGHT) Then
                pValue += Package_Create("COMMON", dWeight, item, packages)
            End If

        End If

    Next

    'Create a Package if no package exist
    dWeight = Calc_DWeight(item)
    pValue += Package_Create("COMMON", dWeight, item, packages)

    Return pValue

End Function
Long Items - It's seems to work well. but I think maybe there's a more efficient way to do it.
VB.NET
Private Shared Function Package_L1( _
    ByVal pItems As List(Of model_rateItems), 
    ByRef packages() As package_type) As Integer

    Dim pValue As Integer = 0
    Dim pdx As Integer = 0

    Dim item As New model_rateItems()
    Dim dWeight As Decimal = 0
    Dim oFlag As Boolean = True

    For Each p As model_rateItems In pItems.OrderByDescending(Function(m) m.Length)

        pdx += 1    'Track our SKU count

        If (p.Qty = 1) Then

            item.Cost += p.Cost
            item.Price += p.Price
            item.Weight += p.Weight
            item.Description = If(pdx = 1, p.Description, ", " & p.Description)
            item.Hazmat = If(p.Hazmat = True, True, item.Hazmat)
            item.DryIce = If(p.DryIce = True, True, item.DryIce)
            item.Origin = If(item.Origin Is String.Empty, p.Origin, item.Origin)

            If (p.Length > item.Length) Then
                'Increase the length, all shorter items fall within the length
                item.Length = p.Length
                item.Width = If(item.Width = 0, p.Width, item.Width)
                item.Height = If(item.Height = 0, p.Height, item.Height)

            Else

                'Increase the Width or height
                If (p.Width > item.Width) Then

                    'The width is wider to make it taller
                    item.Length = item.Length
                    item.Width = p.Width
                    item.Height = item.Height + p.Height

                Else

                    'The width is smaller so make it wider
                    item.Length = item.Length
                    item.Width = item.Width
                    item.Height = item.Height + p.Height

                End If

            End If

            dWeight = Calc_DWeight(item)
            If (dWeight > MAX_DIMENSIONAL_LENGTH Or item.Weight > MAX_GRAVITY_WEIGHT) Then

                'We exceeded the mazimum package size, so create a package and continue the loop
                pValue += Package_Create("LONG", dWeight, item, packages)

                'Rewind to the last loop, after creating a package and start again with a fresh package
                dWeight = 0
                item = New model_rateItems()

            ElseIf (pdx = pItems.Count()) Then

                'There are no more SKU items to process, so just make a package and exit the loop
                pValue += Package_Create("LONG", dWeight, item, packages)
                Exit For

            End If

        Else

            'p.Qty > 1

            'Set the default basis
            item.Description = If(pdx = 1, p.Description, item.Description & "," & p.Description)
            item.Hazmat = If(p.Hazmat = True, True, item.Hazmat)
            item.DryIce = If(p.DryIce = True, True, item.DryIce)
            item.Origin = If(item.Origin Is String.Empty, p.Origin, item.Origin)

            'Set a basis for the item dimesions if it's all 0
            item.Width = If(item.Width = 0, p.Width, item.Width)
            item.Height = If(item.Height = 0, p.Height, item.Height)

            For idx As Integer = 0 To p.Qty - 1

                'Increment the basics of a package
                item.Length = item.Length + p.Length
                item.Weight += p.Weight
                item.Cost += p.Cost
                item.Price += p.Price

                If (item.Length > MAX_DIMENSIONAL_LENGTH And item.Weight < MAX_GRAVITY_WEIGHT) Then

                    'Reduce the Length and increase the width
                    If (p.Length > item.Length) Then

                        item.Length = p.Length
                        item.Width += p.Width
                        item.Height = If(p.Height > item.Height, p.Height, item.Height)

                    Else

                        item.Length = item.Length - p.Length
                        item.Width += p.Width
                        item.Height = If(p.Height > item.Height, p.Height, item.Height)

                    End If

                ElseIf (item.Length < MAX_DIMENSIONAL_LENGTH And item.Weight < MAX_GRAVITY_WEIGHT) Then

                    'Reduce the Length and increase the width
                    If (p.Length > item.Length) Then

                        item.Length = p.Length
                        item.Width += p.Width
                        item.Height = If(p.Height > item.Height, p.Height, item.Height)

                    Else

                        item.Length = item.Length
                        item.Width += p.Width
                        item.Height = If(p.Height > item.Height, p.Height, item.Height)

                    End If

                End If

                'Run a max package size test
                dWeight = Calc_DWeight(item)
                If (dWeight > MAX_DIMENSIONAL_WEIGHT Or item.Weight > MAX_GRAVITY_WEIGHT) Then

                    'We exceeded the mazimum package size, so create a package and continue the loop
                    pValue += Package_Create("LONG", dWeight, item, packages)

                    'Rewind to the last loop, after creating a package and start again with a fresh package
                    dWeight = 0
                    idx = idx - 1
                    item = New model_rateItems()

                End If
            Next    'Loop for Qty of item
        End If
    Next    'Loop for SKU 

    If (pValue = 0) Then

        'Run a max package size test
        dWeight = Calc_DWeight(item)

        'If the items are so small, that a package has not been created, then create a package
        pValue += Package_Create("LONG", dWeight, item, packages)

    End If

    Return pValue

End Function

SuggestionRe: Package Calculations for Shipping, do you see room for improvement Pin
Richard Deeming4-Aug-16 10:29
mveRichard Deeming4-Aug-16 10:29 
GeneralRe: Package Calculations for Shipping, do you see room for improvement Pin
jkirkerx4-Aug-16 12:10
professionaljkirkerx4-Aug-16 12:10 
GeneralRe: Package Calculations for Shipping, do you see room for improvement Pin
Slacker00710-Aug-16 3:35
professionalSlacker00710-Aug-16 3:35 
AnswerRe: Package Calculations for Shipping, do you see room for improvement Pin
Gerry Schmitz5-Aug-16 4:57
mveGerry Schmitz5-Aug-16 4:57 
GeneralRe: Package Calculations for Shipping, do you see room for improvement Pin
jkirkerx5-Aug-16 6:45
professionaljkirkerx5-Aug-16 6:45 
AnswerI created a console app for those that want to play with it Pin
jkirkerx5-Aug-16 8:24
professionaljkirkerx5-Aug-16 8:24 
AnswerRe: Package Calculations for Shipping, do you see room for improvement Pin
ip-address10-Aug-16 2:21
ip-address10-Aug-16 2:21 
GeneralRe: Package Calculations for Shipping, do you see room for improvement Pin
jkirkerx10-Aug-16 6:55
professionaljkirkerx10-Aug-16 6:55 
QuestionCar Engine and Tire heat simulation (for games) Pin
_D4N23-May-17 3:58
_D4N23-May-17 3:58 
AnswerRe: Car Engine and Tire heat simulation (for games) Pin
Gerry Schmitz22-Jul-16 12:25
mveGerry Schmitz22-Jul-16 12:25 
AnswerRe: Car Engine and Tire heat simulation (for games) Pin
jkirkerx4-Aug-16 9:36
professionaljkirkerx4-Aug-16 9:36 
QuestionCan anybody help me with sourse code for quantum key distribution (QKD) written in any general language. Pin
Possible AC4-Jul-16 6:35
Possible AC4-Jul-16 6:35 
AnswerRe: Can anybody help me with sourse code for quantum key distribution (QKD) written in any general language. Pin
Richard MacCutchan4-Jul-16 6:41
mveRichard MacCutchan4-Jul-16 6:41 
AnswerRe: Can anybody help me with sourse code for quantum key distribution (QKD) written in any general language. Pin
Kimberly Weldon5-Jul-16 1:33
Kimberly Weldon5-Jul-16 1:33 
QuestionProtecting PDF File (URGENT) Pin
Member 1261197130-Jun-16 1:12
Member 1261197130-Jun-16 1:12 
AnswerRe: Protecting PDF File (URGENT) Pin
Richard MacCutchan30-Jun-16 1:24
mveRichard MacCutchan30-Jun-16 1:24 
AnswerRe: Protecting PDF File (URGENT) Pin
Eddy Vluggen30-Jun-16 1:42
professionalEddy Vluggen30-Jun-16 1:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.