Re: [rules-users] How to make this rule more memory efficient?

2010-05-04 Thread Ryan Fitzgerald
Hi Wolfgang,

Sorry for the late reply on this.

Actually I did miss your earlier reply.

I applied the changes you suggested and made a few more tweaks and I have been 
able to get the memory down from over 1.5GB (where I was getting OOM 
exceptions) to 300MB.

I now realise that I have to be very careful how I define the patterns and 
order them. Thanks a million for your help.

/Ryan. 

-Original Message-
From: rules-users-boun...@lists.jboss.org 
[mailto:rules-users-boun...@lists.jboss.org] On Behalf Of Wolfgang Laun
Sent: 28 April 2010 10:25
To: Rules Users List
Subject: Re: [rules-users] How to make this rule more memory efficient?

Did you miss my earlier reply proposing an alternative order of patterns? ( I 
just saw that the second eval isn't necessary.) HEre is the revised form:

rule Check consistent references
when
   $proxy1 : ProxyCell()
   $cell1  : Cell( id == $proxy1.id )
   $proxy2 : ProxyCell( id  $proxy1.id,
eval( $cell1.references contains this.name ) )
   $cell2  : Cell( id == $proxy2.id, references not contains $proxy1.name ) 
then
   //report an error.
end

-W

On Wed, Apr 28, 2010 at 10:45 AM, Ryan Fitzgerald 
ryan.fitzger...@ericsson.com wrote:
 Thanks Wolfgang.

 Should I conclude therefore that high memory usage is unavoidable due to the 
 number of facts that must be processed? I was hoping that there might be a 
 clever way of writing the rules so that the rules engine can minimise the 
 network it generates - even if it takes a little longer to execute.

 All of the facts are read from a database and thus loaded into working 
 memory. My fallback position is to not load all these objects into working 
 memory but instead embed into a rule, a service call that queries the db for 
 all inconsistencies (effectively using SQL instead of a drools rule). 
 However, since I will have other rules that operate on these objects in 
 working memory, I was hoping to use these facts for all rules.

 /Ryan.

 -Original Message-
 From: rules-users-boun...@lists.jboss.org 
 [mailto:rules-users-boun...@lists.jboss.org] On Behalf Of Wolfgang 
 Laun
 Sent: 27 April 2010 14:59
 To: Rules Users List
 Subject: Re: [rules-users] How to make this rule more memory efficient?

 If there are n Cell facts,
  $cell1 : Cell()
  $cell2 : Cell()
 needs to create n*n pairs in the network before any reduction may set in.
 Using
  $cell2 : Cell(this != $cell1)
 reduces this by n, so we're still quadratic. Something like
  $cell1 : Cell( $id1 : id )
  $cell2 : Cell( id  $id1 )
 reduces it to n*(n-1)/2 which is less than 50% of the original, but still 
 quadratic.

 -W

 2010/4/26 Swindells, Thomas tswinde...@nds.com:
 You should probably restrict it so that

 $cell2 : Cell(this != $cell1)



 Thomas



 From: rules-users-boun...@lists.jboss.org
 [mailto:rules-users-boun...@lists.jboss.org] On Behalf Of Ryan 
 Fitzgerald
 Sent: 26 April 2010 15:34
 To: rules-users@lists.jboss.org
 Subject: [rules-users] How to make this rule more memory efficient?



 Hi,



 Can anyone advise me on how to make a drools rule more memory efficient?
 Here is the problem:



 I have a Cell and a ProxyCell object classes.



 The ProxyCell represents the Cell when their internal ID's match.



 Each Cell and ProxyCell however has a unique name (not same as ID).



 A Cell can reference (by name) a ProxyCell (as long as the ProxyCell 
 does not represent that actual Cell - which would effectively be a 
 self-reference and is not allowed).



 What I want to do is find out where I have a reference from any 
 instance of Cell - cell1 - to any instance of ProxyCell - proxycell2 
 - but am missing a reference from cell2 to proxycell1 where 
 proxycell2 is a representation of
 cell2 and proxycell1 is a representation of cell1.



 Here is the rule I have written for it:



 rule Check consistent references

 when

     $cell1 : Cell()

     $cell2 : Cell()

     $proxycell1 : ProxyCell ( id = $cell1.id, $cell2.references 
 contains this.name )

     $proxycell2 : ProxyCell ( id = $cell2.id, $cell1.references 
 not contains this.name )

 then

     //report an error.

 end





 I have 10,000 instances of Cell and 10,000 instances of ProxyCell in 
 working memory. For each instance of Cell, it can have references to 
 60 different ProxyCell instances. Loading the Cell and ProxyCell 
 instances into working memory is not a problem. However, when I try 
 to run this rule above, the memory quickly goes above 1GB and I eventually 
 get an out of memory error.



 I was wondering if there is a better way to structure or write this 
 rule so that it doesn't use so much memory.



 Thanks,

 Ryan.



 
 *
 *
  This message is confidential and intended only for 
 the addressee. If you have received this message in error, please 
 immediately

Re: [rules-users] How to make this rule more memory efficient?

2010-05-04 Thread Ryan Fitzgerald
Hi Thomas,

You are correct in your interpretation of what I want to do.

I did consider adding the mappings as their own facts but I was concerned that 
the sheer number of them would overload drools. For each Cell instance, it can 
refer to up to 60 ProxyCell instances. With 20,000 Cell instances (in my 
proto-type), that means 1.2 million mappings.

Can drools handle these kinds of numbers of facts?

Thanks,
Ryan. 

-Original Message-
From: rules-users-boun...@lists.jboss.org 
[mailto:rules-users-boun...@lists.jboss.org] On Behalf Of Swindells, Thomas
Sent: 28 April 2010 10:17
To: Rules Users List
Subject: Re: [rules-users] How to make this rule more memory efficient?

If I understand the following
 What I want to do is find out where I have a reference from any 
 instance of Cell - cell1 - to any instance of ProxyCell - proxycell2 - 
 but am missing a reference from cell2 to proxycell1 where proxycell2 
 is a representation of
 cell2 and proxycell1 is a representation of cell1.


What I think you saying is that if
C1 - P2 then there must be a C2 - P1
Where C2 == P2.cellId and P1 == C1.cellId.

I've not worked this through properly (It's still too early in the working day) 
but do you may make a win by inserting the mappings into working memory as 
their own facts (and so trading memory for processing time).  You can then 
reason over these relationships which should reduce the number of combinations 
that are made.
So have a rules like the following:

