NPKTools.Optimizer
1.0.0
See the version list below for details.
dotnet add package NPKTools.Optimizer --version 1.0.0
NuGet\Install-Package NPKTools.Optimizer -Version 1.0.0
<PackageReference Include="NPKTools.Optimizer" Version="1.0.0" />
paket add NPKTools.Optimizer --version 1.0.0
#r "nuget: NPKTools.Optimizer, 1.0.0"
// Install NPKTools.Optimizer as a Cake Addin #addin nuget:?package=NPKTools.Optimizer&version=1.0.0 // Install NPKTools.Optimizer as a Cake Tool #tool nuget:?package=NPKTools.Optimizer&version=1.0.0
NPKTools.Optimizer
NPKTools.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.
- The FertilizerOptimizer is composed of three main components: an adapter, a mapper, and a solver. It takes a nutrient target in NPK values, a list of available fertilizers, and specific precision settings as inputs to calculate the optimal fertilizer mix. Here's how the flow works with these components:
- Mapper: This component converts the high-level nutrient targets and the list of available fertilizers into a structured optimization problem. It translates real-world data about fertilizers and nutrient requirements into mathematical variables, constraints, and objectives suitable for optimization. After the solver processes these, the mapper also translates the optimized mathematical solution back into practical terms, specifying exact quantities of each fertilizer to use.
- Solver: Once the optimization problem is defined, this component uses mathematical algorithms to find the best combination of fertilizers. The solver processes the variables and constraints set by the mapper to minimize or maximize the objective function, typically focusing on cost efficiency or nutrient precision.
- Adapter: Acts as the bridge between the domain-specific data (fertilizers and nutrient targets) and the optimization tools. It takes the problem as defined by the mapper, passes it to the solver for optimization, and then interprets the output from the solver back into a practical solution, detailing the specific amounts of each fertilizer to use to achieve the nutrient targets.
- Together, these components ensure that the FertilizerOptimizer effectively integrates and processes the inputs to produce an optimized fertilizer mix that meets the specified NPK goals with the required precision.
Developers
This tool was developed by Anatoliy Yermakov.
- LinkedIn: Anatoliy Yermakov
- GitHub: i7aket
Special thanks to Artem Frolov for his invaluable assistance and guidance in the development of this project.
- LinkedIn: Artem Frolov
- GitHub: AqueGen
License:
This project is licensed under the MIT License.
Installation and Configuration
This section guides you through setting up and configuring the necessary components for the project using Dependency Injection (DI).
Direct Instantiation
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>();
}
Example usage
// 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);
Dependencies
NPKOptimizer
- Google OR-Tools: Used for performing optimization calculations.
NPKOptimizer.Tests
- xUnit: Framework for unit testing.
- AutoFixture: Generates test data.
- FluentAssertions: Enhanced assertions for tests.
- Microsoft.AspNetCore.Mvc.Testing: Testing for ASP.NET MVC applications.
- NSubstitute: Library for creating mock and stub objects.
- Microsoft.NET.Test.Sdk: Test SDK for .NET.
Contact Information:
- LinkedIn: Anatoliy Yermakov
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net8.0
- Google.OrTools (>= 9.9.3963)
- NPKTools.Core (>= 1.0.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on NPKTools.Optimizer:
Package | Downloads |
---|---|
NPKTools.Optimizer.Preset
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. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Initial release version. Includes full functionality.