public Boa_AlgorithmComponent(string name, string nickname, string description, string category, string subcategory) : base(name, nickname, description, category, subcategory) { Algorithm = new Boa_Algorithm(); }
protected bool GetAlgorithm(IGH_DataAccess DA, ref Boa_Algorithm algorithm) { if (!DA.GetData(0, ref algorithm)) { algorithm = Boa_Algorithm.Default; return(false); } return(true); }
//Copy constructor public Boa_Algorithm(Boa_Algorithm algorithmSource) { solveAlgorithm = algorithmSource.solveAlgorithm; InputDimension = algorithmSource.InputDimension; OutputDimension = algorithmSource.OutputDimension; InputIsFixedSize = algorithmSource.InputIsFixedSize; OutputIsFixedSize = algorithmSource.OutputIsFixedSize; TryAddParent(algorithmSource.parent); }
public bool GenerateAlgorithm(ref Boa_Algorithm algorithm) { int newInputSize, newOutputSize = 0; SolveAlgorithm parallelAlgorithmSolution; if (inputAlgorithmA.OutputIsFixedSize && inputAlgorithmB.OutputIsFixedSize) { if (!CalculateFixedAlgorithmOutputSize(inputAlgorithmA.OutputDimension, inputAlgorithmB.OutputDimension, ref newOutputSize)) { return(false); } } if (baseAlgorithmA.Equals(baseAlgorithmB)) { newInputSize = baseAlgorithmA.InputDimension; parallelAlgorithmSolution = SolveParallelAlgorithmWithSameBase; hasSameBase = true; } else { //if either algorithms have non-fixed, inputs, then this algorithm will have non-fixed inputs (size 0); if (!baseAlgorithmA.InputIsFixedSize || !baseAlgorithmB.InputIsFixedSize) { newInputSize = 0; if (baseAlgorithmA.InputIsFixedSize) { parallelAlgorithmSolution = SolveFixedAParallelAlgorithm; } else if (baseAlgorithmB.InputIsFixedSize) { parallelAlgorithmSolution = SolveFixedBParallelAlgorithm; } else { parallelAlgorithmSolution = SolveUnFixedParallelAlgorithm; } } else { newInputSize = baseAlgorithmA.InputDimension + baseAlgorithmB.InputDimension; parallelAlgorithmSolution = SolveFixedParallelAlgorithm; } hasSameBase = false; } algorithm = new Boa_Algorithm(parallelAlgorithmSolution, newInputSize, newOutputSize); if (hasSameBase) { algorithm.AddDisjointedBase(baseAlgorithmA); } return(true); }
protected override void SolveInstance(IGH_DataAccess DA) { int iterations = 0; var algorithm = new Boa_Algorithm(); var inputs = new double[0]; if (!GetInputs(DA, ref inputs)) { return; } if (!DA.GetData(2, ref iterations)) { return; } GetAlgorithm(DA, ref algorithm); if (iterations < 1) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Number of iterations must be greater than or equal to one."); return; } GH_Structure <GH_Number> outputDataTree = new GH_Structure <GH_Number>(); GH_Path targetPath = DA.ParameterTargetPath(0); //Feedback loop for (int i = 0; i < iterations; i++) { // on the first iteration if (i == 0) { if (!SolveAlgorithm(ref inputs, algorithm)) { return; } } else { if (!SolveAlgorithm(ref inputs, algorithm, "Number of outputs is less than number of inputs. Algorithm cannot support a feedback loop.")) { return; } } GH_Number[] outputList = new GH_Number[inputs.Length]; for (int j = 0; j < inputs.Length; j++) { outputList[j] = new GH_Number(inputs[j]); } outputDataTree.AppendRange(outputList, targetPath.AppendElement(i)); } DA.SetDataTree(0, outputDataTree); }
public ParallelAlgorithm(Boa_Algorithm algorithmA, Boa_Algorithm algorithmB) { inputAlgorithmA = algorithmA; inputAlgorithmB = algorithmB; baseAlgorithmA = inputAlgorithmA.GetBaseAlgorithm(); baseAlgorithmB = inputAlgorithmB.GetBaseAlgorithm(); inputSizeA = baseAlgorithmA.InputDimension; inputSizeB = baseAlgorithmB.InputDimension; }
/// <summary> /// Checks to see if this algorithm can be made the parent of another. /// </summary> /// <param name="algorithmToCheck"></param> /// <returns></returns> protected bool CanBeParentOf(Boa_Algorithm algorithmToCheck) { if (!OutputIsFixedSize || !algorithmToCheck.InputIsFixedSize) { return(true); } //at this point both algorithms are fixed if (OutputDimension >= algorithmToCheck.InputDimension) { return(true); } return(false); }
protected override void SolveInstance(IGH_DataAccess DA) { Boa_Algorithm algorithm = new Boa_Algorithm(); if (!DA.GetData(0, ref algorithm)) { return; } Interval dimensionDomain = new Interval(algorithm.InputDimension, algorithm.OutputDimension); List <int> chainDimensions = algorithm.GetChainDimensions(); DA.SetData(0, dimensionDomain); DA.SetDataList(1, chainDimensions); DA.SetData(2, chainDimensions.Count - 1); }
public bool TryAddParent(Boa_Algorithm parentToAdd, out string errorDescription) { if (parentToAdd == null) { errorDescription = "Parent is null"; return(false); } if (!parentToAdd.IsValid) { errorDescription = "Parent " + parentToAdd.IsValidWhyNot; return(false); } if (!parentToAdd.CanBeParentOf(this)) { errorDescription = "Algorithms are of incompatible size"; return(false); } //if parent's output is not fixed if (!parentToAdd.OutputIsFixedSize) { if (!parentToAdd.TryMatchOutputDimension(InputDimension)) { errorDescription = "Parenting would result in an input size of 0 or less"; return(false); } } //if this input is not fixed else if (!InputIsFixedSize) { //if this algorithm's size is relative but the parent's size is fixed if (!TryMatchInputDimension(parentToAdd.OutputDimension)) { errorDescription = "Parenting would result in an output size of 0 or less"; return(false); } } parent = parentToAdd; HasParent = true; errorDescription = "Algorithm has been successfully parented"; return(true); }
protected void CreateAndSetAlgorithm(IGH_DataAccess DA, Boa_Algorithm algorithm) { Algorithm = algorithm; Boa_Algorithm parentAlgorithm = new Boa_Algorithm(); string errorDescription = ""; if (DA.GetData(ParentInputIndex, ref parentAlgorithm)) { if (!Algorithm.TryAddParent(parentAlgorithm, out errorDescription)) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, errorDescription); } } DA.SetData(AlgorithmOutputIndex, Algorithm); }
protected override void SolveInstance(IGH_DataAccess DA) { var algorithm = new Boa_Algorithm(); var inputs = new double[0]; if (!GetInputs(DA, ref inputs)) { return; } GetAlgorithm(DA, ref algorithm); if (!SolveAlgorithm(ref inputs, algorithm)) { return; } DA.SetDataList(0, inputs); }
protected bool SolveAlgorithm(ref double[] inputs, Boa_Algorithm algorithm, string errorMessage) { SolutionRemark remark = 0; inputs = algorithm.Solve(inputs, out remark); if (remark.Equals(SolutionRemark.OversizedInputs)) { AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, "Length of input list is oversized. Some values were ignored."); } else if (remark.Equals(SolutionRemark.UndersizedInputs)) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, errorMessage); return(false); } return(true); }
public AddAlgorithms(Boa_Algorithm algorithmA, Boa_Algorithm algorithmB) : base(algorithmA, algorithmB) { }
public void AddDisjointedBase(Boa_Algorithm baseToAdd) { disjointedBase = baseToAdd; hasDisjointedBase = true; }
protected void CreateAndSetAlgorithm(IGH_DataAccess DA, SolveAlgorithm solveAlgorithm, int inputSize, int outputSize) { var algorithm = new Boa_Algorithm(solveAlgorithm, inputSize, outputSize); CreateAndSetAlgorithm(DA, algorithm); }
protected virtual ParallelAlgorithm GenerateParallelAlgorithm(Boa_Algorithm algorithmA, Boa_Algorithm algorithmB) { return(new ParallelAlgorithm(algorithmA, algorithmB)); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { var inputAlgorithmA = new Boa_Algorithm(); var inputAlgorithmB = new Boa_Algorithm(); //baseAlgorithmA = new Boa_Algorithm(); //baseAlgorithmB = new Boa_Algorithm(); if (!DA.GetData(0, ref inputAlgorithmA)) { return; } if (!DA.GetData(1, ref inputAlgorithmB)) { return; } var parallelAlgorithm = GenerateParallelAlgorithm(inputAlgorithmA, inputAlgorithmB); var algorithm = new Boa_Algorithm(); if (!parallelAlgorithm.GenerateAlgorithm(ref algorithm)) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Algorithms outputs are of different sizes and cannot be combined."); return; } Algorithm = algorithm; //baseAlgorithmA = inputAlgorithmA.GetBaseAlgorithm(); //baseAlgorithmB = inputAlgorithmB.GetBaseAlgorithm(); //inputSizeA = baseAlgorithmA.InputDimension; //inputSizeB = baseAlgorithmB.InputDimension; //int newInputSize, newOutputSize = 0; //SolveAlgorithm parallelAlgorithmSolution; //if (inputAlgorithmA.OutputIsFixedSize && inputAlgorithmB.OutputIsFixedSize) // if (!parallelAlgorithm.CalculateFixedAlgorithmOutputSize(inputAlgorithmA.OutputDimension, inputAlgorithmB.OutputDimension, ref newOutputSize)) return; //if (baseAlgorithmA.Equals(baseAlgorithmB)) //{ // newInputSize = baseAlgorithmA.InputDimension; // parallelAlgorithmSolution = SolveParallelAlgorithmWithSameBase; // hasSameBase = true; //} //else //{ // //if either algorithms have non-fixed, inputs, then this algorithm will have non-fixed inputs (size 0); // if (!baseAlgorithmA.InputIsFixedSize || !baseAlgorithmB.InputIsFixedSize) // { // newInputSize = 0; // if (baseAlgorithmA.InputIsFixedSize) // parallelAlgorithmSolution = SolveFixedAParallelAlgorithm; // else if (baseAlgorithmB.InputIsFixedSize) // parallelAlgorithmSolution = SolveFixedBParallelAlgorithm; // else // parallelAlgorithmSolution = SolveUnFixedParallelAlgorithm; // } // else // { // newInputSize = baseAlgorithmA.InputDimension + baseAlgorithmB.InputDimension; // parallelAlgorithmSolution = SolveFixedParallelAlgorithm; // } // hasSameBase = false; //} //Algorithm = new Boa_Algorithm(parallelAlgorithmSolution, newInputSize, newOutputSize); //if (hasSameBase) // Algorithm.AddDisjointedBase(baseAlgorithmA); DA.SetData(AlgorithmOutputIndex, Algorithm); }
protected bool SolveAlgorithm(ref double[] inputs, Boa_Algorithm algorithm) { return(SolveAlgorithm(ref inputs, algorithm, "Length of input list is undersized. Solution was aborted.")); }
public MultiplyAlgorithms(Boa_Algorithm algorithmA, Boa_Algorithm algorithmB) : base(algorithmA, algorithmB) { }
protected override ParallelAlgorithm GenerateParallelAlgorithm(Boa_Algorithm algorithmA, Boa_Algorithm algorithmB) { return(new MultiplyAlgorithms(algorithmA, algorithmB)); }
public bool TryAddParent(Boa_Algorithm parentToAdd) { return(TryAddParent(parentToAdd, out string s)); }