Re: [rules-users] Using global variable in DRL file

2012-07-31 Thread Wolfgang Laun
On 31/07/2012, zeeshan zeeshan.spr...@gmail.com wrote:
 Hi Laune !


 We are able to get the desired output by applying ur first solution. Thanks
 very much Laune :-)

OK, but the second one is better!
-W





 --
 View this message in context:
 http://drools.46999.n3.nabble.com/Using-global-variable-in-DRL-file-tp4018911p4018972.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] Using global variable in DRL file

2012-07-30 Thread zeeshan
HI Laune,

Thanks for ur solutions, first one working fine but* we want agentAPE value
for other rules or atleast we want them on RuleMain.java*(where we create
agent csv bean objects).

Your second solution when we implemented was throwing NULL Pointer
Exception.

Laune can u suggest us way in which we can solve problem related to first
solution 
and if possible can we move with second one.


Thanks





--
View this message in context: 
http://drools.46999.n3.nabble.com/Using-global-variable-in-DRL-file-tp4018911p4018958.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] Using global variable in DRL file

2012-07-30 Thread Wolfgang Laun
Could you please post the exact code of your rule with solution #2 and
the NPE stack trace? You're using Drools 5.4.0?

This works with 5.4.0 - notice the no-loop true. $sum has class
Number, this needs intValue() (or whatever) to match the parameter
type of the setter.

rule accumulate Policy values into Agent
no-loop true
when
$a: Agent( $id: id )
accumulate( Policy( agentId == $id, $v: value ); $sum: sum( $v ) )
then
modify( $a ){ setValue( $sum.intValue() ) }
System.out.println( $a.toString() );
end



On 30/07/2012, zeeshan zeeshan.spr...@gmail.com wrote:
 HI Laune,

 Thanks for ur solutions, first one working fine but* we want agentAPE value
 for other rules or atleast we want them on RuleMain.java*(where we create
 agent csv bean objects).

 Your second solution when we implemented was throwing NULL Pointer
 Exception.

 Laune can u suggest us way in which we can solve problem related to first
 solution
 and if possible can we move with second one.


 Thanks





 --
 View this message in context:
 http://drools.46999.n3.nabble.com/Using-global-variable-in-DRL-file-tp4018911p4018958.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] Using global variable in DRL file

2012-07-30 Thread zeeshan

Hi Laune !

I am using 5.4 version. When I tried ur second solution, it gives
*NullPointerException*. 

Below is Stack trace and also please find my Rule file.




*WARNING: Unhandled Exception thrown: class java.lang.NullPointerException
Jul 30, 2012 2:01:18 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet action threw exception
java.lang.NullPointerException
at
org.drools.common.AbstractRuleBase.addPackages(AbstractRuleBase.java:451)
at org.drools.reteoo.ReteooRuleBase.addPackage(ReteooRuleBase.java:435)
at com.drools.facts.RuleRunner.loadRules(RuleRunner.java:71)
at com.drools.facts.RuleRunner.getStatefulSession(RuleRunner.java:227)
at com.drools.facts.RuleMain.main(RuleMain.java:43)
at com.drools.action.PolicyAction.execute(PolicyAction.java:25)
at
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
at
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
at 
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at 
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Unknown Source)
*



