org.drools.benchmark.manners.MannersBenchmark Maven / Gradle / Ivy
The newest version!
package org.drools.benchmark.manners;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
import java.util.StringTokenizer;
import org.drools.KnowledgeBase;
import org.drools.KnowledgeBaseFactory;
import org.drools.builder.KnowledgeBuilder;
import org.drools.builder.KnowledgeBuilderConfiguration;
import org.drools.builder.KnowledgeBuilderFactory;
import org.drools.builder.ResourceType;
import org.drools.definition.KnowledgePackage;
import org.drools.io.ResourceFactory;
import org.drools.runtime.StatefulKnowledgeSession;
public class MannersBenchmark {
/** Number of guests at the dinner (default: 16). */
private static int numGuests = 16;
/** Number of seats at the table (default: 16). */
private static int numSeats = 16;
/** Minimum number of hobbies each guest should have (default: 2). */
private static int minHobbies = 2;
/** Maximun number of hobbies each guest should have (default: 3). */
private static int maxHobbies = 3;
public static void main(final String[] args) throws Exception {
KnowledgeBuilderConfiguration kbuilderConfig = KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration();
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder( kbuilderConfig );
kbuilder.add( ResourceFactory.newClassPathResource( "manners.drl",
MannersBenchmark.class ),
ResourceType.DRL );
Collection pkgs = kbuilder.getKnowledgePackages();
// add the package to a rulebase
final KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages( pkgs );
for ( int i = 0; i < 10; i++ ) {
StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
String filename;
if ( args.length != 0 ) {
String arg = args[0];
filename = arg;
} else {
filename = "manners128.dat";
}
InputStream is = MannersBenchmark.class.getResourceAsStream( filename );
List list = getInputObjects( is );
for ( Iterator it = list.iterator(); it.hasNext(); ) {
Object object = it.next();
ksession.insert( object );
}
ksession.insert( new Count( 1 ) );
long start = System.currentTimeMillis();
ksession.fireAllRules();
System.err.println( System.currentTimeMillis() - start );
ksession.dispose();
}
}
/**
* Convert the facts from the InputStream
to a list of
* objects.
*/
protected static List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy