private IEnumerable <AggregateVariableLabelModel> ExtractAggregateLabelsFrom(SnapshotLabelAssignment assignment, ConstraintNetwork constraintNetwork) { var aggregatorLabelAccumulator = new List <AggregateVariableLabelModel>(); foreach (var aggregateSolverVariable in constraintNetwork.GetAggregateVariables()) { var internalAccumulator = new List <ValueModel>(); var aggregateVariableModel = _modelSolverMap.GetModelAggregateVariableByName(aggregateSolverVariable.Name); foreach (var variable in aggregateSolverVariable.Variables) { var solverVariable = _modelSolverMap.GetSolverVariableByName(variable.Name); var labelAssignment = assignment.GetAssignmentFor(solverVariable); var variableSolverValue = labelAssignment.Value; var variableModel = _modelSolverMap.GetInternalModelAggregateVariableByName(variable.Name); var variableModelValue = ConvertSolverValueToModel((SingletonVariableModel)variableModel, variableSolverValue); internalAccumulator.Add(new ValueModel(variableModelValue)); } var label = new AggregateVariableLabelModel(aggregateVariableModel, internalAccumulator); aggregatorLabelAccumulator.Add(label); } return(aggregatorLabelAccumulator); }
internal EncapsulatedVariableDomainValue Compute(TernaryConstraintExpression ternaryConstraint) { var valueSetAccumulator = new List <ValueSet>(); var leftSource = ternaryConstraint.GetLeftSource(); var leftPossibleValues = leftSource.PossibleValues; var expression = ternaryConstraint.ExpressionNode; IReadOnlyCollection <int> rightPossibleValues; if (!expression.InnerExpression.RightExpression.IsLiteral) { var rightSource = ternaryConstraint.GetRightSource(); rightPossibleValues = new ReadOnlyCollection <int>(rightSource.PossibleValues.ToList()); } else { var lhsVariable = _modelSolverMap.GetModelVariableByName(leftSource.VariableName); var range = _valueMapper.GetDomainValueFor(lhsVariable); var modelValue = expression.InnerExpression.RightExpression.GetLiteral(); var solverValue = range.MapTo(modelValue); rightPossibleValues = new ReadOnlyCollection <int>(new List <int> { solverValue }); } foreach (var leftPossibleValue in leftPossibleValues) { foreach (var rightPossibleValue in rightPossibleValues) { switch (ternaryConstraint.ExpressionNode.InnerExpression.Operator) { case OperatorType.Equals: if (leftPossibleValue == rightPossibleValue) { if (!expression.InnerExpression.RightExpression.IsLiteral) { var rightSource = ternaryConstraint.GetRightSource(); var valueSet = new ValueSet(new[] { new Value(_modelSolverMap.GetSolverVariableByName(leftSource.VariableName), leftPossibleValue), new Value(_modelSolverMap.GetSolverVariableByName(rightSource.VariableName), rightPossibleValue) }); valueSetAccumulator.Add(valueSet); } else { var valueSet = new ValueSet(new[] { new Value(_modelSolverMap.GetSolverVariableByName(leftSource.VariableName), leftPossibleValue) }); valueSetAccumulator.Add(valueSet); } } break; case OperatorType.NotEqual: if (leftPossibleValue != rightPossibleValue) { if (!expression.InnerExpression.RightExpression.IsLiteral) { var rightSource = ternaryConstraint.GetRightSource(); var valueSet = new ValueSet(new[] { new Value(_modelSolverMap.GetSolverVariableByName(leftSource.VariableName), leftPossibleValue), new Value(_modelSolverMap.GetSolverVariableByName(rightSource.VariableName), rightPossibleValue) }); valueSetAccumulator.Add(valueSet); } else { var valueSet = new ValueSet(new[] { new Value(_modelSolverMap.GetSolverVariableByName(leftSource.VariableName), leftPossibleValue) }); valueSetAccumulator.Add(valueSet); } } break; default: throw new NotImplementedException(); } } } return(new EncapsulatedVariableDomainValue(ternaryConstraint.EncapsulatedVariable, valueSetAccumulator)); }