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; } } } }
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); }
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()))) )); }
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))); }
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))) )); }
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())); }
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>()); }); }
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()); }
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)); }); }
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); }
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); }
/// <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; }
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)); }
public AddFeatureOperation(IMapModel map, FeatureInstance feature) { this.map = map; this.item = feature; }
public void Execute() { this.removedFeature = this.map.GetFeatureInstance(this.id); this.map.RemoveFeatureInstance(this.id); }
public bool Equals_Returns_Correctly(FeatureInstance featureInstance, object other) { return(featureInstance.Equals(other)); }