public CatKind ConstraintToCatKind(Constraint c)
 {
     if (c is ScalarVar)
     {
         return new CatTypeVar(c.ToString());
     }
     else if (c is VectorVar)
     {
         return new CatStackVar(c.ToString());
     }
     else if (c is Vector)
     {
         return CatTypeVectorFromVec(c as Vector);
     }
     else if (c is Relation)
     {
         return CatFxnTypeFromRelation(c as Relation);
     }
     else if (c is RecursiveRelation)
     {
         return new CatRecursiveType();
     }
     else if (c is Constant)
     {
         // TODO: deal with CatCustomKinds
         return new CatSimpleTypeKind(c.ToString());
     }
     else
     {
         throw new Exception("unhandled constraint " + c.ToString());
     }
 }
Exemple #2
0
 public Column(string name, DataType type, Constraint constraint, bool primaryKey)
 {
     Name = name;
     Type = type;
     Constraint = constraint;
     PrimaryKey = primaryKey;
 }
        internal void Create(int numConstraints)
        {
            Vector = new Constraint[numConstraints];

            // Initialize this to out of range.
            firstActiveConstraintIndex = numConstraints;
        }
 public void GetSet_Unique()
 {
     var test = new Constraint("test", ContraintType.Constraint, new List<string>());
     var c = test.Unique;
     test.Unique = !c;
     Assert.Equal(!c, test.Unique);
 }
 public void No_PrimaryKey()
 {
     var c = new Constraint("ix_testing", ContraintType.Index, "testing");
     var test = new Table("test");
     test.Constraints.Add(c);
     Assert.Null(test.PrimaryKey);
 }
        /// <summary>
        /// Constructs a Posture Recognizer from a XML-File
        /// </summary>
        /// <param name="name">name of the given Posture (same as the XML-Source-File)</param>
        /// <param name="XMLPath">full path of the XML-Source-File</param>
        public GeneratedFromXMLPosture(String name, String xmlPath)
            : base(name)
        {
            try
            {
                //Load the XML-Document in a new XmlDocument-Object
                XmlDocument constraintsXML = new XmlDocument();
                constraintsXML.Load(xmlPath);

                //put Angle-Nodes from the XML to a XMLNodeList-Object
                XmlNodeList xmlConstraintsList;
                XmlNode root = constraintsXML.DocumentElement;
                xmlConstraintsList = root.SelectNodes("//posture/constraints/angle");

                //xmlConstraintsList -> constraints
                foreach (XmlNode newConstraint in xmlConstraintsList)
                {
                    Constraint newOne = new Constraint();

                    newOne.JointA = newConstraint.ChildNodes[0].InnerText;
                    newOne.JointB = newConstraint.ChildNodes[1].InnerText;
                    newOne.JointC = newConstraint.ChildNodes[2].InnerText;
                    newOne.min = Convert.ToInt16(newConstraint.ChildNodes[3].InnerText);
                    newOne.max = Convert.ToInt16(newConstraint.ChildNodes[4].InnerText);

                    constraints.Add(newOne);
                }

            }
            catch (Exception e)
            {
                Console.WriteLine("Sorry, could not read " + xmlPath + ". StackTrace following." + e.StackTrace);
            }
        }
 public void Set_PrimaryKey()
 {
     var c = new Constraint("ix_testing", ContraintType.PrimaryKey, "testing");
     var test = new Table("test");
     test.Constraints.Add(c);
     Assert.Equal(c, test.PrimaryKey);
 }
Exemple #8
0
 protected virtual void Visit(Constraint constraint)
 {
     switch (constraint.Type)
     {
         case ConstraintType.Empty:
             this.VisitEmpty(constraint as EmptyConstraint);
             break;
         case ConstraintType.Property:
             this.VisitProperty(constraint as PropertyConstraint);
             break;
         case ConstraintType.TwoPropertiesComparison:
             this.VisitTwoPropertiesComparison(constraint as TwoPropertiesConstraint);
             break;
         case ConstraintType.Sql:
             this.VisitSqlWhereConstraint(constraint as SqlWhereConstraint);
             break;
         case ConstraintType.AndOr:
             this.VisitAndOrConstraint(constraint as AndOrConstraint);
             break;
         case ConstraintType.Group:
             this.VisitGroup(constraint as ConstraintGroup);
             break;
         default:
             break;
     }
 }
Exemple #9
0
		public CSP(ArrayList variables, Constraint constraints, Domain domains) 
		{
			this.variables = variables;
			//this.assignment = new Assignment(variables);
			this.domains = domains;
			this.constraints = constraints;
		}
        public Constraint CombineConstraint(Constraint other, System.Linq.Expressions.ExpressionType op)
        {
            BooleanCombinationConstraint combinedConstraint = new BooleanCombinationConstraint(op);

            combinedConstraint.AddConstraint(this);
            combinedConstraint.AddConstraint(other);

            return combinedConstraint;
        }
        /// <summary>
        /// Constructs an AttributeConstraint for a specified attriute
        /// Type and base constraint.
        /// </summary>
        /// <param name="type"></param>
        /// <param name="baseConstraint"></param>
        public AttributeConstraint(Type type, Constraint baseConstraint)
            : base(baseConstraint)
        {
            this.expectedType = type;

            if (!typeof(Attribute).IsAssignableFrom(expectedType))
                throw new ArgumentException(string.Format(
                    "Type {0} is not an attribute", expectedType), "type");
        }
