[rules-users] Drools (Planner) getting confused between list and map access

aitchnyu jesvinj at technovia.co.in
Mon Feb 27 00:37:20 EST 2012


I am trying to find the total of an attribute of`SubjectTeacherPeriod`. The
`numAttributeMap`property (a map with `String` keys and `int` values) stores
the value. But trying to access it is problematic as Drools thinks that
`$num_value[$attribute]` is a list operation, not a map operation.

I listed my rule and runtime errors:

rule "insertAttributeDayTotal"
        //salience 1 // Do these rules first (optional, for performance)
    when
	$sum_regression_constraint : SumRegressionConstraint(
				    $class : class_,
				    $attribute : attribute//,
				    //$weight : weight;
				   )
	$day_of_week : DayOfWeek()
	$attribute_day_total : Number() from accumulate(
		SubjectTeacherPeriod(
			//period != null,
		        period.class_ == $class,
			period.dayOfWeek == $day_of_week,
		        $num_value : numAttributeMap
		        //$total : num_attribute_map.get($attribute)
			),
		    sum($num_value[$attribute]) //PROBLEM LINE??
		)
    then
	//System.out.println("BUCKET TOTAL "+$id+" "+$bucket_total.intValue());
        insertLogical(new AttributeDaySum($class, $attribute, $day_of_week,
$attribute_day_total.intValue()));
end

*Errors:*
jesvin at Jesvin-Technovia:~/dev/drools/timetabler$ java -server
in.co.technovia.timetabler.TimeTableApp
Exception in thread "main" java.lang.IllegalStateException: There are errors
in the scoreDrl's:
Rule Compilation error : [Rule name='insertAttributeDayTotal']

in/co/technovia/timetabler/domain/Rule_insertAttributeDayTotal_fd3f7d4f98084049887c1596f5a56805.java
(9:1093) : The type of the expression must be an array type but it resolved
to Map

in/co/technovia/timetabler/domain/Rule_insertAttributeDayTotal_fd3f7d4f98084049887c1596f5a56805.java
(9:1104) : Type mismatch: cannot convert from String to int


	at
org.drools.planner.config.solver.SolverConfig.buildRuleBase(SolverConfig.java:238)
	at
org.drools.planner.config.solver.SolverConfig.buildSolver(SolverConfig.java:170)
	at
org.drools.planner.config.XmlSolverConfigurer.buildSolver(XmlSolverConfigurer.java:103)
	at
in.co.technovia.timetabler.TimeTableApp.createSolver(TimeTableApp.java:55)
	at in.co.technovia.timetabler.TimeTableApp.main(TimeTableApp.java:39)



--
View this message in context: http://drools.46999.n3.nabble.com/Drools-Planner-getting-confused-between-list-and-map-access-tp3779757p3779757.html
Sent from the Drools: User forum mailing list archive at Nabble.com.



More information about the rules-users mailing list