Example #1
0
        private CptKey EvidenceToKey(Proposition[] evidence)
        {
            CptKey searchKey = new CptKey(GetKeySize(), true);

            foreach (Proposition e in evidence)
            {
                RandomVariable var = this.vars.Single(d => d.name.Equals(e.name));
                searchKey.Set(keyPosMap[var], (char)e.valueIndex);
            }

            return(searchKey);
        }
Example #2
0
        private void SetKeys(ArraySegment <CptKey> keys, ArraySegment <RandomVariable> remainingVars)
        {
            if (remainingVars.Count == 0)
            {
                return;
            }

            RandomVariable var = remainingVars.Array[remainingVars.Offset];

            remainingVars = new ArraySegment <RandomVariable>(remainingVars.Array, remainingVars.Offset + 1, remainingVars.Count - 1);

            ArraySegment <CptKey>[] tokenSegments = DivideIntoNSegments(keys, var.tokens.Length);
            for (int i = 0; i < tokenSegments.Length; i++)
            {
                ArraySegment <CptKey> segment = tokenSegments[i];
                for (int index = segment.Offset; index < segment.Offset + segment.Count; index++)
                {
                    CptKey key = segment.Array[index];
                    key.Set(keyPosMap[var], (char)i);
                }
                SetKeys(tokenSegments[i], remainingVars);
            }
        }