laune wrote
 
 Could you please post the exact code of your rule with solution #2 and
 the NPE stack trace? You're using Drools 5.4.0?
 
 This works with 5.4.0 - notice the no-loop true. $sum has class
 Number, this needs intValue() (or whatever) to match the parameter
 type of the setter.
 
 rule accumulate Policy values into Agent
 no-loop true
 when
 $a: Agent( $id: id )
 accumulate( Policy( agentId == $id, $v: value ); $sum: sum( $v ) )
 then
 modify( $a ){ setValue( $sum.intValue() ) }
 System.out.println( $a.toString() );
 end
 
 
 
 On 30/07/2012, zeeshan lt;zeeshan.spring@gt; wrote:
 HI Laune,

 Thanks for ur solutions, first one working fine but* we want agentAPE
 value
 for other rules or atleast we want them on RuleMain.java*(where we create
 agent csv bean objects).

 Your second solution when we implemented was throwing NULL Pointer
 Exception.

 Laune can u suggest us way in which we can solve problem related to first
 solution
 and if possible can we move with second one.


 Thanks





 --
 View this message in context:
 http://drools.46999.n3.nabble.com/Using-global-variable-in-DRL-file-tp4018911p4018958.html
 Sent from the Drools: User forum mailing list archive at Nabble.com.
 ___
 rules-users mailing list
 rules-users@.jboss
 https://lists.jboss.org/mailman/listinfo/rules-users

 ___
 rules-users mailing list
 rules-users@.jboss
 https://lists.jboss.org/mailman/listinfo/rules-users
 



http://drools.46999.n3.nabble.com/file/n4018960/Sample.drl Sample.drl 



--
View this message in context: 
http://drools.46999.n3.nabble.com/Using-global-variable-in-DRL-file-tp4018911p4018960.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] Using global variable in DRL file

2012-07-30 Thread Wolfgang Laun
Please read *carefully* - see !! below.

And make sure to check whether a DRL compilation results in an error.
Do not continue with errors.


On 30/07/2012, zeeshan zeeshan.spr...@gmail.com wrote:

 Hi Laune !

 I am using 5.4 version. When I tried ur second solution, it gives
 *NullPointerException*.

 This works with 5.4.0 - notice the no-loop true. $sum has class
 Number, this needs intValue() (or whatever) to match the parameter

!!!!!!

 type of the setter.

 rule accumulate Policy values into Agent
 no-loop true
 when
 $a: Agent( $id: id )
 accumulate( Policy( agentId == $id, $v: value ); $sum: sum( $v ) )
 then
 modify( $a ){ setValue( $sum.intValue() ) }

!

 System.out.println( $a.toString() );
 end



___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] Using global variable in DRL file

2012-07-27 Thread Wolfgang Laun
How do the record counts relate to files? 1800,12k and
9.5k =:= ABPolicyTransactions, ABPolicy, ABAgent?

Are these two rules all there is?

The second one has
$csvPolicy : CSVBeanPolicy()
//$csvAgent : CSVBeanAgent()   --- assume this is not commented out

Now if you do insert CSVBeanAgents, this will create (using the
*assumed* record counts) that you'll get 12,000*9,500 = 114.000,000
activations! This is the reason for your heap problem.

The RHS of this rule has an if, comparing agent ids from both facts.
(If statements on the RHS is an anti-pattern, with rare exceptions!)
Conditions belong into the LHS!

rule accumulate policy APEs into agent APE
when
$csvAgent : CSVBeanAgent( $agno: agentNo, $agAPE: agentAPE )
$csvPolicy : CSVBeanPolicy( agentNo == $agno, $polAPE: policyAPE )
then
modify( $csvAgent ){
   setAgentAPE(  $agAPE + $polAPE )
}
end

Now, inserting all facts will still create some activations, but only
12,000, the number of ABPolicy records.

Firing the rules after each insertion of an agent will not let more
than one activation accumulate - you can't have less that that :)

-W



On 27/07/2012, zeeshan zeeshan.spr...@gmail.com wrote:
 Hi Laune and thanks for replying

 Actually it was not just 50,000, it was 1,00,000 records in single CSV that
 we solved the Heap space problem by your help and we have developed that
 product and successfuly integrated in Liferay Portal... :)

 Now in this case, we have to read* three CSV files* having *1800,12k and
 9.5k* records. Now our concern is that if it was running fine for 100
 thousand records then why it is creating problem data which is much lesser
 than 100 thousand.

 Actually we are thinking in the direction like, it might creating problem
 because increased number of columns in each of three CSV files that we are
 using compare to that 100 thousand records in which we had 8 columns but
 only one file.

 Another concern is ,there may be possibility that as we are generating
 objects from 3 CSV one after another then firing rules might creating
 problem...??  Please help us in finding out what is the reason for this
 problemPlease find the Rulemain.java and Sample .drl file which u asked
 me to provide

 thanks !!

 http://drools.46999.n3.nabble.com/file/n4018939/RuleMain.java RuleMain.java

 http://drools.46999.n3.nabble.com/file/n4018939/RuleRunner.java
 RuleRunner.java  http://drools.46999.n3.nabble.com/file/n4018939/Sample.drl
 Sample.drl




 --
 View this message in context:
 http://drools.46999.n3.nabble.com/Using-global-variable-in-DRL-file-tp4018911p4018939.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] Using global variable in DRL file

