[rules-users] Optaplanner - Issue with real-time, chained and shadow variables

Juan Ignacio Barisich juan.barisich at gmail.com
Mon Nov 4 08:24:43 EST 2013


You are right.
Do you think that is a bug? Or is there a hack to solve this?


2013/11/4 Geoffrey De Smet <ge0ffrey.spam at gmail.com>

>
> On 04-11-13 13:10, Juan Ignacio Barisich wrote:
>
>    Geoffrey, thanks for response.
>  The the Customer "toRemove" instance IS the same instance as which is in
> the workingSolution's Customer list. In fact, in the test example I have
> attached, I get that instance via:
>
> final Customer toRemove = workingSolution.getCustomerList().get(0);
>
> Ok, then that's not the problem indeed.
>
>
>  I try to reproduce the hack in CloudBalancing's problemFactChange
> implementation, but with no success. I mean, I tried:
>
>     // to clean the next variable of previous in the chain
>     Standstill prev = toRemove.getPreviousStandstill();
>    scoreDirector.beforeEntityRemoved(prev);
>    prev.setNextCustomer(null);
>    scoreDirector.afterEntityRemoved(prev);
>
>  but this throw an exception like:
> java.lang.IllegalStateException: The entity (1(after 66)) has a variable
> (previousStandstill) with value (66(after 51)) which has a mappedBy
> variable (nextCustomer) with a value (null) which is not that entity.
>
> Ah, that explains it.
>
> Although you remove the customer instance toRemove,
> one of the other customers still has it as previousStandstill
> and/or one of the other customers still has it as nextStandstill.
>
>
>  Also, i try to clean the previous variable of the following item in the
> chain:
>
>    // to clean the previous variable of the following customer in the chain
>    Customer nextCustomer = toRemove.getNextCustomer();
>    if (nextCustomer != null) {
>       scoreDirector.beforeEntityRemoved(nextCustomer);
>       nextCustomer.setPreviousStandstill(null);
>       scoreDirector.beforeEntityRemoved(nextCustomer);
>    }
>
> but this throw an exception like:
> java.lang.IllegalStateException: The ScoreDirector (class
> org.optaplanner.core.impl.score.director.common.TrailingEntityMapSupport)
> is corrupted, because the entity (10(after null)) for chained
> planningVariable (previousStandstill) cannot be retracted: it was never
> inserted.
>
>  Can you take a look to the test I have attached and guide me to solve
> this?
>
> Thanks a lot.
>  Regards
>
>
>
>
>
>
>
> 2013/11/4 Geoffrey De Smet <ge0ffrey.spam at gmail.com>
>
>>
>> On 01-11-13 19:38, Juan Ignacio Barisich wrote:
>>
>>     Hi everybody
>>  I am using optaplanner in real-time style. My application domain is
>> similar to the "Vehicle Routing" example (
>> http://docs.jboss.org/drools/release/6.0.0.CR5/optaplanner-docs/html_single/index.html#vehicleRouting).
>> I mean, I am using chained variables and shadow variables. I have a problem
>> while trying to remove a fact (an entity), via a ProblemFactChange:
>>
>> java.lang.IllegalArgumentException: The entity instance (...) was never
>> added to this ScoreDirector. Usually the cause is that that specific
>> instance was not in your Solution's entities.
>>
>>  The fact removing that I made is like:
>>
>> solver.addProblemFactChange(new ProblemFactChange() {
>>
>>             @Override
>>             public void doChange(ScoreDirector scoreDirector) {
>>                 ...
>>                 scoreDirector.beforeEntityRemoved(toRemove);
>>                 workingSolution.getCustomerList().remove(toRemove);
>>
>>  the remove() method will make no difference because the Customer
>> "toRemove" instance
>> is not the same instance as which is in the workingSolution's Customer
>> list.
>>
>> See the CloudBalancing's PRoblemFactChange implementation how to solve
>> this.
>> And one of the warnings in the Real-time planning section of the docs to
>> understand it better:)
>>
>>                    scoreDirector.afterEntityRemoved(toRemove);
>>             }
>>         });
>>
>>  I think the problem is there. Do you know what I'm doing wrong?
>>  I have attached a test case based on the "Vehicle Routing". To run it,
>> just put that file into the
>> optaplanner-distribution-6.0.0.CR5/examples/sources/src/test/java/org/optaplanner/examples/vehiclerouting/app/
>> directory.
>>
>>  <http://drools.46999.n3.nabble.com/file/n4017760/serverlog.zip>I'd
>> appreciate any ideas on how to resolve this.
>> Best regards,
>>
>>  Juan Ignacio Barisich
>>
>>
>>
>>
>>
>>
>>  _______________________________________________
>> 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/20131104/739eaaac/attachment-0001.html 


More information about the rules-users mailing list