Rule createRelationship salience [high]
$cell1 : Cell()
$proxy2 : Proxy($cell1.relationships contains this.name) then insert new 
Relationship($cell1.id, $proxy2.id); end

Rule check inverse salience [low]
$relationship : Relationship()
$cell1 : Cell(id == $relationship.cellId)
$proxy2 : Proxy(id == $relationship.proxyId) not exist Relationship(cellId == 
$relationship.proxyId, proxyId == relationship.cellId) then //raise warning or 
whatever end


Hopefully this does what you wants and should be more efficient processing wise 
and activation count wise.
Thomas

 -Original Message-
 From: rules-users-boun...@lists.jboss.org [mailto:rules-users- 
 boun...@lists.jboss.org] On Behalf Of Ryan Fitzgerald
 Sent: 28 April 2010 09:46
 To: Rules Users List
 Subject: Re: [rules-users] How to make this rule more memory efficient?

 Thanks Wolfgang.

 Should I conclude therefore that high memory usage is unavoidable due 
 to the number of facts that must be processed? I was hoping that there 
 might be a clever way of writing the rules so that the rules engine 
 can minimise the network it generates - even if it takes a little longer to 
 execute.

 All of the facts are read from a database and thus loaded into working memory.
 My fallback position is to not load all these objects into working 
 memory but instead embed into a rule, a service call that queries the 
 db for all inconsistencies (effectively using SQL instead of a drools 
 rule). However, since I will have other rules that operate on these 
 objects in working memory, I was hoping to use these facts for all rules.

 /Ryan.

 -Original Message-
 From: rules-users-boun...@lists.jboss.org [mailto:rules-users- 
 boun...@lists.jboss.org] On Behalf Of Wolfgang Laun
 Sent: 27 April 2010 14:59
 To: Rules Users List
 Subject: Re: [rules-users] How to make this rule more memory efficient?

 If there are n Cell facts,
  $cell1 : Cell()
  $cell2 : Cell()
 needs to create n*n pairs in the network before any reduction may set in.
 Using
   $cell2 : Cell(this != $cell1)
 reduces this by n, so we're still quadratic. Something like
  $cell1 : Cell( $id1 : id )
  $cell2 : Cell( id  $id1 )
 reduces it to n*(n-1)/2 which is less than 50% of the original, but 
 still quadratic.

 -W

 2010/4/26 Swindells, Thomas tswinde...@nds.com:
  You should probably restrict it so that
 
  $cell2 : Cell(this != $cell1)
 
 
 
  Thomas
 
 
 
  From: rules-users-boun...@lists.jboss.org
  [mailto:rules-users-boun...@lists.jboss.org] On Behalf Of Ryan 
  Fitzgerald
  Sent: 26 April 2010 15:34
  To: rules-users@lists.jboss.org
  Subject: [rules-users] How to make this rule more memory efficient?
 
 
 
  Hi,
 
 
 
  Can anyone advise me on how to make a drools rule more memory efficient?
  Here is the problem:
 
 
 
  I have a Cell and a ProxyCell object classes.
 
 
 
  The ProxyCell represents the Cell when their internal ID's match.
 
 
 
  Each Cell and ProxyCell however has a unique name (not same as ID).
 
 
 
  A Cell can reference (by name) a ProxyCell (as long as the ProxyCell 
  does not represent that actual Cell - which would effectively be a 
  self-reference and is not allowed).
 
 
 
  What I want to do is find out where I have a reference from any 
  instance of Cell - cell1 - to any instance of ProxyCell - proxycell2 
  - but am missing a reference from cell2 to proxycell1 where 
  proxycell2 is a representation of
  cell2 and proxycell1 is a representation of cell1.
 
 
 
  Here is the rule I have

Re: [rules-users] How to make this rule more memory efficient?

2010-05-04 Thread Greg Barton
It can handle it.  The limiting factor is available heap.

GreG

