private void Init(object owner, IContextLookup globalVars, DynamicCSP objCSP) { var objVariables = Variables.EvaluateTyped(owner, globalVars); var dicoVariables = (from object objVariable in objVariables select ReflectionHelper.GetFriendlyName(objVariable)).ToDictionary(varName => varName, varName => new Variable(varName)); foreach (var objVariable in dicoVariables.Values) { objCSP.AddNewVariable(objVariable); } var objDomains = Domains.EvaluateGeneric(owner, globalVars); var dicoDomains = new Dictionary <string, Domain>(); foreach (KeyValuePair <string, IEnumerable> keyValuePair in objDomains) { var domainArray = new ArrayList(); foreach (object domainItem in keyValuePair.Value) { domainArray.Add(domainItem); } Domain domain = new Domain(domainArray.ToArray()); dicoDomains.Add(keyValuePair.Key, domain); } if (dicoDomains.Count == 0) { throw new ApplicationException("No Domain defined for CSP problem"); } if (dicoDomains.Count == 1) { var domain = dicoDomains.Values.First(); Iterator terator = objCSP.getVariables().iterator(); while (terator.hasNext()) { objCSP.setDomain((Variable)terator.next(), domain); } } else { var varDomains = VariableDomains.GetValue(owner, globalVars); foreach (KeyValuePair <string, Variable> varPair in dicoVariables) { string targetDomain; Domain objDomain; if (varDomains.TryGetValue(varPair.Key, out targetDomain) && dicoDomains.TryGetValue(targetDomain, out objDomain)) { objCSP.setDomain(varPair.Value, objDomain); } else { throw new ApplicationException("Incomplete Variables Domain affectation"); } } } var objConstraints = Constraints.EvaluateTyped(owner, globalVars); foreach (Constraint objConstraint in objConstraints) { objCSP.addConstraint(objConstraint); } }