private void simpleButton3_Click(object sender, EventArgs e) { string strExpression = ""; if (textBox1.Text == "") { MessageBox.Show("表达式不能为空"); return; } if (textBox2.Text == "") { textBox2.Text = "2"; SaveDecimalpoint = 2; } else { SaveDecimalPoint = Convert.ToInt32(textBox2.Text); if (SaveDecimalPoint < 0) { SaveDecimalPoint = 2; textBox2.Text = "2"; } else if (SaveDecimalPoint > 15) { SaveDecimalPoint = 15; textBox2.Text = "15"; } } ExpressionCalculator calc = new ExpressionCalculator(); strExpression = calc.CharConverter(textBox1.Text); textBox1.Text = strExpression; if (!calc.ExpressiontempISIllegal(strExpression, gridView1, true, SaveDecimalPoint)) { return; } }
/// <summary> /// 将字符串类型的数字转换为double类型,支持中文以及带单位 /// </summary> /// <param name="str"></param> /// <param name="doubleResult"></param> /// <param name="kouType"></param> /// <returns></returns> public static bool TryToDouble(string str, out double doubleResult, bool kouType = true) { doubleResult = 0; if (str.IsNullOrWhiteSpace()) { return(false); } if (!kouType) { return(double.TryParse(str, out doubleResult)); } //如果有中文的数字,转为阿拉伯数字 if (ZhNumber.IsContainZhNumber(str)) { str = ZhNumber.ToArabicNumber(str); } if (!double.TryParse(str, NumberStyles.Float, null, out doubleResult)) { if (NumberConvertor.WebUnitDouble(str, out string parsedStr)) { str = parsedStr; } ExpressionCalculator calculator = new ExpressionCalculator();//BUG 没有处理abc等非表达式情况,仍然会认为输入了正确的表达式 if (str.Contains("上")) { str = str.Replace("上", ""); //乘上、加上等 } if (str.Contains("去")) { str = str.Replace("去", ""); } str = str.ReplaceAllFromPairSet(KouStaticData.ZhMathToSymbolMath); var result = calculator.Calculate(str)?.ToString(); if (result != null && result != double.NaN.ToString(CultureInfo.InvariantCulture)) { return(double.TryParse(result, out doubleResult)); } return(false); } return(true); }
static void Main(string[] args) { while (true) { Console.WriteLine("Enter Infix Expression"); string expression = Console.ReadLine(); if (string.IsNullOrWhiteSpace(expression)) { break; } try { Console.WriteLine(ExpressionCalculator.ProcessExpression(expression)); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } } }
public override void BuildParameters(DataRow row, DataObjectStore store, IList <ParameterProfile> paramInfos) { if (!string.IsNullOrEmpty(this.CommandTextLambdaExpression)) { this.DataHandler.CommandText = (string)ExpressionCalculator.CalculateLambdaExpression(ExpressionCalculator.BuildColumnExpression(this.CommandTextLambdaExpression), typeof(string), row, null); } this.DataHandler.Parameters.Clear(); if (!string.IsNullOrEmpty(this.DataObjectName)) { this.DataHandler.Parameters.AddWithValue("Instance", store.GetDataObject(this.DataObjectName)); } else { this.DataHandler.KeepInstanceParamerter = true; } MonadSaveTask.BuildParametersCore(row, paramInfos, this.DataHandler.Parameters); this.workUnitDescription = MonadSaveTask.BuildParametersDescription(row, paramInfos); this.DataHandler.ClearParameterNames(); this.DataHandler.SpecifyParameterNames(store.GetModifiedPropertiesBasedOnDataObject(row, this.DataObjectName)); }
public void Calculate(string filedname, string StrExpressiontemp, int SaveDecimalPoint) { if (ObjectList == null) { return; } IList <Substation_Info> listtemp = ObjectList; ExpressionCalculator ca = new ExpressionCalculator(); if (ca.RowCalculator(StrExpressiontemp, this.gridView, ref listtemp, filedname, SaveDecimalPoint)) { RowCalculate(ref listtemp); //刷新表格,并将焦点行定位到新对象上。 } else { foreach (Substation_Info Subtemp in listtemp) { Services.BaseService.Update <Substation_Info>(Subtemp); } } gridControl.RefreshDataSource(); }
public ExpressionResult Evaluate(double initialValue = 0, Character target = null) { return(ExpressionCalculator.Evaluate(initialValue, Expr, target, Vars)); }
protected bool SaveRecord() { try { ExpressionCalculator ca = new ExpressionCalculator(); if (_obj.L4 != "") { if (ca.ISIllegal(ca.CharConverter(_obj.L4))) { _obj.L2 = ca.Calculator(ca.CharConverter(_obj.L4), 2); } } if (_obj.L13 != "0") _obj.S6 = string.Format("{0:f}", double.Parse(_obj.L14) * 100 / double.Parse(_obj.L13)); } catch { } if (_obj.L2 != 0) _obj.L10 = _obj.L9*100 / _obj.L2; try { int x = int.Parse(_obj.S2); if (x > DateTime.Now.Year) _obj.Flag = "2"; else _obj.Flag = "1"; } catch { _obj.Flag = "1"; } //����/�� ���� // _obj.L30 = projectid; try { _obj.AreaID = projectid; if (IsCreate) { _obj.UID += "|" + projectid; Services.BaseService.Create<Substation_Info>(_obj); } else { Services.BaseService.Update<Substation_Info>(_obj); } } catch (Exception exc) { Debug.Fail(exc.Message); HandleException.TryCatch(exc); return false ; } //�����ѳɹ� return true; }
public AlpsGeneticAlgorithmMainOperator() : base() { Parameters.Add(new ValueLookupParameter <IRandom>("Random", "A pseudo random number generator.")); Parameters.Add(new ValueLookupParameter <IOperator>("Evaluator", "The operator used to evaluate solutions. This operator is executed in parallel, if an engine is used which supports parallelization.")); Parameters.Add(new ValueLookupParameter <IntValue>("EvaluatedSolutions", "The number of times solutions have been evaluated.")); Parameters.Add(new ScopeTreeLookupParameter <DoubleValue>("Quality", "The value which represents the quality of a solution.")); Parameters.Add(new ValueLookupParameter <BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false.")); Parameters.Add(new ValueLookupParameter <IntValue>("PopulationSize", "The size of the population of solutions in each layer.")); Parameters.Add(new ValueLookupParameter <IOperator>("Selector", "The operator used to select solutions for reproduction.")); Parameters.Add(new ValueLookupParameter <IOperator>("Crossover", "The operator used to cross solutions.")); Parameters.Add(new ValueLookupParameter <IOperator>("Mutator", "The operator used to mutate solutions.")); Parameters.Add(new ValueLookupParameter <PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution.")); Parameters.Add(new ValueLookupParameter <IntValue>("Elites", "The numer of elite solutions which are kept in each generation.")); Parameters.Add(new ValueLookupParameter <BoolValue>("ReevaluateElites", "Flag to determine if elite individuals should be reevaluated (i.e., if stochastic fitness functions are used.)")); Parameters.Add(new ValueLookupParameter <BoolValue>("PlusSelection", "Include the parents in the selection of the invividuals for the next generation.")); Parameters.Add(new ScopeTreeLookupParameter <DoubleValue>("Age", "The age of individuals.")); Parameters.Add(new ValueLookupParameter <DoubleValue>("AgeInheritance", "A weight that determines the age of a child after crossover based on the older (1.0) and younger (0.0) parent.")); Parameters.Add(new ValueLookupParameter <DoubleValue>("AgeIncrement", "The value the age the individuals is incremented if they survives a generation.")); var numberOfSelectedParentsCalculator = new ExpressionCalculator() { Name = "NumberOfSelectedParents = 2 * (PopulationSize - (PlusSelection ? 0 : Elites))" }; var selector = new Placeholder() { Name = "Selector (Placeholder)" }; var subScopesProcessor1 = new SubScopesProcessor(); var childrenCreator = new ChildrenCreator(); var uniformSubScopesProcessor1 = new UniformSubScopesProcessor(); var crossover = new Placeholder() { Name = "Crossover (Placeholder)" }; var stochasticBranch = new StochasticBranch() { Name = "MutationProbability" }; var mutator = new Placeholder() { Name = "Mutator (Placeholder)" }; var ageCalculator = new WeightingReducer() { Name = "Calculate Age" }; var subScopesRemover = new SubScopesRemover(); var uniformSubScopesProcessor2 = new UniformSubScopesProcessor(); var evaluator = new Placeholder() { Name = "Evaluator (Placeholder)" }; var subScopesCounter = new SubScopesCounter() { Name = "Increment EvaluatedSolutions" }; var replacementBranch = new ConditionalBranch() { Name = "PlusSelection?" }; var replacementMergingReducer = new MergingReducer(); var replacementBestSelector = new BestSelector(); var replacementRightReducer = new RightReducer(); var subScopesProcessor2 = new SubScopesProcessor(); var bestSelector = new BestSelector(); var rightReducer = new RightReducer(); var mergingReducer = new MergingReducer(); var reevaluateElitesBranch = new ConditionalBranch() { Name = "Reevaluate elites ?" }; var incrementAgeProcessor = new UniformSubScopesProcessor(); var ageIncrementor = new DoubleCounter() { Name = "Increment Age" }; OperatorGraph.InitialOperator = numberOfSelectedParentsCalculator; numberOfSelectedParentsCalculator.CollectedValues.Add(new LookupParameter <IntValue>(PopulationSizeParameter.Name)); numberOfSelectedParentsCalculator.CollectedValues.Add(new LookupParameter <IntValue>(ElitesParameter.Name)); numberOfSelectedParentsCalculator.CollectedValues.Add(new LookupParameter <BoolValue>(PlusSelectionParameter.Name)); numberOfSelectedParentsCalculator.ExpressionResultParameter.ActualName = "NumberOfSelectedSubScopes"; numberOfSelectedParentsCalculator.ExpressionParameter.Value = new StringValue("PopulationSize 0 Elites PlusSelection if - 2 * toint"); numberOfSelectedParentsCalculator.Successor = selector; selector.OperatorParameter.ActualName = SelectorParameter.Name; selector.Successor = subScopesProcessor1; subScopesProcessor1.Operators.Add(new EmptyOperator()); subScopesProcessor1.Operators.Add(childrenCreator); subScopesProcessor1.Successor = replacementBranch; childrenCreator.ParentsPerChild = new IntValue(2); childrenCreator.Successor = uniformSubScopesProcessor1; uniformSubScopesProcessor1.Operator = crossover; uniformSubScopesProcessor1.Successor = uniformSubScopesProcessor2; crossover.OperatorParameter.ActualName = CrossoverParameter.Name; crossover.Successor = stochasticBranch; stochasticBranch.ProbabilityParameter.ActualName = MutationProbabilityParameter.Name; stochasticBranch.RandomParameter.ActualName = RandomParameter.Name; stochasticBranch.FirstBranch = mutator; stochasticBranch.SecondBranch = null; stochasticBranch.Successor = ageCalculator; mutator.OperatorParameter.ActualName = MutatorParameter.Name; mutator.Successor = null; ageCalculator.ParameterToReduce.ActualName = AgeParameter.Name; ageCalculator.TargetParameter.ActualName = AgeParameter.Name; ageCalculator.WeightParameter.ActualName = AgeInheritanceParameter.Name; ageCalculator.Successor = subScopesRemover; subScopesRemover.RemoveAllSubScopes = true; subScopesRemover.Successor = null; uniformSubScopesProcessor2.Parallel.Value = true; uniformSubScopesProcessor2.Operator = evaluator; uniformSubScopesProcessor2.Successor = subScopesCounter; evaluator.OperatorParameter.ActualName = EvaluatorParameter.Name; evaluator.Successor = null; subScopesCounter.ValueParameter.ActualName = EvaluatedSolutionsParameter.Name; subScopesCounter.AccumulateParameter.Value = new BoolValue(true); subScopesCounter.Successor = null; replacementBranch.ConditionParameter.ActualName = PlusSelectionParameter.Name; replacementBranch.TrueBranch = replacementMergingReducer; replacementBranch.FalseBranch = subScopesProcessor2; replacementBranch.Successor = incrementAgeProcessor; replacementMergingReducer.Successor = replacementBestSelector; replacementBestSelector.NumberOfSelectedSubScopesParameter.ActualName = PopulationSizeParameter.Name; replacementBestSelector.CopySelected = new BoolValue(false); replacementBestSelector.Successor = replacementRightReducer; replacementRightReducer.Successor = reevaluateElitesBranch; subScopesProcessor2.Operators.Add(bestSelector); subScopesProcessor2.Operators.Add(new EmptyOperator()); subScopesProcessor2.Successor = mergingReducer; bestSelector.CopySelected = new BoolValue(false); bestSelector.MaximizationParameter.ActualName = MaximizationParameter.Name; bestSelector.NumberOfSelectedSubScopesParameter.ActualName = ElitesParameter.Name; bestSelector.QualityParameter.ActualName = QualityParameter.Name; bestSelector.Successor = rightReducer; rightReducer.Successor = reevaluateElitesBranch; mergingReducer.Successor = null; reevaluateElitesBranch.ConditionParameter.ActualName = ReevaluateElitesParameter.Name; reevaluateElitesBranch.TrueBranch = uniformSubScopesProcessor2; reevaluateElitesBranch.FalseBranch = null; reevaluateElitesBranch.Successor = null; incrementAgeProcessor.Operator = ageIncrementor; incrementAgeProcessor.Successor = null; ageIncrementor.ValueParameter.ActualName = AgeParameter.Name; ageIncrementor.IncrementParameter.Value = null; ageIncrementor.IncrementParameter.ActualName = AgeIncrementParameter.Name; ageIncrementor.Successor = null; }
public static void CreateOutput(object sender, object selectedItem) { if (selectedItem is OutputCollectionViewModel outputCollectionViewModel) { CreateOutput(sender, outputCollectionViewModel.Parent); return; } if (!(selectedItem is GroupViewModel entityGroupViewModel)) { return; } var button = (Button)sender; var type = (string)button.CommandParameter; OutputBase entity; switch (type) { case nameof(RenderArrayHint): entity = RenderArrayHint.New(); break; case nameof(RenderNextDate): entity = RenderNextDate.New("Name", "0001-01-01", "Weekly"); break; case nameof(RenderIndex): entity = RenderIndex.New(); break; case nameof(RenderEntity): entity = RenderEntity.New(); break; case nameof(RenderLink): entity = RenderLink.New(); break; case nameof(RenderProperty): entity = RenderProperty.New("Display Name", "Property Name"); break; case nameof(RenderValue): entity = RenderValue.New("Name", "Value"); break; case nameof(RenderTypeName): entity = RenderTypeName.New("Name"); break; case nameof(RenderTaxPeriodDate): entity = RenderTaxPeriodDate.New("Name", "2020", "1"); break; case nameof(RenderConstant): entity = RenderConstant.New("Name", "Constant Name", typeof(DateTime)); break; case nameof(RenderTaxPeriod): entity = RenderTaxPeriod.New("Name", "Monthly", "0001-01-01"); break; case nameof(RenderDateAdd): entity = RenderDateAdd.New("Name", "0001-01-01", "Day", "1"); break; case nameof(RenderUniqueKeyFromLink): entity = RenderUniqueKeyFromLink.New("Name", "[Link]"); break; case nameof(Avg): entity = Avg.New("Name", "Property"); break; case nameof(Max): entity = Max.New("Name", "Property"); break; case nameof(Min): entity = Min.New("Name", "Property"); break; case nameof(Sum): entity = Sum.New("Name", "Property"); break; case nameof(Count): entity = Count.New("Name"); break; case nameof(ExpressionCalculator): entity = ExpressionCalculator.New("Name", "1 + 2 - 3 * 4 / 5", rounding: RoundingOption.NotSet); break; case nameof(Distinct): entity = Distinct.New("Name", "Property"); break; default: throw new ArgumentOutOfRangeException(); } entityGroupViewModel.Element.Outputs.Add(entity); var viewModelCollection = entityGroupViewModel.Children.OfType <OutputCollectionViewModel>().First(); var viewModel = new OutputViewModel(entity, viewModelCollection); viewModelCollection.Children.Add(viewModel); entityGroupViewModel.IsExpanded = true; viewModelCollection.IsExpanded = true; viewModel.IsSelected = true; viewModel.IsExpanded = true; }
public void Setup() { _sut = new ExpressionCalculator(new OperatorMapper()); }
public void ThirdExpressionTest(double a, double b, double c, double d, double expectedValue) { Assert.AreEqual(expectedValue, ExpressionCalculator.Third(a, b, c, d), 0.0001); }
private void InsertSubstation_Info() { //LayoutList ll1 = this.ctrlLayoutList1.FocusedObject; //if (ll1 == null) // return; string columnname = ""; try { DataTable dts = new DataTable(); OpenFileDialog op = new OpenFileDialog(); op.Filter = "Excel�ļ�(*.xls)|*.xls"; if (op.ShowDialog() == DialogResult.OK) { dts = GetExcel(op.FileName); string str = ""; IList<Substation_Info> lii = new List<Substation_Info>(); DateTime s8 = DateTime.Now; int x=0; str = ""; for (int i = 0; i < dts.Rows.Count; i++) { if (dts.Rows[i][1].ToString().IndexOf("�ϼ�") >= 0) continue; if (dts.Rows[i]["Title"].ToString() == "500ǧ��" || dts.Rows[i]["Title"].ToString() == "220ǧ��" || dts.Rows[i]["Title"].ToString() == "110ǧ������" || dts.Rows[i]["Title"].ToString() == "110ǧ��ר��") { if (dts.Rows[i]["Title"].ToString() == "110ǧ��ר��") { str = "ר��"; } else if (dts.Rows[i]["Title"].ToString() == "110ǧ������") str = "����"; else str = ""; //continue; } try { int.Parse(dts.Rows[i]["S3"].ToString()); } catch { continue; } Substation_Info l1 = new Substation_Info(); foreach (DataColumn dc in dts.Columns) { columnname = dc.ColumnName; if (dts.Rows[i][dc.ColumnName].ToString() == "" ) continue; switch (dc.ColumnName) { case "L2": case "L9": double LL2 = 0; try { LL2 = Convert.ToDouble(dts.Rows[i][dc.ColumnName].ToString()); } catch { } l1.GetType().GetProperty(dc.ColumnName).SetValue(l1, LL2, null); break; case "L10": double L10 = 0; try { L10 = ChangeDou(dts.Rows[i][dc.ColumnName].ToString()); } catch { } l1.GetType().GetProperty(dc.ColumnName).SetValue(l1, L10, null); break; case "L1": case "L3": int LL3 = 0; try { LL3 = Convert.ToInt32(dts.Rows[i][dc.ColumnName].ToString()); } catch { } l1.GetType().GetProperty(dc.ColumnName).SetValue(l1, LL3, null); break; default: l1.GetType().GetProperty(dc.ColumnName).SetValue(l1, dts.Rows[i][dc.ColumnName].ToString(), null); break; } } l1.S4 = str; l1.Flag = selectid; l1.CreateDate = s8.AddSeconds(i); l1.AreaID = ProjectUID; lii.Add(l1); } foreach (Substation_Info lll in lii) { Substation_Info l1 = new Substation_Info(); //l1.UID += "|" + ProjectUID; l1.AreaName = lll.AreaName; l1.Title = lll.Title; l1.AreaID = ProjectUID; l1.Flag = selectid; try { int tx = int.Parse(l1.S2); if (tx > DateTime.Now.Year) l1.Flag = "2"; else l1.Flag = "1"; } catch { l1.Flag = "1"; } string con = "AreaID='" + ProjectUID + "' and Title='" + l1.Title + "' and Flag='" + selectid + "'"; object obj = Services.BaseService.GetObject("SelectSubstation_InfoByCon", con); ExpressionCalculator ca = new ExpressionCalculator(); if (lll.L4 != "") { if (ca.ISIllegal(ca.CharConverter(lll.L4))) { lll.L2 = ca.Calculator(ca.CharConverter(lll.L4), 2); } } if (obj != null) { lll.UID = ((Substation_Info)obj).UID; Services.BaseService.Update<Substation_Info>(lll); } else { lll.UID += "|" + ProjectUID; Services.BaseService.Create<Substation_Info>(lll); } } this.ctrlSubstation_Info1.CalcTotal(); } } catch (Exception ex) { MsgBox.Show(columnname + ex.Message); MsgBox.Show("�����ʽ����ȷ��"); } }
private CombinedOperator CreateEldersEmigrator() { var eldersEmigrator = new CombinedOperator() { Name = "Emigrate Elders" }; var selectorProsessor = new UniformSubScopesProcessor(); var eldersSelector = new EldersSelector(); var shiftToRightMigrator = new UnidirectionalRingMigrator() { Name = "Shift elders to next layer" }; var mergingProsessor = new UniformSubScopesProcessor(); var mergingReducer = new MergingReducer(); var subScopesCounter = new SubScopesCounter(); var reduceToPopulationSizeBranch = new ConditionalBranch() { Name = "ReduceToPopulationSize?" }; var countCalculator = new ExpressionCalculator() { Name = "CurrentPopulationSize = Min(CurrentPopulationSize, PopulationSize)" }; var bestSelector = new BestSelector(); var rightReducer = new RightReducer(); eldersEmigrator.OperatorGraph.InitialOperator = selectorProsessor; selectorProsessor.Operator = eldersSelector; selectorProsessor.Successor = shiftToRightMigrator; eldersSelector.AgeParameter.ActualName = AgeParameter.Name; eldersSelector.AgeLimitsParameter.ActualName = AgeLimitsParameter.Name; eldersSelector.NumberOfLayersParameter.ActualName = NumberOfLayersParameter.Name; eldersSelector.LayerParameter.ActualName = "Layer"; eldersSelector.Successor = null; shiftToRightMigrator.ClockwiseMigrationParameter.Value = new BoolValue(true); shiftToRightMigrator.Successor = mergingProsessor; mergingProsessor.Operator = mergingReducer; mergingReducer.Successor = subScopesCounter; subScopesCounter.ValueParameter.ActualName = CurrentPopulationSizeParameter.Name; subScopesCounter.AccumulateParameter.Value = new BoolValue(false); subScopesCounter.Successor = reduceToPopulationSizeBranch; reduceToPopulationSizeBranch.ConditionParameter.ActualName = ReduceToPopulationSizeParameter.Name; reduceToPopulationSizeBranch.TrueBranch = countCalculator; countCalculator.CollectedValues.Add(new LookupParameter <IntValue>(PopulationSizeParameter.Name)); countCalculator.CollectedValues.Add(new LookupParameter <IntValue>(CurrentPopulationSizeParameter.Name)); countCalculator.ExpressionParameter.Value = new StringValue("CurrentPopulationSize PopulationSize CurrentPopulationSize PopulationSize < if toint"); countCalculator.ExpressionResultParameter.ActualName = CurrentPopulationSizeParameter.Name; countCalculator.Successor = bestSelector; bestSelector.NumberOfSelectedSubScopesParameter.ActualName = CurrentPopulationSizeParameter.Name; bestSelector.CopySelected = new BoolValue(false); bestSelector.Successor = rightReducer; return(eldersEmigrator); }
private CombinedOperator CreateEldersEmigrator() { var eldersEmigrator = new CombinedOperator { Name = "Emigrate Elders" }; var selectorProcessor = new UniformSubScopesProcessor(); var eldersSelector = new EldersSelector(); var shiftToRightMigrator = new UnidirectionalRingMigrator { Name = "Shift elders to next layer" }; var mergingProcessor = new UniformSubScopesProcessor(); var mergingReducer = new MergingReducer(); var subScopesCounter1 = new SubScopesCounter(); var currentPopulationSizeComparator = new Comparator { Name = "Is CurrentPopulationSize greater than 1?" }; var currentPopulationSizeIsGreaterThanOne = new ConditionalBranch { Name = "CurrentPopulationSize > 1" }; var reduceToPopulationSizeBranch = new ConditionalBranch { Name = "ReduceToPopulationSize?" }; var countCalculator = new ExpressionCalculator { Name = "CurrentPopulationSize = Min(CurrentPopulationSize, PopulationSize)" }; var leftSelector = new LeftSelector(); var rankAndCrowdingSorter = new RankAndCrowdingSorter(); var subScopesCounter2 = new SubScopesCounter(); var rightReducer = new RightReducer(); eldersEmigrator.OperatorGraph.InitialOperator = selectorProcessor; selectorProcessor.Operator = eldersSelector; selectorProcessor.Successor = shiftToRightMigrator; eldersSelector.AgeParameter.ActualName = AgeParameter.Name; eldersSelector.AgeLimitsParameter.ActualName = AgeLimitsParameter.Name; eldersSelector.NumberOfLayersParameter.ActualName = NumberOfLayersParameter.Name; eldersSelector.LayerParameter.ActualName = "Layer"; eldersSelector.Successor = null; shiftToRightMigrator.ClockwiseMigrationParameter.Value = new BoolValue(true); shiftToRightMigrator.Successor = mergingProcessor; mergingProcessor.Operator = mergingReducer; mergingReducer.Successor = subScopesCounter1; subScopesCounter1.ValueParameter.ActualName = CurrentPopulationSizeParameter.Name; subScopesCounter1.AccumulateParameter.Value = new BoolValue(false); subScopesCounter1.Successor = currentPopulationSizeComparator; currentPopulationSizeComparator.LeftSideParameter.ActualName = CurrentPopulationSizeParameter.Name; currentPopulationSizeComparator.RightSideParameter.ActualName = OneParameter.Name; currentPopulationSizeComparator.ResultParameter.ActualName = "CurrentPopulationSizeIsGreaterThanOne"; currentPopulationSizeComparator.Comparison = new Comparison(ComparisonType.Greater); currentPopulationSizeComparator.Successor = currentPopulationSizeIsGreaterThanOne; currentPopulationSizeIsGreaterThanOne.ConditionParameter.ActualName = "CurrentPopulationSizeIsGreaterThanOne"; currentPopulationSizeIsGreaterThanOne.TrueBranch = rankAndCrowdingSorter; // We have to sort individuals before reducing, because if we shifted some of them to another layer, it can happen that they are not correctly sorted rankAndCrowdingSorter.DominateOnEqualQualitiesParameter.ActualName = DominateOnEqualQualitiesParameter.Name; rankAndCrowdingSorter.CrowdingDistanceParameter.ActualName = "CrowdingDistance"; rankAndCrowdingSorter.RankParameter.ActualName = "Rank"; rankAndCrowdingSorter.Successor = reduceToPopulationSizeBranch; reduceToPopulationSizeBranch.ConditionParameter.ActualName = ReduceToPopulationSizeParameter.Name; reduceToPopulationSizeBranch.TrueBranch = countCalculator; countCalculator.CollectedValues.Add(new LookupParameter <IntValue>(PopulationSizeParameter.Name)); countCalculator.CollectedValues.Add(new LookupParameter <IntValue>(CurrentPopulationSizeParameter.Name)); countCalculator.ExpressionParameter.Value = new StringValue("CurrentPopulationSize PopulationSize CurrentPopulationSize PopulationSize < if toint"); countCalculator.ExpressionResultParameter.ActualName = CurrentPopulationSizeParameter.Name; countCalculator.Successor = leftSelector; leftSelector.CopySelected = new BoolValue(false); leftSelector.NumberOfSelectedSubScopesParameter.ActualName = CurrentPopulationSizeParameter.Name; leftSelector.Successor = rightReducer; rightReducer.Successor = subScopesCounter2; subScopesCounter2.ValueParameter.ActualName = CurrentPopulationSizeParameter.Name; subScopesCounter2.AccumulateParameter.Value = new BoolValue(false); return(eldersEmigrator); }
public void TestsBrakets() { ExpressionCalculator expression = new ExpressionCalculator(); expression.GetResult("((2+3)*(6+5))/2").Should().Be(((2d + 3d) * (6d + 5d)) / 2d); }
public void SetUp() { subject = new ExpressionCalculator(); }
private void simpleButton1_Click(object sender, EventArgs e) { if (spinEdit1.Text == "") { MessageBox.Show("分类名不能空"); return; } //if ( textBox1.Text == "") // { // MessageBox.Show("表达式不能空"); // return; // } //if ( textBox2.Text == "") //{ // MessageBox.Show("保留小数点位数不能空"); // return; //} if (textBox2.Text=="") { SaveDecimalPoint = 2; textBox2.Text = "2"; } else { SaveDecimalPoint=Convert.ToInt32(textBox2.Text); } if(SaveDecimalPoint>15) { SaveDecimalPoint = 15; textBox2.Text = "15"; } ExpressionCalculator calc = new ExpressionCalculator(); StrExpressiontemp = calc.CharConverter(calc.CharConverter(textBox1.Text)); textBox1.Text = StrExpressiontemp; if (!calc.GetColumnExit(gridView1, calc.CharConverter(spinEdit1.Text),filedname)) { MessageBox.Show("列名" + spinEdit1.Text + "已存在或包含括号[],请重命名"); return; } if (!calc.ExpressiontempISIllegal(StrExpressiontemp, gridView1, false, -1)) return; StrExpressiontemp = textBox1.Text; caption =calc.CharConverter(spinEdit1.Text) ; SaveDecimalpoint = Convert.ToInt32(textBox2.Text); this.DialogResult = DialogResult.OK; }
private void simpleButton3_Click(object sender, EventArgs e) { string strExpression = ""; if (textBox1.Text == "") { MessageBox.Show("表达式不能为空"); return; } if (textBox2.Text == "") { textBox2.Text = "2"; SaveDecimalpoint = 2; } else { SaveDecimalPoint = Convert.ToInt32(textBox2.Text); if (SaveDecimalPoint < 0) { SaveDecimalPoint = 2; textBox2.Text = "2"; } else if (SaveDecimalPoint > 15) { SaveDecimalPoint = 15; textBox2.Text = "15"; } } ExpressionCalculator calc = new ExpressionCalculator(); strExpression = calc.CharConverter(textBox1.Text); textBox1.Text = strExpression; if (!calc.ExpressiontempISIllegal(strExpression, gridView1, true, SaveDecimalPoint)) return; }
private void Initialize() { #region Create parameters Parameters.Add(new ValueLookupParameter <IRandom>("Random", "A pseudo random number generator.")); Parameters.Add(new ValueLookupParameter <BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false.")); Parameters.Add(new ScopeTreeLookupParameter <DoubleValue>("Quality", "The value which represents the quality of a solution.")); Parameters.Add(new ValueLookupParameter <IOperator>("Selector", "The operator used to select solutions for reproduction.")); Parameters.Add(new ValueLookupParameter <IOperator>("Crossover", "The operator used to cross solutions.")); Parameters.Add(new ValueLookupParameter <PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution.")); Parameters.Add(new ValueLookupParameter <IOperator>("Mutator", "The operator used to mutate solutions.")); Parameters.Add(new ValueLookupParameter <IOperator>("Evaluator", "The operator used to evaluate solutions. This operator is executed in parallel, if an engine is used which supports parallelization.")); Parameters.Add(new ValueLookupParameter <IntValue>("Elites", "The numer of elite solutions which are kept in each generation.")); Parameters.Add(new ValueLookupParameter <BoolValue>("ReevaluateElites", "Flag to determine if elite individuals should be reevaluated (i.e., if stochastic fitness functions are used.)")); Parameters.Add(new ValueLookupParameter <IntValue>("MaximumGenerations", "The maximum number of generations which should be processed.")); Parameters.Add(new ValueLookupParameter <VariableCollection>("Results", "The variable collection where results should be stored.")); Parameters.Add(new ValueLookupParameter <IOperator>("Analyzer", "The operator used to analyze each generation.")); Parameters.Add(new ValueLookupParameter <IntValue>("EvaluatedSolutions", "The number of times solutions have been evaluated.")); Parameters.Add(new ValueLookupParameter <IntValue>("PopulationSize", "The size of the population.")); Parameters.Add(new ValueLookupParameter <IntValue>("MinimumPopulationSize", "The minimum size of the population of solutions.")); Parameters.Add(new ValueLookupParameter <IntValue>("MaximumPopulationSize", "The maximum size of the population of solutions.")); Parameters.Add(new ValueLookupParameter <DoubleValue>("ComparisonFactor", "The comparison factor.")); Parameters.Add(new ValueLookupParameter <IntValue>("Effort", "The maximum number of offspring created in each generation.")); Parameters.Add(new ValueLookupParameter <IntValue>("BatchSize", "The number of children that should be created during one iteration of the offspring creation process.")); Parameters.Add(new ValueLookupParameter <ISolutionSimilarityCalculator>("SimilarityCalculator", "The operator used to calculate the similarity between two solutions.")); Parameters.Add(new ScopeParameter("CurrentScope", "The current scope which represents a population of solutions on which the genetic algorithm should be applied.")); #endregion #region Create operators VariableCreator variableCreator = new VariableCreator(); Assigner assigner1 = new Assigner(); ResultsCollector resultsCollector = new ResultsCollector(); Placeholder analyzer1 = new Placeholder(); Placeholder selector = new Placeholder(); SubScopesProcessor subScopesProcessor1 = new SubScopesProcessor(); ChildrenCreator childrenCreator = new ChildrenCreator(); UniformSubScopesProcessor uniformSubScopesProcessor = new UniformSubScopesProcessor(); Placeholder crossover = new Placeholder(); StochasticBranch stochasticBranch = new StochasticBranch(); Placeholder mutator = new Placeholder(); Placeholder evaluator = new Placeholder(); WeightedParentsQualityComparator weightedParentsQualityComparator = new WeightedParentsQualityComparator(); SubScopesRemover subScopesRemover = new SubScopesRemover(); IntCounter intCounter1 = new IntCounter(); IntCounter intCounter2 = new IntCounter(); ConditionalSelector conditionalSelector = new ConditionalSelector(); RightReducer rightReducer1 = new RightReducer(); DuplicatesSelector duplicateSelector = new DuplicatesSelector(); LeftReducer leftReducer1 = new LeftReducer(); ProgressiveOffspringPreserver progressiveOffspringSelector = new ProgressiveOffspringPreserver(); SubScopesCounter subScopesCounter2 = new SubScopesCounter(); ExpressionCalculator calculator1 = new ExpressionCalculator(); ConditionalBranch conditionalBranch1 = new ConditionalBranch(); Comparator comparator1 = new Comparator(); ConditionalBranch conditionalBranch2 = new ConditionalBranch(); LeftReducer leftReducer2 = new LeftReducer(); SubScopesProcessor subScopesProcessor2 = new SubScopesProcessor(); BestSelector bestSelector = new BestSelector(); RightReducer rightReducer2 = new RightReducer(); ScopeCleaner scopeCleaner = new ScopeCleaner(); ScopeRestorer scopeRestorer = new ScopeRestorer(); MergingReducer mergingReducer = new MergingReducer(); IntCounter intCounter3 = new IntCounter(); SubScopesCounter subScopesCounter3 = new SubScopesCounter(); ExpressionCalculator calculator2 = new ExpressionCalculator(); Comparator comparator2 = new Comparator(); ConditionalBranch conditionalBranch3 = new ConditionalBranch(); Placeholder analyzer2 = new Placeholder(); Comparator comparator3 = new Comparator(); ConditionalBranch conditionalBranch4 = new ConditionalBranch(); Comparator comparator4 = new Comparator(); ConditionalBranch conditionalBranch5 = new ConditionalBranch(); Assigner assigner3 = new Assigner(); Assigner assigner4 = new Assigner(); Assigner assigner5 = new Assigner(); ConditionalBranch reevaluateElitesBranch = new ConditionalBranch(); UniformSubScopesProcessor uniformSubScopesProcessor2 = new UniformSubScopesProcessor(); Placeholder evaluator2 = new Placeholder(); SubScopesCounter subScopesCounter4 = new SubScopesCounter(); variableCreator.CollectedValues.Add(new ValueParameter <IntValue>("Generations", new IntValue(0))); // Class RAPGA expects this to be called Generations variableCreator.CollectedValues.Add(new ValueParameter <IntValue>("CurrentPopulationSize", new IntValue(0))); variableCreator.CollectedValues.Add(new ValueParameter <IntValue>("NumberOfCreatedOffspring", new IntValue(0))); variableCreator.CollectedValues.Add(new ValueParameter <IntValue>("NumberOfSuccessfulOffspring", new IntValue(0))); variableCreator.CollectedValues.Add(new ValueParameter <ScopeList>("OffspringList", new ScopeList())); assigner1.Name = "Initialize CurrentPopulationSize"; assigner1.LeftSideParameter.ActualName = "CurrentPopulationSize"; assigner1.RightSideParameter.ActualName = PopulationSizeParameter.Name; resultsCollector.CollectedValues.Add(new LookupParameter <IntValue>("Generations")); resultsCollector.CollectedValues.Add(new LookupParameter <IntValue>("CurrentPopulationSize")); resultsCollector.ResultsParameter.ActualName = "Results"; analyzer1.Name = "Analyzer"; analyzer1.OperatorParameter.ActualName = "Analyzer"; selector.Name = "Selector"; selector.OperatorParameter.ActualName = "Selector"; childrenCreator.ParentsPerChild = new IntValue(2); uniformSubScopesProcessor.Parallel.Value = true; crossover.Name = "Crossover"; crossover.OperatorParameter.ActualName = "Crossover"; stochasticBranch.ProbabilityParameter.ActualName = "MutationProbability"; stochasticBranch.RandomParameter.ActualName = "Random"; mutator.Name = "Mutator"; mutator.OperatorParameter.ActualName = "Mutator"; evaluator.Name = "Evaluator"; evaluator.OperatorParameter.ActualName = "Evaluator"; weightedParentsQualityComparator.ComparisonFactorParameter.ActualName = ComparisonFactorParameter.Name; weightedParentsQualityComparator.LeftSideParameter.ActualName = QualityParameter.Name; weightedParentsQualityComparator.MaximizationParameter.ActualName = MaximizationParameter.Name; weightedParentsQualityComparator.RightSideParameter.ActualName = QualityParameter.Name; weightedParentsQualityComparator.ResultParameter.ActualName = "SuccessfulOffspring"; subScopesRemover.RemoveAllSubScopes = true; intCounter1.Name = "Increment NumberOfCreatedOffspring"; intCounter1.ValueParameter.ActualName = "NumberOfCreatedOffspring"; intCounter1.Increment = null; intCounter1.IncrementParameter.ActualName = BatchSizeParameter.Name; intCounter2.Name = "Increment EvaluatedSolutions"; intCounter2.ValueParameter.ActualName = EvaluatedSolutionsParameter.Name; intCounter2.Increment = null; intCounter2.IncrementParameter.ActualName = BatchSizeParameter.Name; conditionalSelector.ConditionParameter.ActualName = "SuccessfulOffspring"; conditionalSelector.ConditionParameter.Depth = 1; conditionalSelector.CopySelected.Value = false; duplicateSelector.CopySelected.Value = false; progressiveOffspringSelector.OffspringListParameter.ActualName = "OffspringList"; progressiveOffspringSelector.ElitesParameter.ActualName = ElitesParameter.Name; progressiveOffspringSelector.MaximumPopulationSizeParameter.ActualName = MaximumPopulationSizeParameter.Name; subScopesCounter2.Name = "Count Successful Offspring"; subScopesCounter2.ValueParameter.ActualName = "NumberOfSuccessfulOffspring"; calculator1.Name = "NumberOfSuccessfulOffspring == MaximumPopulationSize - Elites"; calculator1.CollectedValues.Add(new ValueLookupParameter <IntValue>("NumberOfSuccessfulOffspring")); calculator1.CollectedValues.Add(new ValueLookupParameter <IntValue>("MaximumPopulationSize")); calculator1.CollectedValues.Add(new ValueLookupParameter <IntValue>("Elites")); calculator1.ExpressionParameter.Value = new StringValue("NumberOfSuccessfulOffspring MaximumPopulationSize Elites - =="); calculator1.ExpressionResultParameter.ActualName = "Break"; conditionalBranch1.Name = "Break?"; conditionalBranch1.ConditionParameter.ActualName = "Break"; comparator1.Name = "NumberOfCreatedOffspring >= Effort"; comparator1.Comparison = new Comparison(ComparisonType.GreaterOrEqual); comparator1.LeftSideParameter.ActualName = "NumberOfCreatedOffspring"; comparator1.RightSideParameter.ActualName = EffortParameter.Name; comparator1.ResultParameter.ActualName = "Break"; conditionalBranch2.Name = "Break?"; conditionalBranch2.ConditionParameter.ActualName = "Break"; bestSelector.CopySelected = new BoolValue(false); bestSelector.MaximizationParameter.ActualName = MaximizationParameter.Name; bestSelector.NumberOfSelectedSubScopesParameter.ActualName = "Elites"; bestSelector.QualityParameter.ActualName = QualityParameter.Name; intCounter3.Name = "Increment Generations"; intCounter3.Increment = new IntValue(1); intCounter3.ValueParameter.ActualName = "Generations"; subScopesCounter3.Name = "Update CurrentPopulationSize"; subScopesCounter3.ValueParameter.ActualName = "CurrentPopulationSize"; subScopesCounter3.AccumulateParameter.Value = new BoolValue(false); calculator2.Name = "Evaluate ActualSelectionPressure"; calculator2.CollectedValues.Add(new ValueLookupParameter <IntValue>("NumberOfCreatedOffspring")); calculator2.CollectedValues.Add(new ValueLookupParameter <IntValue>("Elites")); calculator2.CollectedValues.Add(new ValueLookupParameter <IntValue>("CurrentPopulationSize")); calculator2.ExpressionParameter.Value = new StringValue("NumberOfCreatedOffspring Elites + CurrentPopulationSize /"); calculator2.ExpressionResultParameter.ActualName = "ActualSelectionPressure"; comparator2.Name = "CurrentPopulationSize < 1"; comparator2.Comparison = new Comparison(ComparisonType.Less); comparator2.LeftSideParameter.ActualName = "CurrentPopulationSize"; comparator2.RightSideParameter.Value = new IntValue(1); comparator2.ResultParameter.ActualName = "Terminate"; conditionalBranch3.Name = "Terminate?"; conditionalBranch3.ConditionParameter.ActualName = "Terminate"; analyzer2.Name = "Analyzer"; analyzer2.OperatorParameter.ActualName = "Analyzer"; comparator3.Name = "Generations >= MaximumGenerations"; comparator3.Comparison = new Comparison(ComparisonType.GreaterOrEqual); comparator3.LeftSideParameter.ActualName = "Generations"; comparator3.ResultParameter.ActualName = "Terminate"; comparator3.RightSideParameter.ActualName = MaximumGenerationsParameter.Name; conditionalBranch4.Name = "Terminate?"; conditionalBranch4.ConditionParameter.ActualName = "Terminate"; comparator4.Name = "CurrentPopulationSize < MinimumPopulationSize"; comparator4.Comparison = new Comparison(ComparisonType.Less); comparator4.LeftSideParameter.ActualName = "CurrentPopulationSize"; comparator4.RightSideParameter.ActualName = MinimumPopulationSizeParameter.Name; comparator4.ResultParameter.ActualName = "Terminate"; conditionalBranch5.Name = "Terminate?"; conditionalBranch5.ConditionParameter.ActualName = "Terminate"; assigner3.Name = "Reset NumberOfCreatedOffspring"; assigner3.LeftSideParameter.ActualName = "NumberOfCreatedOffspring"; assigner3.RightSideParameter.Value = new IntValue(0); assigner4.Name = "Reset NumberOfSuccessfulOffspring"; assigner4.LeftSideParameter.ActualName = "NumberOfSuccessfulOffspring"; assigner4.RightSideParameter.Value = new IntValue(0); assigner5.Name = "Reset OffspringList"; assigner5.LeftSideParameter.ActualName = "OffspringList"; assigner5.RightSideParameter.Value = new ScopeList(); reevaluateElitesBranch.ConditionParameter.ActualName = "ReevaluateElites"; reevaluateElitesBranch.Name = "Reevaluate elites ?"; uniformSubScopesProcessor2.Parallel.Value = true; evaluator2.Name = "Evaluator (placeholder)"; evaluator2.OperatorParameter.ActualName = EvaluatorParameter.Name; subScopesCounter4.Name = "Increment EvaluatedSolutions"; subScopesCounter4.ValueParameter.ActualName = EvaluatedSolutionsParameter.Name; #endregion #region Create operator graph OperatorGraph.InitialOperator = variableCreator; variableCreator.Successor = assigner1; assigner1.Successor = resultsCollector; resultsCollector.Successor = analyzer1; analyzer1.Successor = selector; selector.Successor = subScopesProcessor1; subScopesProcessor1.Operators.Add(new EmptyOperator()); subScopesProcessor1.Operators.Add(childrenCreator); subScopesProcessor1.Successor = calculator1; childrenCreator.Successor = uniformSubScopesProcessor; uniformSubScopesProcessor.Operator = crossover; uniformSubScopesProcessor.Successor = intCounter1; crossover.Successor = stochasticBranch; stochasticBranch.FirstBranch = mutator; stochasticBranch.SecondBranch = null; mutator.Successor = null; stochasticBranch.Successor = evaluator; evaluator.Successor = weightedParentsQualityComparator; weightedParentsQualityComparator.Successor = subScopesRemover; intCounter1.Successor = intCounter2; intCounter2.Successor = conditionalSelector; conditionalSelector.Successor = rightReducer1; rightReducer1.Successor = duplicateSelector; duplicateSelector.Successor = leftReducer1; leftReducer1.Successor = progressiveOffspringSelector; progressiveOffspringSelector.Successor = subScopesCounter2; calculator1.Successor = conditionalBranch1; conditionalBranch1.FalseBranch = comparator1; conditionalBranch1.TrueBranch = subScopesProcessor2; comparator1.Successor = conditionalBranch2; conditionalBranch2.FalseBranch = leftReducer2; conditionalBranch2.TrueBranch = subScopesProcessor2; leftReducer2.Successor = selector; subScopesProcessor2.Operators.Add(bestSelector); subScopesProcessor2.Operators.Add(scopeCleaner); subScopesProcessor2.Successor = mergingReducer; bestSelector.Successor = rightReducer2; rightReducer2.Successor = reevaluateElitesBranch; reevaluateElitesBranch.TrueBranch = uniformSubScopesProcessor2; uniformSubScopesProcessor2.Operator = evaluator2; uniformSubScopesProcessor2.Successor = subScopesCounter4; evaluator2.Successor = null; subScopesCounter4.Successor = null; reevaluateElitesBranch.FalseBranch = null; reevaluateElitesBranch.Successor = null; scopeCleaner.Successor = scopeRestorer; mergingReducer.Successor = intCounter3; intCounter3.Successor = subScopesCounter3; subScopesCounter3.Successor = calculator2; calculator2.Successor = comparator2; comparator2.Successor = conditionalBranch3; conditionalBranch3.FalseBranch = analyzer2; conditionalBranch3.TrueBranch = null; analyzer2.Successor = comparator3; comparator3.Successor = conditionalBranch4; conditionalBranch4.FalseBranch = comparator4; conditionalBranch4.TrueBranch = null; conditionalBranch4.Successor = null; comparator4.Successor = conditionalBranch5; conditionalBranch5.FalseBranch = assigner3; conditionalBranch5.TrueBranch = null; conditionalBranch5.Successor = null; assigner3.Successor = assigner4; assigner4.Successor = assigner5; assigner5.Successor = selector; #endregion }
private CombinedOperator CreateLayerOpener() { var layerOpener = new CombinedOperator() { Name = "Open new Layer if needed" }; var maxLayerReached = new Comparator() { Name = "MaxLayersReached = OpenLayers >= NumberOfLayers" }; var maxLayerReachedBranch = new ConditionalBranch() { Name = "MaxLayersReached?" }; var openNewLayerCalculator = new ExpressionCalculator() { Name = "OpenNewLayer = Generations >= AgeLimits[OpenLayers - 1]" }; var openNewLayerBranch = new ConditionalBranch() { Name = "OpenNewLayer?" }; var layerCreator = new LastLayerCloner() { Name = "Create Layer" }; var updateLayerNumber = new Assigner() { Name = "Layer = OpenLayers" }; var historyWiper = new ResultsHistoryWiper() { Name = "Clear History in Results" }; var createChildrenViaCrossover = new AlpsGeneticAlgorithmMainOperator(); var incrEvaluatedSolutionsForNewLayer = new SubScopesCounter() { Name = "Update EvaluatedSolutions" }; var incrOpenLayers = new IntCounter() { Name = "Incr. OpenLayers" }; var newLayerResultsCollector = new ResultsCollector() { Name = "Collect new Layer Results" }; layerOpener.OperatorGraph.InitialOperator = maxLayerReached; maxLayerReached.LeftSideParameter.ActualName = "OpenLayers"; maxLayerReached.RightSideParameter.ActualName = NumberOfLayersParameter.Name; maxLayerReached.ResultParameter.ActualName = "MaxLayerReached"; maxLayerReached.Comparison = new Comparison(ComparisonType.GreaterOrEqual); maxLayerReached.Successor = maxLayerReachedBranch; maxLayerReachedBranch.ConditionParameter.ActualName = "MaxLayerReached"; maxLayerReachedBranch.FalseBranch = openNewLayerCalculator; openNewLayerCalculator.CollectedValues.Add(new LookupParameter <IntArray>(AgeLimitsParameter.Name)); openNewLayerCalculator.CollectedValues.Add(new LookupParameter <IntValue>("Generations")); openNewLayerCalculator.CollectedValues.Add(new LookupParameter <IntValue>(NumberOfLayersParameter.Name)); openNewLayerCalculator.CollectedValues.Add(new LookupParameter <IntValue>("OpenLayers")); openNewLayerCalculator.ExpressionResultParameter.ActualName = "OpenNewLayer"; openNewLayerCalculator.ExpressionParameter.Value = new StringValue("Generations 1 + AgeLimits OpenLayers 1 - [] >"); openNewLayerCalculator.Successor = openNewLayerBranch; openNewLayerBranch.ConditionParameter.ActualName = "OpenNewLayer"; openNewLayerBranch.TrueBranch = layerCreator; layerCreator.NewLayerOperator = updateLayerNumber; layerCreator.Successor = incrOpenLayers; updateLayerNumber.LeftSideParameter.ActualName = "Layer"; updateLayerNumber.RightSideParameter.ActualName = "OpenLayers"; updateLayerNumber.Successor = historyWiper; historyWiper.ResultsParameter.ActualName = "LayerResults"; historyWiper.Successor = createChildrenViaCrossover; // Maybe use only crossover and no elitism instead of "default operator" createChildrenViaCrossover.RandomParameter.ActualName = LocalRandomParameter.Name; createChildrenViaCrossover.EvaluatorParameter.ActualName = EvaluatorParameter.Name; createChildrenViaCrossover.EvaluatedSolutionsParameter.ActualName = "LayerEvaluatedSolutions"; createChildrenViaCrossover.QualityParameter.ActualName = QualityParameter.Name; createChildrenViaCrossover.MaximizationParameter.ActualName = MaximizationParameter.Name; createChildrenViaCrossover.PopulationSizeParameter.ActualName = PopulationSizeParameter.Name; createChildrenViaCrossover.SelectorParameter.ActualName = SelectorParameter.Name; createChildrenViaCrossover.CrossoverParameter.ActualName = CrossoverParameter.Name; createChildrenViaCrossover.MutatorParameter.ActualName = MutatorParameter.Name; createChildrenViaCrossover.MutationProbabilityParameter.ActualName = MutationProbabilityParameter.Name; createChildrenViaCrossover.ElitesParameter.ActualName = ElitesParameter.Name; createChildrenViaCrossover.ReevaluateElitesParameter.ActualName = ReevaluateElitesParameter.Name; createChildrenViaCrossover.PlusSelectionParameter.ActualName = PlusSelectionParameter.Name; createChildrenViaCrossover.AgeParameter.ActualName = AgeParameter.Name; createChildrenViaCrossover.AgeInheritanceParameter.ActualName = AgeInheritanceParameter.Name; createChildrenViaCrossover.AgeIncrementParameter.Value = new DoubleValue(0.0); createChildrenViaCrossover.Successor = incrEvaluatedSolutionsForNewLayer; incrEvaluatedSolutionsForNewLayer.ValueParameter.ActualName = EvaluatedSolutionsParameter.Name; incrEvaluatedSolutionsForNewLayer.AccumulateParameter.Value = new BoolValue(true); incrOpenLayers.ValueParameter.ActualName = "OpenLayers"; incrOpenLayers.Increment = new IntValue(1); incrOpenLayers.Successor = newLayerResultsCollector; newLayerResultsCollector.CollectedValues.Add(new ScopeTreeLookupParameter <ResultCollection>("LayerResults", "Result set for each layer", "LayerResults")); newLayerResultsCollector.CopyValue = new BoolValue(false); newLayerResultsCollector.Successor = null; return(layerOpener); }
protected bool SaveRecord() { try { ExpressionCalculator ca = new ExpressionCalculator(); if (_obj.L4 != "") { if (ca.ISIllegal(ca.CharConverter(_obj.L4))) { _obj.L2 = ca.Calculator(ca.CharConverter(_obj.L4), 2); } } if (_obj.L13 != "0") { _obj.S6 = string.Format("{0:f}", double.Parse(_obj.L14) * 100 / double.Parse(_obj.L13)); } } catch { } if (_obj.L2 != 0) { _obj.L10 = _obj.L9 * 100 / _obj.L2; } try { int x = int.Parse(_obj.S2); if (x > DateTime.Now.Year) { _obj.Flag = "2"; } else { _obj.Flag = "1"; } } catch { _obj.Flag = "1"; } //创建/修改 对象 // _obj.L30 = projectid; try { _obj.AreaID = projectid; if (IsCreate) { _obj.UID += "|" + projectid; Services.BaseService.Create <Substation_Info>(_obj); } else { Services.BaseService.Update <Substation_Info>(_obj); } } catch (Exception exc) { Debug.Fail(exc.Message); HandleException.TryCatch(exc); return(false); } //操作已成功 return(true); }
/// <summary> /// 解析一段表达式 /// </summary> /// <param name="expr"></param> /// <returns></returns> public string ParseExpr(string expr) { return(ExpressionCalculator.Calculate(expr, this)); }
public void test_calculator(string expression, double expected) { ExpressionCalculator.Compute(expression).Should().Be(expected); }