On May 4, 2010, at 10:55, Ryan Fitzgerald ryan.fitzger...@ericsson.com wrote:

Hi Thomas,

You are correct in your interpretation of what I want to do.

I did consider adding the mappings as their own facts but I was concerned that 
the sheer number of them would overload drools. For each Cell instance, it can 
refer to up to 60 ProxyCell instances. With 20,000 Cell instances (in my 
proto-type), that means 1.2 million mappings.

Can drools handle these kinds of numbers of facts?

Thanks,
Ryan. 

-Original Message-
From: rules-users-boun...@lists.jboss.org 
[mailto:rules-users-boun...@lists.jboss.org] On Behalf Of Swindells, Thomas
Sent: 28 April 2010 10:17
To: Rules Users List
Subject: Re: [rules-users] How to make this rule more memory efficient?

If I understand the following
What I want to do is find out where I have a reference from any 
instance of Cell - cell1 - to any instance of ProxyCell - proxycell2 - 
but am missing a reference from cell2 to proxycell1 where proxycell2 
is a representation of
cell2 and proxycell1 is a representation of cell1.


What I think you saying is that if
C1 - P2 then there must be a C2 - P1
Where C2 == P2.cellId and P1 == C1.cellId.

I've not worked this through properly (It's still too early in the working day) 
but do you may make a win by inserting the mappings into working memory as 
their own facts (and so trading memory for processing time).  You can then 
reason over these relationships which should reduce the number of combinations 
that are made.
So have a rules like the following:

Rule createRelationship salience [high]
$cell1 : Cell()
$proxy2 : Proxy($cell1.relationships contains this.name) then insert new 
Relationship($cell1.id, $proxy2.id); end

Rule check inverse salience [low]
$relationship : Relationship()
$cell1 : Cell(id == $relationship.cellId)
$proxy2 : Proxy(id == $relationship.proxyId) not exist Relationship(cellId == 
$relationship.proxyId, proxyId == relationship.cellId) then //raise warning or 
whatever end


Hopefully this does what you wants and should be more efficient processing wise 
and activation count wise.
Thomas

-Original Message-
From: rules-users-boun...@lists.jboss.org [mailto:rules-users- 
boun...@lists.jboss.org] On Behalf Of Ryan Fitzgerald
Sent: 28 April 2010 09:46
To: Rules Users List
Subject: Re: [rules-users] How to make this rule more memory efficient?

Thanks Wolfgang.

Should I conclude therefore that high memory usage is unavoidable due 
to the number of facts that must be processed? I was hoping that there 
might be a clever way of writing the rules so that the rules engine 
can minimise the network it generates - even if it takes a little longer to 
execute.

All of the facts are read from a database and thus loaded into working memory.
My fallback position is to not load all these objects into working 
memory but instead embed into a rule, a service call that queries the 
db for all inconsistencies (effectively using SQL instead of a drools 
rule). However, since I will have other rules that operate on these 
objects in working memory, I was hoping to use these facts for all rules.

/Ryan.

-Original Message-
From: rules-users-boun...@lists.jboss.org [mailto:rules-users- 
boun...@lists.jboss.org] On Behalf Of Wolfgang Laun
Sent: 27 April 2010 14:59
To: Rules Users List
Subject: Re: [rules-users] How to make this rule more memory efficient?

If there are n Cell facts,
$cell1 : Cell()
$cell2 : Cell()
needs to create n*n pairs in the network before any reduction may set in.
Using
 $cell2 : Cell(this != $cell1)
reduces this by n, so we're still quadratic. Something like
$cell1 : Cell( $id1 : id )
$cell2 : Cell( id  $id1 )
reduces it to n*(n-1)/2 which is less than 50% of the original, but 
still quadratic.

-W

2010/4/26 Swindells, Thomas tswinde...@nds.com:
You should probably restrict it so that

$cell2 : Cell(this != $cell1)



Thomas



From: rules-users-boun...@lists.jboss.org
[mailto:rules-users-boun...@lists.jboss.org] On Behalf Of Ryan 
Fitzgerald
Sent: 26 April 2010 15:34
To: rules-users@lists.jboss.org
Subject: [rules-users] How to make this rule more memory efficient?



Hi,



Can anyone advise me on how to make a drools rule more memory efficient?
Here is the problem:



I have a Cell and a ProxyCell object classes.



The ProxyCell represents the Cell when their internal ID's match.



Each Cell and ProxyCell however has a unique name (not same as ID).



A Cell can reference (by name) a ProxyCell (as long as the ProxyCell 
does not represent that actual Cell - which would effectively be a 
self-reference and is not allowed).



What I want to do is find out where I have a reference from any 
instance of Cell - cell1 - to any instance of ProxyCell - proxycell2 
- but am missing a reference from cell2 to proxycell1 where 
proxycell2 is a representation of
cell2 and proxycell1 is a representation of cell1.



Here

Re: [rules-users] How to make this rule more memory efficient?

2010-04-28 Thread Ryan Fitzgerald
Thanks Wolfgang.

Should I conclude therefore that high memory usage is unavoidable due to the 
number of facts that must be processed? I was hoping that there might be a 
clever way of writing the rules so that the rules engine can minimise the 
network it generates - even if it takes a little longer to execute.

