# [fpc-pascal] best method: multiple three state options in a decision tree

Lukasz Sokol el.es.cr at gmail.com
Wed Jan 22 09:52:00 CET 2014

```On 21/01/14 18:42, waldo kitty wrote:
> On 1/21/2014 10:21 AM, Mattias Gaertner wrote:
>> On Tue, 21 Jan 2014 09:51:38 -0500
>> waldo kitty <wkitty42 at windstream.net> wrote:
>>
>>> On 1/18/2014 7:40 PM, waldo kitty wrote:
>>>>
>>>> what is the best method of coding a decision tree with options that have three
>>>> states and all options are additive?
>>>>
>>>> clarification: i have a situation with 5 (at this time) options and all 5 are
>>>> three state... each option can be paired with all other options' states but may
>>>> NOT be paired with its own other states...
>>> [...]
>>>
>>> no one has any ideas or thoughts on this?
>>
>> Maybe I don't understand the question.
>
> that's quite possible... it took me a while to write it the way i did
> after starting over numerous times... i may have also used the wrong
> terms for what i was trying to describe as well as not giving enough
> examples but the example list was getting too large at that point
> anyway ;)>
>> The 5 options with each 3 states sounds like an array[1..5] of TRedGreenBlue.

^This
>
> a lot of stuff i googled up related to 3states came up with
> similar... to me that reads as to be used for graphics and this is a
> console app with no graphics involved... i'm only using the bits to
> denote the combinations available... they select which IF statement
> is used in the actual filter code described below...>
> originally i had thought of using an array but i didn't know the size
> of it and each grouping varies with the number of options...>
>> What do you mean with "additive"
>
> logical AND with some combinations being invalid...
>
> eg:
> optionA:min/max {solitary}
> optionB:max only AND optionE:min only {two ANDed together}
> optionA:min only AND optionB:min/max AND optionC:max only {three ANDed together}
>
> optionA:min/max AND optionA:min only {invalid}
> optionA:min/max AND optionA:max only {invalid}
> optionA:min only AND optionA:max only {invalid}
>
and ^this
[...]
> the current idea is to use a bit for each "state" and then use a case
> statement for the "decision tree" (as shown above) so as to simply
> walk thru the integers that the bit patterns make for the valid
> combinations...>

^and this...
looks like a (good?) use for a dynamic array of TMinMaxState = [mmNone, mmMin, mmMinMax, mmMax];
(then var Options = array[static or dynamic] of TMinMaxState;)

This assumes options have a fixed position in the array however... but the bitwise code was
assuming this anyway.

And yes, 4 states - one of them being mmNone - for the case when you don't want to use certain option.

If there is a lot of options, but not always consecutive - so there would be a lot more of mmNone's
than significant states (IOW the data is sparse) - maybe do

TOption = record
Index : [whatever type would suffice here];
State : TMinMaxState; // [which could then be 3 state not 4]
end;

and use a dynamic array to hold the TOption(s).

Excuse my lameness please :) as I am not a programmer by trade.

-L.

```