2012-07-27 Thread zeeshan
Hi Laune !

I applied your suggested changes but the loop is running infinitely and same
policyAPE is used to generated cumulated value I mean for 1 agent it is
expected that all the policy APEs should sum up to generate Agent APE but
same policy APE getting summed up infinitely.plz find attached of my
consolewe printing in console in following order ---  *
System.out.println($agAPE+ZZeeesshhaaannn+$polAPE);*

Also find my updated RuleMain and Sample.DRL...


thanks very much again !

http://drools.46999.n3.nabble.com/file/n4018946/Sample.drl Sample.drl 
http://drools.46999.n3.nabble.com/file/n4018946/console_snapshot.png
console_snapshot.png 
http://drools.46999.n3.nabble.com/file/n4018946/RuleMain.java RuleMain.java 



--
View this message in context: 
http://drools.46999.n3.nabble.com/Using-global-variable-in-DRL-file-tp4018911p4018946.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] Using global variable in DRL file

2012-07-27 Thread Wolfgang Laun
Sorry, I think I missed this, all you  need is a no-loop in the rule :)
-W



On 27/07/2012, zeeshan zeeshan.spr...@gmail.com wrote:
 Hi Laune !

 I applied your suggested changes but the loop is running infinitely and
 same
 policyAPE is used to generated cumulated value I mean for 1 agent it is
 expected that all the policy APEs should sum up to generate Agent APE but
 same policy APE getting summed up infinitely.plz find attached of my
 consolewe printing in console in following order ---  *
 System.out.println($agAPE+ZZeeesshhaaannn+$polAPE);*

 Also find my updated RuleMain and Sample.DRL...


 thanks very much again !

 http://drools.46999.n3.nabble.com/file/n4018946/Sample.drl Sample.drl
 http://drools.46999.n3.nabble.com/file/n4018946/console_snapshot.png
 console_snapshot.png
 http://drools.46999.n3.nabble.com/file/n4018946/RuleMain.java RuleMain.java




 --
 View this message in context:
 http://drools.46999.n3.nabble.com/Using-global-variable-in-DRL-file-tp4018911p4018946.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] Using global variable in DRL file

2012-07-27 Thread zeeshan
Hi Laune !


  Thanks for ur solution , I resolved the heap Size problem with
your solution but even using *no-loop* is not helping in solving infinite
loop issue . Can u suggest why it is not accessing other agent objects and
simply updating same agent object infinite times..After adding no-loop,
console shows



