A field was accessed by a rule but was not found in the class

23 views
Skip to first unread message

Kent Zhang

unread,
Jul 14, 2021, 9:57:07 PM7/14/21
to OptaPlanner development
Hi Team,
 
In the drools script (projectJobSchedulingConstraints.drl) of example Project Job Scheduling, in the LHS of rule "renewableResourceCapacity", for the class RenewableResourceUsedDay, the variable $capacity gets the value from its field "resourceCapaciy", but I don't find this member from this class. How can it get the capacity?  

Thanks.

Kent Zhang

unread,
Jul 14, 2021, 10:00:40 PM7/14/21
to OptaPlanner development
I'm saying this rule. Thank you a lot!

rule "renewableResourceCapacity"
    when
        RenewableResourceUsedDay($resource : resource, $capacity : resourceCapacity, $usedDay : usedDay)
        accumulate(
            ResourceRequirement(resource == $resource,
                    $executionMode : executionMode,
                    $requirement : requirement)
            and Allocation(executionMode == $executionMode, $usedDay >= startDate, $usedDay < endDate);
            $used : sum($requirement);
            $used > $capacity
        )
    then
        scoreHolder.addHardConstraintMatch(kcontext, 0, $capacity - $used);
end

Lukas Petrovicky

unread,
Jul 15, 2021, 2:44:00 AM7/15/21
to optapla...@googlegroups.com
Kent,

On Thu, Jul 15, 2021 at 3:57 AM Kent Zhang <kent...@gmail.com> wrote:
In the drools script (projectJobSchedulingConstraints.drl) of example Project Job Scheduling, in the LHS of rule "renewableResourceCapacity", for the class RenewableResourceUsedDay, the variable $capacity gets the value from its field "resourceCapaciy", but I don't find this member from this class. How can it get the capacity?  

it doesn't need to be a field. In this particular case, it is a method:


However, this brings up a good benefit of using Constraint Streams instead of DRL. Constraint Streams are pure Java, and therefore your IDE gives you all the information you need.
 
--

Lukáš Petrovický

He/Him/His

Principal Software Engineer, Business Automation

Red Hat Czech, s. r. o.

lukas.pe...@redhat.com    IM: triceo/lpetrovi

Kent Zhang

unread,
Jul 15, 2021, 4:34:12 AM7/15/21
to OptaPlanner development
Thank you very much, Lukas. I ignored this method getResourceCapacity.

I understand that Constraint Stream can express constraints better. I am planning to change the Drools constraints in the existing project to Constraint Stream, but for the example Project Job Scheduling, I still cannot use Constraint Stream to implement it, especially the constraint renewableResourceUsedDay. The insertLogical method, I don’t know how to implement it in Constraint Stream. Will your team provide Constraint Stream implementation constraints for the example Project Job Scheduling ? Thanks again.

Lukas Petrovicky

unread,
Jul 15, 2021, 6:11:24 AM7/15/21
to optapla...@googlegroups.com
On Thu, Jul 15, 2021 at 10:34 AM Kent Zhang <kent...@gmail.com> wrote:
I understand that Constraint Stream can express constraints better. I am planning to change the Drools constraints in the existing project to Constraint Stream, but for the example Project Job Scheduling, I still cannot use Constraint Stream to implement it, especially the constraint renewableResourceUsedDay. The insertLogical method, I don’t know how to implement it in Constraint Stream. Will your team provide Constraint Stream implementation constraints for the example Project Job Scheduling ? Thanks again.

Kent Zhang

unread,
Jul 15, 2021, 8:46:34 PM7/15/21
to optapla...@googlegroups.com
Oh, that's really great, let me learn about it. Thank you, Lukas. 

--
You received this message because you are subscribed to the Google Groups "OptaPlanner development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to optaplanner-d...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/optaplanner-dev/CAEs6%2BmzaeJNa4RAgPJEReUSLm8Td6PgUS7hrdnTS8G8J5QY%3DFw%40mail.gmail.com.


--
With kind regards,
Kent Zhang
Reply all
Reply to author
Forward
0 new messages