NPKTools.Optimizer.Preset is an preconfigured version of the NPKTools.Optimizer. It includes: 17 basic types of macronutrient fertilizers combined into 18 different sets to optimize the selection process. 17 types of micronutrient fertilizers grouped into four main sets: basic, sulfate, nitrate, and chelated. During the selection of macronutrient fertilizers, the service conducts two searches: in the first, sulfur is accounted for as specified, while the second search excludes sulfur coefficients to expand the possible options.
$ dotnet add package NPKTools.Optimizer.PresetThis tool was developed by Anatoliy Yermakov.
Special thanks to Artem Frolov for his invaluable assistance and guidance in the development of this project.
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);
IFertilizerBundleRepository bundles = new FertilizerBundleRepository();
IFertilizerOptimizationService = new FertilizerOptimizationService(optimizer, bundles);
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<IFertilizerOptimizer, FertilizerOptimizationAdapter>();
services.AddSingleton<IFertilizerBundleRepository, FertilizerBundleRepository>();
services.AddSingleton<IFertilizerOptimizationService, FertilizerOptimizationService>();
}
// Creating instances manually without DI
IOptimizationProblemSolver solver = new GoogleOrToolsOptimizationSolver();
IOptimizationProblemMapper mapper = new OptimizationProblemMapper();
IFertilizerOptimizer optimizer = new FertilizerOptimizationAdapter(solver, mapper);
IFertilizerBundleRepository bundles = new FertilizerBundleRepository();
IFertilizerOptimizationService fertilizerOptimizationService = new FertilizerOptimizationService(optimizer, bundles);
// Define your PPM target for optimization
PpmTarget target = new PpmTargetBuilder()
.AddN(150)
.AddP(50)
.AddK(200)
.AddMg(60)
.AddCa(60)
.AddS(80)
.Build();
// Set the options for matching the macro elements precisely
SolutionFinderSettings settings = new SolutionFinderSettingsBuilder()
.AddN(1)
.AddP(1)
.AddK(1)
.AddCa(1)
.AddMg(1)
.AddS(1)
.AddCl(1)
.Build();
// Finding macro solutions based on the specified target
Solutions macroSolutions = fertilizerOptimizationService.FindMacroSolutions(target);
// Finding micro solutions with a different target
PpmTarget microTarget = new PpmTargetBuilder()
.AddFe(2)
.AddCu(0.05)
.AddMn(0.55)
.AddZn(0.33)
.AddB(0.28)
.AddMo(0.05)
.AddSi(0.01)
.AddSe(0.01)
.Build();
Solutions microSolutions = fertilizerOptimizationService.FindMicroSolutions(microTarget);
// Combine both macro and micro nutrient optimizations
(Solutions Macro, Solutions Micro) results = fertilizerOptimizationService.FindSolutions(new PpmTargetBuilder()
.AddN(150)
.AddP(50)
.AddK(200)
.AddMg(60)
.AddCa(100)
.AddS(100)
.AddFe(2)
.AddCu(0.05)
.AddMn(0.55)
.AddZn(0.33)
.AddB(0.28)
.AddMo(0.05)
.AddCl(0.01)
.AddSi(0.01)
.AddSe(0.01)
.Build());
// You can now access results.Macro and results.Micro for specific optimizations
This project is licensed under the MIT License.