All of the facts are read from a database and thus loaded into working memory. 
My fallback position is to not load all these objects into working memory but 
instead embed into a rule, a service call that queries the db for all 
inconsistencies (effectively using SQL instead of a drools rule). However, 
since I will have other rules that operate on these objects in working memory, 
I was hoping to use these facts for all rules.

/Ryan. 

-Original Message-
From: rules-users-boun...@lists.jboss.org 
[mailto:rules-users-boun...@lists.jboss.org] On Behalf Of Wolfgang Laun
Sent: 27 April 2010 14:59
To: Rules Users List
Subject: Re: [rules-users] How to make this rule more memory efficient?

If there are n Cell facts,
 $cell1 : Cell()
 $cell2 : Cell()
needs to create n*n pairs in the network before any reduction may set in.
Using
  $cell2 : Cell(this != $cell1)
reduces this by n, so we're still quadratic. Something like
 $cell1 : Cell( $id1 : id )
 $cell2 : Cell( id  $id1 )
reduces it to n*(n-1)/2 which is less than 50% of the original, but still 
quadratic.

-W

2010/4/26 Swindells, Thomas tswinde...@nds.com:
 You should probably restrict it so that

 $cell2 : Cell(this != $cell1)



 Thomas



 From: rules-users-boun...@lists.jboss.org
 [mailto:rules-users-boun...@lists.jboss.org] On Behalf Of Ryan 
 Fitzgerald
 Sent: 26 April 2010 15:34
 To: rules-users@lists.jboss.org
 Subject: [rules-users] How to make this rule more memory efficient?



 Hi,



 Can anyone advise me on how to make a drools rule more memory efficient?
 Here is the problem:



 I have a Cell and a ProxyCell object classes.



 The ProxyCell represents the Cell when their internal ID's match.



 Each Cell and ProxyCell however has a unique name (not same as ID).



 A Cell can reference (by name) a ProxyCell (as long as the ProxyCell 
 does not represent that actual Cell - which would effectively be a 
 self-reference and is not allowed).



 What I want to do is find out where I have a reference from any 
 instance of Cell - cell1 - to any instance of ProxyCell - proxycell2 - 
 but am missing a reference from cell2 to proxycell1 where proxycell2 
 is a representation of
 cell2 and proxycell1 is a representation of cell1.



 Here is the rule I have written for it:



 rule Check consistent references

 when

     $cell1 : Cell()

     $cell2 : Cell()

     $proxycell1 : ProxyCell ( id = $cell1.id, $cell2.references 
 contains this.name )

     $proxycell2 : ProxyCell ( id = $cell2.id, $cell1.references 
 not contains this.name )

 then

     //report an error.

 end





 I have 10,000 instances of Cell and 10,000 instances of ProxyCell in 
 working memory. For each instance of Cell, it can have references to 
 60 different ProxyCell instances. Loading the Cell and ProxyCell 
 instances into working memory is not a problem. However, when I try to 
 run this rule above, the memory quickly goes above 1GB and I eventually get 
 an out of memory error.



 I was wondering if there is a better way to structure or write this 
 rule so that it doesn't use so much memory.



 Thanks,

 Ryan.



 
 **
  This message is confidential and intended only for 
 the addressee. If you have received this message in error, please 
 immediately notify the postmas...@nds.com and delete it from your 
 system as well as any copies. The content of e-mails as well as 
 traffic data may be monitored by NDS for employment and security 
 purposes. To protect the environment please do not print this e-mail 
 unless necessary.

 NDS Limited. Registered Office: One London Road, Staines, Middlesex, 
 TW18 4EX, United Kingdom. A company registered in England and Wales. 
 Registered no. 3080780. VAT no. GB 603 8808 40-00
 **
 

 
 This message is confidential and intended only for the addressee. If 
 you have received this message in error, please immediately notify the 
 postmas...@nds.com and delete it from your system as well as any 
 copies. The content of e-mails as well as traffic data may be 
 monitored by NDS for employment and security purposes.
 To protect the environment please do not print this e-mail unless necessary.

 An NDS Group Limited company. www.nds.com

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



___
rules-users mailing

Re: [rules-users] How to make this rule more memory efficient?

2010-04-28 Thread Swindells, Thomas
If I understand the following
 What I want to do is find out where I have a reference from any
 instance of Cell - cell1 - to any instance of ProxyCell - proxycell2 -
 but am missing a reference from cell2 to proxycell1 where proxycell2
 is a representation of
 cell2 and proxycell1 is a representation of cell1.


What I think you saying is that if
C1 - P2 then there must be a C2 - P1
Where C2 == P2.cellId and P1 == C1.cellId.

I've not worked this through properly (It's still too early in the working day) 
but do you may make a win by inserting the mappings into working memory as 
their own facts (and so trading memory for processing time).  You can then 
reason over these relationships which should reduce the number of combinations 
that are made.
So have a rules like the following:

Rule createRelationship salience [high]
$cell1 : Cell()
$proxy2 : Proxy($cell1.relationships contains this.name)
then
insert new Relationship($cell1.id, $proxy2.id);
end