*6.902394919998737E7ZZeeesshhaaannn1881.4
6.902583059998737E7ZZeeesshhaaannn2802.0
6.902863259998737E7ZZeeesshhaaannn1881.4
6.90305138738E7ZZeeesshhaaannn2802.0
6.90333158738E7ZZeeesshhaaannn1881.4
6.903519739998738E7ZZeeesshhaaannn2802.0
6.903799939998738E7ZZeeesshhaaannn1881.4
6.903988079998739E7ZZeeesshhaaannn2802.0
6.904268279998739E7ZZeeesshhaaannn1881.4
6.90445641999874E7ZZeeesshhaaannn2802.0
6.90473661999874E7ZZeeesshhaaannn1881.4
6.90492475999874E7ZZeeesshhaaannn2802.0
6.90520495999874E7ZZeeesshhaaannn1881.4
6.90539308741E7ZZeeesshhaaannn2802.0
6.90567328741E7ZZeeesshhaaannn1881.4
6.905861439998741E7ZZeeesshhaaannn2802.0
6.906141639998741E7ZZeeesshhaaannn1881.4
6.906329779998742E7ZZeeesshhaaannn2802.0
6.906609979998742E7ZZeeesshhaaannn1881.4
6.906798119998743E7ZZeeesshhaaannn2802.0
6.907078319998743E7ZZeeesshhaaannn1881.4
6.907266459998743E7ZZeeesshhaaannn2802.0
6.907546659998743E7ZZeeesshhaaannn1881.4
6.90773478744E7ZZeeesshhaaannn2802.0
6.90801498744E7ZZeeesshhaaannn1881.4
6.908203139998744E7ZZeeesshhaaannn2802.0
6.908483339998744E7ZZeeesshhaaannn1881.4
6.908671479998745E7ZZeeesshhaaannn2802.0
6.908951679998745E7ZZeeesshhaaannn1881.4
6.909139819998746E7ZZeeesshhaaannn2802.0
6.909420019998746E7ZZeeesshhaaannn1881.4
*
laune wrote
 
 Sorry, I think I missed this, all you  need is a no-loop in the rule :)
 -W
 
 
 
 On 27/07/2012, zeeshan lt;zeeshan.spring@gt; wrote:
 Hi Laune !

 I applied your suggested changes but the loop is running infinitely and
 same
 policyAPE is used to generated cumulated value I mean for 1 agent it is
 expected that all the policy APEs should sum up to generate Agent APE but
 same policy APE getting summed up infinitely.plz find attached of my
 consolewe printing in console in following order ---  *
 System.out.println($agAPE+ZZeeesshhaaannn+$polAPE);*

 Also find my updated RuleMain and Sample.DRL...


 thanks very much again !

 http://drools.46999.n3.nabble.com/file/n4018946/Sample.drl Sample.drl
 http://drools.46999.n3.nabble.com/file/n4018946/console_snapshot.png
 console_snapshot.png
 http://drools.46999.n3.nabble.com/file/n4018946/RuleMain.java
 RuleMain.java




 --
 View this message in context:
 http://drools.46999.n3.nabble.com/Using-global-variable-in-DRL-file-tp4018911p4018946.html
 Sent from the Drools: User forum mailing list archive at Nabble.com.
 ___
 rules-users mailing list
 rules-users@.jboss
 https://lists.jboss.org/mailman/listinfo/rules-users

 ___
 rules-users mailing list
 rules-users@.jboss
 https://lists.jboss.org/mailman/listinfo/rules-users
 




--
View this message in context: 
http://drools.46999.n3.nabble.com/Using-global-variable-in-DRL-file-tp4018911p4018951.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] Using global variable in DRL file

2012-07-27 Thread Wolfgang Laun
Ah, yes - there are multiple updates of an Agent from several
different policies.

Now, it depend: Is the computed sum of the APEs in the Agent used in
any other rule? If not, the solution is simple. Do not use
modify/update; simply accumulate the values, using the setter, and in
this case you can even omit the no-loop.

rule accumulate policy APEs into agent APE
when
$csvAgent : CSVBeanAgent( $agno: agentNo, $agAPE: agentAPE )
$csvPolicy : CSVBeanPolicy( agentNo == $agno, $polAPE: policyAPE )
then
$csvAgent.setAgentAPE(  $agAPE + $polAPE );
end

If you do need the updated CSVBeanAgent.agentAPE, it's a little more
complicated and I should test the solution before I post it. - Or if
you want to try untested: you'll need an accumulate, like this:

rule accumulate policy APEs into agent APE
no-loop true
when
$csvAgent : CSVBeanAgent( $agno: agentNo, $agAPE: agentAPE )
accumulate( CSVBeanPolicy( agentNo == $agno, $polAPE: policyAPE );
 $sum: sum(  $polAPE ) )
