add example with rule project dependancy
This commit is contained in:
parent
efb424d524
commit
f2d9bc13ca
41 changed files with 2991 additions and 35 deletions
78
cost-calculation-run/README.md
Normal file
78
cost-calculation-run/README.md
Normal 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)
|
||||
36
cost-calculation-run/cost-calculation-run.iml
Normal file
36
cost-calculation-run/cost-calculation-run.iml
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="false">
|
||||
<output url="file://$MODULE_DIR$/target/classes" />
|
||||
<output-test url="file://$MODULE_DIR$/target/test-classes" />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="module" module-name="cost-calculation-extension" />
|
||||
<orderEntry type="module" module-name="cost-calculation-base" />
|
||||
<orderEntry type="library" name="Maven: org.drools:drools-compiler:6.5.0.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.drools:drools-core:6.5.0.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: commons-codec:commons-codec:1.4" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.kie:kie-internal:6.5.0.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.antlr:antlr-runtime:3.5" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.mvel:mvel2:2.2.8.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.thoughtworks.xstream:xstream:1.4.9" level="project" />
|
||||
<orderEntry type="library" name="Maven: xmlpull:xmlpull:1.1.3.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: xpp3:xpp3_min:1.1.4c" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.google.protobuf:protobuf-java:2.6.0" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.jdt.core.compiler:ecj:4.4.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.jbpm:jbpm-bpmn2:6.5.0.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.jbpm:jbpm-flow-builder:6.5.0.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.jbpm:jbpm-flow:6.5.0.Final" level="project" />
|
||||
<orderEntry type="library" name="Maven: joda-time:joda-time:2.2" level="project" />
|
||||
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.5" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.kie:kie-api:6.5.0.Final" level="project" />
|
||||
<orderEntry type="module" module-name="drools-lesson-pojo" />
|
||||
</component>
|
||||
</module>
|
||||
47
cost-calculation-run/pom.xml
Normal file
47
cost-calculation-run/pom.xml
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>droolscourse</artifactId>
|
||||
<groupId>com.pymma-software.droolscourse</groupId>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>cost-calculation-run</artifactId>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.pymma-software.droolscourse</groupId>
|
||||
<artifactId>cost-calculation-extension</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.drools</groupId>
|
||||
<artifactId>drools-compiler</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jdt.core.compiler</groupId>
|
||||
<artifactId>ecj</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jbpm</groupId>
|
||||
<artifactId>jbpm-bpmn2</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.kie</groupId>
|
||||
<artifactId>kie-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.pymma-software.droolscourse</groupId>
|
||||
<artifactId>drools-lesson-pojo</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
|
@ -0,0 +1,96 @@
|
|||
package calculation;
|
||||
|
||||
import cost.*;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.kie.api.runtime.KieContainer;
|
||||
import org.kie.api.runtime.KieSession;
|
||||
import org.kie.api.runtime.StatelessKieSession;
|
||||
import util.KnowledgeSessionHelper;
|
||||
|
||||
@SuppressWarnings("restriction")
|
||||
public class TestExecercice {
|
||||
|
||||
static KieContainer kieContainer;
|
||||
StatelessKieSession sessionStateless = null;
|
||||
KieSession sessionStatefull = null;
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() {
|
||||
kieContainer = KnowledgeSessionHelper.createRuleBase();
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
System.out.println("------------Before------------");
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
System.out.println("------------After------------");
|
||||
}
|
||||
|
||||
private void insertIntoSession(KieSession sessionStatefull, CostCalculationRequest request) {
|
||||
sessionStatefull.insert(request);
|
||||
if (request.getOrder() != null) {
|
||||
sessionStatefull.insert(request.getOrder());
|
||||
for (OrderLine orderLine : request.getOrder().getOrderLines()) {
|
||||
sessionStatefull.insert(orderLine);
|
||||
sessionStatefull.insert(orderLine.getProduct());
|
||||
}
|
||||
}
|
||||
if (request.getTrip() != null) {
|
||||
sessionStatefull.insert(request.getTrip());
|
||||
for (Step step : request.getTrip().getSteps()) {
|
||||
sessionStatefull.insert(step);
|
||||
sessionStatefull.insert(step.getStepStart());
|
||||
sessionStatefull.insert(step.getStepEnd());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFirstOne() {
|
||||
sessionStatefull = KnowledgeSessionHelper.getStatefulKnowledgeSessionForJBPM(kieContainer, "ksession4");
|
||||
City cityOfShangai = new City(City.ShangaiCityName);
|
||||
City cityOfRotterdam = new City(City.RotterdamCityName);
|
||||
City cityOfTournai = new City(City.TournaiCityName);
|
||||
City cityOfLille = new City(City.LilleCityName);
|
||||
Step step1 = new Step(cityOfShangai, cityOfRotterdam, 22000, Step.Ship_TransportType);
|
||||
Step step2 = new Step(cityOfRotterdam, cityOfTournai, 300, Step.train_TransportType);
|
||||
Step step3 = new Step(cityOfTournai, cityOfLille, 20, Step.truck_TransportType);
|
||||
Trip myTrip = new Trip("trip1");
|
||||
myTrip.getSteps().add(step1);
|
||||
myTrip.getSteps().add(step2);
|
||||
myTrip.getSteps().add(step3);
|
||||
CostCalculationRequest request = new CostCalculationRequest();
|
||||
request.setTrip(myTrip);
|
||||
Product drillProduct = new Product("Drill", 0.2, 0.4, 0.3, 2, Product.transportType_pallet);
|
||||
Product screwDriverProduct = new Product("Screwdriver", 0.03, 0.02, 0.2, 0.2, Product.transportType_pallet);
|
||||
Product sandProduct = new Product("Sand", 0.0, 0.0, 0.0, 0.0, Product.transportType_bulkt);
|
||||
Product gravelProduct = new Product("Gravel", 0.0, 0.0, 0.0, 0.0, Product.transportType_bulkt);
|
||||
Product furnitureProduct = new Product("Furniture", 0.0, 0.0, 0.0, 0.0, Product.transportType_individual);
|
||||
Order myOrder = new Order("1");
|
||||
|
||||
myOrder.getOrderLines().add(new OrderLine(1000, drillProduct));
|
||||
myOrder.getOrderLines().add(new OrderLine(1000, screwDriverProduct));
|
||||
myOrder.getOrderLines().add(new OrderLine(35000.0, sandProduct));
|
||||
myOrder.getOrderLines().add(new OrderLine(14000.0, gravelProduct));
|
||||
myOrder.getOrderLines().add(new OrderLine(500, furnitureProduct));
|
||||
request.setOrder(myOrder);
|
||||
long before = System.currentTimeMillis();
|
||||
|
||||
this.insertIntoSession(sessionStatefull, request);
|
||||
sessionStatefull.startProcess("P1");
|
||||
int i = sessionStatefull.fireAllRules();
|
||||
long after = System.currentTimeMillis();
|
||||
System.out.println("NumberRules Executed " + i);
|
||||
System.out.println("Rules executed in " + (after - before) + " ms");
|
||||
Double dd = new Double(i) / (after - before) * 1000;
|
||||
System.out.println("NbreRules/seconde=" + dd);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
editor.link_modal.header
Reference in a new issue