'C++ decision tree storage

I have a decision tree. I feed this decision tree some input values. The decision tree then returns a value.

The input values could be "number of children", "age in years", etc. The decision tree could then return (for example) a certain value that would indiciate how many cars the family possesses or something like that.

This decision tree (if converted to an if-then statement) would look like this:

int i=0;

if (ownedHouses==0)
{
    if (numberOfChildren==4)
    {
        if (ageFather==39)
        {
            if (incomeFamily==40000)
            {
                if (carsAlreadyCrashed==1)
                {
                    i=3;
                }
                else
                {
                    if (carsAlreadyCrashed==2)
                    {
                        if (insurancePaysForCrashes==1)
                        {
                            i=5;
                        }
                      }
                      else
                      {
                            i=4;
                        }
                    }
                    else
                    {
                        i=11;
                    }
                }
            }
            else
            {
                i=2;
            }
        }
        else
        {
            i=9;
        }
    }
    else
    {
        i=22;
    }
else
{
    i=8;
}

This is is just an example. In reality, the resulting if-then statement would be absolutely huge. Although I can parse the data and create such an if-then from it, I could not use such a big if-then-loop in my software.

I am therefore searching for a different way to integrate the decision tree into my software.

I have seen approaches where the decision tree data (in whatever form it is provided...) is parsed at runtime, and then classes with root, nodes and leaves are created from it.

For my purposes this is not fast enough.

Does anybody have any other idea?

Thank you for the help.

Edit: I have changed some of the values to real-life values to make the meaning more clear.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source