Rule check inverse salience [low]
$relationship : Relationship()
$cell1 : Cell(id == $relationship.cellId)
$proxy2 : Proxy(id == $relationship.proxyId)
not exist Relationship(cellId == $relationship.proxyId, proxyId == 
relationship.cellId)
then
//raise warning or whatever
end


Hopefully this does what you wants and should be more efficient processing wise 
and activation count wise.
Thomas

 -Original Message-
 From: rules-users-boun...@lists.jboss.org [mailto:rules-users-
 boun...@lists.jboss.org] On Behalf Of Ryan Fitzgerald
 Sent: 28 April 2010 09:46
 To: Rules Users List
 Subject: Re: [rules-users] How to make this rule more memory efficient?

 Thanks Wolfgang.

 Should I conclude therefore that high memory usage is unavoidable due to the
 number of facts that must be processed? I was hoping that there might be a
 clever way of writing the rules so that the rules engine can minimise the
 network it generates - even if it takes a little longer to execute.

 All of the facts are read from a database and thus loaded into working memory.
 My fallback position is to not load all these objects into working memory but
 instead embed into a rule, a service call that queries the db for all
 inconsistencies (effectively using SQL instead of a drools rule). However,
 since I will have other rules that operate on these objects in working memory,
 I was hoping to use these facts for all rules.

 /Ryan.

 -Original Message-
 From: rules-users-boun...@lists.jboss.org [mailto:rules-users-
 boun...@lists.jboss.org] On Behalf Of Wolfgang Laun
 Sent: 27 April 2010 14:59
 To: Rules Users List
 Subject: Re: [rules-users] How to make this rule more memory efficient?

 If there are n Cell facts,
  $cell1 : Cell()
  $cell2 : Cell()
 needs to create n*n pairs in the network before any reduction may set in.
 Using
   $cell2 : Cell(this != $cell1)
 reduces this by n, so we're still quadratic. Something like
  $cell1 : Cell( $id1 : id )
  $cell2 : Cell( id  $id1 )
 reduces it to n*(n-1)/2 which is less than 50% of the original, but still
 quadratic.

 -W

 2010/4/26 Swindells, Thomas tswinde...@nds.com:
  You should probably restrict it so that
 
  $cell2 : Cell(this != $cell1)
 
 
 
  Thomas
 
 
 
  From: rules-users-boun...@lists.jboss.org
  [mailto:rules-users-boun...@lists.jboss.org] On Behalf Of Ryan
  Fitzgerald
  Sent: 26 April 2010 15:34
  To: rules-users@lists.jboss.org
  Subject: [rules-users] How to make this rule more memory efficient?
 
 
 
  Hi,
 
 
 
  Can anyone advise me on how to make a drools rule more memory efficient?
  Here is the problem:
 
 
 
  I have a Cell and a ProxyCell object classes.
 
 
 
  The ProxyCell represents the Cell when their internal ID's match.
 
 
 
  Each Cell and ProxyCell however has a unique name (not same as ID).
 
 
 
  A Cell can reference (by name) a ProxyCell (as long as the ProxyCell
  does not represent that actual Cell - which would effectively be a
  self-reference and is not allowed).
 
 
 
  What I want to do is find out where I have a reference from any
  instance of Cell - cell1 - to any instance of ProxyCell - proxycell2 -
  but am missing a reference from cell2 to proxycell1 where proxycell2
  is a representation of
  cell2 and proxycell1 is a representation of cell1.
 
 
 
  Here is the rule I have written for it:
 
 
 
  rule Check consistent references
 
  when
 
  $cell1 : Cell()
 
  $cell2 : Cell()
 
  $proxycell1 : ProxyCell ( id = $cell1.id, $cell2.references
  contains this.name )
 
  $proxycell2 : ProxyCell ( id = $cell2.id, $cell1.references
  not contains this.name )
 
  then
 
  //report an error.
 
  end
 
 
 
 
 
  I have 10,000 instances of Cell and 10,000 instances of ProxyCell in
  working memory. For each instance of Cell, it can have references to
  60 different ProxyCell instances. Loading the Cell and ProxyCell
  instances into working memory is not a problem. However, when I try to
  run this rule above, the memory quickly goes above

Re: [rules-users] How to make this rule more memory efficient?

