Exemplo n.º 1
0
 /* Расчет погрешности для выбранной комбинации элементов */
 public static Result calculateError(SchemeForError scheme, ref int detansCount)
 {
     //SchemeForError scheme = new SchemeForError(Scheme.currentScheme, elements, elementToToleranceDictionary);
     PassiveElement[] selectedElements = scheme.getSelectedElements().ToArray();
     Dictionary<string, DetansPair> elementsToDetanPairDictionary =
         getDetans(selectedElements, scheme, ref detansCount);
     string formule = makeErrorFormule(elementsToDetanPairDictionary, false);
     Result result = new Result();
     result.elementNamesToDetansDictionary = elementsToDetanPairDictionary;
     if (scheme.useNegativeValues)
         result.formuleValue = new FormuleValueWithNegative();
     else
         result.formuleValue = new FormuleValue();
     result.formuleValue.formule = formule;
     string value = calculateFormule(formule, scheme);
     if (!String.IsNullOrEmpty(value))
     {
         if (!value.Contains("j"))
             //value = value.Replace('.', ',');
             value = (Convert.ToDouble(value) * 100).ToString();
     }
     result.formuleValue.value = value;
     if (scheme.useNegativeValues)
     {
         formule = makeErrorFormule(elementsToDetanPairDictionary, true);
         string resultForNegative = calculateFormule(formule, scheme);
         if (!String.IsNullOrEmpty(resultForNegative))
             if (!resultForNegative.Contains("j"))
                 //resultForNegative = resultForNegative.Replace('.', ',');
                 resultForNegative = (Convert.ToDouble(resultForNegative) * 100).ToString();
         ((FormuleValueWithNegative)result.formuleValue).negativeValue = resultForNegative;
     }
     detansCount += result.elementNamesToDetansDictionary.Count * 2;
     return result;
 }
Exemplo n.º 2
0
 /* Расчет погрешностей для всех возможных вариантов выбора элементов */
 /* Принимает ассоциативный массив, где ключ - элемент, значение - допуск */
 /* Заполняет ассоциативный массив, где ключ - элементы, значение - Result */
 public static Dictionary<PassiveElement[], Result> calculateAllErrors(SchemeForError scheme, ref int detansCount)
 {
     Dictionary<PassiveElement[], Result> elementsToErrorDictionary = new Dictionary<PassiveElement[], Result>();
     List<PassiveElement> passiveElementsList = new List<PassiveElement>();
     foreach (Element element in Scheme.currentScheme.getElementsList())
     {
         if (element is PassiveElement)
             passiveElementsList.Add((PassiveElement)element);
     }
     Dictionary<PassiveElement, string> elementToToleranceDictionary = scheme.elementToToleranceDictionary;
     int passiveElementsCount = passiveElementsList.Count;
     /* Перебор длин сочетаний элементов */
     for (int i = 1; i <= passiveElementsCount; i++)
     {
         /* Первое сочетание данной длины элементов */
         int[] indexes = makeCombination(i);
         /* Перебор остальных сочетаний элементов */
         while (true)
         {
             List<PassiveElement> selectedElements = new List<PassiveElement>();
             foreach (int index in indexes)
                 selectedElements.Add(passiveElementsList[index - 1]);
             Result result = new Result();
             PassiveElement[] selectedElementsArray = selectedElements.ToArray();
             SchemeForError tempScheme = new SchemeForError(Scheme.currentScheme,
                 selectedElementsArray, scheme.elementToToleranceDictionary, scheme.useNegativeValues);
             result = calculateError(tempScheme, ref detansCount);
             elementsToErrorDictionary.Add(selectedElementsArray, result);
             if (nextCombination(indexes, passiveElementsList.Count) != 0)
                 break;
         }
     }
     return elementsToErrorDictionary;
 }
Exemplo n.º 3
0
        static Dictionary <PassiveElement[], Result> calculateError(SchemeForError scheme, ref int detansCount)
        {
            Dictionary <PassiveElement[], Result> elementsToErrorDictionary = new Dictionary <PassiveElement[], Result>();

            //Dictionary<PassiveElement, string> elementToToleranceDictionary = getElementToToleranceAssociations();
            //schemeForCalculations = new SchemeForError(Scheme.currentScheme, selectedElements.ToArray(), elementToToleranceDictionary);
            elementsToErrorDictionary.Add(scheme.getSelectedElements().ToArray(), Calculations.calculateError(scheme, ref detansCount));
            // = Calculations.calculateError(selectedElements.ToArray());
            return(elementsToErrorDictionary);
        }
