This commit is contained in:
Nicolas Héron 2016-06-03 15:58:31 +02:00
commit 471f730d67
10 changed files with 149 additions and 23 deletions

View file

@ -1,2 +1,8 @@
# droolscourse
blabla
# Drools on boarding course
This is the source code that goes with the git book [Drools On Boarding](https://nheron.gitbooks.io/droolsonboarding/content/) .
The Account project is for the Drools tutorial and the cost-calculation project is the exercice part.
[Exercice project ](cost-calculation/README.md)

View file

@ -0,0 +1,78 @@
# Cost Calculation project
# Requirements
We are working for a retail company that buys its products from different places in Asian mostly. each shop can go to the buying web site and say what he wants and put an order.
Up to now, the transport cost was a estimated but not calculated on the content of the order.
The purpose is to implement such a calculator.
## Data model
A customer puts an order that contains products. An order contains a lost of products with a number.
A product has
* a name
* a height,
* a width,
* a depth,
* transport type : if the product can be put with other products in a pallet, individual(alone) or bulk (like sand for example)
* a weight
A product can be put on a pallet. a pallet 120 cm width and and 80 cm depth. It can be maximum 2 meters height and the weight should not exceed 1400 kg. We should use a simple algorithm to fill each pallet. It will be not optimized but we should used that as a margin of the costs. a product that is bigger than 60 cm in width or depth or higher than 1m should be put alone in a pallet.
All products start from the same city and go to the same city in an order. A trip is composed f steps. Each step can be done by train, boat or truck.
Here is the list of products in our test order.
| Product | Transport type | Number | Height | Weight | depth | weight |
| -- | -- | -- | -- | -- | -- | -- |
| drill | pallet | 1000 | 20cm | 40cm | 30cm | 2 kg |
| screwdriver | pallet | 30000 | 3cm | 2cm | 20cm | 0,2 kg |
| Sand | bulk | | | | | 35 Tons |
| Gravel | bulk | | | | | 14 Tons |
| furniture | individual |23 | | | | 500 kg |
And the trip is a follows :
| # | start city | arrival city | distance (km) | travel mode |
| -- | -- | -- | -- | -- |
| 1 | Shangai | Rotterdam | 22000 | Boat|
| 2 | Rotterdam | Tournai | 300 | Train |
| 3 | Tournai | Lille | 20 | Truck |
there are 3 types of costs :
- transport costs per Pallet
| Transport| Cost
| -- | -- |
| boat | 0,2€/km |
| Train | 0,5€/km |
| Truck | 1€/km |
- Taxes
| City| Cost
| -- | -- |
| Shangai | 0,02€/kg |
| Rotterdam | 0,05€/kg and 1€ per handling person |
| Tournai | 2€ per handling person |
| Lille | 30€ per handling person |
- handling
| City| Cost
| -- | -- |
| Shangai | 20€/hour and a person can handle 13 pallets/hour |
| Rotterdam | 45€/hour and a person can handle 60 pallets/hour |
| Tournai | 67€/hour and can handle 40 pallets/hour |
| Lille | 79€/hour and can handle 30 pallets/hour |
The handling should not take more than 12 hours.
[Data Model ](src/main/java/cost/README.md)
[The rules we implemented ](src/main/resources/rules/README.md)

View file

@ -1,6 +0,0 @@
package cost;
public class CostItem {
}

View file

@ -0,0 +1,42 @@
# Cost Calculation Data model
The first thing to do when using drools is to build the java class model on which the rules will apply.
![](diagram.jpg)
* CostCalculationRequest
This is the top entity that will contain the trip description as well as the order the customer did and witch trip has to be calculated.
And in the same object, we shall put the final result in a list of costs and the complete list of pallets where we will put the products.
* Trip
Contains the list of steps of the trip.
* Step
A step happens between two cities and a unique transport type : train, truck or boat
* City
A city which can ne a harbour, a train station or a a final destination by truck.
* Order
The detail of the customer order.
* OrderLine
It contains the product as well as the number of items.
* LeftToDistribute
As we have to distribute all products in the pallets, we shall store here during the distribution what is left to be distributed.
* Product
The product that is bought and has to be in the transport.
* Pallet
Here is a picture of a pallet.
![](pallet.jpg)
* HandlingCostElement, TaxesCostElement and TransportCostElement
they represent the different costs that we have to calculate.
* CalculatedElement
We shall use this class to store intermediate values.

View file

@ -4,7 +4,7 @@ public class TaxesCostElement implements CostElement {
private double amount;
private City city;
private Pallet pallet;
public double getAmount() {
return amount;
@ -22,18 +22,10 @@ public class TaxesCostElement implements CostElement {
this.city = city;
}
public Pallet getPallet() {
return pallet;
}
public void setPallet(Pallet pallet) {
this.pallet = pallet;
}
@Override
public String toString() {
return "TaxesCostElement [amount=" + amount + ", city=" + city + ", pallet="
+ pallet + "]";
return "TaxesCostElement [amount=" + amount + ", city=" + city + "]";
}
}

View file

@ -1,5 +0,0 @@
package cost;
public class TotalAmount {
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 96 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

View file

@ -0,0 +1,19 @@
# Rules
We shall use a Ruleflow and implement the rules in 3 steps :
* Distribute the products in the pallet
* Calculate the costs
* Calculate and Display the results
This is done in the P1.bpmn2.
![](ruleflow.png)
## Distribute the products in the pallet
## Calculate the costs
## Sum the results

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB