public AttributeValue GetAttributeValueByAttributeIdentifier(string attributeID)
        {
            // Find FeatureSelection which the appropriate AttributeValue
            FeatureSelection featureSelection = featureSelections.FirstOrDefault(f => f.AttributeValues.FirstOrDefault(x => x.AttributeIdentifier == attributeID) != null);
            AttributeValue   attributeValue   = featureSelection.AttributeValues.FirstOrDefault(x => x.AttributeIdentifier == attributeID);

            return(attributeValue);
        }
        // Private methods
        private List <FeatureSelection> GetDescendantFeatureSelections_Recursive(FeatureSelection target)
        {
            List <FeatureSelection> childFeatureSelections = target.GetAllChildrenFeatureSelectionsIncludingFromChildGroups();
            List <FeatureSelection> descendants            = new List <FeatureSelection>(childFeatureSelections);


            foreach (FeatureSelection childFeatureSel in childFeatureSelections)
            {
                descendants.AddRange(this.GetDescendantFeatureSelections_Recursive(childFeatureSel));
            }

            return(descendants);
        }
Esempio n. 3
0
        private FeatureSelection CreateFeatureSelection_Shallow(Feature feature)
        {
            // Set properties
            FeatureSelection newFeatureSelection = new FeatureSelection()
            {
                FeatureName       = feature.Name,
                FeatureIdentifier = feature.Identifier,
                SelectionState    = FeatureSelectionStates.Unselected
            };

            // Create attributes
            foreach (Modelling.BLOs.Attribute attr in feature.Attributes)
            {
                newFeatureSelection.AttributeValues.Add(CreateAttributeValue(attr));
            }

            return(newFeatureSelection);
        }
Esempio n. 4
0
        // Public methods
        public ConfigurationInstance Create_ConfigurationInstance_FromModel(Model model)
        {
            // Get the root feature
            Feature rootFeature = model.Features.Where(f =>
                                                       !model.Relations.Exists(r => r.ChildFeature == f) &&
                                                       !model.GroupRelations.Exists(gr => gr.ChildFeatures.Contains(f))
                                                       ).SingleOrDefault();

            // Create FeatureSelections
            List <FeatureSelection> featureSelectionsList = new List <FeatureSelection>();
            FeatureSelection        rootFeatureSelection  = CreateFeatureSelection_Recursive(rootFeature, model, ref featureSelectionsList);


            // Create a new ConfigurationInstance
            ConfigurationInstance newConfigInstance = new ConfigurationInstance(rootFeatureSelection, featureSelectionsList);

            newConfigInstance.ModelName = model.Name;
            return(newConfigInstance);
        }
        // Public methods
        public List <FeatureSelection> ToggleFeatureAsUser(string featureIdentifier)
        {
            // Variables
            FeatureSelection       toggledFeatureSelection = this.configurationInstance.FeatureSelections.Single(f => f.FeatureIdentifier == featureIdentifier);
            FeatureSelectionStates newSelectionState       = GetNextSelectionStateOnToggle(toggledFeatureSelection.SelectionState);


            // Set the new selectionState, adding it as a decision to the SolverContext
            switch (newSelectionState)
            {
            // Assert-decision  -> Selected
            case FeatureSelectionStates.Selected:
                solverContext.AddOrModifyDecisionAssumption(toggledFeatureSelection.FeatureIdentifier, true, typeof(FeatureSelection));
                toggledFeatureSelection.SelectionState = FeatureSelectionStates.Selected;
                toggledFeatureSelection.ToggledByUser  = true;
                break;

            // Assert-decision  -> Deselected
            case FeatureSelectionStates.Deselected:
                solverContext.AddOrModifyDecisionAssumption(toggledFeatureSelection.FeatureIdentifier, false, typeof(FeatureSelection));
                toggledFeatureSelection.SelectionState = FeatureSelectionStates.Deselected;
                toggledFeatureSelection.ToggledByUser  = true;
                break;

            // Retract-decision  -> Unselected
            case FeatureSelectionStates.Unselected:
                solverContext.RemoveDecisionAssumption(toggledFeatureSelection.FeatureIdentifier, typeof(FeatureSelection));
                toggledFeatureSelection.SelectionState = FeatureSelectionStates.Unselected;
                toggledFeatureSelection.ToggledByUser  = false;
                break;
            }

            // Call feedback algorithm and then recalculate all custom functions
            List <FeatureSelection> changedFeatureSelections = new List <FeatureSelection>();
            bool decisionIsValid = ApplyFeedbackAlgorithm(ref changedFeatureSelections);

            RecalculateCustomFunctions(ref changedFeatureSelections);

            //
            return(changedFeatureSelections);
        }
Esempio n. 6
0
        private FeatureSelection CreateFeatureSelection_Recursive(Feature feature, Model model, ref List <FeatureSelection> featureSelectionsList)
        {
            // 1. Create FeatureSelection with base properties and AttributeValues
            FeatureSelection newFeatureSelection = CreateFeatureSelection_Shallow(feature);


            // 2. Create child FeatureSelections
            var childFeatures = model.Features.Where(ft =>
                                                     model.Relations.Exists(rel => rel.ChildFeature == ft && rel.ParentFeature == feature)
                                                     ).ToList();

            foreach (Feature childFeature in childFeatures)
            {
                newFeatureSelection.ChildFeatureSelections.Add(CreateFeatureSelection_Recursive(childFeature, model, ref featureSelectionsList));
            }


            // 3. Create child Groups and their FeatureSelections
            var childGroupRelations = model.GroupRelations.Where(groupRel => groupRel.ParentFeature == feature).ToList();

            foreach (GroupRelation groupRelation in childGroupRelations)
            {
                Group newGroup = new Group();
                newGroup.GroupRelationType = groupRelation.GroupRelationType;
                var childGroupFeatures = model.Features.Where(ft =>
                                                              model.GroupRelations.Exists(groupRel => groupRel.ParentFeature == feature && groupRel.ChildFeatures.Contains(ft))
                                                              ).ToList();
                foreach (Feature childGroupFeature in childGroupFeatures)
                {
                    newGroup.InnerFeatureSelections.Add(CreateFeatureSelection_Recursive(childGroupFeature, model, ref featureSelectionsList));
                }
                newFeatureSelection.ChildGroups.Add(newGroup);
            }


            featureSelectionsList.Add(newFeatureSelection);
            return(newFeatureSelection);
        }
        public List <FeatureSelection> GetDescendantFeatureSelections(FeatureSelection targetFeatureSelection)
        {
            var descendantFeatureSelections = GetDescendantFeatureSelections_Recursive(targetFeatureSelection);

            return(descendantFeatureSelections);
        }
        // Public Methods
        public FeatureSelection GetFeatureSelectionByFeatureIdentifier(string featureID)
        {
            FeatureSelection featureSelection = featureSelections.FirstOrDefault(x => x.FeatureIdentifier == featureID);

            return(featureSelection);
        }
 // Constructor
 public ConfigurationInstance(FeatureSelection rootFeatureSelection, List <FeatureSelection> featureSelections)
 {
     this.rootFeatureSelection = rootFeatureSelection;
     this.featureSelections    = featureSelections;
 }