internal string CalculateLineOfWeights() { string result; DacSet dacSet = new DacSet(); dividers = PrepareDividers(); for (int i = 0; i < inp.K; i++) { inp.Divide(i, dividers[i]); } var weights = inp.GetWeightsArray(); for (int i = weights.Count - 1; i >= 0; i--) { var resultWeight = new FibonachiWeight(); resultWeight.AddCombinations(weights[i]); dacSet.AddWeight(resultWeight); } var dacSetWeights = dacSet.weights.OrderBy(x => x.weight).ToList(); result = Statistics.GetStatisticOfSimpleWeightsLineToString(inp, dacSetWeights); return(result); }
private FibonachiWeight ApproximateOneWeight(double weightToApproximate, List <BinaryWeight> inputWeights) { FibonachiWeight resultWeight = new FibonachiWeight(); double sum = 0; for (int i = inputWeights.Count - 1; i >= 0; i--) { var tempV = sum + inputWeights[i].weight; if (weightToApproximate >= tempV) { sum = tempV; resultWeight.AddCombinations(inputWeights[i]); } } if (Math.Abs((weightToApproximate - sum) / weightToApproximate) * 100 > inp.d || resultWeight.bitWeightCombinations.Count == 0) { return(null); } SubtractWeightCombinationFromInputArray(resultWeight, inputWeights); resultWeight.error = weightToApproximate - sum; return(resultWeight); }