/* Удаление элемента */ public void transformElementToInfin(PassiveElement element, List<Element> elementsList) { List<Element> modifiedElements = elementToModifiedElementsDictionary[element].modifiedToInfinElements; if (modifiedElements != null) elementsList.AddRange(modifiedElements); //elementsList.Remove(element); }
/* Удаление элемента */ public void transformElementToInfin(PassiveElement element, List <Element> elementsList) { List <Element> modifiedElements = elementToModifiedElementsDictionary[element].modifiedToInfinElements; if (modifiedElements != null) { elementsList.AddRange(modifiedElements); } //elementsList.Remove(element); }
public AdvancedScheme(Scheme baseScheme, PassiveElement[] selectedElements) { elementsList = baseScheme.getElementsList(); itsSelectedElements = new List<PassiveElement>(selectedElements); makePassiveList(); makeActiveList(); makeNullersList(); makeActiveListForZ(); makeActiveListForQ(); makeElementToValueAssociations(); }
/* Расчет допуска для одного элемента (element) из схемы scheme */ static Result calculateTolerance(SchemeForTolerance scheme)/*PassiveElement element, SchemeForTolerance scheme, bool forNegative)*/ { PassiveElement element = scheme.getSelectedElements()[0]; Result result = new Result(); string[] detans = getDetans(element, scheme); result.elementNamesToDetansDictionary = new Dictionary <string, DetansPair>(); result.elementNamesToDetansDictionary.Add("", new DetansPair(detans[1], detans[3])); result.elementNamesToDetansDictionary.Add(element.getRightName(), new DetansPair(detans[0], detans[2])); string formule = makeToleranceFormule(detans, scheme.error, false); 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 (!result.valueForPositive.Contains("j")) value = (Convert.ToDouble(value) * 100 / Convert.ToDouble(element.getFormattedValue())).ToString(); } result.formuleValue.value = value; if (scheme.useNegativeValues) { string negativeValue = calculateFormule(makeToleranceFormule(detans, scheme.error, true), scheme); if (!String.IsNullOrEmpty(negativeValue)) { //if (!result.valueForNegative.Contains("j")) negativeValue = (Convert.ToDouble(negativeValue) * 100 / Convert.ToDouble(element.getFormattedValue())).ToString(); } ((FormuleValueWithNegative)result.formuleValue).negativeValue = negativeValue; } return(result); }
public SchemeForTolerance(Scheme scheme, PassiveElement[] elements, string receivedError, bool useNegativeValues) : base(scheme, elements) { error = receivedError;//(Convert.ToDouble(receivedError) * 0.01).ToString(); this.useNegativeValues = useNegativeValues; addClonesToList(); makeModifiedElementsAssociation(); }
/* Формирование части формулы дробной ССФ */ /* чилителя или знаменателя - определяется значением fractionPart */ string makeSSFFractionPart(Dictionary<string, DetansPair> elementsToDetanPairDictionary, PassiveElement[] selectedElements, int SSFType, int fractionPartType) { string formule = "("; switch (SSFType) { case 1: switch (fractionPartType) { case 1: formule += elementsToDetanPairDictionary[""].itsNumeratorDetan; break; case 2: formule += elementsToDetanPairDictionary[""].itsDenominatorDetan; break; default: return null; } formule += "+"; break; default: return null; } foreach (KeyValuePair<string, DetansPair> elementsToDetanPair in elementsToDetanPairDictionary) { if (elementsToDetanPair.Key.Length > 0) { foreach (string element in elementsToDetanPair.Key.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries)) { formule += element + "*"; } formule += "("; switch (SSFType) { case 1: switch (fractionPartType) { case 1: formule += elementsToDetanPair.Value.itsNumeratorDetan; break; case 2: formule += elementsToDetanPair.Value.itsDenominatorDetan; break; default: return null; } break; default: return null; } formule += ")" + "+"; } } formule = formule.Remove(formule.Length - 1, 1) + ")"; return formule; }
/* Формирование формулы символьной схемной функции из определителей */ string makeSSFFormule(Dictionary<string, DetansPair> elementsToDetanPairDictionary, PassiveElement[] selectedElements, int SSFType) { string formule = ""; string fractionNumerator = ""; string fractionDenominator = ""; string lastKey = Calculations.elementsToNamesString(selectedElements); fractionNumerator = makeSSFFractionPart(elementsToDetanPairDictionary, selectedElements, SSFType, 1); fractionDenominator = makeSSFFractionPart(elementsToDetanPairDictionary, selectedElements, SSFType, 2); formule = "(" + fractionNumerator + ")" + "/" + "(" + fractionDenominator + ")"; return formule; }
static Dictionary<string, DetansPair> getDetans(PassiveElement[] elements, AdvancedScheme scheme, ref int detansCount) { Dictionary<string, DetansPair> elementsToDetanPairDictionary = new Dictionary<string, DetansPair>(); int elementsCount = elements.Length; List<Element> elementsList = new List<Element>(); foreach (PassiveElement element in scheme.passiveElementsList) elementsList.Add(element); List<Element> activeElementsForZ = scheme.activeElementsListForZ; List<Element> activeElementsForQ = scheme.activeElementsListForQ; //elementsList.AddRange(scheme.nullersList); string selectedElementsString = Calculations.elementsToNamesString(elements); for (int i = 0; i <= elementsCount; i++) { int[] indexes = Calculations.makeCombination(i); while (true) { List<Element> removedElements = new List<Element>(); List<Element> subtendedElements = new List<Element>(); List<Element> localElementsList = new List<Element>(elementsList); List<Element> associatedElements = new List<Element>(); for (int j = 0; j < elementsCount; j++) { if (Array.IndexOf(indexes, j + 1) >= 0) { scheme.transformElementToInfin(elements[j], localElementsList); associatedElements.Add(elements[j]); removedElements.Add(elements[j]); } else { scheme.transformElementToZero(elements[j], localElementsList); subtendedElements.Add(elements[j]); } } List<Element> elementsListToZ = new List<Element>(localElementsList); elementsListToZ.AddRange(activeElementsForZ); List<Element> elementsListToQ = new List<Element>(localElementsList); elementsListToQ.AddRange(activeElementsForQ); string pattern = ""; string delimiter = ";"; string removedElementsString = Calculations.elementsToNamesString(removedElements, pattern, delimiter); string keyString = selectedElementsString + "|" + removedElementsString; string numeratorDetan; string denominatorDetan; if (mainForm.elementsStringToDetansMap.ContainsKey(keyString)) { numeratorDetan = mainForm.elementsStringToDetansMap[keyString].itsNumeratorDetan; denominatorDetan = mainForm.elementsStringToDetansMap[keyString].itsDenominatorDetan; } else { numeratorDetan = Calculations.getDetan(elementsListToZ); //mainForm.elementsStringToDetansMap[keyString].itsNumeratorDetan = numeratorDetan; denominatorDetan = Calculations.getDetan(elementsListToQ); Calculations.correctFormule(ref numeratorDetan); Calculations.correctFormule(ref denominatorDetan); //mainForm.elementsStringToDetansMap[keyString].itsDenominatorDetan = denominatorDetan; mainForm.elementsStringToDetansMap.Add( keyString, new DetansPair(numeratorDetan, denominatorDetan)); } //string detanZ = Calculations.getDetan(elementsListToZ); //Calculations.correctFormule(ref detanZ); //string detanQ = Calculations.getDetan(elementsListToQ); //Calculations.correctFormule(ref detanQ); string elementNames = Calculations.elementsToNamesString(associatedElements); elementsToDetanPairDictionary.Add(elementNames, new DetansPair(numeratorDetan, denominatorDetan)); detansCount += 2; if (Calculations.nextCombination(indexes, elements.Length) != 0) break; } } return elementsToDetanPairDictionary; }
public SchemeForSSF(Scheme scheme, PassiveElement[] elements, int SSFtype) : base(scheme, elements) { //error = (Convert.ToDouble(receivedError)*0.01).ToString(); //addClonesToList(); itsSelectedElements = new List<PassiveElement>(elements); itsSSFtype = SSFtype; makeModifiedElementsAssociation(); }
public SchemeForError(Scheme baseScheme, PassiveElement[] elements, Dictionary<PassiveElement, string> elementToToleranceAssociations, bool useNegativeValues) : base(baseScheme, elements) { elementToToleranceDictionary = elementToToleranceAssociations; this.useNegativeValues = useNegativeValues; addClonesToList(); makeModifiedElementsAssociation(); }
/* Частный случай функции getDetans для одного элемента */ static string[] getDetans(PassiveElement selectedElement, SchemeForTolerance scheme) { List <Element> elementsList = new List <Element>();//scheme.passiveElementsList; foreach (PassiveElement element in scheme.passiveElementsList) { elementsList.Add(element); } elementsList.AddRange((selectedElement).clonnedElements); elementsList.Remove((selectedElement).cloneElement); elementsList.AddRange(scheme.nullersList); List <Element> elementToInfinList = new List <Element>(elementsList); List <Element> elementToZeroList = new List <Element>(elementsList); scheme.transformElementToInfin(((PassiveElement)selectedElement).cloneElement, elementToInfinList); scheme.transformElementToZero(((PassiveElement)selectedElement).cloneElement, elementToZeroList); //scheme.transformElementToInfin(element, elementToInfinList); //scheme.transformElementToZero(element, elementToZeroList); List <Element> activeElementsForZ = scheme.getActiveElementsListForZ(); List <Element> activeElementsForQ = scheme.getActiveElementsListForQ(); List <Element> elementsToInfinToZList = new List <Element>(elementToInfinList); elementsToInfinToZList.AddRange(activeElementsForZ); List <Element> elementsToZeroToZList = new List <Element>(elementToZeroList); elementsToZeroToZList.AddRange(activeElementsForZ); List <Element> elementsToInfinToQList = new List <Element>(elementToInfinList); elementsToInfinToQList.AddRange(activeElementsForQ); List <Element> elementsToZeroToQList = new List <Element>(elementToZeroList); elementsToZeroToQList.AddRange(activeElementsForQ); string[] detans = new string[4]; string elementName = selectedElement.getRightName(); string keyForRemoved = elementName + "|" + "δ(" + elementName + ")"; string keyForSubtended = elementName + "|"; if (mainForm.elementsStringToDetansMap.ContainsKey(keyForRemoved)) { detans[0] = mainForm.elementsStringToDetansMap[keyForRemoved].itsNumeratorDetan; detans[2] = mainForm.elementsStringToDetansMap[keyForRemoved].itsDenominatorDetan; } else { detans[0] = getDetan(elementsToInfinToZList); correctFormule(ref detans[0]); detans[2] = getDetan(elementsToInfinToQList); correctFormule(ref detans[2]); DetansPair detansPair = new DetansPair(detans[0], detans[2]); mainForm.elementsStringToDetansMap.Add(keyForRemoved, detansPair); //mainForm.elementsStringToDetansMap[keyForRemoved].itsDenominatorDetan = detans[2]; } if (mainForm.elementsStringToDetansMap.ContainsKey(keyForSubtended)) { detans[1] = mainForm.elementsStringToDetansMap[keyForSubtended].itsNumeratorDetan; detans[3] = mainForm.elementsStringToDetansMap[keyForSubtended].itsDenominatorDetan; } else { detans[1] = getDetan(elementsToZeroToZList); correctFormule(ref detans[1]); detans[3] = getDetan(elementsToZeroToQList); correctFormule(ref detans[3]); DetansPair detansPair = new DetansPair(detans[1], detans[3]); mainForm.elementsStringToDetansMap.Add(keyForSubtended, detansPair); //mainForm.elementsStringToDetansMap[keyForSubtended].itsNumeratorDetan = detans[1]; //mainForm.elementsStringToDetansMap[keyForSubtended].itsDenominatorDetan = detans[3]; } for (int i = 0; i < detans.Length; i++) { correctFormule(ref detans[i]); } return(detans); }
public PassiveElement(PassiveElement element) : base(element) { }
/* Частный случай функции getDetans для одного элемента */ static string[] getDetans(PassiveElement selectedElement, SchemeForTolerance scheme) { List<Element> elementsList = new List<Element>();//scheme.passiveElementsList; foreach (PassiveElement element in scheme.passiveElementsList) { elementsList.Add(element); } elementsList.AddRange((selectedElement).clonnedElements); elementsList.Remove((selectedElement).cloneElement); elementsList.AddRange(scheme.nullersList); List<Element> elementToInfinList = new List<Element>(elementsList); List<Element> elementToZeroList = new List<Element>(elementsList); scheme.transformElementToInfin(((PassiveElement)selectedElement).cloneElement, elementToInfinList); scheme.transformElementToZero(((PassiveElement)selectedElement).cloneElement, elementToZeroList); //scheme.transformElementToInfin(element, elementToInfinList); //scheme.transformElementToZero(element, elementToZeroList); List<Element> activeElementsForZ = scheme.getActiveElementsListForZ(); List<Element> activeElementsForQ = scheme.getActiveElementsListForQ(); List<Element> elementsToInfinToZList = new List<Element>(elementToInfinList); elementsToInfinToZList.AddRange(activeElementsForZ); List<Element> elementsToZeroToZList = new List<Element>(elementToZeroList); elementsToZeroToZList.AddRange(activeElementsForZ); List<Element> elementsToInfinToQList = new List<Element>(elementToInfinList); elementsToInfinToQList.AddRange(activeElementsForQ); List<Element> elementsToZeroToQList = new List<Element>(elementToZeroList); elementsToZeroToQList.AddRange(activeElementsForQ); string[] detans = new string[4]; string elementName = selectedElement.getRightName(); string keyForRemoved = elementName + "|" + "δ(" + elementName + ")"; string keyForSubtended = elementName + "|"; if (mainForm.elementsStringToDetansMap.ContainsKey(keyForRemoved)) { detans[0] = mainForm.elementsStringToDetansMap[keyForRemoved].itsNumeratorDetan; detans[2] = mainForm.elementsStringToDetansMap[keyForRemoved].itsDenominatorDetan; } else { detans[0] = getDetan(elementsToInfinToZList); correctFormule(ref detans[0]); detans[2] = getDetan(elementsToInfinToQList); correctFormule(ref detans[2]); DetansPair detansPair = new DetansPair(detans[0], detans[2]); mainForm.elementsStringToDetansMap.Add(keyForRemoved, detansPair); //mainForm.elementsStringToDetansMap[keyForRemoved].itsDenominatorDetan = detans[2]; } if (mainForm.elementsStringToDetansMap.ContainsKey(keyForSubtended)) { detans[1] = mainForm.elementsStringToDetansMap[keyForSubtended].itsNumeratorDetan; detans[3] = mainForm.elementsStringToDetansMap[keyForSubtended].itsDenominatorDetan; } else { detans[1] = getDetan(elementsToZeroToZList); correctFormule(ref detans[1]); detans[3] = getDetan(elementsToZeroToQList); correctFormule(ref detans[3]); DetansPair detansPair = new DetansPair(detans[1], detans[3]); mainForm.elementsStringToDetansMap.Add(keyForSubtended, detansPair); //mainForm.elementsStringToDetansMap[keyForSubtended].itsNumeratorDetan = detans[1]; //mainForm.elementsStringToDetansMap[keyForSubtended].itsDenominatorDetan = detans[3]; } for (int i = 0; i < detans.Length; i++) { correctFormule(ref detans[i]); } return detans; }
/* Нахождение пар определителей N и D для всех возможных сочетаний элементов */ /* из заданного набора elements */ /* Возвращает ассоциативный массив, где ключ - сочетание элементов, значение - пара определителей */ //static Dictionary<string, detansPair> getDetans( static Dictionary<string, DetansPair> getDetans( PassiveElement[] elements, AdvancedScheme scheme, ref int detansCount) { Dictionary<string, DetansPair> elementsToDetanPairDictionary = new Dictionary<string, DetansPair>(); int elementsCount = elements.Length; List<Element> elementsList = new List<Element>(); foreach (PassiveElement element in scheme.passiveElementsList) { elementsList.Add(element); } List<Element> activeElementsForZ = scheme.activeElementsListForZ; List<Element> activeElementsForQ = scheme.activeElementsListForQ; foreach (PassiveElement element in elements) { elementsList.AddRange((element).clonnedElements); elementsList.Remove((element).cloneElement); } string selectedElementsString = elementsToNamesString(elements); //elementsList.AddRange(scheme.nullersList); /* Перебор длин сочетаний элементов */ for (int i = 0; i <= elementsCount; i++) { /* Первое сочетание данной длины */ int[] indexes = makeCombination(i); /* Перебор остальных сочетаний данной длины */ while (true) { List<Element> removedElements = new List<Element>(); List<Element> subtendedElements = new List<Element>(); List<Element> localElementsList = new List<Element>(elementsList); List<Element> associatedElements = new List<Element>(); /* Перебор элементов данного сочетания */ for (int j = 0; j < elementsCount; j++) { /* Нейтрализация или стягивание элемента */ if (Array.IndexOf(indexes, j + 1) >= 0) { scheme.transformElementToInfin((elements[j]).cloneElement, localElementsList); associatedElements.Add(elements[j]); removedElements.Add(elements[j]); } else { scheme.transformElementToZero((elements[j]).cloneElement, localElementsList); subtendedElements.Add(elements[j]); } } /* Далее - формирование списка элементов и рассчет определителей */ List<Element> elementsListToZ = new List<Element>(localElementsList); elementsListToZ.AddRange(activeElementsForZ); List<Element> elementsListToQ = new List<Element>(localElementsList); elementsListToQ.AddRange(activeElementsForQ); string pattern = "δ(%element%)"; string delimiter = ";"; string removedElementsString = elementsToNamesString(removedElements, pattern, delimiter); string keyString = selectedElementsString + "|" + removedElementsString; string numeratorDetan; string denominatorDetan; if (mainForm.elementsStringToDetansMap.ContainsKey(keyString)) { numeratorDetan = mainForm.elementsStringToDetansMap[keyString].itsNumeratorDetan; denominatorDetan = mainForm.elementsStringToDetansMap[keyString].itsDenominatorDetan; } else { numeratorDetan = getDetan(elementsListToZ); //mainForm.elementsStringToDetansMap[keyString].itsNumeratorDetan = numeratorDetan; denominatorDetan = getDetan(elementsListToQ); correctFormule(ref numeratorDetan); correctFormule(ref denominatorDetan); //mainForm.elementsStringToDetansMap[keyString].itsDenominatorDetan = denominatorDetan; mainForm.elementsStringToDetansMap.Add( keyString, new DetansPair(numeratorDetan,denominatorDetan)); } string elementsString = elementsToNamesString(associatedElements); elementsToDetanPairDictionary.Add(elementsString, new DetansPair(numeratorDetan, denominatorDetan)); detansCount += 2; if (nextCombination(indexes, elements.Length) != 0) break; } } return elementsToDetanPairDictionary; }