Exemplo n.º 1
0
        //detection
        public static DetectedAttributeValue Detection(LocationValue sensingLocation,
                                                        LocationValue emittingLocation,
                                                        DataValue emittingObjectAttribute,
                                                        List<ConeValue> sensingCones,
                                                        Dictionary<string, double> emitters,
                                                        List<SimulationObjectProxy> obstructions,
                                                        ref Random random)
        {
            DetectedAttributeValue returnDAV = new DetectedAttributeValue();
            Vec3D sensingPoint = new Vec3D(sensingLocation);
            Vec3D emittingPoint = new Vec3D(emittingLocation);
            Vec3D sensingDirection = new Vec3D(sensingPoint); //can't set to blank, just ignore.
            double coneAngle = 0.0;
            double angleBetweenSensorAndEmitter = 0.0;

            foreach(ConeValue cone in sensingCones)
            {
                sensingDirection.Set(cone.direction);
                Vec3D closestPoint = FindClosestPoint(sensingPoint, sensingDirection, emittingPoint);
                if (cone.extent > sensingPoint.ScalerDistanceTo(closestPoint))
                {//p* is within the cone's extent. 
                    
                    //determine if emitting point is within the spread of the cone.
                    coneAngle = cone.spread * Math.PI / 180;// System.Math.Atan(emittingPoint.ScalerDistanceTo(closestPoint) / sensingPoint.ScalerDistanceTo(closestPoint));//should be cone.spread
                    angleBetweenSensorAndEmitter = System.Math.Atan(emittingPoint.ScalerDistanceTo(closestPoint) / sensingPoint.ScalerDistanceTo(closestPoint));

                    if (coneAngle < angleBetweenSensorAndEmitter)
                    {
                        continue; //should go to next cone.
                    }
                    if (emitters.ContainsKey(cone.level))
                    {//emitter has an emission at the same level as the cone.
                        //returnDAV = (DetectedAttributeValue)ObfuscateAttributeValue(emittingObjectAttribute, emitters[cone.level], ref random);
                        returnDAV = (DetectedAttributeValue)FuzzAttributeValue(emittingObjectAttribute, emitters[cone.level], ref random);
    
                        return returnDAV;
                    }
                    else
                    { //emitter does not emit the same level as the cone.
                        //should this find next best, or just move on?
                    }
                }
            }

            return null;
        }
