private dynamic computeVariables(dynamic computedValue1, dynamic computedValue2, EF_Operator op)
        {
            switch (op.Operator)
            {
            case EF_Operand.Add: return(computedValue1 + computedValue2);

            case EF_Operand.Subtract: return(computedValue1 - computedValue2);

            case EF_Operand.Multiply: return(computedValue1 * computedValue2);

            case EF_Operand.Divide: return(computedValue1 / computedValue2);

            default: return(0);
            }
        }
Beispiel #2
0
        public Tuple <EF_Equation, EF_Equation> MakeChildren(EF_Equation parent1, EF_Equation parent2)
        {
            VariableType varType;

            if (parent1.EquationType == EquationType.Int)
            {
                varType = VariableType.Int;
            }
            else
            {
                varType = VariableType.Double;
            }

            EquationType parent1Copy_eq = new EquationType();
            EquationType parent2Copy_eq = new EquationType();

            if (parent1.EquationType.Equals(EquationType.Double))
            {
                parent1Copy_eq = EquationType.Double;
                parent2Copy_eq = EquationType.Double;
            }
            else
            {
                parent1Copy_eq = EquationType.Int;
                parent2Copy_eq = EquationType.Int;
            }

            List <EF_Variable> parent1Copy_variables = new List <EF_Variable>();
            List <EF_Variable> parent2Copy_variables = new List <EF_Variable>();

            foreach (EF_Variable variable in parent1.Variables)
            {
                char    symbol = variable.Symbol;
                dynamic value  = variable.Value;

                dynamic coeff = variable.CoEfficient;

                dynamic     power       = variable.Power;
                EF_Variable newVariable = new EF_Variable(symbol, value, coeff, power, varType);

                parent1Copy_variables.Add(newVariable);
            }

            foreach (EF_Variable variable in parent2.Variables)
            {
                char        symbol      = variable.Symbol;
                dynamic     value       = variable.Value;
                dynamic     coeff       = variable.CoEfficient;
                dynamic     power       = variable.Power;
                EF_Variable newVariable = new EF_Variable(symbol, value, coeff, power, varType);

                parent2Copy_variables.Add(newVariable);
            }

            List <EF_Operator> parent1Copy_operators = new List <EF_Operator>();
            List <EF_Operator> parent2Copy_operators = new List <EF_Operator>();

            foreach (EF_Operator oper in parent1.Operators)
            {
                EF_Operand op = new EF_Operand();
                if (oper.Operator == EF_Operand.Add)
                {
                    op = EF_Operand.Add;
                }
                else if (oper.Operator == EF_Operand.Subtract)
                {
                    op = EF_Operand.Subtract;
                }
                else if (oper.Operator == EF_Operand.Multiply)
                {
                    op = EF_Operand.Multiply;
                }
                else
                {
                    op = EF_Operand.Divide;
                }

                EF_Operator opera = new EF_Operator(op);
                parent1Copy_operators.Add(oper);
            }

            foreach (EF_Operator oper in parent2.Operators)
            {
                EF_Operand op = new EF_Operand();
                if (oper.Operator == EF_Operand.Add)
                {
                    op = EF_Operand.Add;
                }
                else if (oper.Operator == EF_Operand.Subtract)
                {
                    op = EF_Operand.Subtract;
                }
                else if (oper.Operator == EF_Operand.Multiply)
                {
                    op = EF_Operand.Multiply;
                }
                else
                {
                    op = EF_Operand.Divide;
                }

                EF_Operator opera = new EF_Operator(op);
                parent2Copy_operators.Add(oper);
            }

            EF_Equation child1 = new EF_Equation(parent1Copy_eq, parent2Copy_variables, parent1Copy_operators);
            EF_Equation child2 = new EF_Equation(parent2Copy_eq, parent1Copy_variables, parent2Copy_operators);

            return(Tuple.Create(child1, child2));
        }