Exemplo n.º 4
0
        static Dictionary <PassiveElement[], Result> calculateAllErrors(SchemeForError scheme, ref int detansCount)
        {
            Dictionary <PassiveElement[], Result> elementsToErrorDictionary = new Dictionary <PassiveElement[], Result>();
            List <PassiveElement> selectedElements = new List <PassiveElement>();

            //foreach (DataGridViewRow row in schemeDataGrid.Rows)
            //{
            //    if (!row.Cells[0].ReadOnly)
            //        selectedElements.Add((PassiveElement)rowToElementDictionary[row]);
            //}
            //Dictionary<PassiveElement, string> elementsToToleranceDictionary = getElementToToleranceAssociations();
            elementsToErrorDictionary = Calculations.calculateAllErrors(scheme, ref detansCount);
            //schemeForCalculations = new SchemeForError(Scheme.currentScheme, selectedElements.ToArray(), elementsToToleranceDictionary);
            return(elementsToErrorDictionary);
        }
Exemplo n.º 5
0
        /* Расчет погрешности для выбранной комбинации элементов */
        public static Result calculateError(SchemeForError scheme, ref int detansCount)
        {
            //SchemeForError scheme = new SchemeForError(Scheme.currentScheme, elements, elementToToleranceDictionary);
            PassiveElement[] selectedElements = scheme.getSelectedElements().ToArray();
            Dictionary <string, DetansPair> elementsToDetanPairDictionary =
                getDetans(selectedElements, scheme, ref detansCount);
            string formule = makeErrorFormule(elementsToDetanPairDictionary, false);
            Result result  = new Result();

            result.elementNamesToDetansDictionary = elementsToDetanPairDictionary;
            if (scheme.useNegativeValues)
            {
                result.formuleValue = new FormuleValueWithNegative();
            }
            else
            {
                result.formuleValue = new FormuleValue();
            }
            result.formuleValue.formule = formule;
            string value = calculateFormule(formule, scheme);

            if (!String.IsNullOrEmpty(value))
            {
                if (!value.Contains("j"))
                {
                    //value = value.Replace('.', ',');
                    value = (Convert.ToDouble(value) * 100).ToString();
                }
            }
            result.formuleValue.value = value;
            if (scheme.useNegativeValues)
            {
                formule = makeErrorFormule(elementsToDetanPairDictionary, true);
                string resultForNegative = calculateFormule(formule, scheme);
                if (!String.IsNullOrEmpty(resultForNegative))
                {
                    if (!resultForNegative.Contains("j"))
                    {
                        //resultForNegative = resultForNegative.Replace('.', ',');
                        resultForNegative = (Convert.ToDouble(resultForNegative) * 100).ToString();
                    }
                }
                ((FormuleValueWithNegative)result.formuleValue).negativeValue = resultForNegative;
            }
            detansCount += result.elementNamesToDetansDictionary.Count * 2;
            return(result);
        }
Exemplo n.º 6
0
        static Dictionary <PassiveElement[], Result> calculateSingleErrors(SchemeForError scheme, ref int detansCount)
        {
            Dictionary <PassiveElement[], Result> elementsToErrorDictionary = new Dictionary <PassiveElement[], Result>();
            //Dictionary<PassiveElement, string> elementToToleranceDictionary = getElementToToleranceAssociations();
            //schemeForCalculations = new SchemeForError(Scheme.currentScheme, selectedElements.ToArray(), elementToToleranceDictionary);
            List <PassiveElement> selectedElements = scheme.getSelectedElements();

            foreach (PassiveElement element in selectedElements)
            {
                List <PassiveElement> selectedElement = new List <PassiveElement>();
                selectedElement.Add(element);
                SchemeForError tempScheme = new SchemeForError(Scheme.currentScheme,
                                                               selectedElement.ToArray(), scheme.elementToToleranceDictionary, scheme.useNegativeValues);
                //scheme.setSelectedElements(selectedElement);
                elementsToErrorDictionary.Add(selectedElement.ToArray(),
                                              Calculations.calculateError(tempScheme, ref detansCount));
            }
            return(elementsToErrorDictionary);
        }
