コード例 #1
0
 /// <summary>
 /// Initializes a variable with a variable name.
 /// </summary>
 protected VariableModel(BundleModel bundle, ModelName variableName)
     : base(variableName)
 {
     Workspace        = bundle.Workspace;
     Parent           = bundle;
     DomainExpression = new VariableDomainExpressionModel();
 }
コード例 #2
0
        /// <summary>
        /// Validate the constraint expression.
        /// </summary>
        /// <param name="bundle">Model to validate.</param>
        /// <param name="theContext">Validation context to capture the errors.</param>
        /// <returns>
        /// Return true if the constraint is valid, return false if
        /// the constraint is not valid.
        /// </returns>
        public override bool Validate(BundleModel bundle, ModelValidationContext theContext)
        {
            if (Expression.Node == null)
            {
                return(false);
            }

            var variableCaptureVisitor = new ConstraintVariableReferenceCaptureVisitor();

            Expression.Node.AcceptVisitor(variableCaptureVisitor);
            var variableReferences = variableCaptureVisitor.GetReferences();

            foreach (var singletonVariableReference in variableReferences.SingletonVariableReferences)
            {
                if (bundle.Variables.FirstOrDefault(_ => _.Name.IsEqualTo(singletonVariableReference.VariableName)) == null)
                {
                    theContext.AddError($"Missing singleton variable {singletonVariableReference.VariableName}");
                    return(false);
                }
            }

            foreach (var aggregateVariableReference in variableReferences.AggregateVariableReferences)
            {
                if (bundle.Aggregates.FirstOrDefault(_ => _.Name.IsEqualTo(aggregateVariableReference.VariableName)) == null)
                {
                    theContext.AddError($"Missing aggregate variable {aggregateVariableReference.VariableName}");
                    return(false);
                }
            }

            return(true);
        }
コード例 #3
0
 public BundleInstanceModel(BundleInstanceModel parent, int count, BundleModel bundle)
 {
     ParentInstance = parent;
     Count          = count;
     Bundle         = bundle;
     Name           = string.Empty;
 }
コード例 #4
0
 /// <summary>
 /// Initializes a variable with a workspace, variable name and domain expression.
 /// </summary>
 protected VariableModel(BundleModel bundle, ModelName variableName, InlineDomainModel theDomain)
     : base(variableName)
 {
     Workspace = bundle.Workspace;
     Parent    = bundle;
     Domain    = theDomain;
 }
コード例 #5
0
        /// <summary>
        /// Initialize a bucket with a name, size and bundle name.
        /// </summary>
        /// <param name="workspace">Workspace the variable resides.</param>
        /// <param name="name">Name of the bucket.</param>
        /// <param name="size">Size of the bucket.</param>
        /// <param name="bundle">Bundle contained within the bucket.</param>
        public BucketVariableModel(WorkspaceModel workspace, ModelName name, int size, BundleModel bundle)
            : base(name)
        {
            if (size <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(size));
            }

            Size   = size;
            Bundle = bundle;
        }
コード例 #6
0
        public AggregateVariableModel(BundleModel bundle, ModelName newVariableName, int aggregateSize, InlineDomainModel theDomain)
            : base(bundle, newVariableName, theDomain)
        {
            if (aggregateSize < DefaultSize)
            {
                throw new ArgumentOutOfRangeException(nameof(aggregateSize));
            }

            Domain         = theDomain;
            this.variables = new VariableModel[aggregateSize];
            for (var i = 0; i < aggregateSize; i++)
            {
                this.variables[i] = CreateNewVariableAt(i + 1);
            }
        }
コード例 #7
0
 /// <summary>
 /// Initialize a variable with a variable name.
 /// </summary>
 public SingletonVariableModel(BundleModel bundle, ModelName variableName)
     : base(bundle, variableName, new InlineDomainModel())
 {
 }
コード例 #8
0
 public AllDifferentConstraintModel(BundleModel bundle, AllDifferentConstraintExpressionModel theExpressionModel)
 {
     Parent     = bundle;
     Expression = theExpressionModel;
 }
コード例 #9
0
 public AllDifferentConstraintModel(BundleModel bundle)
 {
     Parent     = bundle;
     Expression = new AllDifferentConstraintExpressionModel();
 }
コード例 #10
0
 public BundleLabelModel(BundleModel bundle, IReadOnlyCollection <SingletonVariableLabelModel> labels)
 {
     Bundle = bundle;
     Labels = labels;
 }
コード例 #11
0
 public AllDifferentConstraintModel(BundleModel bundle, ModelName theName, AllDifferentConstraintExpressionModel theExpressionModel)
     : base(theName)
 {
     Parent     = bundle;
     Expression = theExpressionModel;
 }
コード例 #12
0
 public ExpressionConstraintModel(BundleModel bundle, ConstraintExpressionModel theExpression)
     : base(new ModelName())
 {
     Parent          = bundle;
     this.expression = theExpression;
 }
コード例 #13
0
 /// <summary>
 /// Validate the constraint.
 /// </summary>
 /// <returns>
 /// Return true if the constraint is valid, return false if
 /// the constraint is not valid.
 /// </returns>
 public virtual bool Validate(BundleModel bundle)
 {
     return(Validate(bundle, new ModelValidationContext()));
 }
コード例 #14
0
 /// <summary>
 /// Validate the constraint placing errors into the validation context.
 /// </summary>
 /// <returns>
 /// Return true if the constraint is valid, return false if
 /// the constraint is not valid.
 /// </returns>
 public abstract bool Validate(BundleModel bundle, ModelValidationContext theContext);
コード例 #15
0
 /// <summary>
 /// Initialize an aggregate variable with workspace and a name.
 /// </summary>
 /// <param name="bundle">Bundle the variable belongs.</param>
 /// <param name="newName">New variable name.</param>
 public AggregateVariableModel(BundleModel bundle, ModelName newName)
     : this(bundle, newName, DefaultSize, new InlineDomainModel())
 {
 }
コード例 #16
0
 /// <summary>
 /// Initialize a variable with a variable name and domain expression.
 /// </summary>
 public SingletonVariableModel(BundleModel bundle, ModelName variableName, InlineDomainModel theDomain)
     : base(bundle, variableName, theDomain)
 {
 }
コード例 #17
0
 private string CreateNameFrom(BundleModel bundle, int i)
 {
     return(bundle.Instance.Name + bundle.Name + "_" + i);
 }
コード例 #18
0
 private BundleInstanceModel CreateInstanceFrom(BundleModel bundle, int count)
 {
     return(new BundleInstanceModel(Bundle.Instance, count, bundle));
 }
コード例 #19
0
 /// <summary>
 /// Initialize a shared domain with a name and domain expression.
 /// </summary>
 public SharedDomainModel(BundleModel bundle, ModelName theName, SharedDomainExpressionModel theExpression)
     : base(theName)
 {
     Parent      = bundle;
     _expression = theExpression;
 }
コード例 #20
0
 public ExpressionConstraintModel(BundleModel bundle, ModelName theName)
     : base(theName)
 {
     Parent          = bundle;
     this.expression = new ConstraintExpressionModel();
 }