示例#1
0
        public void ParseAttributeLine(string line)
        {
            var tokens = line.Split('.');
            var value  = line.Split(',');

            if (!value[0].Contains("Integer"))
            {
                return;
            }
            var nfpVal    = Convert.ToInt32(value[1]);
            var influence = new InfluenceFunction(tokens[0] + " * " + nfpVal);



            //BETTY:
            //F1.Atribute1: Integer[0 to 100],57,0;
            //F1.Atribute0: Integer[0 to 100],4,0;
            //Betty can have multiple Attributes on one Feature
            //Need new InfluenceModel for second Attribute???
            //TODO
            if (!_inflModel.BinaryOptionsInfluence.ContainsKey(_varModel.getBinaryOption(tokens[0])))
            {
                _inflModel.BinaryOptionsInfluence.Add(_varModel.getBinaryOption(tokens[0]), influence);
            }
            //Console.WriteLine(influence.ToString());
        }
示例#2
0
        public override void AddInteractionToModel(int index, List <BinaryOption> tempConfig)
        {
            var function = tempConfig.Aggregate("", (current, op) => current + op.Name + " * ");

            function = function + InteractionValues[index];

            var interF = new InfluenceFunction(function);
            var inter  = new Interaction(interF); //TODO Need to set the BinaryOption for the Interaction?

            _influenceModel.InteractionInfluence.Add(inter, interF);
        }
示例#3
0
        /// <summary>
        /// Writes one interaction to the influence Model
        /// </summary>
        /// <param name="index"></param>
        private void AddInteractionToModel(int index)
        {
            //function e.g.  f1 * f2 * f3 * 1000;
            var function = _featuresInInteraction.Aggregate("", (current, op) => current + op.Name + " * ");

            function = function + InteractionValues[index];

            var interF = new InfluenceFunction(function);
            var inter  = new Interaction(interF); //TODO Need to set the BinaryOption for the Interaction?

            _influenceModel.InteractionInfluence.Add(inter, interF);
        }
示例#4
0
        protected LocationRecord GenerateChildNodeRecord(LocationRecord parent, NavigationGraphEdge connectionEdge)
        {
            var childNode = connectionEdge.ToNode;

            var childNodeRecord = new LocationRecord
            {
                Influence = InfluenceFunction.DetermineInfluence(parent.StrongestInfluenceUnit, childNode.Position),
                StrongestInfluenceUnit = parent.StrongestInfluenceUnit,
                Location = childNode
            };

            return(childNodeRecord);
        }
        private static void transformNumericConstraintsToBoolean(VariabilityModel newVariabilityModel)
        {
            foreach (NonBooleanConstraint constraintToTransform in GlobalState.varModel.NonBooleanConstraints)
            {
                String constraintAsExpression = constraintToTransform.ToString();

                string[]          parts         = constraintAsExpression.Split(new String[] { "=", "<", ">", "<=", ">=" }, StringSplitOptions.None);
                InfluenceFunction leftHandSide  = new InfluenceFunction(parts[0], GlobalState.varModel);
                InfluenceFunction rightHandSide = new InfluenceFunction(parts[parts.Length - 1], GlobalState.varModel);

                // Find all possible assignments for the participating numeric options to turn it into a CNF clause
                // TODO: Maybe use a solver
                List <NumericOption> allParticipatingNumericOptions = leftHandSide.participatingNumOptions.ToList()
                                                                      .Union(rightHandSide.participatingNumOptions.ToList()).Distinct().ToList();

                List <List <double> > allPossibleValues = new List <List <double> >();
                allParticipatingNumericOptions.ForEach(x => allPossibleValues.Add(x.getAllValues()));

                var cartesianProduct = allPossibleValues.First().Select(x => x.ToString());
                foreach (List <double> possibleValue in allPossibleValues.Skip(1))
                {
                    cartesianProduct = from product in cartesianProduct
                                       from newValue in possibleValue
                                       select product + "$" + newValue;
                }

                // Find all invalid Configurations, turn each invalid Configuration into a or clause and combine them to a CNF
                IEnumerable <string> invalidConfigs = cartesianProduct
                                                      .Where(x => !testIfValidConfiguration(x, allParticipatingNumericOptions, constraintToTransform));
                StringBuilder nonBooleanConstraintAsBoolean = new StringBuilder();
                foreach (string validConfig in invalidConfigs)
                {
                    List <string> binaryRepresentation = validConfig.Split(new char[] { '$' })
                                                         .Zip(allParticipatingNumericOptions, (x, y) => "!" + y.Name + "_" + x).ToList();
                    nonBooleanConstraintAsBoolean.Append(binaryRepresentation.First());
                    for (int i = 1; i < binaryRepresentation.Count; i++)
                    {
                        nonBooleanConstraintAsBoolean.Append(" | " + binaryRepresentation.ElementAt(i));
                    }
                    nonBooleanConstraintAsBoolean.Append(" & ");
                }

                if (nonBooleanConstraintAsBoolean.Length > 0)
                {
                    // Remove trailing ' & '
                    nonBooleanConstraintAsBoolean.Length = nonBooleanConstraintAsBoolean.Length - 3;
                    convertToCNF(nonBooleanConstraintAsBoolean.ToString()).ForEach(clause => newVariabilityModel.BinaryConstraints.Add(clause.Trim()));
                }
            }
        }
        /// <summary>
        /// Based on the given learning round, the method intantiates the influence model.
        /// </summary>
        /// <param name="current">The current learning round containing all determined features with their influences.</param>
        private void updateInfluenceModel()
        {
            this.infModel.BinaryOptionsInfluence.Clear();
            this.infModel.NumericOptionsInfluence.Clear();
            this.infModel.InteractionInfluence.Clear();
            LearningRound best        = null;
            double        lowestError = Double.MaxValue;

            foreach (LearningRound r in this.learningHistory)
            {
                if (r.validationError < lowestError)
                {
                    lowestError = r.validationError;
                    best        = r;
                }
            }

            foreach (Feature f in best.FeatureSet)
            {
                //single binary option influence
                if (f.participatingBoolOptions.Count == 1 && f.participatingNumOptions.Count == 0 && f.getNumberOfParticipatingOptions() == 1)
                {
                    this.infModel.BinaryOptionsInfluence.Add(f.participatingBoolOptions.ElementAt(0), f);
                    continue;
                }
                //single numeric option influence
                if (f.participatingBoolOptions.Count == 0 && f.participatingNumOptions.Count == 1 && f.getNumberOfParticipatingOptions() == 1)
                {
                    if (this.infModel.NumericOptionsInfluence.Keys.Contains(f.participatingNumOptions.ElementAt(0)))
                    {
                        InfluenceFunction composed = new InfluenceFunction(this.infModel.NumericOptionsInfluence[f.participatingNumOptions.ElementAt(0)].ToString() + " + " + f.ToString(), f.participatingNumOptions.ElementAt(0));
                        this.infModel.NumericOptionsInfluence[f.participatingNumOptions.ElementAt(0)] = composed;
                    }
                    else
                    {
                        this.infModel.NumericOptionsInfluence.Add(f.participatingNumOptions.ElementAt(0), f);
                    }
                    continue;
                }
                //interaction influence
                Interaction i = new Interaction(f);
                this.infModel.InteractionInfluence.Add(i, f);
            }
        }
