/// <summary> /// Generates an object from its XML representation. /// </summary> /// <param name="reader">The <see cref="T:System.Xml.XmlReader"/> stream from which the object is deserialized.</param> public virtual void ReadXml(System.Xml.XmlReader reader) { reader.Read(); Assembly assembly = Assembly.GetExecutingAssembly(); while (reader.NodeType != XmlNodeType.EndElement) { string operation = reader.Name; Type type = assembly.GetType(assembly.GetName().Name + "." + operation); // Ausnahme beim VariablenOperator if (type == typeof(VariablesOperator)) { VariablesOperator op; reader.Read(); string varName = reader.ReadElementContentAsString(); reader.Read(); if (!VariablesOperator.VarOperatorList.TryGetValue(varName, out op)) { op = new VariablesOperator(varName); VariablesOperator.VarOperatorList.Add(varName, op); } AddOperator(op); } else { XmlSerializer xmlSerializer = new XmlSerializer(type); IOperation op = xmlSerializer.Deserialize(reader) as IOperation; AddOperator(op); } } reader.Read(); }
/// <summary> /// Ein VariablenOperator wird dem Constraint hinzugefügt. /// <remarks> /// Es wird nur ein VariablenOperator hinzugefügt, /// wenn dieser nicht schon hinzugefügt wurd (wird anhand des gleichen Namens erkannt) /// </remarks> /// </summary> /// <param name="varOperator"></param> private void AddVariablesOperator(VariablesOperator varOperator) { if (!_variableNames.Contains(varOperator.Name)) { _variableNames.Add(varOperator.Name); _varOperators.Add(varOperator); } }
void FillVariableInformation(IOperation operation) { if (_operation == null) { return; } if (operation.GetType() == typeof(VariablesOperator)) { VariablesOperator variablesOperator = (VariablesOperator)operation; AddVariablesOperator(variablesOperator); } foreach (IOperation childOperation in operation.GetOperatorList()) { FillVariableInformation(childOperation); } }
protected void BuildConstraints() { // Variablen VariablesOperator o = new VariablesOperator("O"); VariablesOperator x1 = new VariablesOperator("X1"); VariablesOperator w = new VariablesOperator("W"); VariablesOperator u = new VariablesOperator("U"); VariablesOperator x2 = new VariablesOperator("X2"); VariablesOperator t = new VariablesOperator("T"); VariablesOperator f = new VariablesOperator("F"); VariablesOperator r = new VariablesOperator("R"); VariablesOperator x3 = new VariablesOperator("X3"); // Konstanten DoubleOperator ten = new DoubleOperator(10); // O + O = R + 10 * X1 Addition firstAddition = new Addition(o, o); Multiply multiply = new Multiply(ten, x1); Addition secondAddition = new Addition(r, multiply); Equal equal = new Equal(firstAddition, secondAddition); Constraint constraint = new Constraint(equal); _constraintList.Add("O", constraint); _constraintList.Add("R", constraint); _constraintList.Add("X1", constraint); // X1 + W + W = U + 10 * X2 secondAddition = new Addition(w, w); firstAddition = new Addition(x1, secondAddition); multiply = new Multiply(ten, x2); secondAddition = new Addition(u, multiply); equal = new Equal(firstAddition, secondAddition); constraint = new Constraint(equal); _constraintList.Add("X1", constraint); _constraintList.Add("W", constraint); _constraintList.Add("U", constraint); _constraintList.Add("X2", constraint); // X2 + T + T = O + 10 * X3 secondAddition = new Addition(t, t); firstAddition = new Addition(x2, secondAddition); multiply = new Multiply(ten, x3); secondAddition = new Addition(o, multiply); equal = new Equal(firstAddition, secondAddition); constraint = new Constraint(equal); _constraintList.Add("X2", constraint); _constraintList.Add("T", constraint); _constraintList.Add("O", constraint); _constraintList.Add("X3", constraint); // X3 = F equal = new Equal(x3, f); constraint = new Constraint(equal); _constraintList.Add("X3", constraint); _constraintList.Add("F", constraint); ConstraintConfiguration configuration = new ConstraintConfiguration(); // Variablen AddVariable(configuration, "O"); AddVariable(configuration, "X1"); AddVariable(configuration, "W"); AddVariable(configuration, "U"); AddVariable(configuration, "X2"); AddVariable(configuration, "T"); AddVariable(configuration, "F"); AddVariable(configuration, "R"); AddVariable(configuration, "X3"); _begin = CreateNode(null, configuration); }