Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edge case for Delivery Time estimation #10

Closed
kenchoong opened this issue Oct 23, 2022 · 5 comments
Closed

Edge case for Delivery Time estimation #10

kenchoong opened this issue Oct 23, 2022 · 5 comments
Labels

Comments

@kenchoong
Copy link
Owner

TLDR:

  1. Maximize the number of package,
  2. Then maximize the weight,
  3. Then maximize the distance

Change this in getPackageDeliveryCombo method

Beside to meet the requirement, all the possible edge case also need to be handle

Example:

100 5
P1 50 100 OFR002
P2 50 100 OFR001
P3 150 100 OFR003
P4 99 100 OFR001
P5 100 100 OFR001
1 70 200

In this case, P1, P2, P5 should deliver first .

If have more than 1 combination which is highest possible weight, then we have to decide using Distance.

@kenchoong
Copy link
Owner Author

kenchoong commented Oct 24, 2022

Edge case 1:
3 packages total weight is 200, should send first

Base Delivery Cost + (Package Total Weight * 10) +
(Distance to Destination * 5) =

100 5
P1 50 100 OFR002
P2 50 100 OFR001
P3 150 100 OFR003
P4 99 100 OFR001
P5 100 100 OFR001
1 70 200

The result should be
(package id, discount amount, total after discount, delivery time)

P1 0 1100 1.42 
P2 0 1100 1.42 
P3 105 1995 4.26 
P4 0 1590 7.10
P5 0 1600 1.42 

Exact unit test for this case:

it('Delivery time, 3 packages send together', async () => {

Added few several test cases as well like send 4 or 5 package together in the same file above 👆
see PR #11

@kenchoong
Copy link
Owner Author

kenchoong commented Oct 24, 2022

Given 7 packages like this:

P1 30 100
P2 50 100 
P3 120 100 

P5 100  90
P6 85   90 
P7 110 100
P8 75  70

Vehicle 
1 70 200 

Then the sequence should be

Trip 1 [P1, P2, P3] = weight 200 
Trip 2 [P6, P7] = weight 195
Trip 3 [P5, P8] = weight 160 

Then

Trip 1,

P1, P2, P3, (all 3 100/70)  will be [1.42, 1.42, 1.42] 
Current waiting time will be 2.84 (1.42 -lowest * 2) 
2.84 will pass down to next trip

Trip 2

P6 2.84 + 1.28(90/70) = 4.12
P7 2.84 + 1.42(100/70) = 4.26 
  • Current waiting time = 2.84
  • Current waiting time after this trip= 2.84 + (1.42 X 2) = 5.68 (pass down to next trip)
    Note: See Step 4 and Step 1 for stimulation
    In Step 1: It get the highest timeNeeded(Distance/speed)
    In Step 4: Current Waiting Time + highestTimeNeeded X 2

Trip 3

  • Current waiting time = 5.68(Get from last trip)
P5 5.68 + 1.28(90/70) = 6.96
P8 5.68 + 1(70/70) = 6.68

So end up the result look like this, only delivery time stated :

(package id, estimated delivery time)
P1 1.42
P2 1.42 
P3 1.42 

P5 6.96
P6 4.12 
P7 4.26
P8 6.68

@kenchoong
Copy link
Owner Author

kenchoong commented Oct 24, 2022

Added the test case above 👆 in this commit 1e54b69

In this PR #11

@kenchoong
Copy link
Owner Author

kenchoong commented Oct 24, 2022

Solved in PR #11, close for now. If still have issues, comment below

@kenchoong
Copy link
Owner Author

kenchoong commented Oct 24, 2022

Quickly drop down some of my high level thinking above the solution:

For instance I have an original input like this:

[1, 2, 3] 

Then I need to get all the possible combination of the input above, store in an array named subsetArray

[  [ ], [1], [2], [3], [1, 2], [2, 3], [1, 3], [1, 2, 3]  ]

Each of the array inside subsetArray is a combo I want
Read more for Improper subset here
Implement in this commit to find all the possible subset

Then

  • I will loop through subsetArray ,
  • sum all the element inside each combo,
  • only keep the combo which sum up weight less than 200

Then optimize for (aka send first)

  • Combo that have highest number of element
  • If more than one combo having same number of element and is highest number of element, then get the one which having highest sum of weight
  • If more than one combo having same number of element, same sum of weight is highest weight , then pick the one which having higher sum of distance
    This is implemented in this commit

After determine which is the combo

  • remove all the element inside this combo from original input
  • Then repeat the same process again until all packages is sent
    This is implement in this commit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant