Пример #1
0
    /**
     * Returns an OPlus equivalent to the quantifier.
     * For example, the quantifier &exist;<sub>a/b</sub>&nbsp;<i>x</i>&nbsp;:&nbsp;<i>x</i>=<i>k</i>
     * will return the OPlus: &oplus;<sub>a/b</sub>&nbsp;<i>k</i>.
     * @return The OPlus equivalent to the quantifier, null if
     * the quantifier is not equivalent to an OPlus.
     */
    public OPlus toOPlus()
    {
        if (m_operand.GetType() != typeof(OperatorEquals))
        {
            return null;
        }

        OperatorEquals oe = (OperatorEquals)m_operand;
        Operator o = oe.getLeftOperand();
        OPlus op = new OPlus();

        op.m_qualifier = m_qualifier;

        if (o.GetType() == typeof(Constant))
        {
            op.m_operand = o;
        }

        else
        {
            op.m_operand = oe.getRightOperand();
        }

        return op;
    }
Пример #2
0
    public HashSet<GeneratorNode> spawn(FOForAll op)
    {
        HashSet<GeneratorNode> spawnedSet, outSet = new HashSet<GeneratorNode>();
        Atom x = op.getQuantifiedVariable();
        string qualifier = op.getQualifier();

        // Iterate over domain
        HashSet<Constant> oplus_domain = getOPlusDomain(qualifier);
        HashSet<Constant> domain = op.getDomain();
        SubsetIterator<Constant> it;

        if (!m_encounteredQualifiers.Contains(qualifier))
        {
            // We haven't decomposed a For All in the past, so we can
          		// add elements to the message
            it = new SubsetIterator<Constant>(domain, oplus_domain);
        }

        else
        {
            // Otherwise, we stick to the elements we already have to
          		// evaluate this quantifier
            it = new SubsetIterator<Constant>(oplus_domain);
        }

        m_encounteredQualifiers.Add(op.getQualifier());
        m_decomposedAForAll = true;

        if (op.isPathNegation())
        {
            // The quantifier asserts the absence of a path
            GeneratorNode wn = new GeneratorNode(this);
            OPlus opl = new OPlus();

            opl.setQualifier(op.getQualifier());
            opl.setOperand(Operator.m_falseAtom);

            if (!wn.addToOPluses(opl))
            {
                // We can't add this OPlus to the current set. Contradiction! Return the empty set
                return new HashSet<GeneratorNode>();
            }

            return wn.spawn();
        }

        if (op.isPathAssertion())
        {
            // In negated form, the quantifier may assert the existence of a path
            GeneratorNode wn = new GeneratorNode(this);
            OPlus opl = new OPlus();

            opl.setQualifier(op.getQualifier());
            opl.setOperand(Operator.m_trueAtom);

            if (!wn.addToOPluses(opl))
            {
                // We can't add this OPlus to the current set. Contradiction! Return the empty set
                return new HashSet<GeneratorNode>();
            }

            return wn.spawn();
        }

        while (it.hasNext())
        {
            GeneratorNode wn = new GeneratorNode(this);
            HashSet<Constant> subset = it.next();

            foreach (Atom v in subset)
            {
                Operator o2 = op.getOperand();
                Operator o3 = o2.evaluate(x, v);
                OPlus opl = new OPlus(qualifier, v);

                wn.addToGamma(o3);

                if (!wn.addToOPluses(opl))
                {
                    // Contradiction! Skip that branch
                    continue;
                }
            }

            spawnedSet = wn.spawn();

            if (spawnedSet != null)
            {
                foreach (GeneratorNode gn in spawnedSet)
                {
                    outSet.Add(gn);
                }
            }
        }

        return outSet;
    }
Пример #3
0
    protected bool addToOPluses(OPlus o)
    {
        if (o == null)
        {
            return false;
        }

        if (m_opluses.Count == 0)
        {
            m_opluses.Add(o);

            return true;
        }

        // We prevent the OPlus to be added if it does not have the same root
        // as the other OPluses
        string qualifier = o.getQualifier();
        string[] pathParts = qualifier.Split('/');
        string prefix = "/" + pathParts[1];

        foreach (OPlus op in m_opluses)
        {
            if (!op.getQualifier().StartsWith(prefix))
            {
                if (!op.getOperand().Equals(Operator.m_falseAtom) &&
                    !o.getOperand().Equals(Operator.m_falseAtom))
                {
                    // We try to add elements that belong to different
          			// message schemas! Stop there.
                    return false;
                }
            }

            if (o.getQualifier().StartsWith(op.getQualifier()))
            {
                if (op.getOperand().Equals(Operator.m_falseAtom))
                {
                    // We try to add an element while a condition tells us we shouldn't
                    return false;
                }
            }

            if (o.getQualifier().StartsWith(op.getQualifier()))
            {
                if (o.getOperand().Equals(Operator.m_falseAtom))
                {
                    return false;
                }
            }

            m_opluses.Add(o);

            return true;
        }

        return true;
    }
Пример #4
0
    public HashSet<GeneratorNode> spawn(FOExists op)
    {
        HashSet<GeneratorNode> outSet = new HashSet<GeneratorNode>();
        Atom x = op.getQuantifiedVariable();
        string qualifier = op.getQualifier();

        if (m_encounteredQualifiers.Contains(qualifier))
        {
            // We add something along a path where a ForAll has already
          		// been evaluated: soundness is no longer guaranteed for this node
            m_sound = false;
        }

        if (op.isAnOPlus())
        {
            // This is an OPlus; return a node with op transferred to the OPlus set
            GeneratorNode wn = new GeneratorNode(this);

            if (!wn.addToOPluses(op.toOPlus()))
            {
                // We can't add this OPlus to the current set. Contradiction! Return the empty set
                return new HashSet<GeneratorNode>();
            }

            return wn.spawn();
        }

        if (op.isPathAssertion())
        {
            GeneratorNode wn = new GeneratorNode();
            OPlus opl = new OPlus();

            opl.setQualifier(op.getQualifier());
            opl.setOperand(Operator.m_trueAtom);

            if (!wn.addToOPluses(opl))
            {
                // We can't add this OPlus to the current set. Contradiction! Return the empty set
                return new HashSet<GeneratorNode>();
            }

            return wn.spawn();
        }

        // Iterate over domain
        //HashSet<Constant> oplus_domain = getOPlusDomain(qualifier);
        HashSet<Constant> domain = op.getDomain();
        SubsetIterator<Constant> it = new SubsetIterator<Constant>(domain); //,oplus_domain

        while (it.hasNext())
        {
            GeneratorNode wn = new GeneratorNode(this);
            HashSet<Constant> subset = it.next();

            foreach (Atom v in subset)
            {
                Operator o2 = op .getOperand();
                Operator o3 = o2.evaluate(x, v);

                if (!op.isPathAssertion())
                {
                    wn.addToGamma(o3);
                }

                OPlus opl = new OPlus(qualifier, v);

                if (!wn.addToOPluses(opl))
                {
                    // We can't add this OPlus to the current set. Contradiction! Skip that branch
                    continue;
                }
            }

            HashSet<GeneratorNode> spawnedSet = wn.spawn();

            if (spawnedSet != null)
            {
                foreach (GeneratorNode gn in spawnedSet)
                {
                    outSet.Add(gn);
                }
            }
        }

        return outSet;
    }