Exemplo n.º 2
0
 public void SetDataValue(DataValue dv)
 {
     lock (blackboard.blackboardLock)
     {
         if (publish)
         {
             blackboard[objectID][attributeName] = dv;
             ObjectLog.Write(blackboard.simTime, objectID, attributeName, DataValueFactory.XMLSerialize(dv));
         }
         else
         {
             throw new Exception("Error: Simulator tried to modify attribute it doesn't own.");
         }
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Sends a ForceUpdateObjectAttribute event to the Simulation.  These events update a specific object's attribute. 
        /// This event contains an object ID, an attribute name, and an attribute value.  The attribute value can be any
        /// data type in the system
        /// </summary>
        /// <param name="objectID">The object's ID</param>
        /// <param name="updatedAttributeName">An object's Attribute name</param>
        /// <param name="updatedAttributeValue">An object's updated Attribute value</param>
        public void SendObjectAttributeUpdateEvent(String objectID, String updatedAttributeName, DataValue updatedAttributeValue)
        {
            SimulationEvent e = SimulationEventFactory.BuildEvent(ref m_simModel, "ForceUpdateObjectAttribute");
            ((StringValue)e["ObjectID"]).value = objectID;
            ((StringValue)e["AttributeName"]).value = updatedAttributeName;
            ((WrapperValue)e["AttributeValue"]).value = updatedAttributeValue; //the WrapperValue contains any single DataValue class
            ((StringValue)e["UpdateType"]).value = "AGENT";

            SendSimEvent(e);
        }
Exemplo n.º 4
0
/* *************************************************************** */
        private static DataValue FuzzAttributeValue(DataValue dv, double confidence, ref Random random)
        { //maybe pass level as well, have a sim model def of how each model affects clarity?

            DetectedAttributeValue returnValue = new DetectedAttributeValue();
            ((DetectedAttributeValue)returnValue).value = dv;
            ((DetectedAttributeValue)returnValue).stdDev = confidence;
            //check data type
            string attributeType = dv.dataType;

            //switch statement
            switch (attributeType)
            {
                case "LocationType":
                    FuzzLocationValue(ref returnValue, ref random);
                    break;
                case "VelocityType":
                    FuzzVelocityValue(ref returnValue, ref random);
                    break;
                case "IntegerType":
                    FuzzIntegerValue(ref returnValue, ref random);
                    break;
                case "DoubleType":
                    FuzzDoubleValue(ref returnValue, ref random);
                    break;
                case "StringType":
                    FuzzStringValue(ref returnValue, ref random);
                    break;
                default:
                    break;
            }

            return returnValue as DataValue;
        }
Exemplo n.º 5
0
 /// <summary>
 /// Takes a DataValue, and returns a human-readable string representation.
 /// </summary>
 /// <param name="v"></param>
 /// <returns></returns>
 public static string ToString(DataValue v)
 {
     if (v == null)
     {
         return "";
     }
     switch (v.dataType)
     {
         case "StringType":
             return ((StringValue)v).ToString();
         case "DoubleType":
             return ((DoubleValue)v).ToString();
         case "IntegerType":
             return ((IntegerValue)v).ToString();
         case "BooleanType":
             return ((BooleanValue)v).ToString();
         case "LocationType":
             return ((LocationValue)v).ToString();
         case "VelocityType":
             return ((VelocityValue)v).ToString();
         case "AttributeCollectionType":
             return ((AttributeCollectionValue)v).ToString();
         case "CustomAttributesType":
             return ((CustomAttributesValue)v).ToString();
         case "StringListType":
             return ((StringListValue)v).ToString();
         case "PolygonType":
             return ((PolygonValue)v).ToString();
         case "StateTableType":
             return ((StateTableValue)v).ToString();
         case "CapabilityType":
             return ((CapabilityValue)v).ToString();
         case "VulnerabilityType":
             return ((VulnerabilityValue)v).ToString();
         case "ConeType":
             return ((ConeValue)v).ToString();
         case "SensorType":
             return ((SensorValue)v).ToString();
         case "SensorArrayType":
             return ((SensorArrayValue)v).ToString();
         case "EmitterType":
             return ((EmitterValue)v).ToString();
         case "RangeRingDisplayType":
             return ((RangeRingDisplayValue)v).ToString();
         case "AttackCollectionType":
             return ((AttackCollectionValue)v).ToString();
         case "WrapperType":
             return ((WrapperValue)v).ToString();
         case "ClassificationDisplayRulesType":
             return ((ClassificationDisplayRulesValue)v).ToString();
         default:
             return "";
     }
 }
Exemplo n.º 6
0
        /// <summary>
        /// This method takes in two data values, and returns true if their values are equal.
        /// </summary>
        /// <param name="firstDV"></param>
        /// <param name="secondDV"></param>
        /// <returns></returns>
        public static bool CompareDataValues(DataValue firstDV, DataValue secondDV)
        {
            if (firstDV.getType() != secondDV.getType())
            {
                return false;
            }

            switch (firstDV.getType())
            {
                case "StringType":
                    if (((StringValue)firstDV).value == ((StringValue)secondDV).value)
                    {
                        return true;
                    }
                    break;
                case "IntegerType":
                    if (((IntegerValue)firstDV).value == ((IntegerValue)secondDV).value)
                    {
                        return true;
                    }
                    break;
                case "DoubleType":
                    if (((DoubleValue)firstDV).value == ((DoubleValue)secondDV).value)
                    {
                        return true;
                    }
                    break;
                case "BooleanType":
                    if (((BooleanValue)firstDV).value == ((BooleanValue)secondDV).value)
                    {
                        return true;
                    }
                    break;
                case "LocationType":
                    if (Math.Abs(((LocationValue)firstDV).X - ((LocationValue)secondDV).X) < 0.000001 &&
                        Math.Abs(((LocationValue)firstDV).Y - ((LocationValue)secondDV).Y) < 0.000001 &&
                        Math.Abs(((LocationValue)firstDV).Z - ((LocationValue)secondDV).Z) < 0.000001)
                    //if (((LocationValue)firstDV).X == ((LocationValue)secondDV).X &&
                    //    ((LocationValue)firstDV).Y == ((LocationValue)secondDV).Y &&
                    //    ((LocationValue)firstDV).Z == ((LocationValue)secondDV).Z)
                    {
                        return true;
                    }
                    break;
                case "VelocityType":
                    if (Math.Abs(((VelocityValue)firstDV).VX - ((VelocityValue)secondDV).VX) < 0.000001 &&
                        Math.Abs(((VelocityValue)firstDV).VY - ((VelocityValue)secondDV).VY) < 0.000001 &&
                        Math.Abs(((VelocityValue)firstDV).VZ - ((VelocityValue)secondDV).VZ) < 0.000001)
                    //if (((VelocityValue)firstDV).VX == ((VelocityValue)secondDV).VX &&
                    //    ((VelocityValue)firstDV).VY == ((VelocityValue)secondDV).VY &&
                    //    ((VelocityValue)firstDV).VZ == ((VelocityValue)secondDV).VZ)
                    {
                        return true;
                    }
                    break;
                case "AttributeCollectionType":
                    if (((AttributeCollectionValue)firstDV).ToString() == ((AttributeCollectionValue)secondDV).ToString())
                    {
                        return true;
                    }
                    break;
                case "CustomAttributesType":
                    if (((CustomAttributesValue)firstDV).ToString() == ((CustomAttributesValue)secondDV).ToString())
                    {
                        return true;
                    }
                    break;
                case "CapabilityType":
                    if (((CapabilityValue)firstDV).ToString() == ((CapabilityValue)secondDV).ToString())
                    {
                        return true;
                    }
                    break;
                case "ConeType":
                    if (((ConeValue)firstDV).ToString() == ((ConeValue)secondDV).ToString())
                    {
                        return true;
                    }
                    break;
                case "DetectedAttributeType":
                    if (CompareDataValues(((DetectedAttributeValue)firstDV).value, ((DetectedAttributeValue)secondDV).value))
                    {
                        return true;
                    }
                    break;
                case "EmitterType":
                    if (((EmitterValue)firstDV).ToString() == ((EmitterValue)secondDV).ToString())
                    {
                        return true;
                    }
                    break;
                case "PolygonType":
                    if (((PolygonValue)firstDV).ToString() == ((PolygonValue)secondDV).ToString())
                    {
                        return true;
                    }
                    break;
                case "SensorArrayType":
                    if (((SensorArrayValue)firstDV).ToString() == ((SensorArrayValue)secondDV).ToString())
                    {
                        return true;
                    }
                    break;
                case "SensorType":
                    if (((SensorValue)firstDV).ToString() == ((SensorValue)secondDV).ToString())
                    {
                        return true;
                    }
                    break;
                case "StateTableType":
                    if (((StateTableValue)firstDV).ToString() == ((StateTableValue)secondDV).ToString())
                    {
                        return true;
                    }
                    break;
                case "StringListType":
                    if (((StringListValue)firstDV).ToString() == ((StringListValue)secondDV).ToString())
                    {
                        return true;
                    }
                    break;
                case "VulnerabilityType":
                    if (((VulnerabilityValue)firstDV).ToString() == ((VulnerabilityValue)secondDV).ToString())
                    {
                        return true;
                    }
                    break;
                case "RangeRingDisplayType":
                    if (((RangeRingDisplayValue)firstDV).ToString() == ((RangeRingDisplayValue)secondDV).ToString())
                    {
                        return true;
                    }
                    break;
                case "AttackCollectionType":
                    if (((AttackCollectionValue)firstDV).ToString() == ((AttackCollectionValue)secondDV).ToString())
                    {
                        return true;
                    }
                    break;
                case "WrapperType":
                    DataValue firstNestedDV = ((WrapperValue)firstDV).value;
                    DataValue secondNestedDV = ((WrapperValue)firstDV).value;
                    return CompareDataValues(firstNestedDV, secondNestedDV);
                    break;
                case "ClassificationDisplayRulesType":
                    if (((ClassificationDisplayRulesValue)firstDV).ToString() == ((ClassificationDisplayRulesValue)secondDV).ToString())
                    {
                        return true;
                    }
                    break;
                default:
                    throw new Exception("There is no definition for this data type");
                    break;
            }

            return false;

        }
Exemplo n.º 7
0
 /// <summary>
 /// A helper method for building and populating a WrapperValue object.
 /// </summary>
 /// <param name="value"></param>
 /// <returns></returns>
 public static DataValue BuildWrapper(DataValue value)
 {
     DataValue dv = BuildValue("WrapperType");
     ((WrapperValue)dv).value = DataValueFactory.BuildFromDataValue(value);
     return dv;
 }
Exemplo n.º 8
0
 /// <summary>
 /// A Helper method for building and populating a DetectedValue object
 /// </summary>
 /// <exclude/>
 /// <param name="dv"></param>
 /// <param name="confidence"></param>
 /// <returns></returns>
 public static DataValue BuildDetectedValue(DataValue dv, int confidence)
 {
     DataValue dav = new DetectedAttributeValue() as DataValue;
     ((DetectedAttributeValue)dav).value = dv;
     ((DetectedAttributeValue)dav).stdDev = confidence;
     return dav;
 }
Exemplo n.º 9
0
 new public void FromXML(string xml)
 {
     Match m = regex.Match(xml);
     if (m.Success)
     {
         Group g = m.Groups[1];
         value = DataValueFactory.XMLDeserialize(g.Value);
     }
     else
     {
         throw new Exception(String.Format("Invalid XML string in {0}: {1}",dataType,xml));
     }
 }
Exemplo n.º 10
0
 /// <summary>
 /// 
 /// </summary>
 /// <exclude/>
 /// <param name="dv"></param>
 /// <returns></returns>
 public static DataValue BuildFromDataValue(DataValue dv)
 {
     DataValue returnDV;
     switch (dv.dataType)
     {
         case "WrapperType":
             returnDV = DataValueFactory.BuildWrapper(((WrapperValue)dv).value);
             return returnDV;
             break;
         case "StringType":
             returnDV = DataValueFactory.BuildString(((StringValue)dv).value);
             return returnDV;
             break;
         case "IntegerType":
             returnDV = DataValueFactory.BuildInteger(((IntegerValue)dv).value);
             return returnDV;
             break;
         case "DoubleType":
             returnDV = DataValueFactory.BuildDouble(((DoubleValue)dv).value);
             return returnDV;
             break;
         case "LocationType":
             returnDV = DataValueFactory.BuildLocation(((LocationValue)dv).X, ((LocationValue)dv).Y, ((LocationValue)dv).Z, ((LocationValue)dv).exists);
             return returnDV;
             break;
         case "VelocityType":
             returnDV = DataValueFactory.BuildVelocity(((VelocityValue)dv).VX, ((VelocityValue)dv).VY, ((VelocityValue)dv).VZ);
             return returnDV;
             break;
         case "StringListType":
             returnDV = new StringListValue();
             foreach (string s in ((StringListValue)dv).strings)
             {
                 ((StringListValue)returnDV).strings.Add(s);
             }
             return returnDV;
             break;
         case "RangeRingDisplayType":
             returnDV = DataValueFactory.BuildRangeRingDisplayValue(((RangeRingDisplayValue)dv).name, ((RangeRingDisplayValue)dv).type, ((RangeRingDisplayValue)dv).isWeapon, ((RangeRingDisplayValue)dv).rangeIntensities);
             return returnDV;
             break;
         case "AttackCollectionType":
             returnDV = new AttackCollectionValue();
             String errMsg = String.Empty;
             foreach (AttackCollectionValue.AttackValue av in ((AttackCollectionValue)dv).GetCurrentAttacks())
             {
                 AttackCollectionValue.AttackValue newAttack = new AttackCollectionValue.AttackValue(av.attackStartTime, av.attackTimeWindow, av.targetObjectId, av.attackingObjectId, av.capabilityName, av.percentageApplied, av.isSelfdefense);
                 ((AttackCollectionValue)returnDV).AddAttack(newAttack, out errMsg);
             }
             return returnDV;
             break;
         default:
             returnDV = new DataValue();
             returnDV = dv;
             return returnDV;
     }
     return null;
 }
Exemplo n.º 11
0
 public WrapperValue()
 {
     dataType = "WrapperType";
     value = null;
     xmlStartTag = String.Format("<{0}>", dataType);
     xmlEndTag = String.Format("</{0}>", dataType);
 }
Exemplo n.º 12
0
 public void SetValues(DataValue dv, double conf)
 {
     value = dv;
     stdDev = conf;
 }
Exemplo n.º 13
0
 public DetectedAttributeValue()
 {
     dataType = "DetectedAttributeType";
     value = new DataValue();
     stdDev = 0.0;
 }
Exemplo n.º 14
0
        private void RevealObject(SimulationEvent e)
        {
            AttributeCollectionValue atts = (AttributeCollectionValue)e["Attributes"];
            string id = ((StringValue)e["ObjectID"]).value;

            SimulationObjectProxy prox = null;

            prox = GetObjectProxy(id);
            if (prox == null)
                return;

            //Set State info?
            //AD: This is kind of a quick fix.  Gabe would have a better idea on a more permanent
            //solution.
            DataValue stv = new DataValue();
            stv = prox["StateTable"].GetDataValue();
            Dictionary<string, DataValue> tempDict = ((StateTableValue)stv).states;
            tempDict = ((AttributeCollectionValue)tempDict[((StringValue)atts["State"]).value]).attributes;

            foreach (KeyValuePair<String, DataValue> kvp in tempDict)
            {
                if (!atts.attributes.ContainsKey(kvp.Key))
                {//if att exists in atts, it should NOT overwrite reveal attributes.
                    atts.attributes.Add(kvp.Key, kvp.Value);
                }
            }
            ////AD
            foreach (string attname in atts.attributes.Keys)
            {
                if (attname == "ID")
                {
                    continue;
                }
                if (prox.GetKeys().Contains(attname) && prox[attname].IsOwner())
                {
                    prox[attname].SetDataValue(atts[attname]);
                    if (attname == "Sensors")
                    {
                        double maxSensor = -1.0;
                        SensorArrayValue sav = atts[attname] as SensorArrayValue;
                        foreach (SensorValue sv in sav.sensors)
                        {
                            maxSensor = Math.Max(maxSensor, sv.maxRange);
                        }
                        if (maxSensor >= 0)
                        {
                            ObjectDistances.UpdateObjectSensorRange(id, maxSensor);
                        }
                    }
                }
            }
            Dictionary<string, DataValue> x = new Dictionary<string, DataValue>();

            EmitterValue em = (EmitterValue)prox["Emitters"].GetDataValue();
            foreach (string attName in em.attIsEngram.Keys)
            {
                if (em.attIsEngram[attName])
                {
                    if (StateDB.engrams.ContainsKey(attName))
                    {
                        x[attName] = DataValueFactory.BuildString(StateDB.engrams[attName].engramValue);
                    }
                }
            }

            prox["CustomAttributes"].SetDataValue(DataValueFactory.BuildCustomAttributes(x));

        }
Exemplo n.º 15
0
        private DataValue GetNestedDataValue(DataValue dv)
        {
            if (dv is DetectedAttributeValue)
            {
                return ((DetectedAttributeValue)dv).value;
            }

            return dv;
        }