Puzzling simple arithmetic problem


(Rob Forsyth) #1

I’d appreciate inspiration as to what I’m doing wrong here as I’m flummoxed! I have agents based on a shared prototype with four user-defined attributes, all numeric. Three are the results of prior calculations and their values, as revealed by setting them as Key Attributes, are as expected. However the fourth, which is defined in the prototype’s $Rule as

$ConsultantWeekDayPriorityScore = $WhatsFair - $DidLastNight - $DidNightBeforeThat;

(i.e. simply attribute 4 = attribute 1 - attribute 2 - attribute 3) isn’t working. It’s evaluating as just attribute 1 ($WhatsFair). These are “unremarkable” numbers: $WhatsFair is typically between 0.5 and 2 and comes from a simple ratio calculation; $DidLastNight takes values of 0.9 or 0 only and is set by an if/else rule; similarly $DidNightBeforeThat takes 0.5 or 0 only set by an if/else

Any thoughts as to what may be amiss please? (This is TBX 7.0.1)


(eastgate) #2

Likely problems

• One or more attribute names are mistyped. Remember that attribute names are case-sensitive.

• One or more of the attributes in question are not actually numeric attributes.

• Some other agent is also setting $ConsultantWeekDayPriorityScore.

But it’s hard to be sure without the document.


(Mark Anderson) #3

In a case like this I’d make a simulation test using fixed values of $WhatsFair, $DidLastNight and $DidNightBeforeThat. This strikes out any contribution of calculated values. I’d also try attribute 4 = (attribute 1 - attribute 2) - attribute 3, to see if there’s an evaluation issue; in the last attribute 3 is explicitly subtracted from the resolved value of attribute 1-attribute 2. As MB says without seeing more detail (as in the code in the source doc or a text doc that shows the problem) it is hard to diagnose further.


(Rob Forsyth) #4

Thanks as ever both of you. I’m happy to debug methodically: just good to know that something along these lines should work (e.g. there’s no limitation of the code parser in handling sequential subtractions)


(eastgate) #5

To satisfy yourself that sequential subtraction behaves as you expect, make a new document and a new note. Make $MyNumber a key attribute of that note.

Add the following rule to that note:

$MyNumber = 7 -4 -1

Deselect and reselect your note; what now is the value of $MyNumber?


(Rob Forsyth) #6

Thanks Mark that works as expected ($MyNumber = 2)


(eastgate) #7

Now plug in one of your attributes. Work as expected?

Next, plug in the second.


(Rob Forsyth) #8

Sorted, thanks. At some point I’d mistakenly defined $WhatsFair as a set and not a numeric


(Mark Anderson) #9

Thanks for reporting back. Glad it’s sorted out now.