diff --git a/.gitignore b/.gitignore index 7990fe7..7defab2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .vs/ obj/ bin/ -*.user \ No newline at end of file +*.user +BenchmarkDotNet.Artifacts/ \ No newline at end of file diff --git a/Benchmark/Bench.cs b/Benchmark/Bench.cs new file mode 100644 index 0000000..5e2e764 --- /dev/null +++ b/Benchmark/Bench.cs @@ -0,0 +1,97 @@ +using BenchmarkDotNet.Attributes; +using BenchmarkDotNet.Engines; +using Craftimizer.Simulator; +using Craftimizer.Solver; + +namespace Craftimizer.Benchmark; + +[SimpleJob(RunStrategy.Monitoring)] +[MinColumn, Q1Column, Q3Column, MaxColumn] +public class Bench +{ + private static SimulationInput[] Inputs { get; } = new SimulationInput[] { + // https://craftingway.app/rotation/loud-namazu-jVe9Y + // Chondrite Saw + new(new() + { + Craftsmanship = 3304, + Control = 3374, + CP = 575, + Level = 90, + CanUseManipulation = true, + HasSplendorousBuff = false, + IsSpecialist = false, + CLvl = 560, + }, + new() + { + IsExpert = false, + ClassJobLevel = 90, + RLvl = 560, + ConditionsFlag = 0b1111, + MaxDurability = 80, + MaxQuality = 7200, + MaxProgress = 3500, + QualityModifier = 80, + QualityDivider = 115, + ProgressModifier = 90, + ProgressDivider = 130 + }), + + // https://craftingway.app/rotation/sandy-fafnir-doVCs + // Classical Longsword + new(new() + { + Craftsmanship = 3290, + Control = 3541, + CP = 649, + Level = 90, + CanUseManipulation = true, + HasSplendorousBuff = false, + IsSpecialist = false, + CLvl = 560, + }, + new() + { + IsExpert = false, + ClassJobLevel = 90, + RLvl = 580, + ConditionsFlag = 0b1111, + MaxDurability = 70, + MaxQuality = 10920, + MaxProgress = 3900, + QualityModifier = 70, + QualityDivider = 115, + ProgressModifier = 80, + ProgressDivider = 130 + }) + }; + + public static IEnumerable States => Inputs.Select(i => new SimulationState(i)); + + public static IEnumerable Configs => new SolverConfig[] + { + new() + { + Iterations = 100_000, + ForkCount = 32, + FurcatedActionCount = 16, + MaxStepCount = 30, + } + }; + + [ParamsSource(nameof(States))] + public SimulationState State { get; set; } + + [ParamsSource(nameof(Configs))] + public SolverConfig Config { get; set; } + + [Benchmark] + public async Task Solve() + { + var solver = new Solver.Solver(Config, State); + solver.Start(); + var (_, s) = await solver.GetTask().ConfigureAwait(false); + return (float)s.Quality / s.Input.Recipe.MaxQuality; + } +} diff --git a/Benchmark/Craftimizer.Benchmark.csproj b/Benchmark/Craftimizer.Benchmark.csproj index 9d68105..e255672 100644 --- a/Benchmark/Craftimizer.Benchmark.csproj +++ b/Benchmark/Craftimizer.Benchmark.csproj @@ -5,6 +5,8 @@ Exe enable enable + x64 + Debug;Release;Trace diff --git a/Benchmark/Program.cs b/Benchmark/Program.cs index d3717ca..397686c 100644 --- a/Benchmark/Program.cs +++ b/Benchmark/Program.cs @@ -1,3 +1,4 @@ +using BenchmarkDotNet.Running; using Craftimizer.Simulator; using Craftimizer.Simulator.Actions; using Craftimizer.Solver; @@ -7,10 +8,11 @@ namespace Craftimizer.Benchmark; internal static class Program { - private static async Task Main() + private static async Task Main(string[] args) { - //var summary = BenchmarkRunner.Run(); - //return; + Environment.SetEnvironmentVariable("IS_BENCH", "1"); + BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args); + return; //TypeLayout.PrintLayout>(true); //return; @@ -78,7 +80,7 @@ internal static class Program Console.WriteLine($"{state.Quality} {state.CP} {state.Progress} {state.Durability}"); //return; var solver = new Solver.Solver(config, state); - solver.OnLog += s => Console.WriteLine(s); + solver.OnLog += Console.WriteLine; solver.OnNewAction += s => Console.WriteLine(s); solver.Start(); var (_, s) = await solver.GetTask().ConfigureAwait(false); diff --git a/Craftimizer.Test/Craftimizer.Test.csproj b/Craftimizer.Test/Craftimizer.Test.csproj index 5344fb4..f2d7fde 100644 --- a/Craftimizer.Test/Craftimizer.Test.csproj +++ b/Craftimizer.Test/Craftimizer.Test.csproj @@ -7,6 +7,8 @@ false true + x64 + Debug;Release @@ -21,4 +23,8 @@ + + $(DefineConstants);IS_DETERMINISTIC + + diff --git a/Craftimizer.Test/Simulator/Simulator.cs b/Craftimizer.Test/Simulator/Simulator.cs index f628654..20756fc 100644 --- a/Craftimizer.Test/Simulator/Simulator.cs +++ b/Craftimizer.Test/Simulator/Simulator.cs @@ -1,6 +1,4 @@ using Craftimizer.Simulator.Actions; -using System; -using System.Reflection; namespace Craftimizer.Test.Simulator; diff --git a/Craftimizer.Test/Solver/ActionSet.cs b/Craftimizer.Test/Solver/ActionSet.cs index 30e4bef..b6fb34f 100644 --- a/Craftimizer.Test/Solver/ActionSet.cs +++ b/Craftimizer.Test/Solver/ActionSet.cs @@ -105,6 +105,10 @@ public class ActionSetTests [TestMethod] public void TestRandomIndex() { +#if IS_DETERMINISTIC + Assert.Inconclusive("Craftimizer is built for benchmarking; all random actions are deterministic and not actually random."); +#endif + var actions = new[] { ActionType.BasicTouch, diff --git a/Craftimizer.sln b/Craftimizer.sln index 9b6d4a8..b8a6abd 100644 --- a/Craftimizer.sln +++ b/Craftimizer.sln @@ -17,56 +17,43 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Craftimizer.Solver", "Solve {172EE849-AC7E-4F2A-ACAB-EF9D065523B3} = {172EE849-AC7E-4F2A-ACAB-EF9D065523B3} EndProjectSection EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Craftimizer.Test", "Craftimizer.Test\Craftimizer.Test.csproj", "{C3AEA981-9DA8-405C-995B-86528493891B}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Craftimizer.Test", "Craftimizer.Test\Craftimizer.Test.csproj", "{C3AEA981-9DA8-405C-995B-86528493891B}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU Debug|x64 = Debug|x64 - Release|Any CPU = Release|Any CPU Release|x64 = Release|x64 + Trace|x64 = Trace|x64 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {13C812E9-0D42-4B95-8646-40EEBF30636F}.Debug|Any CPU.ActiveCfg = Debug|x64 - {13C812E9-0D42-4B95-8646-40EEBF30636F}.Debug|Any CPU.Build.0 = Debug|x64 {13C812E9-0D42-4B95-8646-40EEBF30636F}.Debug|x64.ActiveCfg = Debug|x64 {13C812E9-0D42-4B95-8646-40EEBF30636F}.Debug|x64.Build.0 = Debug|x64 - {13C812E9-0D42-4B95-8646-40EEBF30636F}.Release|Any CPU.ActiveCfg = Release|x64 - {13C812E9-0D42-4B95-8646-40EEBF30636F}.Release|Any CPU.Build.0 = Release|x64 {13C812E9-0D42-4B95-8646-40EEBF30636F}.Release|x64.ActiveCfg = Release|x64 {13C812E9-0D42-4B95-8646-40EEBF30636F}.Release|x64.Build.0 = Release|x64 - {057C4B64-4D99-4847-9BCF-966571CAE57C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {057C4B64-4D99-4847-9BCF-966571CAE57C}.Debug|Any CPU.Build.0 = Debug|Any CPU - {057C4B64-4D99-4847-9BCF-966571CAE57C}.Debug|x64.ActiveCfg = Debug|Any CPU - {057C4B64-4D99-4847-9BCF-966571CAE57C}.Debug|x64.Build.0 = Debug|Any CPU - {057C4B64-4D99-4847-9BCF-966571CAE57C}.Release|Any CPU.ActiveCfg = Release|Any CPU - {057C4B64-4D99-4847-9BCF-966571CAE57C}.Release|Any CPU.Build.0 = Release|Any CPU - {057C4B64-4D99-4847-9BCF-966571CAE57C}.Release|x64.ActiveCfg = Release|Any CPU - {057C4B64-4D99-4847-9BCF-966571CAE57C}.Release|x64.Build.0 = Release|Any CPU - {172EE849-AC7E-4F2A-ACAB-EF9D065523B3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {172EE849-AC7E-4F2A-ACAB-EF9D065523B3}.Debug|Any CPU.Build.0 = Debug|Any CPU - {172EE849-AC7E-4F2A-ACAB-EF9D065523B3}.Debug|x64.ActiveCfg = Debug|Any CPU - {172EE849-AC7E-4F2A-ACAB-EF9D065523B3}.Debug|x64.Build.0 = Debug|Any CPU - {172EE849-AC7E-4F2A-ACAB-EF9D065523B3}.Release|Any CPU.ActiveCfg = Release|Any CPU - {172EE849-AC7E-4F2A-ACAB-EF9D065523B3}.Release|Any CPU.Build.0 = Release|Any CPU - {172EE849-AC7E-4F2A-ACAB-EF9D065523B3}.Release|x64.ActiveCfg = Release|Any CPU - {172EE849-AC7E-4F2A-ACAB-EF9D065523B3}.Release|x64.Build.0 = Release|Any CPU - {2B0EA452-6DFC-48DB-9049-EA782E600C21}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {2B0EA452-6DFC-48DB-9049-EA782E600C21}.Debug|Any CPU.Build.0 = Debug|Any CPU - {2B0EA452-6DFC-48DB-9049-EA782E600C21}.Debug|x64.ActiveCfg = Debug|Any CPU - {2B0EA452-6DFC-48DB-9049-EA782E600C21}.Debug|x64.Build.0 = Debug|Any CPU - {2B0EA452-6DFC-48DB-9049-EA782E600C21}.Release|Any CPU.ActiveCfg = Release|Any CPU - {2B0EA452-6DFC-48DB-9049-EA782E600C21}.Release|Any CPU.Build.0 = Release|Any CPU - {2B0EA452-6DFC-48DB-9049-EA782E600C21}.Release|x64.ActiveCfg = Release|Any CPU - {2B0EA452-6DFC-48DB-9049-EA782E600C21}.Release|x64.Build.0 = Release|Any CPU - {C3AEA981-9DA8-405C-995B-86528493891B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {C3AEA981-9DA8-405C-995B-86528493891B}.Debug|Any CPU.Build.0 = Debug|Any CPU - {C3AEA981-9DA8-405C-995B-86528493891B}.Debug|x64.ActiveCfg = Debug|Any CPU - {C3AEA981-9DA8-405C-995B-86528493891B}.Debug|x64.Build.0 = Debug|Any CPU - {C3AEA981-9DA8-405C-995B-86528493891B}.Release|Any CPU.ActiveCfg = Release|Any CPU - {C3AEA981-9DA8-405C-995B-86528493891B}.Release|Any CPU.Build.0 = Release|Any CPU - {C3AEA981-9DA8-405C-995B-86528493891B}.Release|x64.ActiveCfg = Release|Any CPU - {C3AEA981-9DA8-405C-995B-86528493891B}.Release|x64.Build.0 = Release|Any CPU + {13C812E9-0D42-4B95-8646-40EEBF30636F}.Trace|x64.ActiveCfg = Release|x64 + {057C4B64-4D99-4847-9BCF-966571CAE57C}.Debug|x64.ActiveCfg = Debug|x64 + {057C4B64-4D99-4847-9BCF-966571CAE57C}.Debug|x64.Build.0 = Debug|x64 + {057C4B64-4D99-4847-9BCF-966571CAE57C}.Release|x64.ActiveCfg = Release|x64 + {057C4B64-4D99-4847-9BCF-966571CAE57C}.Release|x64.Build.0 = Release|x64 + {057C4B64-4D99-4847-9BCF-966571CAE57C}.Trace|x64.ActiveCfg = Trace|x64 + {057C4B64-4D99-4847-9BCF-966571CAE57C}.Trace|x64.Build.0 = Trace|x64 + {172EE849-AC7E-4F2A-ACAB-EF9D065523B3}.Debug|x64.ActiveCfg = Debug|x64 + {172EE849-AC7E-4F2A-ACAB-EF9D065523B3}.Debug|x64.Build.0 = Debug|x64 + {172EE849-AC7E-4F2A-ACAB-EF9D065523B3}.Release|x64.ActiveCfg = Release|x64 + {172EE849-AC7E-4F2A-ACAB-EF9D065523B3}.Release|x64.Build.0 = Release|x64 + {172EE849-AC7E-4F2A-ACAB-EF9D065523B3}.Trace|x64.ActiveCfg = Trace|x64 + {172EE849-AC7E-4F2A-ACAB-EF9D065523B3}.Trace|x64.Build.0 = Trace|x64 + {2B0EA452-6DFC-48DB-9049-EA782E600C21}.Debug|x64.ActiveCfg = Debug|x64 + {2B0EA452-6DFC-48DB-9049-EA782E600C21}.Debug|x64.Build.0 = Debug|x64 + {2B0EA452-6DFC-48DB-9049-EA782E600C21}.Release|x64.ActiveCfg = Release|x64 + {2B0EA452-6DFC-48DB-9049-EA782E600C21}.Release|x64.Build.0 = Release|x64 + {2B0EA452-6DFC-48DB-9049-EA782E600C21}.Trace|x64.ActiveCfg = Trace|x64 + {2B0EA452-6DFC-48DB-9049-EA782E600C21}.Trace|x64.Build.0 = Trace|x64 + {C3AEA981-9DA8-405C-995B-86528493891B}.Debug|x64.ActiveCfg = Debug|x64 + {C3AEA981-9DA8-405C-995B-86528493891B}.Debug|x64.Build.0 = Debug|x64 + {C3AEA981-9DA8-405C-995B-86528493891B}.Release|x64.ActiveCfg = Release|x64 + {C3AEA981-9DA8-405C-995B-86528493891B}.Release|x64.Build.0 = Release|x64 + {C3AEA981-9DA8-405C-995B-86528493891B}.Trace|x64.ActiveCfg = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Craftimizer/Craftimizer.csproj b/Craftimizer/Craftimizer.csproj index 9fd555d..3368159 100644 --- a/Craftimizer/Craftimizer.csproj +++ b/Craftimizer/Craftimizer.csproj @@ -4,6 +4,7 @@ Asriel Camora 1.9.1.0 https://github.com/WorkingRobot/craftimizer.git + Debug;Release diff --git a/Simulator/Craftimizer.Simulator.csproj b/Simulator/Craftimizer.Simulator.csproj index ec99977..da4e1c5 100644 --- a/Simulator/Craftimizer.Simulator.csproj +++ b/Simulator/Craftimizer.Simulator.csproj @@ -4,6 +4,8 @@ net7.0 enable enable + x64 + Debug;Release;Trace @@ -13,4 +15,9 @@ + + $(DefineConstants);IS_DETERMINISTIC + $(DefineConstants);IS_DETERMINISTIC;IS_TRACE + + diff --git a/Solver/ActionSet.cs b/Solver/ActionSet.cs index b4af25f..98c0b9f 100644 --- a/Solver/ActionSet.cs +++ b/Solver/ActionSet.cs @@ -5,8 +5,6 @@ using System.Runtime.CompilerServices; namespace Craftimizer.Solver; -// #define IS_DETERMINISTIC - public struct ActionSet { private uint bits; diff --git a/Solver/Craftimizer.Solver.csproj b/Solver/Craftimizer.Solver.csproj index 8ff7314..0779688 100644 --- a/Solver/Craftimizer.Solver.csproj +++ b/Solver/Craftimizer.Solver.csproj @@ -5,6 +5,8 @@ enable enable True + x64 + Debug;Release;Trace @@ -18,4 +20,9 @@ + + $(DefineConstants);IS_DETERMINISTIC + $(DefineConstants);IS_DETERMINISTIC;IS_TRACE + +