Exemplo n.º 1
0
        private static void ReadFeatures(ITntSource tnt, MapModel model, List <string> features)
        {
            var enumer = tnt.EnumerateAttrs().GetEnumerator();

            for (var y = 0; y < tnt.DataHeight * 2; y++)
            {
                for (var x = 0; x < tnt.DataWidth * 2; x++)
                {
                    enumer.MoveNext();
                    model.Tile.HeightGrid.Set(x, y, enumer.Current.Height);

                    switch (enumer.Current.Feature)
                    {
                    case TileAttr.FeatureNone:
                    case TileAttr.FeatureUnknown:
                        break;

                    case TileAttr.FeatureVoid:
                        model.Voids.Set(x, y, true);
                        break;

                    default:
                        var inst = new FeatureInstance(Guid.NewGuid(), features[enumer.Current.Feature], x, y);
                        model.AddFeatureInstance(inst);
                        break;
                    }
                }
            }
        }
Exemplo n.º 2
0
        public MapModel FromTntAndOta(ITntSource tnt, TdfNode ota)
        {
            var attrs = MapAttributes.Load(ota);
            var model = new MapModel(tnt.DataWidth, tnt.DataHeight, attrs);

            this.ReadTnt(tnt, model);

            var schemaData = ota.Keys["GlobalHeader"].Keys["Schema 0"];

            if (schemaData.Keys.ContainsKey("features"))
            {
                var featureData = schemaData.Keys["features"];
                foreach (var data in featureData.Keys)
                {
                    var node = data.Value;
                    var x    = TdfConvert.ToInt32(node.Entries["XPos"]);
                    var y    = TdfConvert.ToInt32(node.Entries["ZPos"]);
                    var name = node.Entries["Featurename"];

                    if (!model.HasFeatureInstanceAt(x, y))
                    {
                        var inst = new FeatureInstance(Guid.NewGuid(), name, x, y);
                        model.AddFeatureInstance(inst);
                    }
                }
            }

            return(model);
        }
Exemplo n.º 3
0
 private JObject WriteFeatureInstance(FeatureInstance featureInstance)
 {
     return(new JObject(
                new JProperty("type", new JValue(featureInstance.Feature.Id.ToString())),
                new JProperty("internal", new JValue(featureInstance.IsInternal)),
                new JProperty("properties", new JArray(featureInstance.Properties.Select(p => p.Id.ToString())))
                ));
 }
Exemplo n.º 4
0
        public QueueingTheoryInfo GetQueueingTheoryInfo(FeatureInstance featureInstance)
        {
            var publicFeatureInfo            = _queueingTheoryInfos[featureInstance.FeatureId];
            var fractionOfPropertiesIncluded = (double)featureInstance.Properties.Count() / featureInstance.Feature.Properties.Count();
            var serviceTime = publicFeatureInfo.MeanServiceTime * fractionOfPropertiesIncluded;

            return(new QueueingTheoryInfo(publicFeatureInfo.MeanInterArrivalTime, serviceTime, publicFeatureInfo.ChanceOfOccurance, publicFeatureInfo.Types.Select(f => f.Id)));
        }
Exemplo n.º 5
0
        private IFeatureInstance CachedInstanceOf(Type type)
        {
            if (!_instances.TryGetValue(type, out var implementation))
            {
                _instances.Add(type, implementation = new FeatureInstance(type));
            }

            return(implementation);
        }
 private JObject WriteFeature(FeatureInstance feature)
 {
     return(new JObject(
                new JProperty("id", new JValue(feature.Feature.Id.ToString())),
                new JProperty("name", new JValue(feature.Name)),
                new JProperty("internal", new JValue(feature.IsInternal)),
                new JProperty("properties", new JArray(feature.Properties.Select(WriteProperty)))
                ));
 }
Exemplo n.º 7
0
        public void ToString_OnInternalFeature_Returns_NonEmptyString()
        {
            var properties = new[]
            {
                new Property(new PropertyIdentifier("p1"), "p1"),
            };
            var feature = new Feature(new FeatureIdentifier("id"), "id", properties);
            var sot     = new FeatureInstance(feature, properties.Select(p => p.Id), true);

            Assert.False(string.IsNullOrEmpty(sot.ToString()));
        }
Exemplo n.º 8
0
 public void Constructor_WithoutProperties_ThrowsException()
 {
     Assert.Throws <ArgumentException>(() =>
     {
         var properties = new[]
         {
             new Property(new PropertyIdentifier("p1"), "p1"),
         };
         var feature = new Feature(new FeatureIdentifier("id"), "id", properties);
         var sot     = new FeatureInstance(feature, Enumerable.Empty <PropertyIdentifier>());
     });
 }
Exemplo n.º 9
0
        public void GetHashCode_OnIdenticalFeatureInstance_Returns_Same()
        {
            var properties = new[]
            {
                new Property(new PropertyIdentifier("p1"), "p1"),
            };
            var feature = new Feature(new FeatureIdentifier("id"), "id", properties);
            var sot     = new FeatureInstance(feature, properties.Select(p => p.Id), true);

            var other = new FeatureInstance(feature, properties.Select(p => p.Id), true);

            Assert.AreEqual(sot.GetHashCode(), other.GetHashCode());
        }
