private SolverVariable ExtractVariableFrom(ExpressionNode expressionConstraintNode) { switch (expressionConstraintNode.InnerExpression) { case SingletonVariableReferenceNode singletonVariableReference: return(_modelSolverMap.GetSolverSingletonVariableByName(singletonVariableReference.VariableName)); case AggregateVariableReferenceNode aggregateVariableReference: return(_modelSolverMap.GetSolverAggregateVariableByName(aggregateVariableReference.VariableName, aggregateVariableReference.SubscriptStatement.Subscript)); case SingletonVariableReferenceExpressionNode singletonVariableExpression: return(_modelSolverMap.GetSolverSingletonVariableByName(singletonVariableExpression.VariableReference.VariableName)); case AggregateVariableReferenceExpressionNode aggregateVariableExpression: return(_modelSolverMap.GetSolverAggregateVariableByName(aggregateVariableExpression.VariableReference.VariableName, aggregateVariableExpression.VariableReference.SubscriptStatement.Subscript)); case BucketVariableReferenceNode bucketVariableReference: return(_modelSolverMap.GetSolverBucketVariableByName(bucketVariableReference.BucketName, bucketVariableReference.SubscriptStatement.Subscript, bucketVariableReference.VariableName)); default: throw new NotImplementedException(); } }
private void CreateVariables(ModelModel model) { foreach (var variable in model.Variables) { switch (variable) { case SingletonVariableModel singletonVariable: var singletonSolverVariable = _modelSolverMap.GetSolverSingletonVariableByName(singletonVariable.Name); _constraintNetwork.AddVariable(singletonSolverVariable); break; case AggregateVariableModel aggregateVariable: var aggregateSolverVariable = _modelSolverMap.GetSolverAggregateVariableByName(aggregateVariable.Name); _constraintNetwork.AddVariable(aggregateSolverVariable); break; default: throw new NotImplementedException(); } } foreach (var bucketVariable in model.Buckets) { var bucketVariableMap = _modelSolverMap.GetBucketVariableMapByName(bucketVariable.Name); _constraintNetwork.AddVariable(bucketVariableMap); } }
private IEnumerable <SingletonVariableLabelModel> ExtractSingletonLabelsFrom(SnapshotLabelAssignment assignment, ConstraintNetwork constraintNetwork) { var labelAccumulator = new List <SingletonVariableLabelModel>(); foreach (var variable in constraintNetwork.GetSingletonVariables()) { var solverVariable = _modelSolverMap.GetSolverSingletonVariableByName(variable.Name); var labelAssignment = assignment.GetAssignmentFor(solverVariable); var variableSolverValue = labelAssignment.Value; var variableModel = _modelSolverMap.GetModelSingletonVariableByName(variable.Name); var variableModelValue = ConvertSolverValueToModel(variableModel, variableSolverValue); var label = new SingletonVariableLabelModel(variableModel, new ValueModel(variableModelValue)); labelAccumulator.Add(label); } return(labelAccumulator); }