Exemple #12
0
 public static void IsValid(
     Constraint obj,
     MethodReturnEventArgs<bool> e,
     object constrainedObjectParam,
     object constrainedValueParam)
 {
     // the base constraint accepts all values
     e.Result = true;
 }
Exemple #13
0
		public void ShowPopup(View popupView, Constraint xConstraint, Constraint yConstraint, Constraint widthConstraint = null, Constraint heightConstraint = null)
		{
			DismissPopup();
			_popup = popupView;

			_content.InputTransparent = true;
			Children.Add(_popup, xConstraint, yConstraint, widthConstraint, heightConstraint);

			UpdateChildrenLayout();
		}
        public override VersionRangePart Intersects(Constraint constraint)
        {
            #region Sanity checks
            if (constraint == null) throw new ArgumentNullException("constraint");
            #endregion

            // If the exact version lies within the constraint, the exact version remains
            if (constraint.NotBefore != null && _version < constraint.NotBefore) return null;
            if (constraint.Before != null && _version >= constraint.Before) return null;
            return this;
        }
        private void SwapConstraint(Constraint constraint)
        {
            // Swap out the constraint at the current active/inactive border index (which has been updated
            // according to the direction we're moving it).
            Constraint swapConstraint = Vector[firstActiveConstraintIndex];
            swapConstraint.SetVectorIndex(constraint.VectorIndex);
            Vector[constraint.VectorIndex] = swapConstraint;

            // Toggle the state of the constraint being updated.
            Vector[firstActiveConstraintIndex] = constraint;
            constraint.SetActiveState(!constraint.IsActive, firstActiveConstraintIndex);
        }
Exemple #16
0
        public void CanIgnoreTable()
        {
            var db = new Database();
            var table = new Table("dbo", "IgnoredTableWithConstraints");
            var constraint = new Constraint("TestConstraint", "", "");
            table.Constraints.Add(constraint);
            db.DataTables.Add(table);

            db.Ignore(new[] { "IgnoredTableWithConstraints" });

            db.Tables.Any().Should().BeFalse();
        }
 public static SubSpace FromPoint(params double[] coordinates)
 {
     //foreach coordinate, one constraint x[i]=coordinate[y], and the term??
     Constraint[] constraints=new Constraint[coordinates.Length];
     for (int i = 0; i < coordinates.Length; i++)
     {
         double[] constraintCoeffs=new double[coordinates.Length];
         constraintCoeffs[i] = coordinates[i];
         constraints[i] = new DefaultConstraint(constraintCoeffs);
     }
     return new SubSpace(constraints);
 }
        internal DfDvNode Set(DfDvNode parent, Constraint constraintToEval, Variable variableToEval, Variable variableDoneEval)
        {
            this.Parent = parent;
            this.ConstraintToEval = constraintToEval;
            this.VariableToEval = variableToEval;
            this.VariableDoneEval = variableDoneEval;
            this.Depth = 0;
            this.ChildrenHaveBeenPushed = false;

            constraintToEval.Lagrangian = 0.0;
            return this;
        }
        internal void DeactivateConstraint(Constraint constraint)
        {
            Debug.Assert(constraint.IsActive, "Constraint is not active");

            // Swap it from the active region to the end of the inactive region of the Vector.
            Debug.Assert(firstActiveConstraintIndex < Vector.Length, "All constraints are already inactive");
            Debug.Assert(Vector[firstActiveConstraintIndex].IsActive, "Constraint in active region is not active");

            SwapConstraint(constraint);
            ++firstActiveConstraintIndex;

            //Debug_AssertConsistency();
        }
        internal void ActivateConstraint(Constraint constraint)
        {
            Debug.Assert(!constraint.IsActive, "Constraint is already active");

            // Swap it from the inactive region to the start of the active region of the Vector.
            Debug.Assert(firstActiveConstraintIndex > 0, "All constraints are already active");
            --firstActiveConstraintIndex;
            Debug.Assert(!Vector[firstActiveConstraintIndex].IsActive, "Constraint in inactive region is active");

            SwapConstraint(constraint);

            //Debug_AssertConsistency();
        }
 public void ValidateConstraint(Element element, Constraint constraint)
 {
     if (constraint.IsValid)
     {
         report.Add("Constraint", Kind.Valid, "Constraint is valid");
     }
     else 
     {
          report.Add("Constraint", Kind.Failed, 
              "Constraint [{0}] ({1}) has an invalid XPath: {2}", 
              constraint.Name, constraint.HumanReadable, constraint.CompilerError.Message);
     }
 }
 public override void VisitConstraint(Constraint constraint)
 {
     VisitChildrenToFormat (constraint, node => {
         if (node is AstType) {
             node.AcceptVisitor (this);
         } else if (node.Role == Roles.LPar) {
             ForceSpacesBefore (node, false);
             ForceSpacesAfter (node, false);
         } else if (node.Role ==Roles.Comma) {
             ForceSpacesBefore (node, false);
             ForceSpacesAfter (node, true);
         }
     });
 }
        public override bool Equals(Constraint other)
        {
            if (!base.Equals(other))
            {
                return false;
            }

            ConstraintGroup otherAsGroup = other as ConstraintGroup;

            bool isEqual = true;
            0.UpTo(Members.Count, ii => isEqual = Members[ii].Equals(otherAsGroup.Members[ii]));

            return isEqual;
        }
            public void AddSubstitution(Substitution s)
            {
                Constraint c;
                bool needsBuild = !m_constraints.TryGetValue(s.Variable, out c);

                if (s.Value.IsVariable)
                {
                    Constraint c2;
                    if (m_constraints.TryGetValue(s.Value, out c2))
                    {
                        if (needsBuild)
                        {
                            m_constraints[s.Variable] = c2;
                            c2.EquivalentVariables.Add(s.Variable);
                        }
                        else if (!Object.ReferenceEquals(c, c2))
                        {
                            c2.UnionWith(c);
                            foreach (var v in c2.EquivalentVariables)
                                m_constraints[v] = c2;
                        }
                    }
                    else
                    {
                        if (needsBuild)
                        {
                            c = new Constraint();
                            m_constraints[s.Variable] = c;
                            c.EquivalentVariables.Add(s.Variable);
                        }

                        m_constraints[s.Value] = c;
                        c.EquivalentVariables.Add(s.Value);
                    }
                }
                else
                {
                    if (needsBuild)
                    {
                        c = new Constraint();
                        m_constraints[s.Variable] = c;
                        c.EquivalentVariables.Add(s.Variable);
                    }

                    c.Value = s.Value;
                }

                m_substitutions.Add(s);
                m_hashIsDirty = true;
            }
        public Student(EnrollCore core, int id, string clazz, int classno, string name)
        {
            this._core = core;
            this.id = id;
            Class = clazz.Trim();
            ClassNo = classno;
            Name = name.Trim();

            Quota = new Constraint(1);

            if (clazz.Length != 2 || classno <= 0 || name.Length == 0) {
                throw new ArgumentException();
            }
        }
        public void Setup()
        {
            mockAttributeBag = new Mock<IAttributeBag>();
            findBy = null;

            findBy1 = Find.By("1", "true");
            findBy2 = Find.By("2", "true");
            findBy3 = Find.By("3", "true");
            findBy4 = Find.By("4", "true");
            findBy5 = Find.By("5", "true");
            findBy6 = Find.By("6", "true");
            findBy7 = Find.By("7", "true");
            findBy8 = Find.By("8", "true");
        }
