Ejemplo n.º 1
0
        /// <summary>
        /// Invokes if the radio button for switching to a numeric option has been pressed.
        /// </summary>
        /// <param name="sender">Sender</param>
        /// <param name="e">Event</param>
        private void optionTypeNumericRadioButton_CheckedChanged(object sender, EventArgs e)
        {
            if (optionTypeNumericRadioButton.Checked)
            {
                optionTypeBinaryRadioButton.Checked = false;

                ConfigurationOption newOption = new NumericOption(GlobalState.varModel, currentOption.Name);

                foreach (ConfigurationOption opt in currentOption.Children)
                {
                    opt.Parent = newOption;
                    newOption.Children.Add(opt);
                }

                currentOption.Children     = new List <ConfigurationOption>();
                newOption.Parent           = currentOption.Parent;
                newOption.Prefix           = currentOption.Prefix;
                newOption.Postfix          = currentOption.Postfix;
                newOption.OutputString     = currentOption.OutputString;
                newOption.Excluded_Options = currentOption.Excluded_Options;
                newOption.Implied_Options  = currentOption.Implied_Options;

                GlobalState.varModel.deleteOption(currentOption);
                GlobalState.varModel.addConfigurationOption(newOption);

                currentOption = newOption;
                ((NumericOption)currentOption).StepFunction = new InfluenceFunction(currentOption.Name + " + 1", GlobalState.varModel);

                optionalCheckBox.Visible        = false;
                numericSettingsGroupBox.Enabled = true;
                rangeLabel.Text = "( " + ((NumericOption)currentOption).Min_value + ", "
                                  + ((NumericOption)currentOption).Max_value + " )";
                stepSizeLabel.Text = ((NumericOption)currentOption).StepFunction.ToString();
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Samples the value space of one numeric option. The values are equal distributed. The number of values is defined by the <see cref="minNumberOfSamplingsPerNumericOption"/> field. The minimal and
 /// maximal value of the numeric option are not considered during the sampling.
 /// </summary>
 /// <param name="option">The numeric option to sample.</param>
 /// <returns>A list of equal distributed values for the numeric option. The list might be empty.</returns>
 public List <double> sampleOption(NumericOption option)
 {
     if (this.minNumberOfSamplingsPerNumericOption > option.getNumberOfSteps())
     {
         return(sampleOption(option, option.getNumberOfSteps(), false));
     }
     return(sampleOption(option, this.minNumberOfSamplingsPerNumericOption, false));
 }
Ejemplo n.º 3
0
 public ImageToText(NumericOption numericOption, int isMath)
 {
     BodyBase64 = "";
     Phrase     = false;
     Case       = false;
     Numeric    = numericOption;
     Math       = isMath;
     MinLength  = 0;
     MaxLength  = 0;
 }
Ejemplo n.º 4
0
        /*
         * in: VariableFeature vf; is the feature for which we have to know the sampling values
         * in: double percentage; range 0..1 the percentage of all values we need
         * out: void
         * Sets the maximum sampling size according to the percentage. The logarithm must be used, because the values of a single metric value multiplies with the values of all others leading to an exponential number
         * *****************/
        protected int setSamplingValue(NumericOption vf, double percentage)
        {
            double number = vf.getNumberOfSteps() * percentage;

            if (number < this.minNumberOfSamplingsPerNumericOption)
            {
                return(this.minNumberOfSamplingsPerNumericOption);
            }

            return(Convert.ToInt32(number));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Invokes if the 'Add option'-button was pressed.
        ///
        /// This method will add the option the the current variability model and
        /// will dispose this form.
        /// </summary>
        /// <param name="sender">Sender</param>
        /// <param name="e">Event</param>
        private void addOptionButton_Click(object sender, EventArgs e)
        {
            ConfigurationOption newOption = null;

            if (numericRadioButton.Checked)
            {
                newOption = new NumericOption(GlobalState.varModel, this.featureNameTextBox.Text);
                ((NumericOption)newOption).Min_value = Convert.ToDouble(minValueTextBox.Text);
                ((NumericOption)newOption).Max_value = Convert.ToDouble(maxValueTextBox.Text);

                if (stepSizeCheckBox.Checked)
                {
                    ((NumericOption)newOption).StepFunction = new InfluenceFunction(
                        stepSizeTextBox.Text == "" ? "n + 1" : stepSizeTextBox.Text, (NumericOption)newOption);
                }
                else
                {
                    ((NumericOption)newOption).StepFunction = new InfluenceFunction("n + 1", (NumericOption)newOption);
                }
                if (numOptionalCheckBox.Checked)
                {
                    ((NumericOption)newOption).Optional = true;
                    int flag;
                    if (!int.TryParse(deselectedFlagTextBox.Text, out flag))
                    {
                        MessageBox.Show("Invalid deselection flag. Value must be integer.");
                        return;
                    }
                    else
                    {
                        ((NumericOption)newOption).setOptional(true, flag);
                    }
                }
            }
            else
            {
                newOption = new BinaryOption(GlobalState.varModel, this.featureNameTextBox.Text);
                ((BinaryOption)newOption).Optional = optionalCheckBox.Checked;
            }

            if (prePostCheckBox.Checked)
            {
                newOption.Prefix  = prefixTextBox.Text;
                newOption.Postfix = postfixTextBox.Text;
            }

            newOption.OutputString = outputStringTextBox.Text;
            newOption.Parent       = GlobalState.varModel.getOption(this.parentComboBox.Text);

            GlobalState.varModel.addConfigurationOption(newOption);
            this.Close();
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Returns all possible buckets using the <see cref="HybridStrategy.optionsToConsider"/>.
        /// </summary>
        /// <returns>a <see cref="List"/> containing the sum of all value combinations of the features</returns>
        private List <double> ComputeBuckets()
        {
            List <List <double> > allValueSets = new List <List <double> >();

            foreach (ConfigurationOption o in this.optionsToConsider)
            {
                if (o is NumericOption)
                {
                    NumericOption numOpt                = (NumericOption)o;
                    List <double> distances             = new List <double>();
                    List <double> valuesOfNumericOption = numOpt.getAllValues();

                    foreach (double numOptValue in valuesOfNumericOption)
                    {
                        distances.Add(this.metric.ComputeDistanceOfNumericFeature(numOptValue, numOpt.Min_value, numOpt.Max_value));
                    }
                    allValueSets.Add(distances);
                }
                else
                {
                    BinaryOption binOpt = (BinaryOption)o;
                    if (!binOpt.Optional && CountChildren(binOpt, GlobalState.varModel) > 0)
                    {
                        allValueSets.Add(new List <double> {
                            this.metric.ComputeDistanceOfBinaryFeature(1)
                        });
                    }
                    else
                    {
                        allValueSets.Add(new List <double> {
                            this.metric.ComputeDistanceOfBinaryFeature(0), this.metric.ComputeDistanceOfBinaryFeature(1)
                        });
                    }
                }
            }

            List <double> result = ComputeSumOfCartesianProduct(allValueSets);

            // Sort the list
            result.Sort(delegate(double x, double y)
            {
                return(x.CompareTo(y));
            });

            return(result);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Samples the value space of one numeric option. The values are equal distributed. If the numeric option has less values than the desired number of samplings, all values of the numeric option are
        /// returned.
        /// </summary>
        /// <param name="option">The numeric option to sample.</param>
        /// <param name="numberOfSamples">The number of different values of the numeric option.</param>
        /// <param name="useMinMaxValues">States whether the minimal and maximal value of the numeric option have to be considered during sampling.</param>
        /// <returns>A list of equal distributed values for the numeric option. The list might be empty.</returns>
        public static List <double> sampleOption(NumericOption option, long numberOfSamples, bool useMinMaxValues)
        {
            List <double> resultList = new List <double>();

            long numberOfValues = option.getNumberOfSteps();

            if (numberOfValues <= numberOfSamples)
            {
                double val = option.Min_value;
                for (int k = 0; k < numberOfValues; k++)
                {
                    resultList.Add(val);
                    val = option.getNextValue(val);
                }
                return(resultList);
            }

            if (useMinMaxValues)
            {
                resultList.Add(option.Min_value);
                resultList.Add(option.Max_value);

                numberOfSamples -= 2;
            }


            int offsetForOddNumberOfValues = 1;
            int offSetBetweenValues        = (int)Math.Round((double)(numberOfValues - 2 + offsetForOddNumberOfValues) / (double)(numberOfSamples + 1));

            double value = option.Min_value;

            for (int i = 0; i < numberOfSamples; i++)
            {
                int currNumSteps = 0;

                while (currNumSteps < offSetBetweenValues)
                {
                    value = option.getNextValue(value);
                    currNumSteps++;
                }
                resultList.Add(value);
            }
            resultList.Sort();
            return(resultList);
        }
Ejemplo n.º 8
0
        public ImageToText(string filePathOrBase64, NumericOption numeric, int minLenght = 0, int maxLenght = 0, int math = 0, bool phrase = false, bool @case = false)
        {
            if (File.Exists(filePathOrBase64))
            {
                FilePath = filePathOrBase64;
            }
            else
            {
                BodyBase64 = filePathOrBase64;
            }

            Phrase    = phrase;
            Case      = @case;
            Numeric   = numeric;
            Math      = math;
            MinLength = minLenght;
            MaxLength = maxLenght;
        }
Ejemplo n.º 9
0
        public void initVariabilityModel()
        {
            VariabilityModel vm     = new VariabilityModel("test");
            NumericOption    numOpt = new NumericOption(vm, "testNum");

            numOpt.SetValues(new double[] { 0, 5, 10, 15, 20, 25 });
            numOpt.Min_value = 0;
            numOpt.Max_value = 25;
            numOpt.Parent    = vm.Root;
            BinaryOption binOpt = new BinaryOption(vm, "testBin");

            binOpt.Optional = true;
            binOpt.Parent   = vm.Root;
            vm.addConfigurationOption(numOpt);
            vm.addConfigurationOption(binOpt);
            vm.NonBooleanConstraints.Add(new NonBooleanConstraint("testNum > 0", vm));
            GlobalState.varModel = vm;
            this.vm = vm;
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Invokes if the 'Add option'-button was pressed.
        ///
        /// This method will add the option the the current variability model and
        /// will dispose this form.
        /// </summary>
        /// <param name="sender">Sender</param>
        /// <param name="e">Event</param>
        private void addOptionButton_Click(object sender, EventArgs e)
        {
            ConfigurationOption newOption = null;

            if (numericRadioButton.Checked)
            {
                newOption = new NumericOption(GlobalState.varModel, this.featureNameTextBox.Text);
                ((NumericOption)newOption).Min_value = Convert.ToDouble(minValueTextBox.Text);
                ((NumericOption)newOption).Max_value = Convert.ToDouble(maxValueTextBox.Text);

                if (stepSizeCheckBox.Checked)
                {
                    ((NumericOption)newOption).StepFunction = new InfluenceFunction(
                        stepSizeTextBox.Text == "" ? "n + 1": stepSizeTextBox.Text, (NumericOption)newOption);
                }
                else
                {
                    ((NumericOption)newOption).StepFunction = new InfluenceFunction("n + 1", (NumericOption)newOption);
                }
            }
            else
            {
                newOption = new BinaryOption(GlobalState.varModel, this.featureNameTextBox.Text);
                ((BinaryOption)newOption).Optional = optionalCheckBox.Checked;
            }

            if (prePostCheckBox.Checked)
            {
                newOption.Prefix  = prefixTextBox.Text;
                newOption.Postfix = postfixTextBox.Text;
            }

            newOption.OutputString = outputStringTextBox.Text;
            newOption.Parent       = GlobalState.varModel.getOption(this.parentComboBox.Text);

            newOption.Parent.Children.Add(newOption);

            GlobalState.varModel.addConfigurationOption(newOption);
            this.Close();
        }
Ejemplo n.º 11
0
        public static void TestGenerateAllVariants()
        {
            CplexVariantGenerator vg             = new CplexVariantGenerator();
            List <Configuration>  configurations = vg
                                                   .GenerateAllVariants(GlobalState.varModel, GlobalState.varModel.getOptions());

            // Assert that all possible configurations are sampled
            Assert.AreEqual(864, configurations.Count);

            NumericOption numOpt1 = GlobalState.varModel.getNumericOption("numOpt1");
            NumericOption numOpt2 = GlobalState.varModel.getNumericOption("numOpt2");

            // Assert that all configurations contain the numeric options
            Assert.True(configurations.TrueForAll(conf => conf.NumericOptions.ContainsKey(numOpt1) &&
                                                  conf.NumericOptions.ContainsKey(numOpt2)));

            // Assert that ever possible value of the first numeric option appears at least once
            // and that all values are only within the valid range
            Assert.True(configurations.Any(conf => Convert.ToInt32(conf.NumericOptions[numOpt1]) == 0));
            Assert.True(configurations.Any(conf => Convert.ToInt32(conf.NumericOptions[numOpt1]) == 2));
            Assert.True(configurations.TrueForAll(conf =>
            {
                int numOpt1Val = Convert.ToInt32(conf.NumericOptions[numOpt1]);
                return(numOpt1Val == 0 || numOpt1Val == 2);
            }));

            // Assert that ever possible value of the second numeric option appears at least once
            // and that all values are only within the valid range
            Assert.True(configurations.Any(conf => Convert.ToInt32(conf.NumericOptions[numOpt2]) == 1));
            Assert.True(configurations.Any(conf => Convert.ToInt32(conf.NumericOptions[numOpt2]) == 2));
            Assert.True(configurations.Any(conf => Convert.ToInt32(conf.NumericOptions[numOpt2]) == 4));
            Assert.True(configurations.Any(conf => Convert.ToInt32(conf.NumericOptions[numOpt2]) == 8));
            Assert.True(configurations.TrueForAll(conf =>
            {
                int numOpt2Val = Convert.ToInt32(conf.NumericOptions[numOpt2]);
                return(numOpt2Val == 1 || numOpt2Val == 2 ||
                       numOpt2Val == 4 || numOpt2Val == 8);
            }));
        }
Ejemplo n.º 12
0
        /// <summary>
        /// This method creates recursively a list of all configurations.
        /// </summary>
        /// <returns>The configuration list.</returns>
        /// <param name="valuesOfOptions">The values of all numeric options.</param>
        /// <param name="remainingOptions">The remaining options to add.</param>
        private List <Dictionary <NumericOption, double> > createConfigurationList(Dictionary <NumericOption, List <double> > valuesOfOptions,
                                                                                   List <NumericOption> remainingOptions)
        {
            List <Dictionary <NumericOption, double> > result;

            NumericOption currentOption = remainingOptions[0];

            remainingOptions.Remove(currentOption);
            List <double> valuesOfCurrentOption = valuesOfOptions[currentOption];

            result = new List <Dictionary <NumericOption, double> >();

            if (remainingOptions.Count == 0)
            {
                foreach (double value in valuesOfCurrentOption)
                {
                    Dictionary <NumericOption, double> newDict = new Dictionary <NumericOption, double>();
                    newDict.Add(currentOption, value);
                    result.Add(newDict);
                }
            }
            else
            {
                List <Dictionary <NumericOption, double> > previousConfigurations = createConfigurationList(valuesOfOptions, remainingOptions);

                foreach (Dictionary <NumericOption, double> config in previousConfigurations)
                {
                    foreach (double value in valuesOfCurrentOption)
                    {
                        Dictionary <NumericOption, double> newDict = new Dictionary <NumericOption, double>(config);
                        newDict.Add(currentOption, value);
                        result.Add(newDict);
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Generates a constraint system based on a variability model. The constraint system can be used to check for satisfiability of configurations as well as optimization.
        /// </summary>
        /// <param name="variables">Empty input, outputs a list of CSP terms that correspond to the configuration options of the variability model</param>
        /// <param name="optionToTerm">A map to get for a given configuration option the corresponding CSP term of the constraint system</param>
        /// <param name="termToOption">A map that gives for a given CSP term the corresponding configuration option of the variability model</param>
        /// <param name="vm">The variability model for which we generate a constraint system</param>
        /// <returns>The generated constraint system consisting of logical terms representing configuration options as well as their boolean constraints.</returns>
        internal static ConstraintSystem GetGeneralConstraintSystem(out Dictionary <CspTerm, bool> variables, out Dictionary <ConfigurationOption, CspTerm> optionToTerm, out Dictionary <CspTerm, ConfigurationOption> termToOption, VariabilityModel vm)
        {
            ConstraintSystem S = ConstraintSystem.CreateSolver();

            optionToTerm = new Dictionary <ConfigurationOption, CspTerm>();
            termToOption = new Dictionary <CspTerm, ConfigurationOption>();
            variables    = new Dictionary <CspTerm, bool>();

            foreach (ConfigurationOption o in vm.getOptions())
            {
                CspDomain binDomain = S.DefaultBoolean;
                CspTerm   temp;
                if (o is BinaryOption)
                {
                    temp = S.CreateVariable(binDomain, o);
                }
                else
                {
                    NumericOption numOpt = (NumericOption)o;
                    temp = S.CreateVariable(S.CreateIntegerInterval((int)numOpt.Min_value, (int)numOpt.Max_value), o);
                }

                optionToTerm.Add(o, temp);
                termToOption.Add(temp, o);
                if (o is NumericOption)
                {
                    variables.Add(temp, false);
                }
                else
                {
                    variables.Add(temp, true);
                }
            }

            List <List <ConfigurationOption> > alreadyHandledAlternativeOptions = new List <List <ConfigurationOption> >();

            //Constraints of a single configuration option
            foreach (ConfigurationOption current in vm.getOptions())
            {
                CspTerm cT = optionToTerm[current];
                if (current.Parent == null || current.Parent == vm.Root)
                {
                    if ((current is BinaryOption && ((BinaryOption)current).Optional == false && current.Excluded_Options.Count == 0))
                    {
                        S.AddConstraints(S.Implies(S.True, cT));
                    }
                    else
                    {
                        S.AddConstraints(S.Implies(cT, optionToTerm[vm.Root]));
                    }
                }

                if (current.Parent != null && current.Parent != vm.Root)
                {
                    CspTerm parent = optionToTerm[(BinaryOption)current.Parent];
                    S.AddConstraints(S.Implies(cT, parent));
                    if (current is BinaryOption && ((BinaryOption)current).Optional == false && current.Excluded_Options.Count == 0)
                    {
                        S.AddConstraints(S.Implies(parent, cT));//mandatory child relationship
                    }
                }

                // Add numeric integer values
                if (current is NumericOption)
                {
                    NumericOption  numOpt = (NumericOption)current;
                    List <double>  values = numOpt.getAllValues();
                    List <CspTerm> equals = new List <CspTerm>();
                    foreach (double d in values)
                    {
                        equals.Add(S.Equal((int)d, cT));
                    }
                    S.AddConstraints(S.Or(equals.ToArray()));
                }

                //Alternative or other exclusion constraints
                if (current.Excluded_Options.Count > 0 && current is BinaryOption)
                {
                    BinaryOption binOpt = (BinaryOption)current;
                    List <ConfigurationOption> alternativeOptions = binOpt.collectAlternativeOptions();
                    if (alternativeOptions.Count > 0)
                    {
                        //Check whether we handled this group of alternatives already
                        foreach (var alternativeGroup in alreadyHandledAlternativeOptions)
                        {
                            foreach (var alternative in alternativeGroup)
                            {
                                if (current == alternative)
                                {
                                    goto handledAlternative;
                                }
                            }
                        }

                        //It is not allowed that an alternative group has no parent element
                        CspTerm parent = null;
                        if (current.Parent == null)
                        {
                            parent = S.True;
                        }
                        else
                        {
                            parent = optionToTerm[(BinaryOption)current.Parent];
                        }

                        CspTerm[] terms = new CspTerm[alternativeOptions.Count + 1];
                        terms[0] = cT;
                        int i = 1;
                        foreach (BinaryOption altEle in alternativeOptions)
                        {
                            CspTerm temp = optionToTerm[altEle];
                            terms[i] = temp;
                            i++;
                        }
                        S.AddConstraints(S.Implies(parent, S.ExactlyMofN(1, terms)));
                        alreadyHandledAlternativeOptions.Add(alternativeOptions);
                        handledAlternative : { }
                    }

                    //Excluded option(s) as cross-tree constraint(s)
                    List <List <ConfigurationOption> > nonAlternative = binOpt.getNonAlternativeExlcudedOptions();
                    if (nonAlternative.Count > 0)
                    {
                        foreach (var excludedOption in nonAlternative)
                        {
                            CspTerm[] orTerm = new CspTerm[excludedOption.Count];
                            int       i      = 0;
                            foreach (var opt in excludedOption)
                            {
                                CspTerm target = optionToTerm[(BinaryOption)opt];
                                orTerm[i] = target;
                                i++;
                            }
                            S.AddConstraints(S.Implies(cT, S.Not(S.Or(orTerm))));
                        }
                    }
                }
                //Handle implies
                if (current.Implied_Options.Count > 0)
                {
                    foreach (List <ConfigurationOption> impliedOr in current.Implied_Options)
                    {
                        CspTerm[] orTerms = new CspTerm[impliedOr.Count];
                        //Possible error: if a binary option impies a numeric option
                        for (int i = 0; i < impliedOr.Count; i++)
                        {
                            orTerms[i] = optionToTerm[(BinaryOption)impliedOr.ElementAt(i)];
                        }
                        S.AddConstraints(S.Implies(optionToTerm[current], S.Or(orTerms)));
                    }
                }
            }

            //Handle global cross-tree constraints involving multiple options at a time
            // the constraints should be in conjunctive normal form
            foreach (string constraint in vm.BinaryConstraints)
            {
                bool     and = false;
                string[] terms;
                if (constraint.Contains("&"))
                {
                    and   = true;
                    terms = constraint.Split('&');
                }
                else
                {
                    terms = constraint.Split('|');
                }

                CspTerm[] cspTerms = new CspTerm[terms.Count()];
                int       i        = 0;
                foreach (string t in terms)
                {
                    string optName = t.Trim();
                    if (optName.StartsWith("-") || optName.StartsWith("!"))
                    {
                        optName = optName.Substring(1);
                        BinaryOption binOpt     = vm.getBinaryOption(optName);
                        CspTerm      cspElem    = optionToTerm[binOpt];
                        CspTerm      notCspElem = S.Not(cspElem);
                        cspTerms[i] = notCspElem;
                    }
                    else
                    {
                        BinaryOption binOpt  = vm.getBinaryOption(optName);
                        CspTerm      cspElem = optionToTerm[binOpt];
                        cspTerms[i] = cspElem;
                    }
                    i++;
                }
                if (and)
                {
                    S.AddConstraints(S.And(cspTerms));
                }
                else
                {
                    S.AddConstraints(S.Or(cspTerms));
                }
            }
            return(S);
        }
Ejemplo n.º 14
0
        private Control createControl
            (ref int index, TabPage page, FieldInfo field, Expandable exa, dynamic value)
        {
            Dictionary <string, string>   strRes      = exa.strRes;
            Dictionary <string, string[]> comboBoxRes = exa.comboBoxItemRes;

            string desc = field.Name;
            Type   type = field.FieldType;

            string[] comboBoxItems = null;
            decimal  maximun = 100, minimun = 0, increment = 1;
            int      decimalPlaces = 0;

            if (field.GetCustomAttributes(typeof(NonSettable), false).Length != 0)
            {
                return(null);
            }

            object[] oAttr = field.GetCustomAttributes(typeof(Description), false);
            if (oAttr.Length != 0)
            {
                Description attr = (Description)oAttr[0];
                desc = strRes[attr.strResId];
            }

            oAttr = field.GetCustomAttributes(typeof(NumericOption), false);
            if (oAttr.Length != 0)
            {
                NumericOption attr = (NumericOption)oAttr[0];
                maximun       = attr.maximun;
                minimun       = attr.minimun;
                increment     = attr.increment;
                decimalPlaces = attr.decimalPlaces;
            }

            oAttr = field.GetCustomAttributes(typeof(ComboBoxOption), false);
            if (oAttr.Length != 0)
            {
                ComboBoxOption attr = (ComboBoxOption)oAttr[0];
                comboBoxItems = comboBoxRes[attr.key];
            }

            Label lab = new Label
            {
                AutoSize = true,
                Size     = new Size(33, 12),
                Text     = desc
            };

            Control control = null;

            if (type.Equals(typeof(string)) && comboBoxItems != null)
            {
                ComboBox tmp = new ComboBox
                {
                    Anchor        = (AnchorStyles.Top | AnchorStyles.Right),
                    DropDownStyle = ComboBoxStyle.DropDownList,
                    Location      = new Point(valueBox_x, 6 + index * 28),
                    Size          = new Size(150, 22),
                };
                tmp.Items.AddRange(comboBoxItems);
                tmp.SelectedIndex = 0;
                for (int i = 0; i < comboBoxItems.Length; i++)
                {
                    if (value == comboBoxItems[i])
                    {
                        tmp.SelectedIndex = i;
                        break;
                    }
                }
                control      = tmp;
                lab.Location = new Point(8, 6 + index * 28 + 3);
            }
            else if (type.Equals(typeof(string)))
            {
                control = new TextBox
                {
                    Anchor   = (AnchorStyles.Top | AnchorStyles.Right),
                    Text     = value,
                    Location = new Point(valueBox_x, 6 + index * 28),
                    Size     = new Size(150, 22),
                };
                lab.Location = new Point(8, 6 + index * 28 + 5);
            }
            else if (type.Equals(typeof(bool)))
            {
                control = new CheckBox()
                {
                    Anchor   = (AnchorStyles.Top | AnchorStyles.Right),
                    Checked  = value,
                    Location = new Point(valueBox_x, 6 + index * 28),
                    Size     = new Size(15, 14),
                    Text     = ""
                };
                lab.Location = new Point(8, 6 + index * 28 + 1);
            }
            else if (NumericTypes.Contains(type))
            {
                control = new NumericUpDown()
                {
                    Anchor        = (AnchorStyles.Top | AnchorStyles.Right),
                    Value         = Convert.ToDecimal(value),
                    DecimalPlaces = decimalPlaces,
                    Maximum       = maximun,
                    Minimum       = minimun,
                    Increment     = increment,
                    TextAlign     = HorizontalAlignment.Right,
                    Location      = new Point(valueBox_x, 6 + index * 28),
                    Size          = new Size(100, 22),
                };
                lab.Location = new Point(8, 6 + index * 28 + 2);
            }

            if (control != null)
            {
                control.Tag = field;
            }
            page.Controls.Add(control);
            page.Controls.Add(lab);
            index++;

            return(control);
        }
Ejemplo n.º 15
0
        public VariabilityModel createVarModel()
        {
            VariabilityModel varMod = new VariabilityModel("testModel_1");

            // -------------------- BINARY OPTIONS ----------------
            BinaryOption binOp1 = new BinaryOption(varMod, "binOpt1");

            binOp1.Optional = false;
            binOp1.Prefix   = "--";
            varMod.addConfigurationOption(binOp1);


            BinaryOption binOp2 = new BinaryOption(varMod, "binOpt2");

            binOp2.Optional     = true;
            binOp2.Prefix       = "-?";
            binOp2.Postfix      = "kg";
            binOp2.Parent       = binOp1;
            binOp2.OutputString = "binOpt2";
            varMod.addConfigurationOption(binOp2);

            BinaryOption binOp3 = new BinaryOption(varMod, "binOpt3");

            binOp3.Optional = true;
            binOp3.Prefix   = "";
            binOp3.Postfix  = "";
            binOp3.Parent   = binOp1;
            List <List <ConfigurationOption> > exclude    = new List <List <ConfigurationOption> >();
            List <ConfigurationOption>         subExclude = new List <ConfigurationOption>();

            subExclude.Add(binOp2);
            exclude.Add(subExclude);
            binOp3.Excluded_Options = exclude;
            varMod.addConfigurationOption(binOp3);


            BinaryOption binOp4 = new BinaryOption(varMod, "binOpt4");

            binOp4.Optional = true;
            binOp4.Prefix   = "4_";
            binOp4.Postfix  = "_4";
            binOp4.Parent   = binOp1;
            List <List <ConfigurationOption> > implied    = new List <List <ConfigurationOption> >();
            List <ConfigurationOption>         subimplied = new List <ConfigurationOption>();

            subimplied.Add(binOp2);
            implied.Add(subimplied);
            binOp4.Implied_Options = implied;
            varMod.addConfigurationOption(binOp4);

            // -------------------- NUMERIC OPTIONS ----------------

            NumericOption numOpt1 = new NumericOption(varMod, "numOpt1");

            numOpt1.Prefix       = "num1-";
            numOpt1.Postfix      = "--";
            numOpt1.Min_value    = 0;
            numOpt1.Max_value    = 10;
            numOpt1.StepFunction = new InfluenceFunction("n + 2");
            varMod.addConfigurationOption(numOpt1);

            NumericOption numOpt2 = new NumericOption(varMod, "numOpt2");

            numOpt2.Prefix       = "";
            numOpt2.Postfix      = "";
            numOpt2.Min_value    = 0.1;
            numOpt2.Max_value    = 5;
            numOpt2.StepFunction = new InfluenceFunction("n * 2");
            varMod.addConfigurationOption(numOpt2);


            return(varMod);
        }