Where do I code the calculation for a derieved property of the planning entity?
by aitchnyu
I am making a 2X2 sudoku game, modeled after Nqueens example. A `Digit` class
is assigned a `column` and `row` object. The `row` is the planning entity.
But a sudoku game also has a `block`, which is to be calculated from `row`
and `column`. Two digits cannot share a block. A block is null when the row
is null, and a numerical value that will be equal for all digits in the row.
Question: where do I tell the `Digit` object to recalculate it's `block`? I
did it in doMove, but it is misses most places the object is updated (as per
my attempts at logging). Must I set it to update itself when the `row`
property of the object changes, say at `setRow()`?
A 2X2 sudoku: http://mypuzzle.org/sudoku/kid.html
private integer block;
...
public Integer getBlock(){
return block;
}
public void setBlock(int not_used){
if(this.row==null)
this.block=null;
else
this.block=10*(this.row.getIndex()/2)+this.column.getIndex()/2;
}
--
View this message in context: http://drools.46999.n3.nabble.com/Where-do-I-code-the-calculation-for-a-d...
Sent from the Drools: User forum mailing list archive at Nabble.com.
14 years, 2 months
null POJO attribute causing template issues -- is there a better way?
by dunnlow
Hi,
I'm using a template to validate information in my POJO. I've got a row for
the different valid possibilities.
My template rule (in guvnor) looks like:
WHEN
There is a MyBean[$mb] with:
itemname matches templateItemName
cost greater than templateCost
caveat matches templateCaveat
THEN
. 8<
(I have columns in my template for templateItemName, templateCost and
templateCaveat).
Almost always, I don't care about the value in $mb.caveat, so I have a ".*"
in the entry for that row. This works fine as long as $mb bean has a caveat
(ie, $mb.caveat !=null). But when caveat is null the check for caveat
matches templateCaveat (where templateCaveat = ".*") fails. I tried the
regex ".*|null" but that doesn't work either, which I suppose isn't so
surprising (although I never see a NPE error msg).
Modifying the template like this doesn't work:
itemname matches templateItemName
cost greater than templateCost
any of the following:
caveat==null
caveat matches templateCaveat
because when a null valued caveat comes in, this then matches both the rule
I want to fire and the lone one or two with a constraint on that field
(something other than ".*"). I know I can set the salience so that the rows
with ".*" fire first, but that seems REALLY ugly.
I also considered putting in a rule with a high salience that adds a dummy
caveat if one doesn't exist, but this still seems somewhat ugly.
What I'd like to do is have a constraint such as: if caveat matches
templateCaveat or (if caveat is null and templateCaveat does not match ".*")
Does anyone have any insight about the best way to implement this?
Thank you,
-J
--
View this message in context: http://drools.46999.n3.nabble.com/null-POJO-attribute-causing-template-is...
Sent from the Drools: User forum mailing list archive at Nabble.com.
14 years, 2 months
bytecode representation of rules
by Mainul Raju
Hello All:
I have been trying to get the byte code representation of rules (.drl files). I would appreciate it if anyone could kindly provide me any way to do that.
I have created a rule based application with 100 rules in 5 different .drl files. My intention is to analyze the application with some byte code analyzer (i.e. soot). For the purpose of hat static analysis, I need the byte-code representation of rules which I can't get from drools.
Thanks in advance.
//
Mainul
14 years, 2 months
How to troubleshoot Drools planner doing nothing?
by aitchnyu
I wrote a program in Drools. But it does not do anything. As the logs show,
the solver finishes in 2 ms and the 'best solution' is an untouched version
of the initial state.
I also noted that not a single movefactory object was created. And at 500
moves/sec and 2 milliseconds of execution, only one move was attempted.
Where do I start troubleshooting?
SudokuGenerator sg = new SudokuGenerator();
Solution sudoku = sg.createSudoku();
Solver solver = createSolver();
solver.setPlanningProblem(sudoku);
solver.solve();
System.out.println("solver over");
Sudoku result = (Sudoku) solver.getBestSolution();
result.displaySolution(); //a method that prints the state of the solution
*Output logs in TRACE mode*
jesvin@Jesvin-Technovia:~/dev/drools/sudoku$ java in.co.technovia.sudoku.App
2012-01-30 17:23:33,795 [main] INFO Solver started: time spend (1), score
(0), new best score (0), random seed (0).
2012-01-30 17:23:33,796 [main] INFO Solved: time spend (2), best score (0),
average calculate count per second (500).
*Contents of the solver XML*
<?xml version="1.0" encoding="UTF-8"?>
<solver>
<environmentMode>DEBUG</environmentMode>
<solutionClass>in.co.technovia.sudoku.domain.Sudoku</solutionClass>
<planningEntityClass>in.co.technovia.sudoku.domain.Digit</planningEntityClass>
<scoreDrl>/score.drl</scoreDrl>
<scoreDefinition>
<scoreDefinitionType>SIMPLE</scoreDefinitionType>
</scoreDefinition>
<termination>
<scoreAttained>0</scoreAttained>
</termination>
<constructionHeuristic>
<constructionHeuristicType>FIRST_FIT</constructionHeuristicType>
</constructionHeuristic>
<localSearch>
<selector>
<moveFactoryClass>in.co.technovia.sudoku.solution.RowChangeMoveFactory</moveFactoryClass>
</selector>
<acceptor>
<completeSolutionTabuSize>1000</completeSolutionTabuSize>
</acceptor>
<forager>
</forager>
</localSearch>
</solver>
--
View this message in context: http://drools.46999.n3.nabble.com/How-to-troubleshoot-Drools-planner-doin...
Sent from the Drools: User forum mailing list archive at Nabble.com.
14 years, 2 months
How to enable logging in my application?
by aitchnyu
I want to enable logging in my application. Since Drools planner uses log4j,
how can I enable it's logging in my application?
In the current form, my application runs as:
jesvin@Jesvin-Technovia:~/dev/drools/sudoku$ java in.co.technovia.sudoku.App
log4j:WARN No appenders could be found for logger
(org.drools.planner.core.solver.DefaultSolver).
log4j:WARN Please initialize the log4j system properly.
--
View this message in context: http://drools.46999.n3.nabble.com/How-to-enable-logging-in-my-application...
Sent from the Drools: User forum mailing list archive at Nabble.com.
14 years, 2 months
Planner has trouble creating a configurer: how to debug
by aitchnyu
I tried to create a solver from XML configuration. But the entire process
returns a *cryptic error message *that makes no sense.
How do I fix this? And how can I make sense of this to actually solve
similar problems like this?
Please excuse me if I made any bad karma. This is my first post on this (and
any) mailing list.
jesvin@Jesvin-Technovia:~/dev/drools/sudoku$ java App
Exception in thread "main" java.lang.NullPointerException
at
org.drools.planner.core.domain.solution.SolutionDescriptor.processPropertyAnnotations(SolutionDescriptor.java:69)
at
org.drools.planner.core.domain.solution.SolutionDescriptor.<init>(SolutionDescriptor.java:61)
at
org.drools.planner.config.solver.SolverConfig.buildSolutionDescriptor(SolverConfig.java:197)
at
org.drools.planner.config.solver.SolverConfig.buildSolver(SolverConfig.java:167)
at
org.drools.planner.config.XmlSolverConfigurer.buildSolver(XmlSolverConfigurer.java:103)
at App.createSolver(App.java:62)
at App.main(App.java:40)
The function that throws it is listed here. The line is of course `return
configurer.buildSolver();`.
private static Solver createSolver(){
XmlSolverConfigurer configurer = new XmlSolverConfigurer();
File file = new File("solver.xml");
FileInputStream fin = null;
try{
fin = new FileInputStream(file);
}
catch(IOException e){
System.out.println("Unable to read drl");
}
configurer.configure(fin);
//configurer.configure("/home/jesvin/dev/drools/sudoku/solver.xml");
return configurer.buildSolver();
}
The content of the XML:
<?xml version="1.0" encoding="UTF-8"?>
<solver>
<environmentMode>DEBUG</environmentMode>
<solutionClass>domain.Sudoku</solutionClass>
<planningEntityClass>domain.Digit</planningEntityClass>
<scoreDrl>score.drl</scoreDrl>
<scoreDefinition>
<scoreDefinitionType>SIMPLE</scoreDefinitionType>
</scoreDefinition>
<termination>
<scoreAttained>0</scoreAttained>
</termination>
<constructionHeuristic>
<constructionHeuristicType>FIRST_FIT</constructionHeuristicType>
<moveFactoryClass>solution.RowChangeMoveFactory</moveFactoryClass>
</selector>
<acceptor>
<completeSolutionTabuSize>1000</completeSolutionTabuSize>
</acceptor>
<forager>
</forager>
</localSearch>
</solver>
--
View this message in context: http://drools.46999.n3.nabble.com/Planner-has-trouble-creating-a-configur...
Sent from the Drools: User forum mailing list archive at Nabble.com.
14 years, 2 months
declarative agenda & ruleflow
by Michal Bali
Hi Mauricio
in response to:
http://drools.46999.n3.nabble.com/rules-users-Declarative-agenda-final-AP...
here is an example with declarative agenda and ruleflow, the knowledgebase
consists of the following rule file plus bpmn ruleflow file that has only
two ruleflow groups "setup" and then "validation".
if I turn on the
knowledgeBaseConfiguration.setOption(DeclarativeAgendaOption.ENABLED); no
rule is fired
tried with
<drools.ver>5.3.0.Final</drools.ver>
<jbpm.version>5.1.2.Final</jbpm.version>
----------------
package droolsbestpractices;
import org.drools.runtime.rule.Activation;
dialect "mvel"
declare Customer
name : String @key
level : Integer @key
end
//user can decide to bypass ...
rule initialize
ruleflow-group "setUp"
when
then
System.out.println(kcontext.rule.name);
Customer customer1 = new Customer("John", 1);
insert(customer1);
end
rule customerLevelLow @bypass('customerValidation')
ruleflow-group "validate"
when
Customer( level < 3 )
then
System.out.println(kcontext.rule.name);
end
rule customerLevelBypass @activationListener('direct')
when
$a : Activation( bypass == 'customerValidation' )
then
System.out.println(kcontext.rule.name);
kcontext.blockActivation( $a );
end
--------------------------
Best regards,
Michal
14 years, 2 months
query created in guvnor 5.3.0.final does not return expected results
by vadlam
I have created a query in guvnor 5.3 in a separate drl file as follows.
query "get total Documents created"
document : Document( )
end
I have several rules that create Documents as part of the ruleflow.
on the java side
ksession.fireAllRules(new RuleFilter()); // the rulefilter does not really
do anything except log the
//rules
executing
org.drools.runtime.rule.QueryResults results =
ksession.getQueryResults("get total Documents created");
System.out.println( "we have " + results.size() +"
Documents" );
I see that the returned results size is 0
but the following code returns the documents as expected.
Collection responseObjects = ksession.getObjects();
is there anything I am missing with respect to the query ? I use a ruleflow
. does the query need to be part of any of the ruleflowgroups within the
ruleflow ?
is there a way to know whether the query ran or not ?
--
View this message in context: http://drools.46999.n3.nabble.com/query-created-in-guvnor-5-3-0-final-doe...
Sent from the Drools: User forum mailing list archive at Nabble.com.
14 years, 2 months