then
 modify( $csvAgent ){ setAgentAPE( $sum ) }
end

Note that this assumes that the old value in agentAPE is 0 or can be
overwritten; otherwise you might need to add the old value to the
$sum.

-W







On 27/07/2012, zeeshan zeeshan.spr...@gmail.com wrote:
 Hi Laune !


   Thanks for ur solution , I resolved the heap Size problem
 with
 your solution but even using *no-loop* is not helping in solving infinite
 loop issue . Can u suggest why it is not accessing other agent objects and
 simply updating same agent object infinite times..After adding no-loop,
 console shows



 *6.902394919998737E7ZZeeesshhaaannn1881.4
 6.902583059998737E7ZZeeesshhaaannn2802.0
 6.902863259998737E7ZZeeesshhaaannn1881.4
 6.90305138738E7ZZeeesshhaaannn2802.0
 6.90333158738E7ZZeeesshhaaannn1881.4
 6.903519739998738E7ZZeeesshhaaannn2802.0
 6.903799939998738E7ZZeeesshhaaannn1881.4
 6.903988079998739E7ZZeeesshhaaannn2802.0
 6.904268279998739E7ZZeeesshhaaannn1881.4
 6.90445641999874E7ZZeeesshhaaannn2802.0
 6.90473661999874E7ZZeeesshhaaannn1881.4
 6.90492475999874E7ZZeeesshhaaannn2802.0
 6.90520495999874E7ZZeeesshhaaannn1881.4
 6.90539308741E7ZZeeesshhaaannn2802.0
 6.90567328741E7ZZeeesshhaaannn1881.4
 6.905861439998741E7ZZeeesshhaaannn2802.0
 6.906141639998741E7ZZeeesshhaaannn1881.4
 6.906329779998742E7ZZeeesshhaaannn2802.0
 6.906609979998742E7ZZeeesshhaaannn1881.4
 6.906798119998743E7ZZeeesshhaaannn2802.0
 6.907078319998743E7ZZeeesshhaaannn1881.4
 6.907266459998743E7ZZeeesshhaaannn2802.0
 6.907546659998743E7ZZeeesshhaaannn1881.4
 6.90773478744E7ZZeeesshhaaannn2802.0
 6.90801498744E7ZZeeesshhaaannn1881.4
 6.908203139998744E7ZZeeesshhaaannn2802.0
 6.908483339998744E7ZZeeesshhaaannn1881.4
 6.908671479998745E7ZZeeesshhaaannn2802.0
 6.908951679998745E7ZZeeesshhaaannn1881.4
 6.909139819998746E7ZZeeesshhaaannn2802.0
 6.909420019998746E7ZZeeesshhaaannn1881.4
 *
 laune wrote

 Sorry, I think I missed this, all you  need is a no-loop in the rule :)
 -W



 On 27/07/2012, zeeshan lt;zeeshan.spring@gt; wrote:
 Hi Laune !

 I applied your suggested changes but the loop is running infinitely and
 same
 policyAPE is used to generated cumulated value I mean for 1 agent it is
 expected that all the policy APEs should sum up to generate Agent APE
 but
 same policy APE getting summed up infinitely.plz find attached of my
 consolewe printing in console in following order ---  *
 System.out.println($agAPE+ZZeeesshhaaannn+$polAPE);*

 Also find my updated RuleMain and Sample.DRL...


 thanks very much again !

 http://drools.46999.n3.nabble.com/file/n4018946/Sample.drl Sample.drl
 http://drools.46999.n3.nabble.com/file/n4018946/console_snapshot.png
 console_snapshot.png
 http://drools.46999.n3.nabble.com/file/n4018946/RuleMain.java
 RuleMain.java




 --
 View this message in context:
 http://drools.46999.n3.nabble.com/Using-global-variable-in-DRL-file-tp4018911p4018946.html
 Sent from the Drools: User forum mailing list archive at Nabble.com.
 ___
 rules-users mailing list
 rules-users@.jboss
 https://lists.jboss.org/mailman/listinfo/rules-users

 ___
 rules-users mailing list
 rules-users@.jboss
 https://lists.jboss.org/mailman/listinfo/rules-users





 --
 View this message in context:
 http://drools.46999.n3.nabble.com/Using-global-variable-in-DRL-file-tp4018911p4018951.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


