internal void AssignTo(ValueSet valueSet) { _assignments.Add(valueSet); }
internal bool Remove(ValueSet valueSet) { return(_assignments.Remove(valueSet)); }
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)); }