public void SetVariables(IEnumerable <string> variableNames) { // remove and add parameter again // parameter has to be FixedValueParameter otherwise a user could create new ReadOnlyItemList // value has to be ReadOnlyItemList otherwise elements could be changed Parameters.Remove("TraceVariableNames"); Parameters.Add(new FixedValueParameter <ReadOnlyItemList <StringValue> >("TraceVariableNames", "", new ReadOnlyItemList <StringValue>(new ItemList <StringValue>(variableNames.Select(x => new StringValue(x).AsReadOnly()))))); pythonSemanticHelper = new PythonProcessSemanticHelper(TraceVariableNames, LimitTrace); }
public CFGPythonTraceTableEvaluator() { Parameters.Add(new LookupParameter <ISymbolicExpressionTree>("SymbolicExpressionTree", "")); Parameters.Add(new FixedValueParameter <ReadOnlyItemList <StringValue> >("TraceVariableNames", "", new ReadOnlyItemList <StringValue>())); Parameters.Add(new FixedValueParameter <IntValue>("LimitTrace", "", new IntValue(1000))); Parameters.Add(new LookupParameter <ItemArray <PythonStatementSemantic> >("Semantic", "")); pythonSemanticHelper = new PythonProcessSemanticHelper(TraceVariableNames, LimitTrace); RegisterEventHandlers(); }
protected override void Manipulate(IRandom random, ISymbolicExpressionTree symbolicExpressionTree) { MutationExceptionsParameter.ActualValue = new ItemCollection <StringValue>(); var pythonSemanticHelper = new PythonProcessSemanticHelper(ProblemData.Variables.GetVariableNames(), 1000); // hardcoded value!!! // TODO: object created for every mutation var input = PythonHelper.ConvertToPythonValues(ProblemData.Input, ProblemData.TrainingIndices); var output = PythonHelper.ConvertToPythonValues(ProblemData.Output, ProblemData.TrainingIndices); var beforeResults = pythonSemanticHelper.EvaluateAndTraceProgram(PythonProcessParameter.ActualValue, PythonHelper.FormatToProgram(symbolicExpressionTree, ProblemData.LoopBreakConst, ProblemData.FullHeader, ProblemData.FullFooter), input, output, ProblemData.TrainingIndices, ProblemData.FullHeader, ProblemData.FullFooter, symbolicExpressionTree, Timeout); ReplaceBranch(random, symbolicExpressionTree, ProblemData, Semantics, PythonProcess, Timeout, MaximumSymbolicExpressionTreeLength.Value, MaximumSymbolicExpressionTreeDepth.Value, MaxCompares.Value); var afterResults = pythonSemanticHelper.EvaluateAndTraceProgram(PythonProcessParameter.ActualValue, PythonHelper.FormatToProgram(symbolicExpressionTree, ProblemData.LoopBreakConst, ProblemData.FullHeader, ProblemData.FullFooter), input, output, ProblemData.TrainingIndices, ProblemData.FullHeader, ProblemData.FullFooter, symbolicExpressionTree, Timeout); if (SemanticallyEquivalentMutationParameter.ActualValue.Value == NoMutation) { AddStatisticsNoMutation(); } else { AddStatistics(beforeResults, afterResults); } }
protected void AddStatistics(ItemArray <PythonStatementSemantic> semantic0, ISymbolicExpressionTree child) { if (NumberOfPossibleBranchesSelectedParameter.ActualValue == null) { NumberOfPossibleBranchesSelected = 0; } if (NumberOfAllowedBranchesParameter.ActualValue == null) { NumberOfAllowedBranches = 0; } if (NumberOfNoChangeDetectedParameter.ActualValue == null) { NumberOfNoChangeDetected = 0; } if (NumberOfCrossoverTriesParameter.ActualValue == null) { NumberOfCrossoverTries = 0; } if (TypeSelectedForSimilarityParameter.ActualValue == null) { TypeSelectedForSimilarityParameter.ActualValue = new StringValue("Random crossover"); } var parentQualities = QualityParameter.ActualValue; double parent0Quality = parentQualities[0].Value; double parent1Quality = parentQualities[1].Value; var pythonSemanticHelper = new PythonProcessSemanticHelper(ProblemData.Variables.GetVariableNames(), 1000); // hardcoded value!!! // TODO: object created for every crossover var childResults = pythonSemanticHelper.EvaluateAndTraceProgram(PythonProcessParameter.ActualValue, PythonHelper.FormatToProgram(child, ProblemData.LoopBreakConst, ProblemData.FullHeader, ProblemData.FullFooter), PythonHelper.ConvertToPythonValues(ProblemData.Input, ProblemData.TrainingIndices), PythonHelper.ConvertToPythonValues(ProblemData.Output, ProblemData.TrainingIndices), ProblemData.TrainingIndices, ProblemData.FullHeader, ProblemData.FullFooter, child, Timeout); var childQuality = childResults.Item3; SemanticLocalityParameter.ActualValue = new DoubleValue(Math.Abs(parent0Quality - childQuality)); ConstructiveEffectParameter.ActualValue = new IntValue(childQuality < parent0Quality ? childQuality < parent1Quality ? 2 : 1 : 0); if (!String.IsNullOrEmpty(childResults.Item4)) { SemanticallyDifferentFromRootedParentParameter.ActualValue = new BoolValue(true); return; // no semantics is available, but the child is different because it failed, which is different from its parent } // first semantic statement is <predefined> which contains all code and therefore all changes to res* var parent0Semantic = semantic0.First(); var childSemantic = childResults.Item5.First(); // check all results var resKeys = parent0Semantic.After.Keys.Where(x => x.StartsWith("res")); SemanticallyDifferentFromRootedParentParameter.ActualValue = new BoolValue(false); foreach (var resKey in resKeys) { var parent0Res = parent0Semantic.After.Keys.Contains(resKey) ? parent0Semantic.After[resKey] : parent0Semantic.Before[resKey]; var child0Res = childSemantic.After.Keys.Contains(resKey) ? childSemantic.After[resKey] : childSemantic.Before[resKey]; var enumParent = parent0Res.GetEnumerator(); var enumChild = child0Res.GetEnumerator(); var type = ProblemData.Variables.GetTypesOfVariables().First(x => x.Value.Contains(resKey)).Key; if (type.IsListType()) { // always move forward both enumerators (do not use short-circuit evaluation!) while (enumParent.MoveNext() & enumChild.MoveNext()) { if (!JToken.EqualityComparer.Equals((JArray)enumParent.Current, (JArray)enumChild.Current)) { SemanticallyDifferentFromRootedParentParameter.ActualValue.Value = true; break; } } if (enumParent.MoveNext() || enumChild.MoveNext()) { SemanticallyDifferentFromRootedParentParameter.ActualValue.Value = true; } } else { // always move forward both enumerators (do not use short-circuit evaluation!) while (enumParent.MoveNext() & enumChild.MoveNext()) { if (!enumParent.Current.Equals(enumChild.Current)) { SemanticallyDifferentFromRootedParentParameter.ActualValue.Value = true; break; } } if (enumParent.MoveNext() || enumChild.MoveNext()) { SemanticallyDifferentFromRootedParentParameter.ActualValue.Value = true; } } // break if a change has already been found if (SemanticallyDifferentFromRootedParentParameter.ActualValue.Value) { break; } } }
private void AfterDeserialization() { RegisterEventHandlers(); pythonSemanticHelper = new PythonProcessSemanticHelper(TraceVariableNames, LimitTrace); }
protected CFGPythonTraceTableEvaluator(CFGPythonTraceTableEvaluator <T> original, Cloner cloner) : base(original, cloner) { RegisterEventHandlers(); pythonSemanticHelper = new PythonProcessSemanticHelper(original.TraceVariableNames, original.LimitTrace); }
private void LimitTraceParameter_ValueChanged(object sender, EventArgs e) { pythonSemanticHelper = new PythonProcessSemanticHelper(TraceVariableNames, LimitTrace); }