Welcome, Guest. Please Login
Tinderbox
  News:
IMPORTANT MESSAGE! This forum has now been replaced by a new forum at http://forum.eastgate.com and no further posting or member registration is allowed. The forum is still accessible via read-only access for reference purposes. If you wish to discuss content here, please use the new forum. N.B. - posting in the new forum requires a fresh registration in the new forum (sorry - member data can't be ported).
  HomeHelpSearchLogin  
 
Pages: 1
Send Topic Print
Action preventing update of subsequent agents (Read 5094 times)
Loryn
Full Member
*
Offline



Posts: 97

Action preventing update of subsequent agents
Jun 17th, 2008, 6:44pm
 
OK. So here's a puzzle.

My mental model of Tinderbox is that an Agent performs a query, returns results, and then executes the Agent Action against the results.

As mentioned elsewhere, I initially had code of the form:

Code:
Field1(agent) = count(collect_if(child,$TextFrom="Number1",$Name));
Field2(agent) = count(collect_if(child,$TextFrom="Number2",$Name));
Field3(agent) = count(collect_if(child,$TextFrom="Number3",$Name));
TermScore(agent) = ($Field1*2) + ($Field2*1) + ($Field3*0.5) 



I then added a guard capability to limit execution of the code.

Code:
if( !(ComputedCount(agent)=$ChildCount(agent) | ComputedTotal(TermScoreTotaller)=$ComputedTotal(agent)) )
{
Field1(agent) = count(collect_if(child,$TextFrom="Number1",$Name));
Field2(agent) = count(collect_if(child,$TextFrom="Number2",$Name));
Field3(agent) = count(collect_if(child,$TextFrom="Number3",$Name));
TermScore(agent) = ($Field1*2) + ($Field2*1) + ($Field3*0.5);

ComputedCount(agent)=$ChildCount(agent); ComputedTotal(agent)=$ComputedTotal(TermScoreTotaller);
} 



At first, I was elated at the speedup. Alas, I found that the use of this code made all but the first agent fail to query.

I think I could figure out what was going wrong if all but the first agent action failed to execute. But I can't understand how what I've written in this agent action could possibly prevent subsequent agents from querying.

:'(

Back to top
 
 
  IP Logged
Mark Bernstein
YaBB Administrator
*
Offline

designer of
Tinderbox

Posts: 2871
Eastgate Systems, Inc.
Re: Action preventing update of subsequent agents
Reply #1 - Jun 18th, 2008, 10:19am
 
If an agent's action or query can't be parsed, Tinderbox may "give up" and stop evaluating agents, on the assumption that subsequent agents might be working with the wrong answers from the flawed agent.
Back to top
 
 
WWW   IP Logged
Loryn
Full Member
*
Offline



Posts: 97

Re: Action preventing update of subsequent agents
Reply #2 - Jun 18th, 2008, 6:13pm
 
Thank you, Mark!

Seems that I had to add a $ sign to the variables in the if test. Corrected and working code is:

Code:
if( !($ComputedCount(agent)=$ChildCount(agent) | $ComputedTotal(TermScoreTotaller)=$ComputedTotal(agent)) )
{
Field1(agent) = count(collect_if(child,$TextFrom="Number1",$Name));
Field2(agent) = count(collect_if(child,$TextFrom="Number2",$Name));
Field3(agent) = count(collect_if(child,$TextFrom="Number3",$Name));
TermScore(agent) = ($Field1*2) + ($Field2*1) + ($Field3*0.5);

ComputedCount(agent)=$ChildCount(agent); ComputedTotal(agent)=$ComputedTotal(TermScoreTotaller);
}  



The now-working guard function improved performance from the original 23.0 secs to 4.2 seconds, according to Agent Update Time.
Back to top
 
 
  IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: Action preventing update of subsequent agents
Reply #3 - Jun 18th, 2008, 6:44pm
 
Ah, that makes sense.  Inside the 'if' comparison - the bit in () - the equals sign is an equality check (such as to give a Boolean true/false result) as using in TB agent queries;  i.e. the test is one that in some scripting languages would be written as '==' instead of '='.

Elsewhere in your example, the the '=' is setting the value of the left side of the '=' to the value of the right side as in an Action or Rule. In Actions & rules, it is not necessary to use a $ sign as it's taken as implied  - though there's nothing to stop you using a $ prefix if you prefer to.

Bottom line, '=' means different things in different contexts.  In a query statement '=' denotes equality, whereas in an action is denotes assignment.

[It was difficult to guess at before as, taken out of context of a TBX, the code sample wasn't obvious as to what it was doing]
Back to top
 
 

--
Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
Pages: 1
Send Topic Print