NPKTools.Optimizer helps adjust the ratio of each fertilizer to achieve the desired PPM (parts per million) profile. Additionally, it is capable of calculating the PPM of a mixture of fertilizers.
$ dotnet add package NPKTools.OptimizerNPKTools.Optimizer is a tool developed on the .NET platform that helps adjust the ratio of each fertilizer to achieve the desired PPM (parts per million) profile. Additionally, it is capable of calculating the PPM of a mixture of fertilizers.
This tool was developed by Anatoliy Yermakov.
Special thanks to Artem Frolov for his invaluable assistance and guidance in the development of this project.
This project is licensed under the MIT License.
This section guides you through setting up and configuring the necessary components for the project using Dependency Injection (DI).
To manually instantiate the components without using DI, use the following example:
// Creating instances manually without DI
IOptimizationProblemSolver solver = new GoogleOrToolsOptimizationSolver();
IOptimizationProblemMapper mapper = new OptimizationProblemMapper();
IFertilizerOptimizer optimizer = new FertilizerOptimizationAdapter(solver, mapper);
Using Dependency Injection For integrating these components into a project that supports Dependency Injection, such as an ASP.NET Core application, configure your services in the Startup.cs or a similar configuration file as follows:
public void ConfigureServices(IServiceCollection services)
{
// Registering services in the DI container
services.AddSingleton<IOptimizationProblemSolver, GoogleOrToolsOptimizationSolver>();
services.AddSingleton<IOptimizationProblemMapper, OptimizationProblemMapper>();
services.AddSingleton<FertilizerOptimizationAdapter>();
}
// Setup the optimizer
IOptimizationProblemSolver solver = new GoogleOrToolsOptimizationSolver();
IOptimizationProblemMapper mapper = new OptimizationProblemMapper();
IFertilizerOptimizer optimizer = new FertilizerOptimizationAdapter(solver, mapper);
// Define your PPM target for optimization
PpmTarget target = new PpmTargetBuilder()
.AddN(150)
.AddP(50)
.AddK(200)
.AddMg(60)
.AddCa(60)
.AddS(80)
.Build();
// Configure the solution finder settings
SolutionFinderSettings settings = new SolutionFinderSettingsBuilder()
.AddN(1)
.AddP(1)
.AddK(1)
.AddCa(1)
.AddMg(1)
.AddS(1)
.AddCl(1)
.Build();
// Create a list of fertilizers for optimization
IList<FertilizerOptimizationModel> collection = new List<FertilizerOptimizationModel>()
{
new FertilizerBuilder().AddNo3(11.863).AddCaNonChelated(16.972).Build(),
new FertilizerBuilder().AddNo3(13.854).AddK(38.672).Build(),
new FertilizerBuilder().AddNo3(17.499).AddNh4(17.499).Build(),
new FertilizerBuilder().AddMgNonChelated(9.861).AddS(13.008).Build(),
new FertilizerBuilder().AddP(22.761).AddK(28.731).Build(),
new FertilizerBuilder().AddS(18.401).AddK(44.874).Build(),
new FertilizerBuilder().AddMgNonChelated(9.479).AddNo3(10.925).Build(),
new FertilizerBuilder().AddS(18.969).AddMnNonChelated(32.506).Build()
};
// Optimize the solution
Solution solution = optimizer.Optimize(target, collection, settings);