public double MeasureHeight(T view, int width)
        {
            //var variable = GetCompositeVariableFromViewAndAttribute(view, view, LayoutAttribute.Width);
            var  variable    = GetVariableFromViewAndAttribute(view, LayoutAttribute.Right);
            bool editSession = AddEditVar(solver, variable, width);

            var height = MeasureHeight(view);

            if (editSession)
            {
                EndEdit();
            }
            solver.Resolve();

            return(height);
        }
Esempio n. 2
0
        protected override Size ArrangeOverride(Size finalSize)
        {
            SetValue(FindClVariableByUIElementAndProperty(this, "Width"),
                     finalSize.Width, ClStrength.Required);
            SetValue(FindClVariableByUIElementAndProperty(this, "Height"),
                     finalSize.Height, ClStrength.Required);

            foreach (UIElement child in InternalChildren)
            {
                SetValue(FindClVariableByUIElementAndProperty(child, "Width"),
                         child.DesiredSize.Width, ClStrength.Strong);
                SetValue(FindClVariableByUIElementAndProperty(child, "Height"),
                         child.DesiredSize.Height, ClStrength.Strong);
            }

            solver.Resolve();

            foreach (UIElement child in InternalChildren)
            {
                String Id = GetId(child);
                child.Arrange(new Rect(
                                  new Point(((ClVariable)ControlVariables[Id + "_X"]).Value,
                                            ((ClVariable)ControlVariables[Id + "_Y"]).Value),
                                  new Size(((ClVariable)ControlVariables[Id + "_Width"]).Value,
                                           ((ClVariable)ControlVariables[Id + "_Height"]).Value)));
            }
            return(finalSize);
        }
Esempio n. 3
0
        public static bool AddDel(int nCns, int nVars, int nResolves)
        {
            Timer  timer    = new Timer();
            double ineqProb = 0.12;
            int    maxVars  = 3;

            Console.WriteLine("starting timing test. nCns = " + nCns +
                              ", nVars = " + nVars + ", nResolves = " + nResolves);

            timer.Start();
            ClSimplexSolver solver = new ClSimplexSolver();

            ClVariable[] rgpclv = new ClVariable[nVars];
            for (int i = 0; i < nVars; i++)
            {
                rgpclv[i] = new ClVariable(i, "x");
                solver.AddStay(rgpclv[i]);
            }

            ClConstraint[] rgpcns = new ClConstraint[nCns];
            int            nvs    = 0;
            int            k;
            int            j;
            double         coeff;

            for (j = 0; j < nCns; j++)
            {
                // number of variables in this constraint
                nvs = RandomInRange(1, maxVars);
                ClLinearExpression expr = new ClLinearExpression(UniformRandomDiscretized() * 20.0 - 10.0);
                for (k = 0; k < nvs; k++)
                {
                    coeff = UniformRandomDiscretized() * 10 - 5;
                    int iclv = (int)(UniformRandomDiscretized() * nVars);
                    expr.AddExpression(Cl.Times(rgpclv[iclv], coeff));
                }
                if (UniformRandomDiscretized() < ineqProb)
                {
                    rgpcns[j] = new ClLinearInequality(expr);
                }
                else
                {
                    rgpcns[j] = new ClLinearEquation(expr);
                }
                if (Trace)
                {
                    TracePrint("Constraint " + j + " is " + rgpcns[j]);
                }
            }

            Console.WriteLine("done building data structures");
            Console.WriteLine("time = " + timer.ElapsedTime);
            timer.Start();
            int cExceptions = 0;

            for (j = 0; j < nCns; j++)
            {
                // add the constraint -- if it's incompatible, just ignore it
                try
                {
                    solver.AddConstraint(rgpcns[j]);
                }
                catch (ExClRequiredFailure)
                {
                    cExceptions++;
                    if (Trace)
                    {
                        TracePrint("got exception adding " + rgpcns[j]);
                    }

                    rgpcns[j] = null;
                }
            }
            Console.WriteLine("done adding constraints [" + cExceptions + " exceptions]");
            Console.WriteLine("time = " + timer.ElapsedTime + "\n");
            timer.Start();

            int e1Index = (int)(UniformRandomDiscretized() * nVars);
            int e2Index = (int)(UniformRandomDiscretized() * nVars);

            Console.WriteLine("indices " + e1Index + ", " + e2Index);

            ClEditConstraint edit1 = new ClEditConstraint(rgpclv[e1Index], ClStrength.Strong);
            ClEditConstraint edit2 = new ClEditConstraint(rgpclv[e2Index], ClStrength.Strong);

            solver
            .AddConstraint(edit1)
            .AddConstraint(edit2);

            Console.WriteLine("done creating edit constraints -- about to start resolves");
            Console.WriteLine("time = " + timer.ElapsedTime + "\n");
            timer.Start();

            for (int m = 0; m < nResolves; m++)
            {
                solver.Resolve(rgpclv[e1Index].Value * 1.001,
                               rgpclv[e2Index].Value * 1.001);
            }

            Console.WriteLine("done resolves -- now removing constraints");
            Console.WriteLine("time = " + timer.ElapsedTime + "\n");

            solver.RemoveConstraint(edit1);
            solver.RemoveConstraint(edit2);

            timer.Start();

            for (j = 0; j < nCns; j++)
            {
                if (rgpcns[j] != null)
                {
                    solver.RemoveConstraint(rgpcns[j]);
                }
            }

            Console.WriteLine("done removing constraints and AddDel timing test");
            Console.WriteLine("time = " + timer.ElapsedTime + "\n");

            timer.Start();

            return(true);
        }