/// <summary> /// Provides the value of the function /// </summary> /// <param name="context"></param> /// <param name="actuals">the actual parameters values</param> /// <param name="explain"></param> /// <returns>The value for the function application</returns> public override IValue Evaluate(InterpretationContext context, Dictionary <Actual, IValue> actuals, ExplanationPart explain) { IValue retVal = null; AssignParameters(context, actuals); Graph graph = createGraphForValue(context, context.FindOnStack(FunctionA).Value, explain); if (graph != null) { foreach (Graph.Segment segment in graph.Segments) { if (segment.Expression.A == 0.0) { double speed = segment.Expression.V0; Function function = context.FindOnStack(FunctionB).Value as Function; if (function.FormalParameters.Count > 0) { Parameter functionParameter = (Parameter)function.FormalParameters[0]; Actual actual = functionParameter.CreateActual(); actual.Value = new DoubleValue(EFSSystem.DoubleType, speed); Dictionary <Actual, IValue> values = new Dictionary <Actual, IValue>(); values[actual] = new DoubleValue(EFSSystem.DoubleType, speed); IValue solution = function.Evaluate(context, values, explain); double doubleValue = GetDoubleValue(solution); if (doubleValue >= segment.Start && doubleValue <= segment.End) { retVal = new DoubleValue(EFSSystem.DoubleType, doubleValue); break; } } else { FunctionB.AddError("The FunctionB doesn't have any parameter"); break; } } else { FunctionA.AddError("The FunctionA is not a step function"); break; } } } else { FunctionA.AddError("Cannot create graph for " + FunctionA); } if (retVal == null) { FunctionA.AddError("Cannot compute the intersection of " + FunctionA + " and " + FunctionB); FunctionB.AddError("Cannot compute the intersection of " + FunctionA + " and " + FunctionB); } return(retVal); }
/// <summary> /// Provides the value of the function /// </summary> /// <param name="instance">the instance on which the function is evaluated</param> /// <param name="actuals">the actual parameters values</param> /// <param name="localScope">the values of local variables</param> /// <returns>The value for the function application</returns> public override Values.IValue Evaluate(Interpreter.InterpretationContext context, Dictionary <Variables.Actual, Values.IValue> actuals) { Values.IValue retVal = null; AssignParameters(context, actuals); Graph graph = createGraphForValue(context, context.findOnStack(FunctionA).Value); if (graph != null) { foreach (Graph.Segment segment in graph.Segments) { if (segment.Expression.a == 0.0) { double speed = segment.Expression.v0; Function function = context.findOnStack(FunctionB).Value as Function; if (function.FormalParameters.Count > 0) { Parameter functionParameter = function.FormalParameters[0] as Parameter; Variables.Actual actual = functionParameter.createActual(); actual.Value = new Values.DoubleValue(EFSSystem.DoubleType, speed); Dictionary <Variables.Actual, Values.IValue> values = new Dictionary <Variables.Actual, Values.IValue>(); values[actual] = new Values.DoubleValue(EFSSystem.DoubleType, speed); Values.IValue solution = function.Evaluate(context, values); double doubleValue = getDoubleValue(solution); if (doubleValue >= segment.Start && doubleValue <= segment.End) { retVal = new Values.DoubleValue(EFSSystem.DoubleType, doubleValue); break; } } else { Log.Error("The FunctionB doesn't have any parameter"); break; } } else { Log.Error("The FunctionA is not a step function"); break; } } } else { Log.Error("Cannot create graph for " + FunctionA.ToString()); } if (retVal == null) { Log.Error("Cannot compute the intersection of " + FunctionA.ToString() + " and " + FunctionB.ToString()); } return(retVal); }
static void Main(string[] args) { FunctionA problem = new FunctionA(0, 20); //50 osobników, 20 bitów każdy QIGA2 algorytm = new QIGA2(problem, 100); //50 pokoleń algorytm.solve(20); }
/// <summary> /// Constructor /// </summary> /// <param name="efsSystem"></param> /// <param name="name">the name of the cast function</param> public IntersectAt(EFSSystem efsSystem) : base(efsSystem, "IntersectAt") { FunctionA = (Parameter)Generated.acceptor.getFactory().createParameter(); FunctionA.Name = "FunctionA"; FunctionA.Type = EFSSystem.AnyType; FunctionA.setFather(this); FormalParameters.Add(FunctionA); FunctionB = (Parameter)Generated.acceptor.getFactory().createParameter(); FunctionB.Name = "FunctionB"; FunctionB.Type = EFSSystem.AnyType; FunctionB.setFather(this); FormalParameters.Add(FunctionB); }