示例#1
0
        /// <summary>
        /// Retrieve the Id associated with a list index of a specific data type.
        /// </summary>
        /// <param name="listIndex">The list index to retrieve.</param>
        /// <param name="dataType">The data type to search up.</param>
        /// <returns>Returns the Id of the provided index.</returns>
        public static Guid IdFromList(int listIndex, VariableDataTypes dataType)
        {
            if (listIndex < 0 || listIndex > GetNamesByType(dataType).Length)
            {
                return(Guid.Empty);
            }

            return(Lookup.KeyList.OrderBy(pairs => Lookup[pairs]?.TimeCreated).Where(pairs => ((PlayerVariableBase)Lookup[pairs]).Type == dataType).Select(pairs => ((PlayerVariableBase)Lookup[pairs]).Id).ToArray()[listIndex]);
        }
示例#2
0
 //Constructor
 public Z3Variable(string identifier, VariableDataTypes dataType, Term term)
 {
     _identifier = identifier;
     _dataType = dataType;
     _term = term;
 }
示例#3
0
        private Term CreateValueTerm(VariableDataTypes dataType, object value)
        {
            //Create a term for the new value in Z3
            Term newValue = null;
            switch (dataType)
            {
                //Bool
                case VariableDataTypes.Boolean:
                    bool boolValue = (bool)value;
                    switch (boolValue)
                    {
                        case true:
                            newValue = _context.MkTrue();
                            break;
                        case false:
                            newValue = _context.MkFalse();
                            break;
                    }
                    break;

                //Int
                case VariableDataTypes.Integer:
                    int intValue = (int)value;
                    newValue = _context.MkIntNumeral(intValue);
                    break;
            }

            return newValue;
        }
示例#4
0
        private Z3ValueAssumption CreateValueAssumption(Term variableTerm, VariableDataTypes dataType, object value)
        {
            //Terms
            Term newValue = CreateValueTerm(dataType, value);
            Term equals = _context.MkEq(variableTerm, newValue);

            //Assert and create reference object
            Z3ValueAssumption assumption = new Z3ValueAssumption(variableTerm, newValue);
            return assumption;
        }
示例#5
0
        public void AddVariable(string variableID, VariableDataTypes dataType)
        {
            //Exception handling
            if (_variables.ContainsKey(variableID))
                throw new Exception("A variable already exists with the given id!");

            //Create the variable in the Z3 context
            Sort termType = null;
            switch (dataType)
            {
                case VariableDataTypes.Boolean:
                    termType = _context.MkBoolSort();
                    break;
                case VariableDataTypes.Integer:
                    termType = _context.MkIntSort();
                    break;
            }
            Term term = _context.MkConst(variableID, termType);

            //Keep track of the variable added
            Z3Variable variable = new Z3Variable(variableID, dataType, term);
            _variables.Add(variableID, variable);
        }
示例#6
0
        public void AddValueAssumption(string variableID, VariableDataTypes dataType, object value)
        {
            //Variables
            Z3Variable variable = _variables[variableID];
            Term variableTerm = variable.Term;

            //Exception handling
            if (_valueAssumptions.ContainsKey(variableID))
                throw new Exception("An assumption already exists for the given variable!");
            if (variable.DataType != dataType)
                throw new Exception("Variable is of a different data type than " + dataType.ToString() + "!");

            //Create, register and assert the assumption
            Z3ValueAssumption assumption = CreateValueAssumption(variableTerm, dataType, value);
            AssertValueAssumption(assumption);
            _valueAssumptions.Add(variableID, assumption);
        }
示例#7
0
        public void AddOrModifyValueAssumption(string variableID, VariableDataTypes dataType, object value)
        {
            //Variables
            Z3Variable variable = _variables[variableID];
            Term variableTerm = variable.Term;

            //Exceptions
            if (variable.DataType != dataType)
                throw new Exception("Variable is of a different data type than " + dataType.ToString() + "!");

            //Remove assumption, if it already exists
            if (_valueAssumptions.ContainsKey(variableID))
            {
                RemoveValueAssumption(variableID);
            }

            //Add the new assumption
            AddValueAssumption(variableID, dataType, value);
        }
示例#8
0
 /// <summary>
 /// Retrieve the list index of an Id within a specific data type list.
 /// </summary>
 /// <param name="id">The Id to look up.</param>
 /// <param name="dataType">The data type to search up.</param>
 /// <returns>Returns the list Index of the provided Id.</returns>
 public static int ListIndex(Guid id, VariableDataTypes dataType)
 {
     return(Lookup.KeyList.OrderBy(pairs => Lookup[pairs]?.TimeCreated).Where(pairs => ((PlayerVariableBase)Lookup[pairs]).Type == dataType).Select(pairs => ((PlayerVariableBase)Lookup[pairs]).Id).ToList().IndexOf(id));
 }
示例#9
0
 /// <summary>
 /// Retrieve an array of variable names of the supplied data type.
 /// </summary>
 /// <param name="dataType">The data type to retrieve names of.</param>
 /// <returns>Returns an array of names.</returns>
 public static string[] GetNamesByType(VariableDataTypes dataType)
 {
     return(Lookup.KeyList.OrderBy(pairs => Lookup[pairs]?.TimeCreated).Where(pairs => ((PlayerVariableBase)Lookup[pairs]).Type == dataType).Select(pairs => ((PlayerVariableBase)Lookup[pairs]).Name).ToArray());
 }