Exemplo n.º 7
0
        /* Расчет погрешностей для всех возможных вариантов выбора элементов */
        /* Принимает ассоциативный массив, где ключ - элемент, значение - допуск */
        /* Заполняет ассоциативный массив, где ключ - элементы, значение - Result */
        public static Dictionary <PassiveElement[], Result> calculateAllErrors(SchemeForError scheme, ref int detansCount)
        {
            Dictionary <PassiveElement[], Result> elementsToErrorDictionary = new Dictionary <PassiveElement[], Result>();
            List <PassiveElement> passiveElementsList = new List <PassiveElement>();

            foreach (Element element in Scheme.currentScheme.getElementsList())
            {
                if (element is PassiveElement)
                {
                    passiveElementsList.Add((PassiveElement)element);
                }
            }
            Dictionary <PassiveElement, string> elementToToleranceDictionary = scheme.elementToToleranceDictionary;
            int passiveElementsCount = passiveElementsList.Count;

            /* Перебор длин сочетаний элементов */
            for (int i = 1; i <= passiveElementsCount; i++)
            {
                /* Первое сочетание данной длины элементов */
                int[] indexes = makeCombination(i);
                /* Перебор остальных сочетаний элементов */
                while (true)
                {
                    List <PassiveElement> selectedElements = new List <PassiveElement>();
                    foreach (int index in indexes)
                    {
                        selectedElements.Add(passiveElementsList[index - 1]);
                    }
                    Result           result = new Result();
                    PassiveElement[] selectedElementsArray = selectedElements.ToArray();
                    SchemeForError   tempScheme            = new SchemeForError(Scheme.currentScheme,
                                                                                selectedElementsArray, scheme.elementToToleranceDictionary, scheme.useNegativeValues);
                    result = calculateError(tempScheme, ref detansCount);
                    elementsToErrorDictionary.Add(selectedElementsArray, result);
                    if (nextCombination(indexes, passiveElementsList.Count) != 0)
                    {
                        break;
                    }
                }
            }
            return(elementsToErrorDictionary);
        }
Exemplo n.º 8
0
 static Dictionary<PassiveElement[], Result> calculateSingleErrors(SchemeForError scheme, ref int detansCount)
 {
     Dictionary<PassiveElement[], Result> elementsToErrorDictionary = new Dictionary<PassiveElement[], Result>();
     //Dictionary<PassiveElement, string> elementToToleranceDictionary = getElementToToleranceAssociations();
     //schemeForCalculations = new SchemeForError(Scheme.currentScheme, selectedElements.ToArray(), elementToToleranceDictionary);
     List<PassiveElement> selectedElements = scheme.getSelectedElements();
     foreach (PassiveElement element in selectedElements)
     {
         List<PassiveElement> selectedElement = new List<PassiveElement>();
         selectedElement.Add(element);
         SchemeForError tempScheme = new SchemeForError(Scheme.currentScheme,
             selectedElement.ToArray(), scheme.elementToToleranceDictionary, scheme.useNegativeValues);
         //scheme.setSelectedElements(selectedElement);
         elementsToErrorDictionary.Add(selectedElement.ToArray(),
             Calculations.calculateError(tempScheme, ref detansCount));
     }
     return elementsToErrorDictionary;
 }
Exemplo n.º 9
0
 static Dictionary<PassiveElement[], Result> calculateError(SchemeForError scheme, ref int detansCount)
 {
     Dictionary<PassiveElement[], Result> elementsToErrorDictionary = new Dictionary<PassiveElement[], Result>();
     //Dictionary<PassiveElement, string> elementToToleranceDictionary = getElementToToleranceAssociations();
     //schemeForCalculations = new SchemeForError(Scheme.currentScheme, selectedElements.ToArray(), elementToToleranceDictionary);
     elementsToErrorDictionary.Add(scheme.getSelectedElements().ToArray(), Calculations.calculateError(scheme, ref detansCount));
     // = Calculations.calculateError(selectedElements.ToArray());
     return elementsToErrorDictionary;
 }
Exemplo n.º 10
0
 static Dictionary<PassiveElement[], Result> calculateAllErrors(SchemeForError scheme, ref int detansCount)
 {
     Dictionary<PassiveElement[], Result> elementsToErrorDictionary = new Dictionary<PassiveElement[], Result>();
     List<PassiveElement> selectedElements = new List<PassiveElement>();
     //foreach (DataGridViewRow row in schemeDataGrid.Rows)
     //{
     //    if (!row.Cells[0].ReadOnly)
     //        selectedElements.Add((PassiveElement)rowToElementDictionary[row]);
     //}
     //Dictionary<PassiveElement, string> elementsToToleranceDictionary = getElementToToleranceAssociations();
     elementsToErrorDictionary = Calculations.calculateAllErrors(scheme, ref detansCount);
     //schemeForCalculations = new SchemeForError(Scheme.currentScheme, selectedElements.ToArray(), elementsToToleranceDictionary);
     return elementsToErrorDictionary;
 }