2010-04-28 Thread Wolfgang Laun
Did you miss my earlier reply proposing an alternative order of
patterns? ( I just saw that the second eval isn't necessary.) HEre is
the revised form:

rule Check consistent references
when
   $proxy1 : ProxyCell()
   $cell1  : Cell( id == $proxy1.id )
   $proxy2 : ProxyCell( id  $proxy1.id,
eval( $cell1.references contains this.name ) )
   $cell2  : Cell( id == $proxy2.id, references not contains $proxy1.name )
then
   //report an error.
end

-W

On Wed, Apr 28, 2010 at 10:45 AM, Ryan Fitzgerald
ryan.fitzger...@ericsson.com wrote:
 Thanks Wolfgang.

 Should I conclude therefore that high memory usage is unavoidable due to the 
 number of facts that must be processed? I was hoping that there might be a 
 clever way of writing the rules so that the rules engine can minimise the 
 network it generates - even if it takes a little longer to execute.

 All of the facts are read from a database and thus loaded into working 
 memory. My fallback position is to not load all these objects into working 
 memory but instead embed into a rule, a service call that queries the db for 
 all inconsistencies (effectively using SQL instead of a drools rule). 
 However, since I will have other rules that operate on these objects in 
 working memory, I was hoping to use these facts for all rules.

 /Ryan.

 -Original Message-
 From: rules-users-boun...@lists.jboss.org 
 [mailto:rules-users-boun...@lists.jboss.org] On Behalf Of Wolfgang Laun
 Sent: 27 April 2010 14:59
 To: Rules Users List
 Subject: Re: [rules-users] How to make this rule more memory efficient?

 If there are n Cell facts,
  $cell1 : Cell()
  $cell2 : Cell()
 needs to create n*n pairs in the network before any reduction may set in.
 Using
  $cell2 : Cell(this != $cell1)
 reduces this by n, so we're still quadratic. Something like
  $cell1 : Cell( $id1 : id )
  $cell2 : Cell( id  $id1 )
 reduces it to n*(n-1)/2 which is less than 50% of the original, but still 
 quadratic.

 -W

 2010/4/26 Swindells, Thomas tswinde...@nds.com:
 You should probably restrict it so that

 $cell2 : Cell(this != $cell1)



 Thomas



 From: rules-users-boun...@lists.jboss.org
 [mailto:rules-users-boun...@lists.jboss.org] On Behalf Of Ryan
 Fitzgerald
 Sent: 26 April 2010 15:34
 To: rules-users@lists.jboss.org
 Subject: [rules-users] How to make this rule more memory efficient?



 Hi,



 Can anyone advise me on how to make a drools rule more memory efficient?
 Here is the problem:



 I have a Cell and a ProxyCell object classes.



 The ProxyCell represents the Cell when their internal ID's match.



 Each Cell and ProxyCell however has a unique name (not same as ID).



 A Cell can reference (by name) a ProxyCell (as long as the ProxyCell
 does not represent that actual Cell - which would effectively be a
 self-reference and is not allowed).



 What I want to do is find out where I have a reference from any
 instance of Cell - cell1 - to any instance of ProxyCell - proxycell2 -
 but am missing a reference from cell2 to proxycell1 where proxycell2
 is a representation of
 cell2 and proxycell1 is a representation of cell1.



 Here is the rule I have written for it:



 rule Check consistent references

 when

     $cell1 : Cell()

     $cell2 : Cell()

     $proxycell1 : ProxyCell ( id = $cell1.id, $cell2.references
 contains this.name )

     $proxycell2 : ProxyCell ( id = $cell2.id, $cell1.references
 not contains this.name )

 then

     //report an error.

 end





 I have 10,000 instances of Cell and 10,000 instances of ProxyCell in
 working memory. For each instance of Cell, it can have references to
 60 different ProxyCell instances. Loading the Cell and ProxyCell
 instances into working memory is not a problem. However, when I try to
 run this rule above, the memory quickly goes above 1GB and I eventually get 
 an out of memory error.



 I was wondering if there is a better way to structure or write this
 rule so that it doesn't use so much memory.



 Thanks,

 Ryan.



 
 **
  This message is confidential and intended only for
 the addressee. If you have received this message in error, please
 immediately notify the postmas...@nds.com and delete it from your
 system as well as any copies. The content of e-mails as well as
 traffic data may be monitored by NDS for employment and security
 purposes. To protect the environment please do not print this e-mail
 unless necessary.

 NDS Limited. Registered Office: One London Road, Staines, Middlesex,
 TW18 4EX, United Kingdom. A company registered in England and Wales.
 Registered no. 3080780. VAT no. GB 603 8808 40-00
 **
 

 
 This message is confidential and intended only for the addressee. If
 you have

Re: [rules-users] How to make this rule more memory efficient?

2010-04-27 Thread Ryan Fitzgerald
Thanks Thomas. I included this but it makes little difference.

/Ryan.


From: rules-users-boun...@lists.jboss.org 
[mailto:rules-users-boun...@lists.jboss.org] On Behalf Of Swindells, Thomas
Sent: 26 April 2010 15:55
To: Rules Users List
Subject: Re: [rules-users] How to make this rule more memory efficient?

You should probably restrict it so that
$cell2 : Cell(this != $cell1)

Thomas

From: rules-users-boun...@lists.jboss.org 
[mailto:rules-users-boun...@lists.jboss.org] On Behalf Of Ryan Fitzgerald
Sent: 26 April 2010 15:34
To: rules-users@lists.jboss.org
Subject: [rules-users] How to make this rule more memory efficient?

Hi,

Can anyone advise me on how to make a drools rule more memory efficient? Here 
is the problem:

I have a Cell and a ProxyCell object classes.

The ProxyCell represents the Cell when their internal ID's match.

Each Cell and ProxyCell however has a unique name (not same as ID).

A Cell can reference (by name) a ProxyCell (as long as the ProxyCell does not 
represent that actual Cell - which would effectively be a self-reference and is 
not allowed).

What I want to do is find out where I have a reference from any instance of 
Cell - cell1 - to any instance of ProxyCell - proxycell2 - but am missing a 
reference from cell2 to proxycell1 where proxycell2 is a representation of 
cell2 and proxycell1 is a representation of cell1.

Here is the rule I have written for it:

rule Check consistent references
when
$cell1 : Cell()
$cell2 : Cell()
$proxycell1 : ProxyCell ( id = $cell1.id, $cell2.references contains 
this.name )
$proxycell2 : ProxyCell ( id = $cell2.id, $cell1.references not 
contains this.name )
then
//report an error.
end


I have 10,000 instances of Cell and 10,000 instances of ProxyCell in working 
memory. For each instance of Cell, it can have references to 60 different 
ProxyCell instances. Loading the Cell and ProxyCell instances into working 
memory is not a problem. However, when I try to run this rule above, the memory 
quickly goes above 1GB and I eventually get an out of memory error.

I was wondering if there is a better way to structure or write this rule so 
that it doesn't use so much memory.

Thanks,
Ryan.




**
This message is confidential and intended only for the addressee. If you have 
received this message in error, please immediately notify the 
postmas...@nds.com and delete it from your system as well as any copies. The 
content of e-mails as well as traffic data may be monitored by NDS for 
employment and security purposes. To protect the environment please do not 
print this e-mail unless necessary.

NDS Limited. Registered Office: One London Road, Staines, Middlesex, TW18 4EX, 
United Kingdom. A company registered in England and Wales. Registered no. 
3080780. VAT no. GB 603 8808 40-00
**


This message is confidential and intended only for the addressee. If you have 
received this message in error, please immediately notify the 
postmas...@nds.com and delete it from your system as well as any copies. The 
content of e-mails as well as traffic data may be monitored by NDS for 
employment and security purposes.
To protect the environment please do not print this e-mail unless necessary.

An NDS Group Limited company. www.nds.com
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] How to make this rule more memory efficient?

