public Result <IStep> Create(IStepType type, DateTime startDate) { return(Result.Ok(type) .Ensure(st => st.GetType() == StepTypeEnum.Aging.ToStepType().GetType(), type.ToString() + CannotFindStepImplementationMessage) .Map <IStepType, IStep>(st => { if (st.Equals(StepTypeEnum.Mashing.ToStepType())) { return new BasicStep(st, startDate, MashingStepTypes); } else if (st.Equals(StepTypeEnum.Boiling.ToStepType())) { return new BasicStep(st, startDate, BoilingStepTypes); } else if (st.Equals(StepTypeEnum.Fermenting.ToStepType())) { return new BasicStep(st, startDate, FermentingStepTypes); } else if (st.Equals(StepTypeEnum.Aging.ToStepType())) { return new BasicStep(st, startDate, AgingStepTypes); } else if (st.Equals(StepTypeEnum.Packaging.ToStepType())) { return new BottlingStep(new BasicStep(st, startDate, PackagingStepTypes)); } return new BasicStep(st, startDate, new HashSet <IStepType>()); })); }
public Result MoveToNextStep(IStepType nextStepType) { return(Result.Ok(CurrentStep) .Ensure(step => step.NextStepTypes.Contains(nextStepType), CannotGoToNextStepMessage + nextStepType.Name) .OnSuccess(step => step.IsFinalized ? Result.Ok() : step.Finalize(DateTime.Now, CurrentSize)) .OnSuccess(() => _stepFactory.Create(nextStepType, DateTime.Now)) .OnSuccess(nextStep => _steps.Add(nextStep))); }
// in place public static void gaussElimination(IStepType StepType, Matrix matrix, bool withGaussJordan = true) { uint width = matrix.width; uint height = matrix.height; void rowOperation(uint iRow, uint kRow) { // split into two loops because we can't touch the value at [iRow, iRow], because we divide by it for (uint j = 0; j < iRow; j++) { StepType.doOperationForRowsAndColumn(matrix, iRow, kRow, j); } for (uint j = iRow + 1; j < width; j++) { StepType.doOperationForRowsAndColumn(matrix, iRow, kRow, j); } StepType.doOperationForRowsAndColumn(matrix, iRow, kRow, iRow); } // bring into echelon form for (uint iterationRow = 0; iterationRow < height; iterationRow++) { for (uint kRow = iterationRow + 1; kRow < height; kRow++) { rowOperation(iterationRow, kRow); } } // calculate result matrix // this is the extension called gauss-jordan elimination if (withGaussJordan) { void multipleRowBy(uint row, double value) { for (int i = 0; i < width; i++) { matrix[(int)row, i] = matrix[(int)row, i] * value; } } for (int bottomRow = (int)height - 1; bottomRow >= 0; bottomRow--) // loop must work with int because of underflow { multipleRowBy((uint)bottomRow, (double)1.0 / matrix[(int)bottomRow, (int)bottomRow]); for (int iterationRow = 0; iterationRow < bottomRow; iterationRow++) { rowOperation((uint)bottomRow, (uint)iterationRow); } } } }
internal BasicStep( IStepType stepType, DateTime startDate, ISet <IStepType> nextStepTypes) : base(new FinalizableStepInfo(stepType, startDate), nextStepTypes) { }
public FinalizableStepInfo(IStepType stepType, DateTime startDate) { Type = stepType; StartDate = startDate; }