示例#7
0
        /// <summary>
        /// Computes the influence of all configuration options based on the measurements of the given result db. It uses linear programming (simplex) and is an exact algorithm.
        /// </summary>
        /// <param name="nfp">The non-functional property for which the influences of configuration options are to be computed. If null, we use the property of the global model.</param>
        /// <param name="infModel">The influence model containing options and interactions. The state of the model will be changed by the result of the process</param>
        /// <param name="db">The result database containing the measurements.</param>
        /// <returns>A map of binary options to their computed influences.</returns>
        public Dictionary <BinaryOption, double> computeOptionInfluences(NFProperty nfp, InfluenceModel infModel, ResultDB db)
        {
            List <BinaryOption>         variables      = infModel.Vm.BinaryOptions;
            List <double>               results        = new List <double>();
            List <List <BinaryOption> > configurations = new List <List <BinaryOption> >();

            foreach (Configuration c in db.Configurations)
            {
                configurations.Add(c.getBinaryOptions(BinaryOption.BinaryValue.Selected));
                if (nfp != null)
                {
                    results.Add(c.GetNFPValue(nfp));
                }
                else
                {
                    results.Add(c.GetNFPValue());
                }
            }
            List <String> errorEqs = new List <string>();
            Dictionary <String, double> faultRates             = new Dictionary <string, double>();
            List <int> indexOfErrorMeasurements                = new List <int>();
            Dictionary <String, double> featureValuedAsStrings = solve(variables, results, configurations, infModel.InteractionInfluence.Keys.ToList());

            foreach (String current in featureValuedAsStrings.Keys)
            {
                BinaryOption temp = infModel.Vm.getBinaryOption(current);
                this.featureValues[temp] = featureValuedAsStrings[current];
                InfluenceFunction influence = new InfluenceFunction(temp.Name + " + " + featureValuedAsStrings[current].ToString(), infModel.Vm);
                if (infModel.BinaryOptionsInfluence.Keys.Contains(temp))
                {
                    infModel.BinaryOptionsInfluence[temp] = influence;
                }
                else
                {
                    infModel.BinaryOptionsInfluence.Add(temp, influence);
                }
            }
            return(this.featureValues);
        }