[rules-users] Using global variable in DRL file

2012-07-26 Thread zeeshan
Hi All !

I am trying use global variable in DRL file but when I am using it, gives
Exception. Please have a look at the DRL file -




package com.drools.rules
import com.drools.facts.*; 
*global CSVBeanAgent csvAgent;*  [here I have declared the Global variable]



rule Calculating Agent APE

salience 35
no-loop true
when

$csvPolicy : CSVBeanPolicy()
//$csvAgent : CSVBeanAgent()
then
  
  
   System.out.println(For agent ---z in rule setting premium form
rate+$csvPolicy.getPremiumMode());
double policyAPE=$csvPolicy.getPolicyAPE();
System.out.println(policyAPE+policyAPE);
*System.out.println(Agent
+csvAgent);*
double agentAPE=0.0;
  if(csvAgent.getAgentNo()==$csvPolicy.getAgentNo()){
  System.out.println(inside if);
 agentAPE=agentAPE+policyAPE;
  }
  csvAgent.setAgentAPE(agentAPE);
   System.out.println(AgentAPE+csvAgent.getAgentAPE());
   update($csvPolicy);
 
end


Above is my rulethe Bold one is I am trying to the value of *csvAgent*,
it gives *null* value. Please help me in finding the solution i.e. How to
declare the global variable and how to use it in DRL file.

Thanks !


 



--
View this message in context: 
http://drools.46999.n3.nabble.com/Using-global-variable-in-DRL-file-tp4018911.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] Using global variable in DRL file

2012-07-26 Thread Michael Anstis
Try reading the Drools Expert User Guide section about the use of Globals :)

Globals are not Facts to be reason in the Left-Hand-Side (WHEN) part of a
rule.

Either use the Global (assuming it contains static data) and initialize it
correctly from within Java code (see the User Guide) or insert it as a Fact
and reason with it.

With kind regards,

Mike

On 26 July 2012 09:38, zeeshan zeeshan.spr...@gmail.com wrote:

 Hi All !

 I am trying use global variable in DRL file but when I am using it, gives
 Exception. Please have a look at the DRL file -




 package com.drools.rules
 import com.drools.facts.*;
 *global CSVBeanAgent csvAgent;*  [here I have declared the Global variable]



 rule Calculating Agent APE

 salience 35
 no-loop true
 when

 $csvPolicy : CSVBeanPolicy()
 //$csvAgent : CSVBeanAgent()
 then


System.out.println(For agent ---z in rule setting premium form
 rate+$csvPolicy.getPremiumMode());
 double policyAPE=$csvPolicy.getPolicyAPE();
 System.out.println(policyAPE+policyAPE);
 *System.out.println(Agent
 +csvAgent);*
 double agentAPE=0.0;
   if(csvAgent.getAgentNo()==$csvPolicy.getAgentNo()){
   System.out.println(inside if);
  agentAPE=agentAPE+policyAPE;
   }
   csvAgent.setAgentAPE(agentAPE);

  System.out.println(AgentAPE+csvAgent.getAgentAPE());
update($csvPolicy);

 end


 Above is my rulethe Bold one is I am trying to the value of *csvAgent*,
 it gives *null* value. Please help me in finding the solution i.e. How to
 declare the global variable and how to use it in DRL file.

 Thanks !






 --
 View this message in context:
 http://drools.46999.n3.nabble.com/Using-global-variable-in-DRL-file-tp4018911.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] Using global variable in DRL file

2012-07-26 Thread zeeshan
Hi Mike !

Earlier I tried it inserting as a Fact in using Statefull Session in my
RuleMain.java but was facing Java Heap Space error...so I tried
Declaring as a Global in RuleMain.java like this


