Пример #1
0
        void AddEditVar(ClSimplexSolver solver, ClVariable variable)
        {
            if (!isStay.ContainsKey(variable.Name))
            {
                isStay.Add(variable.Name, 1);
                solver.AddStay(variable);
                solver.AddEditVar(variable, ClStrength.Strong);
            }
            else
            {
                var status = isStay[variable.Name];

                if (status == 0)
                {
                    solver.AddEditVar(variable);
                    isStay[variable.Name] = 1;
                }
            }
        }
Пример #2
0
        bool AddEditVar(ClSimplexSolver solver, ClVariable variable, int value)
        {
            if (!isStay.ContainsKey(variable.Name))
            {
                isStay.Add(variable.Name, 0);
                variable.ChangeValue(value);

                solver.AddStay(variable);
                return(false);
            }
            else
            {
                var status = isStay[variable.Name];
                if (status == 0)
                {
                    solver.AddEditVar(variable);
                    isStay[variable.Name] = 1;
                }

                BeginEdit();
                solver.SuggestValue(variable, value);
                return(true);
            }
        }
Пример #3
0
        public static bool Multiedit()
        {
            try
            {
                bool okResult = true;

                ClVariable      x      = new ClVariable("x");
                ClVariable      y      = new ClVariable("y");
                ClVariable      w      = new ClVariable("w");
                ClVariable      h      = new ClVariable("h");
                ClSimplexSolver solver = new ClSimplexSolver();

                solver
                .AddStay(x)
                .AddStay(y)
                .AddStay(w)
                .AddStay(h);

                solver
                .AddEditVar(x)
                .AddEditVar(y)
                .BeginEdit();

                solver
                .SuggestValue(x, 10)
                .SuggestValue(y, 20)
                .Resolve();

                Console.WriteLine("x = " + x.Value + "; y = " + y.Value);
                Console.WriteLine("w = " + w.Value + "; h = " + h.Value);

                okResult = okResult &&
                           Cl.Approx(x, 10) && Cl.Approx(y, 20) &&
                           Cl.Approx(w, 0) && Cl.Approx(h, 0);

                solver
                .AddEditVar(w)
                .AddEditVar(h)
                .BeginEdit();

                solver
                .SuggestValue(w, 30)
                .SuggestValue(h, 40)
                .EndEdit();

                Console.WriteLine("x = " + x.Value + "; y = " + y.Value);
                Console.WriteLine("w = " + w.Value + "; h = " + h.Value);

                okResult = okResult &&
                           Cl.Approx(x, 10) && Cl.Approx(y, 20) &&
                           Cl.Approx(w, 30) && Cl.Approx(h, 40);

                solver
                .SuggestValue(x, 50)
                .SuggestValue(y, 60)
                .EndEdit();

                Console.WriteLine("x = " + x.Value + "; y = " + y.Value);
                Console.WriteLine("w = " + w.Value + "; h = " + h.Value);

                okResult = okResult &&
                           Cl.Approx(x, 50) && Cl.Approx(y, 60) &&
                           Cl.Approx(w, 30) && Cl.Approx(h, 40);

                return(okResult);
            }
            catch (ExClRequiredFailure)
            {
                // we want this exception to get thrown
                Console.WriteLine("-- got the exception");
                return(true);
            }
        }