[rules-users] Can SolverFactory receive the plain xml? [Planner]
André Fróes
arfmoraes at gmail.com
Wed Jan 23 10:53:56 EST 2013
I"ve seen that i can do this:
solverFactory.getSolverConfig().getScoreDirectorFactoryConfig.setRuleBase(ruleBase);
but this ruleBase still pointing a drl file, i would like to pass a String
to this rulebase, one from my database.
----------- another implementation i tried
final Reader source = new InputStreamReader(
HelloWorldExample.class.getResourceAsStream( "HelloWorld.drl" ) );
final PackageBuilder builder = new PackageBuilder();
builder.addPackageFromDrl( source );
if ( builder.hasErrors() ) {
System.out.println( builder.getErrors().toString() );
throw new RuntimeException( "Unable to compile
\"HelloWorld.drl\".");
}
final Package pkg = builder.getPackage();
final RuleBase ruleBase = RuleBaseFactory.newRuleBase();
ruleBase.addPackage( pkg );
2013/1/22 Geoffrey De Smet <ge0ffrey.spam at gmail.com>
> in the manual, look for setRuleBase(), it's how you can set the DRL at
> runtime
>
> Op 22-01-13 20:17, André Fróes schreef:
>
> Can it be done for the drl file pointed at xml file? Instead of pass the
> path to drl file, the drl content?
>
> here's what i've done to use the xml by java over the cloudcomputing
> example:
>
> --------------------
>
> String t = "<?xml version=\"1.0\"
> encoding=\"UTF-8\"?><solver><solutionClass>org.drools.planner.examples.cloudbalancing.domain.CloudBalance</solutionClass><planningEntityClass>org.drools.planner.examples.cloudbalancing.domain.CloudProcess</planningEntityClass><scoreDirectorFactory><scoreDefinitionType>HARD_AND_SOFT</scoreDefinitionType><scoreDrl>/org/drools/planner/examples/cloudbalancing/solver/cloudBalancingScoreRules.drl</scoreDrl></scoreDirectorFactory><termination><maximumSecondsSpend>120</maximumSecondsSpend></termination><constructionHeuristic><constructionHeuristicType>FIRST_FIT_DECREASING</constructionHeuristicType><constructionHeuristicPickEarlyType>FIRST_LAST_STEP_SCORE_EQUAL_OR_IMPROVING</constructionHeuristicPickEarlyType></constructionHeuristic><localSearch><acceptor><planningEntityTabuSize>7</planningEntityTabuSize></acceptor><forager!
> ><mi
> nimalAcceptedSelection>1000</minimalAcceptedSelection></forager></localSearch></solver>";
>
> byte b[] = t.getBytes();
> ByteArrayInputStream bt = new ByteArrayInputStream(b);
> SolverFactory solverFactory = new
> XmlSolverFactory().configure(bt);
> Solver solver = solverFactory.buildSolver();
> ---------------------
>
> cloudBalancingScoreRules.drl is the file I want to get from database as
> text and apply it to the xml. Is it possible to do inside this
> configuration or will I have to implement a xml file pointing it everytime?
>
>
>
> 2013/1/22 Geoffrey De Smet <ge0ffrey.spam at gmail.com>
>
>> Use a ByteArrayInputStream based on that String
>> and give it to:
>> org.drools.planner.config.XmlSolverFactory#configure(InputStream)
>>
>> Op 22-01-13 15:51, André Fróes schreef:
>>
>> Can I provide the plain xml code to a SolverFactory?
>>
>> SolverFactory solverFactory = new XmlSolverFactory(<<xmlHere>>);
>>
>> I know that I can provide the path to a config file.
>>
>>
>> _______________________________________________
>> rules-users mailing listrules-users at lists.jboss.orghttps://lists.jboss.org/mailman/listinfo/rules-users
>>
>>
>>
>> _______________________________________________
>> rules-users mailing list
>> rules-users at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/rules-users
>>
>>
>
>
> _______________________________________________
> rules-users mailing listrules-users at lists.jboss.orghttps://lists.jboss.org/mailman/listinfo/rules-users
>
>
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20130123/bec203ac/attachment.html
More information about the rules-users
mailing list