brewphone
brewphone

Reputation: 1366

OptaPlanner, DRL error, accumulating longs getting double

My first OptaPlanner project, to assign tasks to workers. When launching the app got following error:

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.optaplanner.core.api.solver.SolverManager]: Factory method 'solverManager' threw exception; nested exception is java.lang.IllegalStateException: There are errors in a score DRL:
Error Messages:
Message [id=1, kieBase=defaultKieBase, level=ERROR, path=com....taskassignment/TaskAssignmentRules.drl, line=7, column=0
   text=Rule Compilation error The method addSoftConstraintMatch(RuleContext, long) in the type HardMediumSoftLongScoreHolder is not applicable for the arguments (RuleContext, double)]

The Task class is like this:

public class Task {
    ...
    private long durationInSec; // how long the task takes
    ...
}

want to have a fairness rule, so that all workers have the similar total durations, the DRL is here:

package com.....taskassignment;
import org.optaplanner.core.api.score.buildin.hardmediumsoftlong.HardMediumSoftLongScoreHolder;
import com.....domain.*;

global HardMediumSoftLongScoreHolder scoreHolder;

rule "fairness"
    when
        $worker : Worker(name != null)
        accumulate(
            Task(worker == $worker, $d : durationInSec);
            $s : sum($d*$d)
        )       
    then
        scoreHolder.addSoftConstraintMatch(kcontext, -$s);
end

Don't understand why $s is a double? If the last line is like:

scoreHolder.addSoftConstraintMatch(kcontext, -1);

then no error showed up. How can I fix this? I use HardMediumSoftLongScore because I think double is slower than long.

Upvotes: 0

Views: 54

Answers (1)

brewphone
brewphone

Reputation: 1366

this fixed the issue

scoreHolder.addSoftConstraintMatch(kcontext, -$s.longValue());

Upvotes: 1

Related Questions