Beispiel #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();
 }
        /// <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);
        }
 public BundleInstanceModel(BundleInstanceModel parent, int count, BundleModel bundle)
 {
     ParentInstance = parent;
     Count          = count;
     Bundle         = bundle;
     Name           = string.Empty;
 }
Beispiel #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;
 }
        /// <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;
        }
Beispiel #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);
            }
        }
 /// <summary>
 /// Initialize a variable with a variable name.
 /// </summary>
 public SingletonVariableModel(BundleModel bundle, ModelName variableName)
     : base(bundle, variableName, new InlineDomainModel())
 {
 }
Beispiel #8
0
 public AllDifferentConstraintModel(BundleModel bundle, AllDifferentConstraintExpressionModel theExpressionModel)
 {
     Parent     = bundle;
     Expression = theExpressionModel;
 }
Beispiel #9
0
 public AllDifferentConstraintModel(BundleModel bundle)
 {
     Parent     = bundle;
     Expression = new AllDifferentConstraintExpressionModel();
 }
 public BundleLabelModel(BundleModel bundle, IReadOnlyCollection <SingletonVariableLabelModel> labels)
 {
     Bundle = bundle;
     Labels = labels;
 }
Beispiel #11
0
 public AllDifferentConstraintModel(BundleModel bundle, ModelName theName, AllDifferentConstraintExpressionModel theExpressionModel)
     : base(theName)
 {
     Parent     = bundle;
     Expression = theExpressionModel;
 }
 public ExpressionConstraintModel(BundleModel bundle, ConstraintExpressionModel theExpression)
     : base(new ModelName())
 {
     Parent          = bundle;
     this.expression = theExpression;
 }
 /// <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()));
 }
 /// <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);
Beispiel #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())
 {
 }
 /// <summary>
 /// Initialize a variable with a variable name and domain expression.
 /// </summary>
 public SingletonVariableModel(BundleModel bundle, ModelName variableName, InlineDomainModel theDomain)
     : base(bundle, variableName, theDomain)
 {
 }
Beispiel #17
0
 private string CreateNameFrom(BundleModel bundle, int i)
 {
     return(bundle.Instance.Name + bundle.Name + "_" + i);
 }
Beispiel #18
0
 private BundleInstanceModel CreateInstanceFrom(BundleModel bundle, int count)
 {
     return(new BundleInstanceModel(Bundle.Instance, count, bundle));
 }
Beispiel #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;
 }
 public ExpressionConstraintModel(BundleModel bundle, ModelName theName)
     : base(theName)
 {
     Parent          = bundle;
     this.expression = new ConstraintExpressionModel();
 }