2010-04-27 Thread Wolfgang Laun
If there are n Cell facts,
 $cell1 : Cell()
 $cell2 : Cell()
needs to create n*n pairs in the network before any reduction may set in.
Using
  $cell2 : Cell(this != $cell1)
reduces this by n, so we're still quadratic. Something like
 $cell1 : Cell( $id1 : id )
 $cell2 : Cell( id  $id1 )
reduces it to n*(n-1)/2 which is less than 50% of the original, but
still quadratic.

-W

2010/4/26 Swindells, Thomas tswinde...@nds.com:
 You should probably restrict it so that

 $cell2 : Cell(this != $cell1)



 Thomas



 From: rules-users-boun...@lists.jboss.org
 [mailto:rules-users-boun...@lists.jboss.org] On Behalf Of Ryan Fitzgerald
 Sent: 26 April 2010 15:34
 To: rules-users@lists.jboss.org
 Subject: [rules-users] How to make this rule more memory efficient?



 Hi,



 Can anyone advise me on how to make a drools rule more memory efficient?
 Here is the problem:



 I have a Cell and a ProxyCell object classes.



 The ProxyCell represents the Cell when their internal ID's match.



 Each Cell and ProxyCell however has a unique name (not same as ID).



 A Cell can reference (by name) a ProxyCell (as long as the ProxyCell does
 not represent that actual Cell - which would effectively be a self-reference
 and is not allowed).



 What I want to do is find out where I have a reference from any instance of
 Cell - cell1 - to any instance of ProxyCell - proxycell2 - but am missing a
 reference from cell2 to proxycell1 where proxycell2 is a representation of
 cell2 and proxycell1 is a representation of cell1.



 Here is the rule I have written for it:



 rule Check consistent references

 when

     $cell1 : Cell()

     $cell2 : Cell()

     $proxycell1 : ProxyCell ( id = $cell1.id, $cell2.references contains
 this.name )

     $proxycell2 : ProxyCell ( id = $cell2.id, $cell1.references not
 contains this.name )

 then

     //report an error.

 end





 I have 10,000 instances of Cell and 10,000 instances of ProxyCell in working
 memory. For each instance of Cell, it can have references to 60 different
 ProxyCell instances. Loading the Cell and ProxyCell instances into working
 memory is not a problem. However, when I try to run this rule above, the
 memory quickly goes above 1GB and I eventually get an out of memory error.



 I was wondering if there is a better way to structure or write this rule so
 that it doesn't use so much memory.



 Thanks,

 Ryan.



 
 **
 This message is confidential and intended only for the addressee. If you
 have received this message in error, please immediately notify the
 postmas...@nds.com and delete it from your system as well as any copies. The
 content of e-mails as well as traffic data may be monitored by NDS for
 employment and security purposes. To protect the environment please do not
 print this e-mail unless necessary.

 NDS Limited. Registered Office: One London Road, Staines, Middlesex, TW18
 4EX, United Kingdom. A company registered in England and Wales. Registered
 no. 3080780. VAT no. GB 603 8808 40-00
 **

 
 This message is confidential and intended only for the addressee. If you
 have received this message in error, please immediately notify the
 postmas...@nds.com and delete it from your system as well as any copies. The
 content of e-mails as well as traffic data may be monitored by NDS for
 employment and security purposes.
 To protect the environment please do not print this e-mail unless necessary.

 An NDS Group Limited company. www.nds.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] How to make this rule more memory efficient?