HashMapString, Object globals = new HashMapString, Object();

StatefulSession statefulSession=new
RuleRunner().getStatefulSession(RULES_FILES8,null,null, globals, null);
...



//local block for Agent
{
System.out.println(agent block);
String 
csvPath=C:/Users/new_user/Desktop/CIMS/ABAgent.csv;
  try{
File f = new File(csvPath); 
InputStream is = new FileInputStream( f ); 
Reader rdr = new InputStreamReader( is ); 
LineNumberReader lnrdr = new LineNumberReader( rdr ); 

String line; 
while( (line = lnrdr.readLine()) != null ){ 
if( line.charAt(0) == '' ) continue; 
String[] tokens = line.split( ; ); 
if( tokens.length != 3 ) continue; 

int agentId = Integer.parseInt( tokens[0] ); 
int agentNo  = Integer.parseInt( tokens[1] ); 
String agentStatus = tokens[2]; 
   /* System.out.println(1+agentId);
System.out.println(2+agentNo);
System.out.println(3+agentStatus);*/

CSVBeanAgent csvAg = new CSVBeanAgent(); 
csvAg.setAgentId(agentId);
csvAg.setAgentNo(agentNo);
csvAg.setAgentStatus(agentStatus);
   
 //statefulSession.insert(csvAg);

*globals.put(csvAg.getAgentId()+, csvAg);*

} 
   
  }catch (Exception e) {
System.out.println(e);
} 
}




System.out.println(fire all rule);


statefulSession.fireAllRules();
//statefulSession2.fireAllRules();



log.debug( End Firing Rules =);

// Close the session
 statefulSession.dispose();
}
}



--
View this message in context: 
http://drools.46999.n3.nabble.com/Using-global-variable-in-DRL-file-tp4018911p4018915.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] Using global variable in DRL file

2012-07-26 Thread Michael Anstis
So, you have multiple CSVBeanAgent's (created from a text file somewhere).
These are stored in a Map created in Java called globals.

Where do you actually set the global in WorkingMemory: See
http://docs.jboss.org/drools/release/5.4.0.Final/drools-expert-docs/html/ch04.html#d0e4482
.

Furthermore, the Global will be of type Map not CSVBeanAgent, unless you
want a Global for each CSVBeanAgent - but then how do you decide which you
need.

Personally, I'd go back to inserting CSVBeanAgents as Facts and tackle the
Java Heap Space issue... there are definitely things you are not telling us.

With kind regards,

Mike

On 26 July 2012 10:37, zeeshan zeeshan.spr...@gmail.com wrote:

 Hi Mike !

 Earlier I tried it inserting as a Fact in using Statefull Session in my
 RuleMain.java but was facing Java Heap Space error...so I tried
 Declaring as a Global in RuleMain.java like this


 HashMapString, Object globals = new HashMapString, Object();

 StatefulSession statefulSession=new
 RuleRunner().getStatefulSession(RULES_FILES8,null,null, globals, null);
 ...
 


 //local block for Agent
 {
 System.out.println(agent block);
 String
 csvPath=C:/Users/new_user/Desktop/CIMS/ABAgent.csv;
   try{
 File f = new File(csvPath);
 InputStream is = new FileInputStream( f );
 Reader rdr = new InputStreamReader( is );
 LineNumberReader lnrdr = new LineNumberReader( rdr
 );

 String line;
 while( (line = lnrdr.readLine()) != null ){
 if( line.charAt(0) == '' ) continue;
 String[] tokens = line.split( ; );
 if( tokens.length != 3 ) continue;

 int agentId = Integer.parseInt( tokens[0] );
 int agentNo  = Integer.parseInt( tokens[1] );
 String agentStatus = tokens[2];
/* System.out.println(1+agentId);
 System.out.println(2+agentNo);
 System.out.println(3+agentStatus);*/

 CSVBeanAgent csvAg = new CSVBeanAgent();
 csvAg.setAgentId(agentId);
 csvAg.setAgentNo(agentNo);
 csvAg.setAgentStatus(agentStatus);

  //statefulSession.insert(csvAg);

 *globals.put(csvAg.getAgentId()+, csvAg);*

 }

   }catch (Exception e) {
 System.out.println(e);
 }
 }




 System.out.println(fire all rule);


 statefulSession.fireAllRules();
 //statefulSession2.fireAllRules();



 log.debug( End Firing Rules =);

 // Close the session
  statefulSession.dispose();
 }
 }



 --
 View this message in context:
 http://drools.46999.n3.nabble.com/Using-global-variable-in-DRL-file-tp4018911p4018915.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] Using global variable in DRL file

