public WorkflowGlobal(string name, string description, List <Data> modelDataInputs, List <Data> modelDataOutputs, List <WorkflowComponent> components, List <WorkflowComponent> scheduledComponents, List <ISolver> solvers, bool isAuxiliary = true, string scheduleMode = "", string parentName = "") : base(name, description, modelDataInputs, modelDataOutputs, components, scheduledComponents, isAuxiliary, scheduleMode, parentName) { List <Data> allData = ScheduledComponents.GetAllData(); ScheduledComponents.GetInputsOutputsStatus(allData, out List <Data> defaultInputs, out List <Data> defaultOutputs); var outputsHash = new HashSet <string>(ModelDataOutputs.Select(d => d.Id)); foreach (Data dt in defaultInputs) { if (outputsHash.Contains(dt.Id)) { ReversedInputs.Add(dt); } } var inputsHash = new HashSet <string>(ModelDataInputs.Select(d => d.Id)); foreach (Data dt in defaultOutputs) { if (inputsHash.Contains(dt.Id)) { ReversedOutputs.Add(dt); } } Solvers = solvers; }
public WorkflowReversedModel(string name, string description, List <Data> modelDataInputs, List <Data> modelDataOutputs, Model model, List <ISolver> solvers, string parentName = "") : base(name, description, modelDataInputs, modelDataOutputs, new List <WorkflowComponent>() { model }, new List <WorkflowComponent>() { model }, true, parentName) { //this.Model = model; var outputsHash = new HashSet <string>(ModelDataOutputs.Select(d => d.Id)); foreach (Data dt in model.ModelDataInputs) { if (outputsHash.Contains(dt.Id)) { ReversedInputs.Add(dt); } } var inputsHash = new HashSet <string>(ModelDataInputs.Select(d => d.Id)); foreach (Data dt in model.ModelDataOutputs) { if (inputsHash.Contains(dt.Id)) { ReversedOutputs.Add(dt); } } Solvers = solvers; }
public string GetReversedName(List <Data> inputs, List <Data> outputs) { var reversedIN = inputs.GetNames().Except(ModelDataInputs.GetNames()); var reversedOUT = outputs.GetNames().Except(ModelDataOutputs.GetNames()); var reversed = new HashSet <string>(reversedIN.Union(reversedOUT)); string reversalID = ModelDataInputs.Aggregate(String.Empty, (t, d) => t += reversed.Contains(d.Name) ? '1' : '0', t => t += ':'); reversalID = ModelDataOutputs.Aggregate(reversalID, (t, d) => t += reversed.Contains(d.Name) ? '1' : '0'); return($"{Id}:Reversed:{reversalID}"); }
public bool IsReversed(IEnumerable<string> outputs) { if (outputs.Count() != ModelDataOutputs.Count) return true; var hash = new HashSet<string>(ModelDataOutputs.Select(d => d.Id)); foreach (string data in outputs) if (!hash.Contains(data)) return true; return false; }
public virtual Workflow Copy(string id, string name = null, string parentName = null) { return(new Workflow(id, Description, ModelDataInputs.ToList(), ModelDataOutputs.ToList(), Components.ToList(), ScheduledComponents.ToList(), IsAuxiliary, ScheduleMode, parentName ?? parentName)); }
public override Workflow Copy(string id, string name = null, string parentName = null) { return(new WorkflowUncertaintyParametrised(id, Description, InnerWorkflow, ModelDataInputs.ToList(), ModelDataOutputs.ToList(), InputDistributions.ToList(), OutputDistributions.ToList(), UncertaintyPropagator, parentName ?? parentName)); }
public override Workflow Copy(string id, string name = null, string parentName = null) { return(new WorkflowReversedModel(id, Description, ModelDataInputs.ToList(), ModelDataOutputs.ToList(), Model, Solvers.ToList(), parentName ?? parentName)); }
public override Workflow Copy(string id, string name = null, string parentName = null) { return(new WorkflowSCC(id, Description, ModelDataInputs.ToList(), ModelDataOutputs.ToList(), Components.ToList(), ScheduledComponents.ToList(), Solvers.ToList(), parentName ?? parentName)); }
public override bool Execute() { int Ninputs = ModelDataInputs.Count; int Nout = Math.Min(methodInfo.GetParameters().Where(p => p.IsOut).Count(), ModelDataOutputs.Count); object[] parameters = ModelDataInputs.Concat(ModelDataOutputs.Take(Nout)).Select(i => i.Value).ToArray(); //for (int i = 0; i < Nout; i++) // inputs.Add(ModelDataOutputs[i].Value); //inputs.Add(Activator.CreateInstance(Type.GetType(param.ParameterType.FullName.TrimEnd('&')))); try { //object[] parameters = inputs.ToArray(); object outputs = methodInfo.Invoke(classInstance, parameters); Type outputType = outputs?.GetType() ?? typeof(void); for (int i = 0; i < Nout; i++) { ModelDataOutputs[i].Value = parameters[Ninputs + i]; } int idx = 0; if (outputs is object[] arr) { int N = Math.Min(arr.Length, ModelDataOutputs.Count); for (int i = 0; i < N; i++) { // Assign ModelDataOutputs[Nout + i].Value = arr[i]; } idx = N; } else if (outputType.IsSuported()) { ModelDataOutputs.First().Value = outputs; idx = 1; } else { PropertyInfo[] properties = outputType.GetProperties().Where(p => p.GetMethod.IsPublic && p.PropertyType.IsSuported()).ToArray(); FieldInfo[] fields = outputType.GetFields().Where(f => f.IsPublic && f.FieldType.IsSuported()).ToArray(); int N = Math.Min(properties.Length, ModelDataOutputs.Count); int M = Math.Min(fields.Length, ModelDataOutputs.Count - N); for (int i = 0; i < N; i++) { // Assign ModelDataOutputs[Nout + i].Value = properties[i].GetValue(outputs); } for (int i = 0; i < M; i++) { // Assign ModelDataOutputs[Nout + N + i].Value = fields[i].GetValue(outputs); } idx = N + M; } } catch (Exception e) { Console.WriteLine(e.Message); return(false); } return(true); }