Comments (5)
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:
Added few several test cases as well like send 4 or 5 package together in the same file above 👆
see PR #11
from courrier-service.
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
from courrier-service.
Added the test case above 👆 in this commit 1e54b69
In this PR #11
from courrier-service.
Solved in PR #11, close for now. If still have issues, comment below
from courrier-service.
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 highestnumber of element
- If more than one combo having same
number of element
and is highestnumber 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
from courrier-service.
Related Issues (3)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from courrier-service.