2012-07-26 Thread zeeshan
Hi MIke !

Yes we have multiple CSVBeanAgent objects that initially we tried to insert
in statefull session but we faced heap size issue. This Heap Issue was
resolved by *Laune* using CSV, and we are following similar approach here
too but we faced heap size issue. So we followed global variable approach.

   Instead of inserting CSVBEanAGent objects in statefull session, we
inserted it in t he global variable of type Hashmap. By this we avoided Heap
size issue, but now the problem is Global variable in all the Rules as well
as retreive that updated global value back in RuleMain.java file.

So can u help us in finding other solution or  through global variable??


Thanks.



--
View this message in context: 
http://drools.46999.n3.nabble.com/Using-global-variable-in-DRL-file-tp4018911p4018917.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] Using global variable in DRL file

2012-07-26 Thread Wolfgang Laun
This was the 50,000 lines spreadsheet?

IIRC, the data in the Bean wasn't engineered with memory saving in mind.
Could you please post this class again, and we'll see how to tone it
down to get then all into the heap.

-W

On 26/07/2012, zeeshan zeeshan.spr...@gmail.com wrote:
 Hi MIke !

 Yes we have multiple CSVBeanAgent objects that initially we tried to insert
 in statefull session but we faced heap size issue. This Heap Issue was
 resolved by *Laune* using CSV, and we are following similar approach here
 too but we faced heap size issue. So we followed global variable approach.

Instead of inserting CSVBEanAGent objects in statefull session, we
 inserted it in t he global variable of type Hashmap. By this we avoided
 Heap
 size issue, but now the problem is Global variable in all the Rules as well
 as retreive that updated global value back in RuleMain.java file.

 So can u help us in finding other solution or  through global
 variable??


 Thanks.



 --
 View this message in context:
 http://drools.46999.n3.nabble.com/Using-global-variable-in-DRL-file-tp4018911p4018917.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] Using global variable in DRL file

2012-07-26 Thread zeeshan
Hi Laune and thanks for replying

Actually it was not just 50,000, it was 1,00,000 records in single CSV that
we solved the Heap space problem by your help and we have developed that
product and successfuly integrated in Liferay Portal... :)

Now in this case, we have to read* three CSV files* having *1800,12k and
9.5k* records. Now our concern is that if it was running fine for 100
thousand records then why it is creating problem data which is much lesser
than 100 thousand. 

Actually we are thinking in the direction like, it might creating problem
because increased number of columns in each of three CSV files that we are
using compare to that 100 thousand records in which we had 8 columns but
only one file. 

Another concern is ,there may be possibility that as we are generating
objects from 3 CSV one after another then firing rules might creating
problem...??  Please help us in finding out what is the reason for this
problemPlease find the Rulemain.java and Sample .drl file which u asked
me to provide

thanks !!

http://drools.46999.n3.nabble.com/file/n4018939/RuleMain.java RuleMain.java 
http://drools.46999.n3.nabble.com/file/n4018939/RuleRunner.java
RuleRunner.java  http://drools.46999.n3.nabble.com/file/n4018939/Sample.drl
Sample.drl 




--
View this message in context: 
http://drools.46999.n3.nabble.com/Using-global-variable-in-DRL-file-tp4018911p4018939.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