Re: [rules-users] Optaplanner - Issue with real-time, chained and shadow variables
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. I'd appreciate any ideas on how to resolve this. Best regards, Juan Ignacio Barisich ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] [OptaPlanner] Help on Construction Heuristics
Either: 1) add a hard constraint to penalize what you don't want 2) look into ValueRangeProvider from entity (see docs), which effectively makes it a build-in hard constraint. 3) Use Filtering in both the Local Search selectors as the CH selectors (but the CH selector usage is not yet documented). This 3) option is very difficult, especially for SwapMove's. I recommend 1) by default. Also don't expect that CH's give you a feasible solution, use LS on top of CH's to get a good, feasible solution. See "phase overview" section in the docs. On 03-11-13 17:29, Tales Costa wrote: Hi all, I am new to Optaplanner and would like some help on understanding how to control the planning value chosen byOptaplanner. Based on the info on User Guide and the NQueen example, I understand that for Local Search algorithms one can use the Move interface (for example to forbid some specific row change). However, for the Construction heuristics have not found any similar option. For these algoritms the only option seems to be to make load adjustements on the score calculations (as the nqueens example does for queens on the same row). Is this correct or am I missing something ? Regards Tales ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] peephole technique - cast to java.lang.Number problem
MVEL was my first suspect as well, but the same rules in java dialect (just added setters/getters) produced same exceptions. Alex On 04 Nov 2013, at 07:43, Wolfgang Laun wolfgang.l...@gmail.com wrote: You never know what an expression suffers when it is thrown into the MVEL machinery, (Mario's continuing efforts notwithstanding). Documentation is sparse... To be on the safe side, I'd probably have written rule count old when $le : LastEvent($ev: event ) $last: Event( this == $ev ) $old : Event( this before [1ms , 5s] $last ) then System.out.println($old); end -W On 03/11/2013, Alexander Wolf m...@alexander-wolf.net wrote: Okey I got a little further: This works: rule count old when $le : LastEvent($ts : event.timestamp) $old : Event(this before [1ms , 5s] $ts) then System.out.println($old); end but then why does this not work ?! rule count old when $le : LastEvent($event : event) $old : Event(this before [1ms , 5s] $event.timestamp) then System.out.println($old); end To me this seems to be a bug, that occurs as soon as I set an event as member of a fact (the LastEvent) - implementing the peephole technique. At least I got it to do what I want...but not as niceley... as expected. - On 02 Nov 2013, at 18:11, Alexander Wolf m...@alexander-wolf.net wrote: Drools 5.5.0 + Fusion / stateful session / STREAM mode Hi, I try to improve my rules using peephole technique (Thanks @W) I think I got it right, but now I am stuck with a problem. I want to keep a reference to my latest inserted event. Problem: the rule print old gives me an Exception (see below). I think the peephole itself works pretty well, but somehow my Event Object (POJO with: Date timestamp, int value) is making problems when I try to use before. (see marked line, when commenting it out, the rules run alright) dialect mvel import java.util.Date import com.testmodel.Event //declarations declare Event @role(event) @timestamp( timestamp ) end declare LastEvent event: Event end rule init when //once... then System.out.println(init); LastEvent l = new LastEvent(); Event e = new Event(); e.timestamp = new Date(); e.value = 0; l.event = e; insert(l); end rule update LastEvent no-loop salience 99 when $event : Event() $last : LastEvent() then System.out.println(update LastEvent); retract ($last) LastEvent l = new LastEvent(); l.event = $event; insert(l); end rule count old when LastEvent($last : event) $old : Event(this before [0 , 5s] $last) // THIS IS EVIL?! then System.out.println($old); end My test code looks like this: Event event = new Event(new Date(), 1); ksession.insert(event); ksession.fireAllRules(); //sleep 1+ sec Thread.sleep(1001); Event event2 = new Event(new Date(), 2); ksession.insert(event2); ksession.fireAllRules(); And this is the Exception I get: Exception executing consequence for rule init in testEasierLife: [Error: drools.insert(l): com.testmodel.Event cannot be cast to java.lang.Number] [Near : {... System.out.println(init); }] ^ [Line: 1, Column: 1] at org.drools.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:39) at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1297) at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:1221) at org.drools.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1456) at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:710) at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:674) at org.drools.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:230) at com.Test.test(PeepholeTest.java:65) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) at
Re: [rules-users] Creating selection filter for PlanningEntity with 4 planning variables
I'd like to filter out planning values that are incoherent between each other. -- View this message in context: http://drools.46999.n3.nabble.com/Creating-selection-filter-for-PlanningEntity-with-4-planning-variables-tp4026575p4026618.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Optaplanner - Issue with real-time, chained and shadow variables
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); 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. 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.s...@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.zipI'd appreciate any ideas on how to resolve this. Best regards, Juan Ignacio Barisich ___ rules-users mailing listrules-users@lists.jboss.orghttps://lists.jboss.org/mailman/listinfo/rules-users ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Creating selection filter for PlanningEntity with 4 planning variables
Can you give an example? This sounds like just another hard constraint. On 04-11-13 12:27, maciekpob wrote: I'd like to filter out planning values that are incoherent between each other. -- View this message in context: http://drools.46999.n3.nabble.com/Creating-selection-filter-for-PlanningEntity-with-4-planning-variables-tp4026575p4026618.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Optaplanner - Issue with real-time, chained and shadow variables
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.s...@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
Re: [rules-users] peephole technique - cast to java.lang.Number problem
Maybe s.o. can contradict, but in 5.5.0 (and even before) it's MVEL for dealing with constraint expressions anyway, behind the scenes. -W On 04/11/2013, Alexander Wolf m...@alexander-wolf.net wrote: MVEL was my first suspect as well, but the same rules in java dialect (just added setters/getters) produced same exceptions. Alex On 04 Nov 2013, at 07:43, Wolfgang Laun wolfgang.l...@gmail.com wrote: You never know what an expression suffers when it is thrown into the MVEL machinery, (Mario's continuing efforts notwithstanding). Documentation is sparse... To be on the safe side, I'd probably have written rule count old when $le : LastEvent($ev: event ) $last: Event( this == $ev ) $old : Event( this before [1ms , 5s] $last ) then System.out.println($old); end -W On 03/11/2013, Alexander Wolf m...@alexander-wolf.net wrote: Okey I got a little further: This works: rule count old when $le : LastEvent($ts : event.timestamp) $old : Event(this before [1ms , 5s] $ts) then System.out.println($old); end but then why does this not work ?! rule count old when $le : LastEvent($event : event) $old : Event(this before [1ms , 5s] $event.timestamp) then System.out.println($old); end To me this seems to be a bug, that occurs as soon as I set an event as member of a fact (the LastEvent) - implementing the peephole technique. At least I got it to do what I want...but not as niceley... as expected. - On 02 Nov 2013, at 18:11, Alexander Wolf m...@alexander-wolf.net wrote: Drools 5.5.0 + Fusion / stateful session / STREAM mode Hi, I try to improve my rules using peephole technique (Thanks @W) I think I got it right, but now I am stuck with a problem. I want to keep a reference to my latest inserted event. Problem: the rule print old gives me an Exception (see below). I think the peephole itself works pretty well, but somehow my Event Object (POJO with: Date timestamp, int value) is making problems when I try to use before. (see marked line, when commenting it out, the rules run alright) dialect mvel import java.util.Date import com.testmodel.Event //declarations declare Event @role(event) @timestamp( timestamp ) end declare LastEvent event: Event end rule init when //once... then System.out.println(init); LastEvent l = new LastEvent(); Event e = new Event(); e.timestamp = new Date(); e.value = 0; l.event = e; insert(l); end rule update LastEvent no-loop salience 99 when $event : Event() $last : LastEvent() then System.out.println(update LastEvent); retract ($last) LastEvent l = new LastEvent(); l.event = $event; insert(l); end rule count old when LastEvent($last : event) $old : Event(this before [0 , 5s] $last) // THIS IS EVIL?! then System.out.println($old); end My test code looks like this: Event event = new Event(new Date(), 1); ksession.insert(event); ksession.fireAllRules(); //sleep 1+ sec Thread.sleep(1001); Event event2 = new Event(new Date(), 2); ksession.insert(event2); ksession.fireAllRules(); And this is the Exception I get: Exception executing consequence for rule init in testEasierLife: [Error: drools.insert(l): com.testmodel.Event cannot be cast to java.lang.Number] [Near : {... System.out.println(init); }] ^ [Line: 1, Column: 1] at org.drools.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:39) at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1297) at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:1221) at org.drools.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1456) at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:710) at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:674) at org.drools.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:230) at com.Test.test(PeepholeTest.java:65) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271) at
Re: [rules-users] Optaplanner - Issue with real-time, chained and shadow variables
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.s...@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.s...@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.zipI'd appreciate any ideas on how to resolve this. Best regards, Juan Ignacio Barisich ___ rules-users mailing listrules-users@lists.jboss.orghttps://lists.jboss.org/mailman/listinfo/rules-users ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users ___ rules-users mailing listrules-users@lists.jboss.orghttps://lists.jboss.org/mailman/listinfo/rules-users ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Optaplanner - Issue with real-time, chained and shadow variables
On 04-11-13 14:24, Juan Ignacio Barisich wrote: You are right. Do you think that is a bug? Or is there a hack to solve this? User problem :) Do something like: toRemove.getPreviousStandstill().setNextStandstill(toRemove.getNextStandstill); toRemove.getNextStandstill().setPreviousStandstill(toRemove.getPreviousStandstill); It might need a cast and instanceof check to Customer. 2013/11/4 Geoffrey De Smet ge0ffrey.s...@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?
[rules-users] how can I modify a batch of objects
Hi all, I am trying to identify a port scan event. The basic fact is connection log. For each combination of src (source IP) and dst (destination IP) , detect a port scan event, if over 60 seconds there were at least 20 connection logs with different service and protocol. The event will stay closed for 10 minute - no event will be sent during this time for this combination of src and dst. The event will contain the connection logs' ids (markers). I tried to implement it using accumulate and over window:time but it consumes too much memory. So I am trying to imitate this functionality using several rules and facts. My drl contains the following lines (among others): declare CorrelatedEvent @role( event) @expires( 600s ) end declare CandidatesWindow @role( event) @expires( 60s ) end rule Create Port Scan Event - 1 enabled true dialect java no-loop when $log : Log() not CorrelatedEvent(getId() == portScan , groupByFieldsMap.get(src) == $log.fieldsMap.get(src) ,groupByFieldsMap.get(dst) == $log.fieldsMap.get(dst)) $windows : ArrayList() from collect( CandidatesWindow(getRuleId() == portScan , groupByFieldsMap.get(src) == $log.fieldsMap.get(src) , groupByFieldsMap.get(dst) == $log.fieldsMap.get(dst))) then String id = $log.fieldsMap.get(port).toString(); System.out.println(new Date().toString()+ windowSize: + $windows.size()); for (Object windowObj : $windows) { CandidatesWindow window = (CandidatesWindow) windowObj; modify ( window ) { addLog($log, id) } } CandidatesWindow newWindow = new CandidatesWindow(portScan, true); newWindow.groupByFieldsMap.put(src, $log.fieldsMap.get(src)); newWindow.groupByFieldsMap.put(dst, $log.fieldsMap.get(dst)); newWindow.addLog($log, id); insert(newWindow); end This imitates sliding time windows. when I tested it, I got the following exception: Exception executing consequence for rule Create Port Scan Event - 1 in com.checkpoint.correlation.impl.drools.package1: java.util.ConcurrentModificationException at org.drools.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:39) at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1297) at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:1221) at org.drools.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1456) at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:710) at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:674) at org.drools.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:230) at com.checkpoint.correlation.impl.drools.DroolsCEPEngineV1.insertEvents(DroolsCEPEngineV1.java:173) at com.checkpoint.correlation.impl.feeder.JsonFileFeeder.init(JsonFileFeeder.java:68) at com.checkpoint.correlation.server.CorrelationServer.initFeeder(CorrelationServer.java:63) at com.checkpoint.correlation.server.CorrelationServer.run(CorrelationServer.java:28) at com.checkpoint.correlation.server.CorrelationServer.runServer(CorrelationServer.java:101) at com.checkpoint.correlation.server.CorrelationServer.main(CorrelationServer.java:85) Caused by: java.util.ConcurrentModificationException at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:819) at java.util.ArrayList$Itr.next(ArrayList.java:791) at com.checkpoint.correlation.impl.drools.package1.Rule_Create_Port_Scan_Event___1_2f94bc67f9064c6e9614982cf9bc8859.defaultConsequence(Rule_Create_Port_Scan_Event___1_2f94bc67f9064c6e9614982cf9bc8859.java:11) at com.checkpoint.correlation.impl.drools.package1.Rule_Create_Port_Scan_Event___1_2f94bc67f9064c6e9614982cf9bc8859DefaultConsequenceInvokerGenerated.evaluate(Unknown Source) at com.checkpoint.correlation.impl.drools.package1.Rule_Create_Port_Scan_Event___1_2f94bc67f9064c6e9614982cf9bc8859DefaultConsequenceInvoker.evaluate(Unknown Source) at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1287) ... 11 more It is caused by modify ( window ) in the for loop. How can I make it work? Thanks. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Ask for help with OptaPlanner
Ge0ffery, Thank you very much for the reply. I have double-checked my code, and I did use addAll() here. I also used one of my simplest OptaPlanner projects as a test, and the same thing occurred. Later last Friday I found out a workaround of picking up planning entity first (in my rule definition). Then I can access to the problem facts via condition match. But this made the code complex and not elegant. Would you elaborate more if I misunderstand how OptaPlanner solver behaves? Once again, I really appreciate your help and your effort on this powerful software. Cheers, -- View this message in context: http://drools.46999.n3.nabble.com/rules-users-Ask-for-help-with-OptaPlanner-tp4026583p4026626.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] Ask for help with OptaPlanner
rule " test rule" when $s : Shift($i : index) $d : Demand(shift.getIndex() == $i) then System.out.println("Test rule fired."); end So your Solution.getProblemFacts() method adds all Shifts and all Demands? Then the rule should fire if there is indeed such a combination. Write a SimpleScoreCalculator to verify this (see docs). Later on, you can reuse that SimpleScoreCalculator in assertionScoreDirectorFactory to validate your DRL (which is much faster). On 04-11-13 16:26, nkgxgongxi wrote: Ge0ffery, Thank you very much for the reply. I have double-checked my code, and I did use addAll() here. I also used one of my simplest OptaPlanner projects as a test, and the same thing occurred. Later last Friday I found out a workaround of picking up planning entity first (in my rule definition). Then I can access to the problem facts via condition match. But this made the code complex and not elegant. Would you elaborate more if I misunderstand how OptaPlanner solver behaves? Once again, I really appreciate your help and your effort on this powerful software. Cheers, -- View this message in context: http://drools.46999.n3.nabble.com/rules-users-Ask-for-help-with-OptaPlanner-tp4026583p4026626.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] [OptaPlanner] Help on Construction Heuristics
Ok, I will try option 1 first. Thanks On Mon, Nov 4, 2013 at 6:14 AM, Geoffrey De Smet ge0ffrey.s...@gmail.comwrote: Either: 1) add a hard constraint to penalize what you don't want 2) look into ValueRangeProvider from entity (see docs), which effectively makes it a build-in hard constraint. 3) Use Filtering in both the Local Search selectors as the CH selectors (but the CH selector usage is not yet documented). This 3) option is very difficult, especially for SwapMove's. I recommend 1) by default. Also don't expect that CH's give you a feasible solution, use LS on top of CH's to get a good, feasible solution. See phase overview section in the docs. On 03-11-13 17:29, Tales Costa wrote: Hi all, I am new to Optaplanner and would like some help on understanding how to control the planning value chosen by Optaplanner. Based on the info on User Guide and the NQueen example, I understand that for Local Search algorithms one can use the Move interface (for example to forbid some specific row change). However, for the Construction heuristics have not found any similar option. For these algoritms the only option seems to be to make load adjustements on the score calculations (as the nqueens example does for queens on the same row). Is this correct or am I missing something ? Regards Tales ___ rules-users mailing listrules-users@lists.jboss.orghttps://lists.jboss.org/mailman/listinfo/rules-users ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] [drools-fusion] Detecting a Trend in Data
Guys thank you so much for that quick response and fantastic solutions!! Davide, thank you for your input! The 2nd approach would be very useful especially if I have to go from detecting unbroken trends to detecting statical trends! laune, I used your approach and it gave me exactly the kind of flexibility I needed to detect different trends. Thank you again for your help, I was about ready to give up on this! Eugene -- View this message in context: http://drools.46999.n3.nabble.com/drools-fusion-Detecting-a-Trend-in-Data-tp4026609p4026629.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
[rules-users] 5.6.0.CR1 causes exceptions
Just upgraded to the release candidate. I was using my own version of 5.6 that I had compiled a few months ago and everything was working fine. Almost every single rule file now throws this exception when it gets added to the knowledge base. java.lang.NoSuchMethodError: org.drools.base.ClassFieldReader.hasReadAccessor()Z at org.drools.base.ClassFieldAccessorStore.getReader(ClassFieldAccessorStore.java:129) at org.drools.base.ClassFieldAccessorStore.getReader(ClassFieldAccessorStore.java:104) at org.drools.rule.builder.PatternBuilder.getFieldReadAccessor(PatternBuilder.java:1572) at org.drools.rule.builder.PatternBuilder.buildRuleBindings(PatternBuilder.java:1123) at org.drools.rule.builder.PatternBuilder.buildCcdDescr(PatternBuilder.java:691) at org.drools.rule.builder.PatternBuilder.build(PatternBuilder.java:651) at org.drools.rule.builder.PatternBuilder.processConstraintsAndBinds(PatternBuilder.java:505) at org.drools.rule.builder.PatternBuilder.build(PatternBuilder.java:322) at org.drools.rule.builder.PatternBuilder.build(PatternBuilder.java:133) at org.drools.rule.builder.GroupElementBuilder.build(GroupElementBuilder.java:67) at org.drools.rule.builder.RuleBuilder.build(RuleBuilder.java:85) at org.drools.compiler.PackageBuilder.addRule(PackageBuilder.java:3169) at org.drools.compiler.PackageBuilder.compileRules(PackageBuilder.java:1036) at org.drools.compiler.PackageBuilder.compileAllRules(PackageBuilder.java:944) at org.drools.compiler.PackageBuilder.addPackage(PackageBuilder.java:936) at org.drools.compiler.PackageBuilder.addPackageFromDrl(PackageBuilder.java:468) at org.drools.compiler.PackageBuilder.addKnowledgeResource(PackageBuilder.java:698) at org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:51) at org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:40) Sent from my iPhone ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
[rules-users] Data enumeration in Guvnor
In advanced data enumeration in Guvnor, it is possible to define list of values for a given condition. Like ZipCode, field1 = 55000, field2 = ['1','2','3'], field1 = 55000, field2 = ['1','2','3'] ZipCode, field1 = 66600, field2 = ['10','20','30'] But if I have something like ZipCode, field1 = OTHER, field2 value should not be bound. I should be able to fill anything. But, Guvnor does not allow me once field1 is bound to something else. Please let me know if anyone has had this issue before. -- View this message in context: http://drools.46999.n3.nabble.com/Data-enumeration-in-Guvnor-tp4026631.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
[rules-users] Guvnor Data Enumeration
In the Advanced Data Enumeration in Guvnor, it is possible to define list of values for a field by fixing value on another field as follows ZipCode, field1 = 55000, field2 = ['1','2','3'] ZipCode, field1 = 66600, field2 = ['10','20','30'] ZipCode is the fact class, field1 and field2 are its members. But if I have something like ZipCode, field1 = OTHER, field2 value should not be bound. I should be able to fill anything. But, Guvnor does not allow it once field1 is bound to something else. Please let me know if anyone has had this issue before. -- View this message in context: http://drools.46999.n3.nabble.com/Guvnor-Data-Enumeration-tp4026633.html Sent from the Drools: User forum mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] 5.6.0.CR1 causes exceptions
I suspect that you are unwittingly loading one of your old jars, or an older version. Are you using version 5.6.RC1 consistently across k-api/core/compiler etc? Davide On 11/04/2013 02:24 PM, Jonathan Knehr wrote: Just upgraded to the release candidate. I was using my own version of 5.6 that I had compiled a few months ago and everything was working fine. Almost every single rule file now throws this exception when it gets added to the knowledge base. java.lang.NoSuchMethodError: org.drools.base.ClassFieldReader.hasReadAccessor()Z at org.drools.base.ClassFieldAccessorStore.getReader(ClassFieldAccessorStore.java:129) at org.drools.base.ClassFieldAccessorStore.getReader(ClassFieldAccessorStore.java:104) at org.drools.rule.builder.PatternBuilder.getFieldReadAccessor(PatternBuilder.java:1572) at org.drools.rule.builder.PatternBuilder.buildRuleBindings(PatternBuilder.java:1123) at org.drools.rule.builder.PatternBuilder.buildCcdDescr(PatternBuilder.java:691) at org.drools.rule.builder.PatternBuilder.build(PatternBuilder.java:651) at org.drools.rule.builder.PatternBuilder.processConstraintsAndBinds(PatternBuilder.java:505) at org.drools.rule.builder.PatternBuilder.build(PatternBuilder.java:322) at org.drools.rule.builder.PatternBuilder.build(PatternBuilder.java:133) at org.drools.rule.builder.GroupElementBuilder.build(GroupElementBuilder.java:67) at org.drools.rule.builder.RuleBuilder.build(RuleBuilder.java:85) at org.drools.compiler.PackageBuilder.addRule(PackageBuilder.java:3169) at org.drools.compiler.PackageBuilder.compileRules(PackageBuilder.java:1036) at org.drools.compiler.PackageBuilder.compileAllRules(PackageBuilder.java:944) at org.drools.compiler.PackageBuilder.addPackage(PackageBuilder.java:936) at org.drools.compiler.PackageBuilder.addPackageFromDrl(PackageBuilder.java:468) at org.drools.compiler.PackageBuilder.addKnowledgeResource(PackageBuilder.java:698) at org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:51) at org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:40) Sent from my iPhone ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
Re: [rules-users] how can I modify a batch of objects
The memory consumption has to be tackled by reducing the number of half-baked activations. I understand that you have to monitor certain connections (excluding those that can or have to be filtered out). And an observation window has to keep track of what goes on between one source s1 and one destination d1 within 60 s after the first event. rule one when $log: Log( $src: ..., $dst: ..., $ts: ... ) not Monitor( source == $src, destination == $dst ) then create Monitor m, register $log in it, m.setStartTime( $ts ); insert m end rule two no-loop when $m: Monitor( $src:..., $dst:..., $start:... ) $log: Log( ... == $src, ... == $dst, timestamp - $start 60s ) then keep track of $log in $m end You'll need more rules, one to detect a violation of the limit and another one to discard a Monitor after 60 seconds of inactivity. Notice that sequences of s1-d1 will not create additional network activity for each member of the sequence - that's the whole point of this exercise. -W On 04/11/2013, Elran Dvir elr...@checkpoint.com wrote: Hi all, I am trying to identify a port scan event. The basic fact is connection log. For each combination of src (source IP) and dst (destination IP) , detect a port scan event, if over 60 seconds there were at least 20 connection logs with different service and protocol. The event will stay closed for 10 minute - no event will be sent during this time for this combination of src and dst. The event will contain the connection logs' ids (markers). I tried to implement it using accumulate and over window:time but it consumes too much memory. So I am trying to imitate this functionality using several rules and facts. My drl contains the following lines (among others): declare CorrelatedEvent @role( event) @expires( 600s ) end declare CandidatesWindow @role( event) @expires( 60s ) end rule Create Port Scan Event - 1 enabled true dialect java no-loop when $log : Log() not CorrelatedEvent(getId() == portScan , groupByFieldsMap.get(src) == $log.fieldsMap.get(src) ,groupByFieldsMap.get(dst) == $log.fieldsMap.get(dst)) $windows : ArrayList() from collect( CandidatesWindow(getRuleId() == portScan , groupByFieldsMap.get(src) == $log.fieldsMap.get(src) , groupByFieldsMap.get(dst) == $log.fieldsMap.get(dst))) then String id = $log.fieldsMap.get(port).toString(); System.out.println(new Date().toString()+ windowSize: + $windows.size()); for (Object windowObj : $windows) { CandidatesWindow window = (CandidatesWindow) windowObj; modify ( window ) { addLog($log, id) } } CandidatesWindow newWindow = new CandidatesWindow(portScan, true); newWindow.groupByFieldsMap.put(src, $log.fieldsMap.get(src)); newWindow.groupByFieldsMap.put(dst, $log.fieldsMap.get(dst)); newWindow.addLog($log, id); insert(newWindow); end This imitates sliding time windows. when I tested it, I got the following exception: Exception executing consequence for rule Create Port Scan Event - 1 in com.checkpoint.correlation.impl.drools.package1: java.util.ConcurrentModificationException at org.drools.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:39) at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1297) at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:1221) at org.drools.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1456) at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:710) at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:674) at org.drools.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:230) at com.checkpoint.correlation.impl.drools.DroolsCEPEngineV1.insertEvents(DroolsCEPEngineV1.java:173) at com.checkpoint.correlation.impl.feeder.JsonFileFeeder.init(JsonFileFeeder.java:68) at com.checkpoint.correlation.server.CorrelationServer.initFeeder(CorrelationServer.java:63) at com.checkpoint.correlation.server.CorrelationServer.run(CorrelationServer.java:28) at com.checkpoint.correlation.server.CorrelationServer.runServer(CorrelationServer.java:101) at com.checkpoint.correlation.server.CorrelationServer.main(CorrelationServer.java:85) Caused by: java.util.ConcurrentModificationException at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:819) at java.util.ArrayList$Itr.next(ArrayList.java:791) at