Exemple #27
0
 public void Create_Script()
 {
     var c = new Column("testing", ColumnTypes.Integer, true, null);
     var cc = new Constraint("ix_testing", ContraintType.Index, "testing");
     var test = new Table("test");
     test.Constraints.Add(cc);
     test.Columns.Add(c);
     //set the table reference
     foreach (var ccc in test.Constraints)
     {
         ccc.Table = test.Info;
     }
     Assert.Contains("test", test.Script());
 }
        public void Setup()
        {
            mockAttributeBag = new MockAttributeBag("1", "true");
            mockAttributeBag.Add("2","false");
            mockAttributeBag.Add("4", "true");
            mockAttributeBag.Add("5", "false");

            findBy = null;

            findBy1 = Find.By("1", "true");
            findBy2 = Find.By("2", "true");
            findBy3 = Find.By("3", "true");
            findBy4 = Find.By("4", "true");
            findBy5 = Find.By("5", "true");
        }
        public void ReadConstraints(Element element, XPathNavigator node)
        {
            foreach (XPathNavigator nav in node.Select("f:definition/f:constraint", ns))
            {
                Constraint constraint = new Constraint();
                
                XPathNavigator xName = nav.SelectSingleNode("f:name/@value", ns);
                string key = OptionalValue(nav, "f:key/@value");
                constraint.Name = (xName != null) ? xName.Value : element.Path+", Key:"+key;

                constraint.XPath = nav.SelectSingleNode("f:xpath/@value", ns).Value;
                constraint.HumanReadable = OptionalValue(nav, "f:human/@value");
                element.Constraints.Add(constraint);
            }   
        }
 public static void Compile(Constraint constraint)
 {
     try
     {
         constraint.Compiled = true;
         var expr = XPathExpression.Compile(constraint.XPath);
         expr.SetContext(FhirNamespaceManager.CreateManager());
         constraint.Expression = expr;
         constraint.IsValid = true;
     }
     catch (Exception e)
     {
         constraint.CompilerError = e;
         constraint.IsValid = false;
     }
 }
 public FileUpload FileUpload(Constraint findBy)
 {
     return(All.FileUpload(findBy));
 }
 public Label Label(Constraint findBy)
 {
     return(All.Label(findBy));
 }
 public Form Form(Constraint findBy)
 {
     return(All.Form(findBy));
 }
 public TChildElement ElementOfType <TChildElement>(Constraint findBy) where TChildElement : Element
 {
     return(All.ElementOfType <TChildElement>(findBy));
 }
 public Link Link(Constraint findBy)
 {
     return(All.Link(findBy));
 }
 public CheckBox CheckBox(Constraint findBy)
 {
     return(All.CheckBox(findBy));
 }
 public TextField TextField(Constraint findBy)
 {
     return(All.TextField(findBy));
 }
 public Area Area(Constraint findBy)
 {
     return(All.Area(findBy));
 }
        public void GreaterIntExprAndScalar()
        {
            Solver solver = new Solver("Solver");
            IntVar x      = solver.MakeIntVar(3, 13, "x");

            Assert.Equal(3, x.Min());
            Assert.Equal(13, x.Max());

            // Arithmetic operator with a scalar
            IntExpr e2a = (x >= 7) + 1;

            Assert.Equal("(Watch<x >= 7>(0 .. 1) + 1)", e2a.ToString());
            IntExpr e2b = 1 + (x >= 7);

            Assert.Equal("(Watch<x >= 7>(0 .. 1) + 1)", e2b.ToString());

            IntExpr e2c = (x >= 7) - 1;

            Assert.Equal("(Watch<x >= 7>(0 .. 1) + -1)", e2c.ToString());
            IntExpr e2d = 1 - (x >= 7);

            Assert.Equal("Not(Watch<x >= 7>(0 .. 1))", e2d.ToString());

            IntExpr e2e = (x >= 7) * 2;

            Assert.Equal("(Watch<x >= 7>(0 .. 1) * 2)", e2e.ToString());
            IntExpr e2f = 2 * (x >= 7);

            Assert.Equal("(Watch<x >= 7>(0 .. 1) * 2)", e2f.ToString());

            // Relational operator with a scalar
            Constraint c8a = (x >= 7) == 1;

            Assert.Equal("(Watch<x >= 7>(0 .. 1) == 1)", c8a.ToString());
            Constraint c8b = 1 == (x >= 7);

            Assert.Equal("(Watch<x >= 7>(0 .. 1) == 1)", c8b.ToString());

            Constraint c8c = (x >= 7) != 1;

            Assert.Equal("(Watch<x >= 7>(0 .. 1) != 1)", c8c.ToString());
            Constraint c8d = 1 != (x >= 7);

            Assert.Equal("(Watch<x >= 7>(0 .. 1) != 1)", c8d.ToString());

            Constraint c8e = (x >= 7) >= 1;

            Assert.Equal("(Watch<x >= 7>(0 .. 1) >= 1)", c8e.ToString());
            Constraint c8f = 1 >= (x >= 7);

            Assert.Equal("TrueConstraint()", c8f.ToString());

            Constraint c8g = (x >= 7) > 1;

            Assert.Equal("FalseConstraint()", c8g.ToString());
            Constraint c8h = 1 > (x >= 7);

            Assert.Equal("(Watch<x >= 7>(0 .. 1) <= 0)", c8h.ToString());

            Constraint c8i = (x >= 7) <= 1;

            Assert.Equal("TrueConstraint()", c8i.ToString());
            Constraint c8j = 1 <= (x >= 7);

            Assert.Equal("(Watch<x >= 7>(0 .. 1) >= 1)", c8j.ToString());

            Constraint c8k = (x >= 7) < 1;

            Assert.Equal("(Watch<x >= 7>(0 .. 1) <= 0)", c8k.ToString());
            Constraint c8l = 1 < (x >= 7);

            Assert.Equal("FalseConstraint()", c8l.ToString());
        }
 public Button Button(Constraint findBy)
 {
     return(All.Button(findBy));
 }
 public Table Table(Constraint findBy)
 {
     return(All.Table(findBy));
 }
 public TableBody TableBody(Constraint findBy)
 {
     return(All.TableBody(findBy));
 }
 public TableCell TableCell(Constraint findBy)
 {
     return(All.TableCell(findBy));
 }
 public TableRow TableRow(Constraint findBy)
 {
     return(All.TableRow(findBy));
 }
 public Element ElementWithTag(string tagName, Constraint findBy, params string[] inputTypes)
 {
     return(All.ElementWithTag(tagName, findBy, inputTypes));
 }
        public void ConstraintAndIntVar()
        {
            Solver solver = new Solver("Solver");
            IntVar x      = solver.MakeIntVar(3, 13, "x");

            Assert.Equal(3, x.Min());
            Assert.Equal(13, x.Max());

            Constraint c1 = x == 7;

            Assert.Equal("(x(3..13) == 7)", c1.ToString());

            IntVar y = solver.MakeIntVar(5, 17, "y");

            Assert.Equal(5, y.Min());
            Assert.Equal(17, y.Max());

            // Arithmetic operator with IntVar
            IntExpr e3a = c1 + y;

            Assert.Equal("(Watch<x == 7>(0 .. 1) + y(5..17))", e3a.ToString());
            IntExpr e3b = y + c1;

            Assert.Equal("(Watch<x == 7>(0 .. 1) + y(5..17))", e3b.ToString());

            IntExpr e3c = c1 - y;

            Assert.Equal("(Watch<x == 7>(0 .. 1) - y(5..17))", e3c.ToString());
            IntExpr e3d = y - c1;

            Assert.Equal("(y(5..17) - Watch<x == 7>(0 .. 1))", e3d.ToString());

            IntExpr e3e = c1 * y;

            Assert.Equal("(Watch<x == 7>(0 .. 1) * y(5..17))", e3e.ToString());
            IntExpr e3f = y * c1;

            Assert.Equal("(Watch<x == 7>(0 .. 1) * y(5..17))", e3f.ToString());

            // Relational operator with an IntVar
            Constraint c9a = c1 == y;

            Assert.Equal("Watch<x == 7>(0 .. 1) == y(5..17)", c9a.ToString());
            Constraint c9b = y == c1;

            Assert.Equal("y(5..17) == Watch<x == 7>(0 .. 1)", c9b.ToString());

            Constraint c9c = c1 != y;

            Assert.Equal("Watch<x == 7>(0 .. 1) != y(5..17)", c9c.ToString());
            Constraint c9d = y != c1;

            Assert.Equal("y(5..17) != Watch<x == 7>(0 .. 1)", c9d.ToString());

            Constraint c9e = c1 >= y;

            Assert.Equal("y(5..17) <= Watch<x == 7>(0 .. 1)", c9e.ToString());
            Constraint c9f = y >= c1;

            Assert.Equal("Watch<x == 7>(0 .. 1) <= y(5..17)", c9f.ToString());

            Constraint c9g = c1 > y;

            Assert.Equal("y(5..17) < Watch<x == 7>(0 .. 1)", c9g.ToString());
            Constraint c9h = y > c1;

            Assert.Equal("Watch<x == 7>(0 .. 1) < y(5..17)", c9h.ToString());

            Constraint c9i = c1 <= y;

            Assert.Equal("Watch<x == 7>(0 .. 1) <= y(5..17)", c9i.ToString());
            Constraint c9j = y <= c1;

            Assert.Equal("y(5..17) <= Watch<x == 7>(0 .. 1)", c9j.ToString());

            Constraint c9k = c1 < y;

            Assert.Equal("Watch<x == 7>(0 .. 1) < y(5..17)", c9k.ToString());
            Constraint c9l = y < c1;

            Assert.Equal("y(5..17) < Watch<x == 7>(0 .. 1)", c9l.ToString());
        }
 public Element Element(Constraint findBy)
 {
     return(All.Element(findBy));
 }
 public TControl Control <TControl>(Constraint findBy) where TControl : Control, new()
 {
     return(All.Control <TControl>(findBy));
 }
 public SelectList SelectList(Constraint findBy)
 {
     return(All.SelectList(findBy));
 }
        private void Setup()
        {
            Title = ViewModel.InitialTitle;
            // image
            this.ContentViewImage.Content = this.ImageContentManage;


            // Toolbar items
            this.ToolbarItems.Add(ToolbarUser);


            // GridButtons
            // grid.Children.Add(item ,col, col+colSpan, row, row+rowspan)
            this.GridButtons.Children.Add(ImageButtonUploadPhotos, 0, 1, 0, 1);
            this.GridButtons.Children.Add(ImageButtonDeletePhotos, 1, 2, 0, 1);
            this.GridButtons.Children.Add(ButtonSubscribe, 0, 2, 1, 2);


            // Label wrapping is buggy, so we put the wrapped label in 1x1 grid
            var gridSummary = new Grid {
                RowDefinitions =
                {
                    new RowDefinition {
                        Height = new GridLength(1, GridUnitType.Auto)
                    },                                                                           // row 0
                    new RowDefinition {
                        Height = new GridLength(1, GridUnitType.Auto)
                    },                                                                           // row 1
                }
            };

            gridSummary.Children.Add(this.LabelURL, 0, 0);
            gridSummary.Children.Add(this.LabelMessage, 0, 1);

            // flexlayout
            this.FlexLayoutMainContent.Children.Add(this.ContentViewImage);
            this.FlexLayoutMainContent.Children.Add(this.LabelInstruction);
            this.FlexLayoutMainContent.Children.Add(gridSummary);
            this.FlexLayoutMainContent.Children.Add(this.GridButtons);

            this.ScrollViewContent.Content = new StackLayout {
                Children =
                {
                    this.FlexLayoutMainContent,
                }
            };

            RelativeLayout relativelayout = new RelativeLayout();

            // stack
            relativelayout.Children.Add(ScrollViewContent, Constraint.Constant(0), Constraint.Constant(0),
                                        Constraint.RelativeToParent((parent) => {
                return(parent.Width);
            }), Constraint.RelativeToParent((parent) => {
                return(parent.Height);
            }));

            // loading
            relativelayout.Children.Add(CustomActivityIndicator, Constraint.Constant(0), Constraint.Constant(0),
                                        Constraint.RelativeToParent((parent) => {
                return(parent.Width);
            }), Constraint.RelativeToParent((parent) => {
                return(parent.Height);
            }));

            Content = relativelayout;
        }
        public void GreaterIntExprAndIntVar()
        {
            Solver solver = new Solver("Solver");
            IntVar x      = solver.MakeIntVar(3, 13, "x");

            Assert.Equal(3, x.Min());
            Assert.Equal(13, x.Max());

            IntVar y = solver.MakeIntVar(5, 17, "y");

            Assert.Equal(5, y.Min());
            Assert.Equal(17, y.Max());

            // Arithmetic operator with IntVar
            IntExpr e3a = (x >= 7) + y;

            Assert.Equal("(Watch<x >= 7>(0 .. 1) + y(5..17))", e3a.ToString());
            IntExpr e3b = y + (x >= 7);

            Assert.Equal("(Watch<x >= 7>(0 .. 1) + y(5..17))", e3b.ToString());

            IntExpr e3c = (x >= 7) - y;

            Assert.Equal("(Watch<x >= 7>(0 .. 1) - y(5..17))", e3c.ToString());
            IntExpr e3d = y - (x >= 7);

            Assert.Equal("(y(5..17) - Watch<x >= 7>(0 .. 1))", e3d.ToString());

            IntExpr e3e = (x >= 7) * y;

            Assert.Equal("(Watch<x >= 7>(0 .. 1) * y(5..17))", e3e.ToString());
            IntExpr e3f = y * (x >= 7);

            Assert.Equal("(Watch<x >= 7>(0 .. 1) * y(5..17))", e3f.ToString());

            // Relational operator with an IntVar
            Constraint c9a = (x >= 7) == y;

            Assert.Equal("Watch<x >= 7>(0 .. 1) == y(5..17)", c9a.ToString());
            Constraint c9b = y == (x >= 7);

            Assert.Equal("y(5..17) == Watch<x >= 7>(0 .. 1)", c9b.ToString());

            Constraint c9c = (x >= 7) != y;

            Assert.Equal("Watch<x >= 7>(0 .. 1) != y(5..17)", c9c.ToString());
            Constraint c9d = y != (x >= 7);

            Assert.Equal("y(5..17) != Watch<x >= 7>(0 .. 1)", c9d.ToString());

            Constraint c9e = (x >= 7) >= y;

            Assert.Equal("y(5..17) <= Watch<x >= 7>(0 .. 1)", c9e.ToString());
            Constraint c9f = y >= (x >= 7);

            Assert.Equal("Watch<x >= 7>(0 .. 1) <= y(5..17)", c9f.ToString());

            Constraint c9g = (x >= 7) > y;

            Assert.Equal("y(5..17) < Watch<x >= 7>(0 .. 1)", c9g.ToString());
            Constraint c9h = y > (x >= 7);

            Assert.Equal("Watch<x >= 7>(0 .. 1) < y(5..17)", c9h.ToString());

            Constraint c9i = (x >= 7) <= y;

            Assert.Equal("Watch<x >= 7>(0 .. 1) <= y(5..17)", c9i.ToString());
            Constraint c9j = y <= (x >= 7);

            Assert.Equal("y(5..17) <= Watch<x >= 7>(0 .. 1)", c9j.ToString());

            Constraint c9k = (x >= 7) < y;

            Assert.Equal("Watch<x >= 7>(0 .. 1) < y(5..17)", c9k.ToString());
            Constraint c9l = y < (x >= 7);

            Assert.Equal("y(5..17) < Watch<x >= 7>(0 .. 1)", c9l.ToString());
        }
 public RadioButton RadioButton(Constraint findBy)
 {
     return(All.RadioButton(findBy));
 }
        public void ConstraintAndIntExpr()
        {
            Solver solver = new Solver("Solver");
            IntVar x      = solver.MakeIntVar(3, 13, "x");

            Assert.Equal(3, x.Min());
            Assert.Equal(13, x.Max());
            Constraint c1 = x == 7;

            Assert.Equal("(x(3..13) == 7)", c1.ToString());

            IntVar y = solver.MakeIntVar(5, 17, "y");

            Assert.Equal(5, y.Min());
            Assert.Equal(17, y.Max());

            // Arithmetic operator with an IntExpr
            IntExpr e11a = c1 + (y == 11);

            Assert.Equal("(Watch<x == 7>(0 .. 1) + Watch<y == 11>(0 .. 1))", e11a.ToString());
            IntExpr e11b = (y == 11) + c1;

            Assert.Equal("(Watch<x == 7>(0 .. 1) + Watch<y == 11>(0 .. 1))", e11b.ToString());
            IntExpr e11c = c1 - (y == 11);

            Assert.Equal("(Watch<x == 7>(0 .. 1) - Watch<y == 11>(0 .. 1))", e11c.ToString());
            IntExpr e11d = (y == 11) - c1;

            Assert.Equal("(Watch<y == 11>(0 .. 1) - Watch<x == 7>(0 .. 1))", e11d.ToString());
            IntExpr e11e = c1 * (y == 11);

            Assert.Equal("(Watch<x == 7>(0 .. 1) * Watch<y == 11>(0 .. 1))", e11e.ToString());
            IntExpr e11f = (y == 11) * c1;

            Assert.Equal("(Watch<x == 7>(0 .. 1) * Watch<y == 11>(0 .. 1))", e11f.ToString());

            // Relational operator with an IntExpr
            Constraint c12a = c1 == (y == 11);

            Assert.Equal("Watch<x == 7>(0 .. 1) == Watch<y == 11>(0 .. 1)", c12a.ToString());
            Constraint c12b = (y == 11) == c1;

            Assert.Equal("Watch<y == 11>(0 .. 1) == Watch<x == 7>(0 .. 1)", c12b.ToString());
            Constraint c12c = c1 != (y == 11);

            Assert.Equal("Watch<x == 7>(0 .. 1) != Watch<y == 11>(0 .. 1)", c12c.ToString());
            Constraint c12d = (y == 11) != c1;

            Assert.Equal("Watch<y == 11>(0 .. 1) != Watch<x == 7>(0 .. 1)", c12d.ToString());
            Constraint c12e = c1 >= (y == 11);

            Assert.Equal("Watch<y == 11>(0 .. 1) <= Watch<x == 7>(0 .. 1)", c12e.ToString());
            Constraint c12f = (y == 11) >= c1;

            Assert.Equal("Watch<x == 7>(0 .. 1) <= Watch<y == 11>(0 .. 1)", c12f.ToString());
            Constraint c12g = c1 > (y == 11);

            Assert.Equal("Watch<y == 11>(0 .. 1) < Watch<x == 7>(0 .. 1)", c12g.ToString());
            Constraint c12h = (y == 11) > c1;

            Assert.Equal("Watch<x == 7>(0 .. 1) < Watch<y == 11>(0 .. 1)", c12h.ToString());
            Constraint c12i = c1 <= (y == 11);

            Assert.Equal("Watch<x == 7>(0 .. 1) <= Watch<y == 11>(0 .. 1)", c12i.ToString());
            Constraint c12j = (y == 11) <= c1;

            Assert.Equal("Watch<y == 11>(0 .. 1) <= Watch<x == 7>(0 .. 1)", c12j.ToString());
            Constraint c12k = c1 < (y == 11);

            Assert.Equal("Watch<x == 7>(0 .. 1) < Watch<y == 11>(0 .. 1)", c12k.ToString());
            Constraint c12l = (y == 11) < c1;

            Assert.Equal("Watch<y == 11>(0 .. 1) < Watch<x == 7>(0 .. 1)", c12l.ToString());
        }