2010-04-26 Thread Swindells, Thomas
You should probably restrict it so that
$cell2 : Cell(this != $cell1)

Thomas

From: rules-users-boun...@lists.jboss.org 
[mailto:rules-users-boun...@lists.jboss.org] On Behalf Of Ryan Fitzgerald
Sent: 26 April 2010 15:34
To: rules-users@lists.jboss.org
Subject: [rules-users] How to make this rule more memory efficient?

Hi,

Can anyone advise me on how to make a drools rule more memory efficient? Here 
is the problem:

I have a Cell and a ProxyCell object classes.

The ProxyCell represents the Cell when their internal ID's match.

Each Cell and ProxyCell however has a unique name (not same as ID).

A Cell can reference (by name) a ProxyCell (as long as the ProxyCell does not 
represent that actual Cell - which would effectively be a self-reference and is 
not allowed).

What I want to do is find out where I have a reference from any instance of 
Cell - cell1 - to any instance of ProxyCell - proxycell2 - but am missing a 
reference from cell2 to proxycell1 where proxycell2 is a representation of 
cell2 and proxycell1 is a representation of cell1.

Here is the rule I have written for it:

rule Check consistent references
when
$cell1 : Cell()
$cell2 : Cell()
$proxycell1 : ProxyCell ( id = $cell1.id, $cell2.references contains 
this.name )
$proxycell2 : ProxyCell ( id = $cell2.id, $cell1.references not 
contains this.name )
then
//report an error.
end


I have 10,000 instances of Cell and 10,000 instances of ProxyCell in working 
memory. For each instance of Cell, it can have references to 60 different 
ProxyCell instances. Loading the Cell and ProxyCell instances into working 
memory is not a problem. However, when I try to run this rule above, the memory 
quickly goes above 1GB and I eventually get an out of memory error.

I was wondering if there is a better way to structure or write this rule so 
that it doesn't use so much memory.

Thanks,
Ryan.




**
This message is confidential and intended only for the addressee. If you have 
received this message in error, please immediately notify the 
postmas...@nds.com and delete it from your system as well as any copies. The 
content of e-mails as well as traffic data may be monitored by NDS for 
employment and security purposes. To protect the environment please do not 
print this e-mail unless necessary.

NDS Limited. Registered Office: One London Road, Staines, Middlesex, TW18 4EX, 
United Kingdom. A company registered in England and Wales. Registered no. 
3080780. VAT no. GB 603 8808 40-00
**


This message is confidential and intended only for the addressee. If you have 
received this message in error, please immediately notify the 
postmas...@nds.com and delete it from your system as well as any copies. The 
content of e-mails as well as traffic data may be monitored by NDS for 
employment and security purposes.
To protect the environment please do not print this e-mail unless necessary.

An NDS Group Limited company. www.nds.com
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] How to make this rule more memory efficient?

2010-04-26 Thread Wolfgang Laun
The general idea of the inverted approach shown below is to keep the
fan-out in the Rete network as small as possible. Note the id 
$proxy1.id, which reduces the ProxyCells that are considered. Also,
the lookup of the the name if $proxy2 in the references of $cell1
should keep things bounded.  - I hope I got alle the 1s and 2s right,
but you should get the general idea ;-)

rule Check consistent references
when
$proxy1 : ProxyCell()
$cell1  : Cell( id == $proxy1.id )
$proxy2 : ProxyCell( id  $proxy1.id,
 eval( $cell1.references contains this.name ) )
$cell2  : Cell( id == $proxy2.id,
eval( this.references not contains $proxy1.name ) )
then
//report an error.
end

-W

2010/4/26 Ryan Fitzgerald ryan.fitzger...@ericsson.com:
 Hi,

 Can anyone advise me on how to make a drools rule more memory efficient?
 Here is the problem:

 I have a Cell and a ProxyCell object classes.

 The ProxyCell represents the Cell when their internal ID's match.

 Each Cell and ProxyCell however has a unique name (not same as ID).

 A Cell can reference (by name) a ProxyCell (as long as the ProxyCell does
 not represent that actual Cell - which would effectively be a self-reference
 and is not allowed).

 What I want to do is find out where I have a reference from any instance of
 Cell - cell1 - to any instance of ProxyCell - proxycell2 - but am missing a
 reference from cell2 to proxycell1 where proxycell2 is a representation of
 cell2 and proxycell1 is a representation of cell1.

 Here is the rule I have written for it:

 rule Check consistent references
 when
     $cell1 : Cell()
     $cell2 : Cell()
     $proxycell1 : ProxyCell ( id = $cell1.id, $cell2.references contains
 this.name )
     $proxycell2 : ProxyCell ( id = $cell2.id, $cell1.references not
 contains this.name )
 then
     //report an error.
 end


 I have 10,000 instances of Cell and 10,000 instances of ProxyCell in working
 memory. For each instance of Cell, it can have references to 60 different
 ProxyCell instances. Loading the Cell and ProxyCell instances into working
 memory is not a problem. However, when I try to run this rule above, the
 memory quickly goes above 1GB and I eventually get an out of memory error.

 I was wondering if there is a better way to structure or write this rule so
 that it doesn't use so much memory.

 Thanks,
 Ryan.

 ___
 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