Exemplo n.º 10
0
 public void Constructor_ForPublicFeatureInstance_WithoutAllProperties_ThrowsException()
 {
     Assert.Throws <ArgumentException>(() =>
     {
         var properties = new[]
         {
             new Property(new PropertyIdentifier("p1"), "p1"),
             new Property(new PropertyIdentifier("p2"), "p2"),
         };
         var feature = new Feature(new FeatureIdentifier("id"), "id", properties);
         var sot     = new FeatureInstance(feature, properties.Take(1).Select(p => p.Id));
     });
 }
Exemplo n.º 11
0
        public void Constructors_Sets_Fields_Correctly()
        {
            var properties = new []
            {
                new Property(new PropertyIdentifier("p1"), "p1"),
            };
            var feature = new Feature(new FeatureIdentifier("id"), "id", properties);
            var sot     = new FeatureInstance(feature, new [] { new PropertyIdentifier("p1") }, true);

            Assert.True(sot.IsInternal);
            CollectionAssert.AreEqual(properties, sot.Properties);
            Assert.AreEqual(feature, sot.Feature);
            Assert.AreEqual(feature.Name, sot.Name);
            Assert.AreEqual(sot.FeatureId, feature.Id);
        }
Exemplo n.º 12
0
        private FeatureBase getBestFeature(RulePart rulePart, FeatureCover cover)
        {
            FeatureInstance bestFeatureInstance = null;
            var             bestPMI             = double.NegativeInfinity;

            foreach (var featureInstance in cover.FeatureInstances)
            {
                //select best feature according to pointwise mutual information
                var featurePMI = getPointwiseMutualInformation(rulePart, featureInstance.Feature);
                if (featurePMI > bestPMI)
                {
                    bestPMI             = featurePMI;
                    bestFeatureInstance = featureInstance;
                }
            }

            return(bestFeatureInstance.Feature);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Creates a tuple type with resolved arguments.
        /// </summary>
        /// <param name="entityDeclarationList">The resolved list of fields.</param>
        /// <param name="sharing">The type sharing.</param>
        /// <param name="resolvedTypeName">The type name upon return.</param>
        /// <param name="resolvedType">The type upon return.</param>
        public static void BuildType(IList <IEntityDeclaration> entityDeclarationList, BaseNode.SharingType sharing, out ITypeName resolvedTypeName, out ICompiledType resolvedType)
        {
            ISealableDictionary <IFeatureName, IFeatureInstance> FeatureTable = new SealableDictionary <IFeatureName, IFeatureInstance>();

            foreach (IEntityDeclaration Item in entityDeclarationList)
            {
                Debug.Assert(Item.ValidEntity.IsAssigned);
                IScopeAttributeFeature ValidEntity = Item.ValidEntity.Item;

                Debug.Assert(ValidEntity.ValidFeatureName.IsAssigned);
                IFeatureName FeatureName = ValidEntity.ValidFeatureName.Item;

                IClass           EmbeddingClass  = Item.EmbeddingClass;
                IFeatureInstance FeatureInstance = new FeatureInstance(EmbeddingClass, ValidEntity);

                FeatureTable.Add(FeatureName, FeatureInstance);
            }

            ITupleType ResolvedTupleType = new TupleType(entityDeclarationList, sharing, FeatureTable);

            resolvedTypeName = new TypeName(ResolvedTupleType.TypeFriendlyName);
            resolvedType     = ResolvedTupleType;
        }
Exemplo n.º 14
0
            public IEnumerator <TestCaseData> GetEnumerator()
            {
                var properties = new[]
                {
                    new Property(new PropertyIdentifier("p1"), "p1"),
                };
                var feature = new Feature(new FeatureIdentifier("id"), "id", properties);
                var sot     = new FeatureInstance(feature, properties.Select(p => p.Id));

                var identicalFeatureInstance = new FeatureInstance(feature, properties.Select(p => p.Id));

                var internalFeatureInstance = new FeatureInstance(feature, properties.Select(p => p.Id), true);

                yield return(new TestCaseData(sot, sot).Returns(true));

                yield return(new TestCaseData(sot, identicalFeatureInstance).Returns(true));

                yield return(new TestCaseData(sot, internalFeatureInstance).Returns(false));

                yield return(new TestCaseData(sot, 3).Returns(false));

                yield return(new TestCaseData(sot, null).Returns(false));
            }
Exemplo n.º 15
0
 public AddFeatureOperation(IMapModel map, FeatureInstance feature)
 {
     this.map  = map;
     this.item = feature;
 }
Exemplo n.º 16
0
 public void Execute()
 {
     this.removedFeature = this.map.GetFeatureInstance(this.id);
     this.map.RemoveFeatureInstance(this.id);
 }
Exemplo n.º 17
0
 public bool Equals_Returns_Correctly(FeatureInstance featureInstance, object other)
 {
     return(featureInstance.Equals(other));
 }