示例#8
0
        private static Expr TranslateMixedConstraint(InfluenceFunction influenceFunction, Dictionary <BinaryOption, Expr> optionMapping, Context context, Dictionary <ConfigurationOption, Expr> optionToTerm)
        {
            string[] expression = influenceFunction.getExpressionTree();

            if (expression.Length == 0)
            {
                return(null);
            }

            Stack <Expr> expressionStack = new Stack <Expr>();

            for (int i = 0; i < expression.Length; i++)
            {
                if (!InfluenceFunction.isOperatorEval(expression[i]))
                {
                    double value;
                    if (Double.TryParse(expression[i], out value))
                    {
                        expressionStack.Push(context.MkFPNumeral(value, context.MkFPSortDouble()));
                    }
                    else
                    {
                        ConfigurationOption option = GlobalState.varModel.getOption(expression[i]);
                        Expr expr = null;
                        if (option is BinaryOption && optionMapping.ContainsKey((BinaryOption)option))
                        {
                            expr = optionMapping[(BinaryOption)option];
                        }
                        else
                        {
                            expr = optionToTerm[option];
                        }

                        expressionStack.Push(expr);
                    }
                }
                else
                {
                    // Be aware of the rounding mode
                    FPRMExpr roundingMode = context.MkFPRoundNearestTiesToEven();
                    switch (expression[i])
                    {
                    case "+":
                        FPExpr left  = (FPExpr)expressionStack.Pop();
                        FPExpr right = (FPExpr)expressionStack.Pop();

                        expressionStack.Push(context.MkFPAdd(roundingMode, left, right));
                        break;

                    case "-":
                        FPExpr leftSub  = (FPExpr)expressionStack.Pop();
                        FPExpr rightSub = (FPExpr)expressionStack.Pop();

                        expressionStack.Push(context.MkFPSub(roundingMode, leftSub, rightSub));
                        break;

                    case "/":
                        FPExpr leftDiv  = (FPExpr)expressionStack.Pop();
                        FPExpr rightDiv = (FPExpr)expressionStack.Pop();

                        expressionStack.Push(context.MkFPDiv(roundingMode, leftDiv, rightDiv));
                        break;

                    case "*":
                        FPExpr leftMul  = (FPExpr)expressionStack.Pop();
                        FPExpr rightMul = (FPExpr)expressionStack.Pop();

                        expressionStack.Push(context.MkFPMul(roundingMode, leftMul, rightMul));
                        break;

                    // Note that the logarithm function is not supported by z3.
                    default:
                        throw new ArgumentException("The operator " + expression[i] + " is currently not supported in mixed constraints by z3.");
                    }
                }
            }

            return(expressionStack.Pop());
        }
示例#9
0
        //this method should return true if it finished processing, and false if it still needs to continue
        public bool MapFloodDijkstra()
        {
            var processedNodes = 0;

            while (Open.CountOpen() > 0)
            {
                processedNodes++;

                if (processedNodes > NodesPerFlood)
                {
                    return(false);
                }
                LocationRecord currentRecord = Open.GetBestAndRemove();
                Closed.AddToClosed(currentRecord);

                int outConnections = currentRecord.Location.OutEdgeCount;
                for (int i = 0; i < outConnections; i++)
                {
                    var   location  = GenerateChildNodeRecord(currentRecord, currentRecord.Location.EdgeOut(i));
                    float influence = InfluenceFunction.DetermineInfluence(currentRecord.StrongestInfluenceUnit, location.Location.Position);

                    if (InfluenceThreshold.CompareTo(influence) > 0)
                    {
                        continue;
                    }

                    LocationRecord neighborRecord = Closed.SearchInClosed(location);

                    if (neighborRecord != null)
                    {
                        if (neighborRecord.Influence >= influence)
                        {
                            continue;
                        }
                        else
                        {
                            Closed.RemoveFromClosed(neighborRecord);
                        }
                    }
                    else
                    {
                        neighborRecord = Open.SearchInOpen(location);

                        if (neighborRecord != null)
                        {
                            if (neighborRecord.Influence < influence)
                            {
                                neighborRecord.StrongestInfluenceUnit = currentRecord.StrongestInfluenceUnit;
                                neighborRecord.Influence = influence;
                            }
                            continue;
                        }
                        else //we found a new record not in open or closed
                        {
                            neighborRecord          = new LocationRecord();
                            neighborRecord.Location = location.Location;
                        }
                    }

                    neighborRecord.StrongestInfluenceUnit = currentRecord.StrongestInfluenceUnit;
                    neighborRecord.Influence = influence;
                    Open.AddToOpen(neighborRecord);
                }
            }

            this.InProgress = false;
            //this.CleanUp();
            return(true);
        }
示例#10
0
        //public static string GTPStatusInfluence(GoBoard board)
        //{


        //    return GTPInfluenceByFunction("", board, GetStatusInfluence);
        //}


        public static string GTPInfluenceByFunction(string dataDirectory, GoBoard board, InfluenceFunction infFunc)
        {
            StringBuilder s = new StringBuilder(512);

            var influence = infFunc.Invoke(dataDirectory, board);

            s.Append("INFLUENCE ");
            for (int x = 0; x < board.BoardSize; x++)
            {
                for (int y = 0; y < board.BoardSize; y++)
                {
                    s.AppendFormat("{0} {1} ", board.At(x, y), influence[board.At(x, y)].ToString(CultureInfo.InvariantCulture));
                }
            }

            return(s.ToString());
        }