Exemple #54
0
        public CameraPage()
        {
            BindingContext = captureModel = new CaptureViewModel();
            Title          = "Camera";
            layout         = new RelativeLayout();

            if (CrossMedia.Current.IsCameraAvailable)
            {
                BackgroundColor = Color.Black;

                // Camera Preview
                cameraPreview = new XCameraView();
                //cameraPreview.CameraOption = Settings.CameraOption;
                cameraPreview.CaptureBytesCallback = new Action <byte[]>(ProcessCameraPhoto);
                cameraPreview.CameraReady         += (s, e) => StartCamera();

                layout.Children.Add(cameraPreview,
                                    Constraint.Constant(0),
                                    Constraint.RelativeToParent((parent) =>
                {
                    var viewHeight = MathUtils.FitSize4X3(parent.Width, parent.Height).Height;
                    return(parent.Height / 2 - viewHeight / 2);
                }),
                                    Constraint.RelativeToParent((parent) =>
                {
                    return(MathUtils.FitSize4X3(parent.Width, parent.Height).Width);
                }),
                                    Constraint.RelativeToParent((parent) =>
                {
                    return(MathUtils.FitSize4X3(parent.Width, parent.Height).Height);
                }));

                // Capture Button
                var buttonSize    = 60;
                var captureButton = new Button();
                captureButton.Clicked          += CaptureButton_Clicked;
                captureButton.BackgroundColor   = Color.LightGray.MultiplyAlpha(.5);
                captureButton.WidthRequest      = buttonSize;
                captureButton.HeightRequest     = buttonSize;
                captureButton.CornerRadius      = buttonSize / 2;
                captureButton.BorderWidth       = 1;
                captureButton.BorderColor       = Color.DarkGray;
                captureButton.HorizontalOptions = LayoutOptions.Center;

                layout.Children.Add(captureButton,
                                    Constraint.RelativeToParent((parent) => { return((parent.Width * .5) - (buttonSize * .5)); }),
                                    Constraint.RelativeToParent((parent) => { return((parent.Height * .9) - (buttonSize * .5)); }));

                // Last Capture
                cachedCapture                 = new CachedImage();
                cachedCapture.Aspect          = Aspect.AspectFill;
                cachedCapture.BackgroundColor = Color.White;

                layout.Children.Add(cachedCapture,
                                    Constraint.Constant(20),
                                    Constraint.RelativeToView(captureButton, (parent, sibling) => { return(sibling.Y); }),
                                    Constraint.Constant(buttonSize),
                                    Constraint.Constant(buttonSize));

                this.ToolbarItems.Add(
                    new ToolbarItem("Toggle", null, () => ToggleCamera())
                {
                    Icon = "toggle.png"
                }
                    );
            }

            else
            {
                messageLabel = new Label()
                {
                    WidthRequest            = 300,
                    TextColor               = Color.SlateGray,
                    HorizontalOptions       = LayoutOptions.Center,
                    HorizontalTextAlignment = TextAlignment.Center
                };
                messageLabel.Text = "The camera not supported on this device.";

                layout.Children.Add(messageLabel,
                                    Constraint.RelativeToParent((parent) =>
                {
                    return(parent.Width * .5 - messageLabel.Width * .5);
                }),
                                    Constraint.RelativeToParent((parent) =>
                {
                    return(parent.Height * .4);
                })
                                    );

                titleLabel = new Label()
                {
                    WidthRequest            = 300,
                    HeightRequest           = 20,
                    FontAttributes          = FontAttributes.Bold,
                    TextColor               = Color.Black,
                    HorizontalOptions       = LayoutOptions.Center,
                    HorizontalTextAlignment = TextAlignment.Center
                };
                titleLabel.Text = "No Camera";
                layout.Children.Add(titleLabel,
                                    Constraint.RelativeToParent((parent) =>
                {
                    return(parent.Width * .5 - titleLabel.Width * .5);
                }),
                                    Constraint.RelativeToView(messageLabel, (parent, sibling) =>
                {
                    return(sibling.Y - titleLabel.Height - 10);
                })
                                    );
            }

            Content = layout;
        }
        public void ConstraintAndScalar()
        {
            Solver solver = new Solver("Solver");
            IntVar x      = solver.MakeIntVar(3, 13, "x");

            Assert.Equal(3, x.Min());
            Assert.Equal(13, x.Max());

            Constraint c1 = (x == 7);

            Assert.Equal("(x(3..13) == 7)", c1.ToString());

            // Arithmetic operator with a scalar
            IntExpr e2a = c1 + 1;

            Assert.Equal("(Watch<x == 7>(0 .. 1) + 1)", e2a.ToString());
            IntExpr e2b = 1 + c1;

            Assert.Equal("(Watch<x == 7>(0 .. 1) + 1)", e2b.ToString());

            IntExpr e2c = c1 - 1;

            Assert.Equal("(Watch<x == 7>(0 .. 1) + -1)", e2c.ToString());
            IntExpr e2d = 1 - c1;

            Assert.Equal("Not(Watch<x == 7>(0 .. 1))", e2d.ToString());

            IntExpr e2e = c1 * 2;

            Assert.Equal("(Watch<x == 7>(0 .. 1) * 2)", e2e.ToString());
            IntExpr e2f = 2 * c1;

            Assert.Equal("(Watch<x == 7>(0 .. 1) * 2)", e2f.ToString());

            IntExpr e2g = c1 / 4;

            Assert.Equal("(Watch<x == 7>(0 .. 1) div 4)", e2g.ToString());

            // Relational operator with a scalar
            Constraint c8a = c1 == 1;

            Assert.Equal("(Watch<x == 7>(0 .. 1) == 1)", c8a.ToString());
            Constraint c8b = 1 == c1;

            Assert.Equal("(Watch<x == 7>(0 .. 1) == 1)", c8b.ToString());

            Constraint c8c = c1 != 1;

            Assert.Equal("(Watch<x == 7>(0 .. 1) != 1)", c8c.ToString());
            Constraint c8d = 1 != c1;

            Assert.Equal("(Watch<x == 7>(0 .. 1) != 1)", c8d.ToString());

            Constraint c8e = c1 >= 1;

            Assert.Equal("(Watch<x == 7>(0 .. 1) >= 1)", c8e.ToString());
            Constraint c8f = 1 >= c1;

            Assert.Equal("TrueConstraint()", c8f.ToString());

            Constraint c8g = c1 > 1;

            Assert.Equal("FalseConstraint()", c8g.ToString());
            Constraint c8h = 1 > c1;

            Assert.Equal("(Watch<x == 7>(0 .. 1) <= 0)", c8h.ToString());

            Constraint c8i = c1 <= 1;

            Assert.Equal("TrueConstraint()", c8i.ToString());
            Constraint c8j = 1 <= c1;

            Assert.Equal("(Watch<x == 7>(0 .. 1) >= 1)", c8j.ToString());

            Constraint c8k = c1 < 1;

            Assert.Equal("(Watch<x == 7>(0 .. 1) <= 0)", c8k.ToString());
            Constraint c8l = 1 < c1;

            Assert.Equal("FalseConstraint()", c8l.ToString());
        }
 public Div Div(Constraint findBy)
 {
     return(All.Div(findBy));
 }
 public Para Para(Constraint findBy)
 {
     return(All.Para(findBy));
 }
 public Image Image(Constraint findBy)
 {
     return(All.Image(findBy));
 }
 public RenameConfiguration GetConstraintRenameConfiguration(Constraint constraint)
 {
     return(this.ConstraintsToRename.FirstOrDefault(x => x.Name == constraint.Name));
 }
 public Span Span(Constraint findBy)
 {
     return(All.Span(findBy));
 }